/**
 * Design tokens — single source of truth for radius, space, surfaces, buttons.
 * Loaded early from bootstrap_head. Components consume these variables.
 */
:root {
    /* Typography */
    --app-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Radii */
    --app-radius: 14px;
    --app-radius-sm: 10px;
    --app-radius-lg: 18px;
    --app-btn-radius: 12px;
    --app-btn-radius-sm: 10px;
    --app-btn-radius-lg: 14px;

    /* Spacing scale */
    --app-space-1: 0.25rem;
    --app-space-2: 0.5rem;
    --app-space-3: 0.75rem;
    --app-space-4: 1rem;
    --app-space-5: 1.5rem;
    --app-space-6: 2rem;

    /* Layout */
    --app-content-max: 1080px;
    --app-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
    --app-shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.18);

    /* Brand */
    --app-primary: #6366f1;
    --app-primary-dark: #4f46e5;
    --app-success: #10b981;
    --app-danger: #ef4444;
    --app-warning: #f59e0b;
    --app-info: #0ea5e9;

    /* Surfaces (light default) */
    --app-surface: #ffffff;
    --app-surface-2: #f8fafc;
    --app-surface-3: #f1f5f9;
    --app-border: rgba(15, 23, 42, 0.08);
    --app-text: #0f172a;
    --app-text-muted: #64748b;

    /* Buttons */
    --app-btn-pad-y: 0.55rem;
    --app-btn-pad-x: 1.15rem;
    --app-btn-font-weight: 600;

    /* Bootstrap alignment */
    --bs-border-radius: var(--app-btn-radius);
    --bs-border-radius-sm: var(--app-btn-radius-sm);
    --bs-border-radius-lg: var(--app-btn-radius-lg);
    --bs-btn-border-radius: var(--app-btn-radius);
    --bs-body-font-family: var(--app-font);
    --bs-primary: var(--app-primary);
    --bs-success: var(--app-success);
    --bs-danger: var(--app-danger);
    --bs-warning: var(--app-warning);
    --bs-info: var(--app-info);
}

/* Dark surfaces — data-bs-theme, data-theme, html.theme-dark */
[data-bs-theme="dark"],
[data-theme="dark"],
html.theme-dark {
    color-scheme: dark;
    --app-surface: #1e1e2e;
    --app-surface-2: #16161f;
    --app-surface-3: #12121a;
    --app-border: rgba(255, 255, 255, 0.1);
    --app-text: #e2e8f0;
    --app-text-muted: #94a3b8;
    --app-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --app-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

/* Content width helper */
.app-content-width {
    width: 100%;
    max-width: var(--app-content-max);
    margin-left: auto;
    margin-right: auto;
}

/* Theme-safe surface utilities (prefer over bg-light / bg-white) */
.app-surface {
    background: var(--app-surface) !important;
    color: var(--app-text);
}
.app-surface-2 {
    background: var(--app-surface-2) !important;
    color: var(--app-text);
}
.app-border {
    border-color: var(--app-border) !important;
}
.app-text-muted {
    color: var(--app-text-muted) !important;
}

/* Soften Bootstrap light/dark hardcodes inside themed shell (all themes) */
.bg-light,
.card-header.bg-light,
.card-footer.bg-light,
.list-group-item.bg-light,
.table .bg-light,
.modal .bg-light,
.offcanvas .bg-light {
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
}
.bg-white {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .bg-light,
[data-theme="dark"] .bg-light,
html.theme-dark .bg-light {
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .bg-white,
[data-theme="dark"] .bg-white,
html.theme-dark .bg-white {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .text-dark,
[data-theme="dark"] .text-dark,
html.theme-dark .text-dark {
    color: var(--app-text) !important;
}
/* Bootstrap table-light → theme surface */
.table-light,
thead.table-light,
tr.table-light,
.table > :not(caption) > * > .table-light {
    --bs-table-bg: var(--app-surface-2) !important;
    --bs-table-color: var(--app-text) !important;
    --bs-table-border-color: var(--app-border) !important;
    --bs-table-striped-bg: var(--app-surface-2) !important;
    --bs-table-hover-bg: var(--app-surface) !important;
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .border,
[data-theme="dark"] .border,
html.theme-dark .border,
[data-bs-theme="dark"] .border-bottom,
[data-theme="dark"] .border-bottom,
html.theme-dark .border-bottom {
    border-color: var(--app-border) !important;
}

/* Sticky shop filters */
.shop-filter-sticky {
    position: sticky;
    top: 0.75rem;
    z-index: 30;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    backdrop-filter: blur(8px);
}
[data-bs-theme="dark"] .shop-filter-sticky,
[data-theme="dark"] .shop-filter-sticky,
html.theme-dark .shop-filter-sticky {
    background: color-mix(in srgb, var(--app-surface) 92%, transparent);
}

/* Skeleton loading */
.app-skeleton {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.app-skeleton-card {
    height: 220px;
    border-radius: var(--app-radius);
    background: linear-gradient(90deg, var(--app-surface-2) 25%, var(--app-surface-3) 37%, var(--app-surface-2) 63%);
    background-size: 400% 100%;
    animation: app-skel 1.2s ease infinite;
    border: 1px solid var(--app-border);
}
@keyframes app-skel {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

/* Empty state */
.app-empty-state {
    text-align: center;
    padding: var(--app-space-6) var(--app-space-4);
    border: 1px dashed var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface-2);
    color: var(--app-text-muted);
}
.app-empty-state .app-empty-icon {
    font-size: 2.25rem;
    opacity: 0.7;
    margin-bottom: var(--app-space-3);
    display: block;
}
.app-empty-state h5,
.app-empty-state .app-empty-title {
    color: var(--app-text);
    font-weight: 600;
    margin-bottom: var(--app-space-2);
}

/* Health strip */
.app-health-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--app-space-3);
    margin-bottom: var(--app-space-4);
}
.app-health-chip {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-radius: var(--app-radius-sm);
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    min-height: 3.25rem;
}
.app-health-chip .dot {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    flex-shrink: 0;
}
.app-health-chip.is-ok .dot { background: var(--app-success); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.app-health-chip.is-warn .dot { background: var(--app-warning); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2); }
.app-health-chip.is-bad .dot { background: var(--app-danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }
.app-health-chip .label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-text-muted);
    line-height: 1.1;
}
.app-health-chip .value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--app-text);
    line-height: 1.2;
}

/* Confirm dialog (toast-style) */
.app-confirm-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200100;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.app-confirm-dialog {
    width: min(420px, 100%);
    background: var(--app-surface);
    color: var(--app-text);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow-lg);
    padding: 1.25rem 1.35rem;
}
.app-confirm-dialog h6 {
    margin: 0 0 0.5rem;
    font-weight: 700;
}
.app-confirm-dialog p {
    margin: 0 0 1rem;
    color: var(--app-text-muted);
    font-size: 0.95rem;
}
.app-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Toast polish */
#toast-container.app-toast-container,
.app-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200050;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 1.5rem));
    pointer-events: none;
}
.app-toast-container .toast {
    pointer-events: auto;
    border-radius: var(--app-btn-radius);
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    box-shadow: var(--app-shadow);
}

/* Command palette nav hint */
.nav-cmdk-hint kbd {
    font-size: 0.7rem;
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
    border: 1px solid var(--app-border);
    background: var(--app-surface-2);
    color: var(--app-text-muted);
}
