/* ============================================================
   VisFlow theme tokens (design theme ported from Aidithi)
   Single source of truth for site colors (light / dark).

   Architecture:
   - Light theme lives in :root.
   - Dark theme overrides live in [data-theme="dark"].
   - The active theme is chosen by the data-theme attribute on <html>,
     set by the no-flash inline script (initial paint) and theme.js
     (toggle + live system follow).

   To theme any current or future page, consume these tokens with
   var(--token) instead of hardcoded hex values. Do NOT hardcode colors.
   ============================================================ */

/* ---- Light theme (default) ---- */
:root {
    color-scheme: light;
    /* Core palette */
    --bg-main: #F8FAFC; /* Crisp Light Gray */
    --bg-surface: #CEE1F0; /* Pure White */
    --text-primary: #0F172A; /* Slate Black */
    --text-secondary: #64748B; /* Muted Steel Gray */
    --accent-primary: #1E3A8A; /* Sapphire Blue */
    --accent-secondary: #3B82F6; /* Bright Blue */
    --bg-formcontrols: #cbd5d7; /* contrast color */
    /* Sidebar tokens — the sidebar is a dark-blue "sapphire" gradient with
       silver text in BOTH themes (a colored-nav look), so these are literal
       values defined once here and inherited by dark mode. Consume these —
       not the core palette — for anything inside .sidebar. */
    --sidebar-bg: linear-gradient(180deg, #0A1120 0%, #12336E 50%, #0B1730 100%); /* Deep Sapphire Gradient */
    --sidebar-text: #CBD5E1; /* Platinum Silver */
    --sidebar-text-muted: #94A3B8; /* Muted Silver Slate */
    --sidebar-text-hover: #FFFFFF; /* Pure White */
    --sidebar-item-hover: rgba(255, 255, 255, 0.08); /* Subtle Silver Glow */
    --sidebar-item-active: rgba(59, 130, 246, 0.28); /* Sapphire Glow Active Overlay */
    --sidebar-accent: #FFFFFF; /* active bar + brand name */
    --sidebar-border: rgba(255, 255, 255, 0.10); /* Faint Metallic Edge */
    --sidebar-decor: block; /* decorative radial rings visible */
    /* Supporting tokens */
    --border: #E2E8F0;
    --surface-hover: #F1F5F9;
    --accent-soft: rgba(30, 58, 138, .10);
    --accent-contrast: #FFFFFF;
    --on-accent: var(--accent-contrast); /* alias: text/icon on the accent */
    --shadow: rgba(15, 23, 42, .08);
    /* Accent depth (hovers / gradients) */
    --accent-strong: #172554;
    --accent-primary-rgb: 30, 58, 138;
    /* Extra surface / border levels */
    --bg-inset: #EDF2F7;
    --border-strong: #CBD5E1;
    /* Semantic status (keep their meaning; theme-tuned) */
    --success: #178352;
    --success-soft: rgba(23, 131, 82, .12);
    --warning: #F59E0B;
    --warning-soft: #FFFBEB;
    --danger: #DC3545;
    --danger-soft: rgba(220, 53, 69, .12);
    --info: #2563EB;
    --info-soft: #EFF6FF;
    --pink: #CE8C2D;
    --pink-soft: #BD9F6F;
    --text-on-status: #FFFFFF; /* white text on solid status fills, both themes */
    /* Chart series (categorical slots 1-3, in this fixed order). Validated against the
       card surface in each theme; on the light surface orange/aqua sit under 3:1, so every
       chart ships a visible table view as relief. */
    --series-1: #2a78d6; /* blue   */
    --series-2: #eb6834; /* orange */
    --series-3: #1baf7a; /* aqua   */
    /* Sidebar geometry + structural (theme-agnostic) */
    --sidebar-width: 248px;
    --sidebar-width-collapsed: 80px;
    --nav-radius: 12px;
    --nav-transition: 0.25s ease;
}

    /* ---- Dark theme ---- */
    :root[data-theme="dark"],
    [data-theme="dark"] {
        color-scheme: dark;
        /* Core palette */
        --bg-main: #0B0F19; /* Ultra Dark Slate */
        --bg-surface: #111827; /* Dark Charcoal Surface */
        --text-primary: #F8FAFC; /* Bright Silver White */
        --text-secondary: #94A3B8; /* Cool Muted Silver */
        --accent-primary: #3B82F6; /* Vivid Sapphire Glow */
        --accent-secondary: #60A5FA; /* Electric Blue Accent */
        --bg-formcontrols: #2f4950ab; /* contrast color */
        /* Sidebar tokens are shared with light mode (see :root) — the nav is
           the same sapphire gradient in both themes, so no overrides here. */
        /* Supporting tokens */
        --border: #1E293B;
        --surface-hover: #1E293B;
        --accent-soft: rgba(59, 130, 246, .14);
        --accent-contrast: #FFFFFF;
        --shadow: rgba(0, 0, 0, .50);
        /* Accent depth (hovers / gradients) */
        --accent-strong: #2563EB;
        --accent-primary-rgb: 59, 130, 246;
        /* Extra surface / border levels */
        --bg-inset: #070A12;
        --border-strong: #334155;
        /* Semantic status (keep their meaning; theme-tuned) */
        --success: #3DBE86;
        --success-soft: rgba(61, 190, 134, .16);
        --warning: #F59E0B;
        --warning-soft: rgba(245, 158, 11, .16);
        --danger: #F16B77;
        --danger-soft: rgba(241, 107, 119, .16);
        --info: #3B82F6;
        --info-soft: rgba(59, 130, 246, .18);
        --pink: #CE8C2D;
        --pink-soft: rgba(206, 140, 45, .16);
        /* Chart series - the same three hues stepped for the dark surface */
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        /* geometry/structural tokens are inherited from :root */
    }

/* ---- Base mappings ---- */
body {
    background: var(--bg-main);
    color: var(--text-primary);
}

/* Smooth theme switching for the common surfaces */
body,
.sidebar,
.topbar,
.queue-container,
.queue-card,
.empty-state,
.dropdown-menu {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

/* ============================================================
   Bootstrap 5.1 theming bridge
   Bootstrap 5.1 has no data-bs-theme, so its components keep their
   built-in colors (blue btn-primary, white cards, etc.). We remap
   them to our tokens here. Everything is token-driven, so it flips
   automatically under [data-theme="dark"] — no separate dark rules
   needed. Loads AFTER bootstrap.min.css in every layout.
   ============================================================ */

/* ---- Buttons ----
   Bootstrap 5.1 buttons set colors directly (the --bs-btn-* variables are
   5.2+), so we override the real properties. !important keeps our theme
   ahead of Bootstrap's own :hover/:active selectors. */
.btn-primary {
    background-color: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    color: var(--on-accent) !important;
}
    .btn-primary:hover,
    .btn-primary:focus,
    .btn-primary:active,
    .btn-primary.active,
    .btn-primary:disabled,
    .btn-primary.disabled {
        background-color: var(--accent-strong) !important;
        border-color: var(--accent-strong) !important;
        color: var(--on-accent) !important;
    }
    .btn-primary:disabled,
    .btn-primary.disabled {
        background-color: var(--accent-primary) !important;
        border-color: var(--accent-primary) !important;
    }

.btn-secondary {
    background-color: var(--accent-secondary) !important;
    border-color: var(--accent-secondary) !important;
    color: var(--on-accent) !important;
}
    .btn-secondary:hover,
    .btn-secondary:focus,
    .btn-secondary:active,
    .btn-secondary.active {
        background-color: var(--accent-secondary) !important;
        border-color: var(--accent-secondary) !important;
        color: var(--on-accent) !important;
        filter: brightness(0.94);
    }

.btn-outline-primary {
    color: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    background-color: transparent !important;
}
    .btn-outline-primary:hover,
    .btn-outline-primary:focus,
    .btn-outline-primary:active,
    .btn-outline-primary.active {
        color: var(--on-accent) !important;
        background-color: var(--accent-primary) !important;
        border-color: var(--accent-primary) !important;
    }

.btn-success { background-color: var(--success) !important; border-color: var(--success) !important; color: var(--text-on-status) !important; }
.btn-danger  { background-color: var(--danger)  !important; border-color: var(--danger)  !important; color: var(--text-on-status) !important; }
.btn-warning { background-color: var(--warning) !important; border-color: var(--warning) !important; color: var(--text-on-status) !important; }
.btn-info    { background-color: var(--info)    !important; border-color: var(--info)    !important; color: var(--text-on-status) !important; }
    .btn-success:hover, .btn-danger:hover, .btn-warning:hover, .btn-info:hover,
    .btn-success:active, .btn-danger:active, .btn-warning:active, .btn-info:active,
    .btn-success:focus, .btn-danger:focus, .btn-warning:focus, .btn-info:focus {
        color: var(--text-on-status) !important;
        filter: brightness(0.94);
    }

.btn-light {
    background-color: var(--bg-surface) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}
    .btn-light:hover, .btn-light:focus, .btn-light:active {
        background-color: var(--surface-hover) !important;
        border-color: var(--border) !important;
        color: var(--text-primary) !important;
    }

.btn-link {
    color: var(--accent-primary) !important;
}
    .btn-link:hover { color: var(--accent-strong) !important; }

/* ---- Surfaces ---- */
.card,
.modal-content,
.list-group-item,
.offcanvas,
.accordion-item,
.accordion-button {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border);
}

.dropdown-menu {
    background-color: var(--bg-formcontrols);
    color: var(--text-primary);
    border-color: var(--border);
}
    .dropdown-item { color: var(--text-primary); }
    .dropdown-item:hover, .dropdown-item:focus {
        background-color: var(--surface-hover);
        color: var(--accent-primary);
    }
    .dropdown-item.active, .dropdown-item:active {
        background-color: var(--accent-primary);
        color: var(--on-accent);
    }
    .dropdown-header { color: var(--text-secondary); }

.card-header,
.card-footer,
.modal-header,
.modal-footer {
    background-color: var(--bg-surface);
    border-color: var(--border);
}

/* ---- Forms ---- */
.form-control,
.form-select,
.input-group-text {
    background-color: var(--bg-formcontrols);
    color: var(--text-primary);
    border-color: var(--border);
}

    .form-control::placeholder {
        color: var(--text-secondary);
        opacity: 1;
    }

    .form-control:focus,
    .form-select:focus {
        background-color: var(--bg-surface);
        color: var(--text-primary);
        border-color: var(--accent-primary);
        box-shadow: 0 0 0 0.25rem var(--accent-soft);
    }

    .form-control:disabled,
    .form-control[readonly] {
        background-color: var(--bg-inset);
        color: var(--text-secondary);
    }

.form-check-input:checked {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.form-check-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 0.25rem var(--accent-soft);
}

/* ---- Tables ---- */
.table {
    color: var(--text-primary);
    border-color: var(--border);
}
    .table > :not(caption) > * > * {
        border-bottom-color: var(--border);
        color: var(--text-primary);
    }
    .table > thead {
        color: var(--text-secondary);
    }
    /* 5.1 striped/hover use an accent-bg box-shadow trick; set cells directly */
    .table-striped > tbody > tr:nth-of-type(odd) > * {
        background-color: var(--surface-hover);
        color: var(--text-primary);
    }
    .table-hover > tbody > tr:hover > * {
        background-color: var(--surface-hover);
        color: var(--text-primary);
    }

/* ---- Nav / tabs / pagination ---- */
.nav-tabs {
    border-color: var(--border);
}

    .nav-tabs .nav-link {
        color: var(--text-secondary);
    }

        .nav-tabs .nav-link.active {
            color: var(--accent-primary);
            background-color: var(--bg-surface);
            border-color: var(--border) var(--border) var(--bg-surface);
        }

.page-link {
    color: var(--accent-primary);
    background-color: var(--bg-surface);
    border-color: var(--border);
}
    .page-link:hover {
        color: var(--accent-strong);
        background-color: var(--surface-hover);
        border-color: var(--border);
    }
.page-item.active .page-link {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--on-accent);
}
.page-item.disabled .page-link {
    background-color: var(--bg-surface);
    border-color: var(--border);
    color: var(--text-secondary);
}

/* ---- Badges ---- */
.badge.bg-primary,
.badge.text-bg-primary {
    background-color: var(--accent-primary) !important;
    color: var(--on-accent) !important;
}

.badge.bg-success, .badge.text-bg-success { background-color: var(--success) !important; color: var(--text-on-status) !important; }
.badge.bg-danger,  .badge.text-bg-danger  { background-color: var(--danger)  !important; color: var(--text-on-status) !important; }
.badge.bg-warning, .badge.text-bg-warning { background-color: var(--warning) !important; color: var(--text-on-status) !important; }
.badge.bg-info,    .badge.text-bg-info    { background-color: var(--info)    !important; color: var(--text-on-status) !important; }

/* ---- Utilities (Bootstrap sets these with !important) ---- */
.bg-white, .bg-light { background-color: var(--bg-surface) !important; }
.text-muted { color: var(--text-secondary) !important; }
.text-dark { color: var(--text-primary) !important; }
.text-primary { color: var(--accent-primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.border, .border-top, .border-bottom, .border-start, .border-end { border-color: var(--border) !important; }

.dropdown-divider,
hr {
    border-color: var(--border);
    color: var(--border);
}

.modal-backdrop {
    background-color: #000;
}
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    padding: 24px 16px;
    /* Sapphire gradient with soft radial highlights layered on top */
    background:
        radial-gradient( circle at 20% 80%, rgba(255, 255, 255, 0.08), transparent 35% ),
        radial-gradient( circle at 90% 60%, rgba(255, 255, 255, 0.06), transparent 40% ),
        var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: 4px 0 24px var(--shadow);
    overflow: hidden;
}

/* Decorative rings — visible in both themes via --sidebar-decor. */
.sidebar::before {
    content: "";
    display: var(--sidebar-decor);
    position: absolute;
    width: 420px;
    height: 420px;
    right: -220px;
    bottom: -100px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: -40px -30px 0 -1px rgba(255, 255, 255, 0.05), -80px -60px 0 -1px rgba(255, 255, 255, 0.04);
    pointer-events: none;
}

.sidebar::after {
    content: "";
    display: var(--sidebar-decor);
    position: absolute;
    width: 300px;
    height: 300px;
    right: -180px;
    bottom: -180px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.035);
    pointer-events: none;
}

.sidebar > * {
    position: relative;
    z-index: 2;
}
/* Sidebar brand (CompanyBranding component, sidebar variant) */
.logo-section {
    padding: 25px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
}

    .logo-section h5 {
        width: 100%;
        text-align: center;
        color: var(--sidebar-accent);
    }

.sidebar-logo-img {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: contain;
}

.menu-title {
    padding: 20px 30px 10px;
    font-size: 12px;
    font-weight: 700;
    color: var(--sidebar-text-muted);
    letter-spacing: 2px;
}

.sidebar-menu {
    padding: 0 15px;
}
    .sidebar-menu .nav-link {
        position: relative;
        display: flex;
        align-items: center;
        gap: 15px;
        padding: 14px 15px;
        color: var(--sidebar-text);
        border-radius: 10px;
        margin-bottom: 8px;
        font-weight: 500;
        transition: background var(--nav-transition), color var(--nav-transition);
    }

        .sidebar-menu .nav-link:hover,
        .sidebar-menu .nav-link.active {
            color: var(--sidebar-text-hover);
            background: var(--sidebar-item-hover);
        }

        .sidebar-menu .nav-link.active {
            background: var(--sidebar-item-active);
        }

            .sidebar-menu .nav-link.active::before {
                content: "";
                position: absolute;
                right: -15px;
                top: 10px;
                height: 35px;
                width: 4px;
                background: var(--sidebar-accent);
                border-radius: 10px;
            }

/* Topbar */
.topbar {
    position: fixed;
    left: var(--sidebar-width);
    right: 0;
    top: 0;
    height: 70px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 30px;
    z-index: 999;
}

.notification {
    position: relative;
    margin-right: 25px;
    color: var(--text-secondary);
    font-size: 20px;
}

.badge-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--accent-secondary);
    color: var(--accent-contrast);
    font-size: 10px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    text-align: center;
    line-height: 18px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.profile-dropdown {
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px var(--shadow);
    padding: 8px;
    min-width: 180px;
    background: var(--bg-surface);
    color: var(--text-primary);
}

    .profile-dropdown .dropdown-item {
        border-radius: 8px;
        padding: 10px 14px;
        color: var(--text-primary);
    }

        .profile-dropdown .dropdown-item:hover {
            background: var(--surface-hover);
            color: var(--accent-primary);
        }

.profile-image {
    width: 38px;
    height: 38px;
    background: var(--border);
    border-radius: 10px;
}

.user-info h6 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.user-info small {
    color: var(--text-secondary);
}

/* Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: 70px;
    padding: 30px;
    min-height: calc(100vh - 70px);
}

@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width-collapsed);
    }

    .menu-title,
    .menu-text,
    .user-info {
        display: none;
    }

    .topbar {
        left: var(--sidebar-width-collapsed);
    }

    .main-content {
        margin-left: var(--sidebar-width-collapsed);
    }

    .sidebar-menu .nav-link {
        justify-content: center;
    }
}