/* =========================================================================
   People Analytics · Design System
   Corporate-grade tokens with light + dark theme
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

/* -------------------------------------------------------------------------
   Theme tokens
   ------------------------------------------------------------------------- */

:root {
    color-scheme: light dark;

    /* Brand */
    --brand-600: #1e40af;
    --brand-500: #2563eb;
    --brand-400: #3b82f6;
    --brand-300: #60a5fa;
    --brand-200: #93c5fd;

    --gold-600: #b45309;
    --gold-500: #d97706;
    --gold-400: #f59e0b;

    /* Feedback */
    --success: #16a34a;
    --success-strong: #15803d;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;

    /* Radii */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-pill: 9999px;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Typography */
    --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    --tracking-tight: -0.015em;
    --tracking-tighter: -0.025em;

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-emphatic: cubic-bezier(0.22, 1, 0.36, 1);
    --dur-fast: 160ms;
    --dur-med: 240ms;
    --dur-slow: 420ms;

    --glass-backdrop: blur(18px) saturate(150%);
}

/* Light theme (default) */
:root, :root[data-theme="light"] {
    --bg-primary: #f5f7fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef2f8;

    --bg-card: rgba(255, 255, 255, 0.72);
    --bg-card-solid: #ffffff;
    --bg-card-hover: rgba(255, 255, 255, 0.94);
    --bg-elevated: rgba(255, 255, 255, 0.85);
    --bg-inset: rgba(15, 23, 42, 0.04);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    --accent-blue: #2563eb;
    --accent-blue-hover: #1d4ed8;
    --accent-blue-soft: rgba(37, 99, 235, 0.10);
    --accent-purple: #7c3aed;
    --accent-purple-soft: rgba(124, 58, 237, 0.10);
    --accent-green: #16a34a;
    --accent-green-soft: rgba(22, 163, 74, 0.10);
    --accent-red: #dc2626;
    --accent-red-soft: rgba(220, 38, 38, 0.10);
    --accent-amber: #d97706;
    --accent-amber-soft: rgba(217, 119, 6, 0.10);

    --border-color: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);
    --border-highlight: rgba(37, 99, 235, 0.35);
    --divider: rgba(15, 23, 42, 0.06);

    --shadow-subtle: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-lifted: 0 6px 12px -6px rgba(15, 23, 42, 0.12), 0 18px 32px -12px rgba(30, 64, 175, 0.18);
    --shadow-focus: 0 0 0 4px rgba(37, 99, 235, 0.18);

    --aurora-1: radial-gradient(60% 50% at 15% 10%, rgba(37, 99, 235, 0.14) 0%, transparent 60%);
    --aurora-2: radial-gradient(45% 40% at 85% 0%, rgba(217, 119, 6, 0.10) 0%, transparent 60%);
    --aurora-3: radial-gradient(80% 60% at 50% 110%, rgba(124, 58, 237, 0.08) 0%, transparent 60%);

    --sidebar-bg: rgba(255, 255, 255, 0.75);
    --sidebar-border: rgba(15, 23, 42, 0.08);

    --bg-card-flat: #ffffff;
    --border-flat: rgba(15, 23, 42, 0.08);
    --shadow-flat: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* Dark theme */
:root[data-theme="dark"] {
    --bg-primary: #060a17;
    --bg-secondary: #0e1526;
    --bg-tertiary: #131c33;

    --bg-card: rgba(20, 28, 48, 0.68);
    --bg-card-solid: #131c33;
    --bg-card-hover: rgba(30, 41, 65, 0.86);
    --bg-elevated: rgba(20, 28, 48, 0.82);
    --bg-inset: rgba(255, 255, 255, 0.04);

    --text-primary: #f1f5f9;
    --text-secondary: #a3b3cc;
    --text-muted: #6b7a94;
    --text-inverse: #0f172a;

    --accent-blue: #60a5fa;
    --accent-blue-hover: #93c5fd;
    --accent-blue-soft: rgba(96, 165, 250, 0.14);
    --accent-purple: #c084fc;
    --accent-purple-soft: rgba(192, 132, 252, 0.14);
    --accent-green: #34d399;
    --accent-green-soft: rgba(52, 211, 153, 0.14);
    --accent-red: #f87171;
    --accent-red-soft: rgba(248, 113, 113, 0.14);
    --accent-amber: #fbbf24;
    --accent-amber-soft: rgba(251, 191, 36, 0.14);

    --border-color: rgba(148, 163, 184, 0.12);
    --border-strong: rgba(148, 163, 184, 0.22);
    --border-highlight: rgba(96, 165, 250, 0.45);
    --divider: rgba(148, 163, 184, 0.10);

    --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.35);
    --shadow-lifted: 0 8px 18px -6px rgba(0, 0, 0, 0.55), 0 22px 48px -18px rgba(96, 165, 250, 0.28);
    --shadow-focus: 0 0 0 4px rgba(96, 165, 250, 0.25);

    --aurora-1: radial-gradient(60% 50% at 15% 10%, rgba(96, 165, 250, 0.18) 0%, transparent 60%);
    --aurora-2: radial-gradient(45% 40% at 85% 0%, rgba(251, 191, 36, 0.10) 0%, transparent 60%);
    --aurora-3: radial-gradient(80% 60% at 50% 110%, rgba(192, 132, 252, 0.14) 0%, transparent 60%);

    --sidebar-bg: rgba(12, 18, 34, 0.75);
    --sidebar-border: rgba(148, 163, 184, 0.10);

    --bg-card-flat: #131c33;
    --border-flat: rgba(148, 163, 184, 0.12);
    --shadow-flat: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* System-preference fallback when no data-theme is set yet */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-primary: #060a17;
        --bg-secondary: #0e1526;
        --bg-tertiary: #131c33;
        --bg-card: rgba(20, 28, 48, 0.68);
        --bg-card-solid: #131c33;
        --bg-card-hover: rgba(30, 41, 65, 0.86);
        --bg-elevated: rgba(20, 28, 48, 0.82);
        --bg-inset: rgba(255, 255, 255, 0.04);
        --text-primary: #f1f5f9;
        --text-secondary: #a3b3cc;
        --text-muted: #6b7a94;
        --text-inverse: #0f172a;
        --accent-blue: #60a5fa;
        --accent-blue-hover: #93c5fd;
        --accent-blue-soft: rgba(96, 165, 250, 0.14);
        --accent-purple: #c084fc;
        --accent-purple-soft: rgba(192, 132, 252, 0.14);
        --accent-green: #34d399;
        --accent-green-soft: rgba(52, 211, 153, 0.14);
        --accent-red: #f87171;
        --accent-red-soft: rgba(248, 113, 113, 0.14);
        --accent-amber: #fbbf24;
        --accent-amber-soft: rgba(251, 191, 36, 0.14);
        --border-color: rgba(148, 163, 184, 0.12);
        --border-strong: rgba(148, 163, 184, 0.22);
        --border-highlight: rgba(96, 165, 250, 0.45);
        --divider: rgba(148, 163, 184, 0.10);
        --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.35);
        --shadow-lifted: 0 8px 18px -6px rgba(0, 0, 0, 0.55), 0 22px 48px -18px rgba(96, 165, 250, 0.28);
        --shadow-focus: 0 0 0 4px rgba(96, 165, 250, 0.25);
        --aurora-1: radial-gradient(60% 50% at 15% 10%, rgba(96, 165, 250, 0.18) 0%, transparent 60%);
        --aurora-2: radial-gradient(45% 40% at 85% 0%, rgba(251, 191, 36, 0.10) 0%, transparent 60%);
        --aurora-3: radial-gradient(80% 60% at 50% 110%, rgba(192, 132, 252, 0.14) 0%, transparent 60%);
        --sidebar-bg: rgba(12, 18, 34, 0.75);
        --sidebar-border: rgba(148, 163, 184, 0.10);
        --bg-card-flat: #131c33;
        --border-flat: rgba(148, 163, 184, 0.12);
        --shadow-flat: 0 1px 2px rgba(0, 0, 0, 0.35);
    }
}

/* -------------------------------------------------------------------------
   Reset
   ------------------------------------------------------------------------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: var(--tracking-tight);
    transition: background-color var(--dur-med) var(--ease-out),
                color var(--dur-med) var(--ease-out);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        var(--aurora-1),
        var(--aurora-2),
        var(--aurora-3),
        var(--bg-primary);
    pointer-events: none;
    transition: background-image var(--dur-slow) var(--ease-out);
}

a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-out);
}

a:hover {
    color: var(--accent-blue-hover);
    text-decoration: underline;
}

::selection {
    background: var(--accent-blue-soft);
    color: var(--text-primary);
}

/* -------------------------------------------------------------------------
   Scrollbar
   ------------------------------------------------------------------------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-blue); background-clip: padding-box; }

/* -------------------------------------------------------------------------
   App shell
   ------------------------------------------------------------------------- */

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 264px;
    background-color: var(--sidebar-bg);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.25rem 0.9rem;
    flex-shrink: 0;
    transition: background-color var(--dur-med) var(--ease-out),
                border-color var(--dur-med) var(--ease-out);
    position: relative;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--divider);
    margin-bottom: 1.25rem;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-600) 60%, #4c1d95 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 6px 16px -8px rgba(37, 99, 235, 0.6),
                inset 0 1px 0 rgba(255, 255, 255, 0.35);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.brand-mark i {
    font-size: 1.35rem;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
    position: relative;
    z-index: 1;
}

.brand-mark::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.35), transparent 55%);
}

.sidebar-header h2 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: var(--tracking-tighter);
    color: var(--text-primary);
    line-height: 1.1;
}

.sidebar-header .brand-tag {
    display: block;
    font-family: var(--font-family);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: 2px;
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    overflow-y: auto;
    padding-right: 0.15rem;
    scrollbar-width: thin;
}

.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.9rem 0.75rem 0.3rem;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 0.85rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.88rem;
    position: relative;
    transition: color var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
}

.sidebar-item a i {
    font-size: 1.15rem;
    color: var(--text-muted);
    transition: color var(--dur-fast) var(--ease-out),
                transform var(--dur-med) var(--ease-out);
}

.sidebar-item a:hover {
    color: var(--text-primary);
    background-color: var(--bg-inset);
    text-decoration: none;
}
.sidebar-item a:hover i { color: var(--accent-blue); transform: translateX(1px); }

.sidebar-item.active a {
    color: var(--text-primary);
    background: linear-gradient(90deg, var(--accent-blue-soft), transparent 90%);
    font-weight: 600;
}
.sidebar-item.active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 22%;
    bottom: 22%;
    width: 3px;
    border-radius: var(--radius-pill);
    background: linear-gradient(180deg, var(--brand-400), var(--brand-600));
    box-shadow: 0 0 10px 0 var(--brand-400);
}
.sidebar-item.active a i { color: var(--accent-blue); }

.sidebar-footer {
    border-top: 1px solid var(--divider);
    padding-top: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* Theme toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    background-color: var(--bg-inset);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    justify-content: space-between;
    transition: background-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
}

.theme-toggle:hover {
    background-color: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-highlight);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.theme-toggle-track {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 22px;
    background: linear-gradient(90deg, var(--accent-amber) 0%, var(--brand-500) 100%);
    border-radius: var(--radius-pill);
    position: relative;
    flex-shrink: 0;
}

.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-500);
    font-size: 0.7rem;
    transition: transform var(--dur-med) var(--ease-emphatic),
                color var(--dur-fast) var(--ease-out);
}

:root[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(22px);
    color: var(--brand-600);
}

/* User profile */
.user-profile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
    background: var(--bg-inset);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
}

.user-profile .user-name {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.user-profile .user-role {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
}

.icon-btn:hover {
    background: var(--bg-inset);
    color: var(--accent-red);
    border-color: var(--border-color);
}

.icon-btn i { font-size: 1.15rem; }

/* -------------------------------------------------------------------------
   Main content
   ------------------------------------------------------------------------- */

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 2.25rem 3rem;
    position: relative;
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.75rem;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--divider);
    animation: fadeInDown var(--dur-slow) var(--ease-out) both;
}

.header-title h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: var(--tracking-tighter);
    color: var(--text-primary);
    line-height: 1.15;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}

.header-title strong { color: var(--text-primary); font-weight: 600; }

/* -------------------------------------------------------------------------
   Cards & surfaces
   ------------------------------------------------------------------------- */

.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.4rem;
    box-shadow: var(--shadow-subtle);
    margin-bottom: 1.25rem;
    position: relative;
    transition: transform var(--dur-med) var(--ease-out),
                box-shadow var(--dur-med) var(--ease-out),
                border-color var(--dur-med) var(--ease-out),
                background-color var(--dur-med) var(--ease-out);
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), transparent 60%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.6;
}

:root[data-theme="dark"] .card::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 55%);
    opacity: 0.9;
}

.card--flat {
    background: var(--bg-card-flat);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--border-flat);
    box-shadow: var(--shadow-flat);
}

.card--flat::before { display: none; }

.card-hover {
    cursor: pointer;
}

.card-hover:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lifted);
    border-color: var(--border-highlight);
}

/* KPI card */
.kpi-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.4rem;
    box-shadow: var(--shadow-subtle);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    position: relative;
    overflow: hidden;
    transition: transform var(--dur-med) var(--ease-out),
                box-shadow var(--dur-med) var(--ease-out),
                border-color var(--dur-med) var(--ease-out);
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 140px;
    height: 140px;
    background: radial-gradient(circle at 100% 0%, var(--kpi-glow, var(--accent-blue-soft)) 0%, transparent 65%);
    pointer-events: none;
    opacity: 0.9;
    transition: opacity var(--dur-med) var(--ease-out);
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lifted);
    border-color: var(--border-highlight);
}

.kpi-card:hover::after { opacity: 1; }

.kpi-label {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.kpi-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: var(--tracking-tighter);
    color: var(--text-primary);
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    line-height: 1.1;
}

.kpi-value-sm {
    font-size: 1.7rem;
}

.kpi-caption {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: auto;
    display: block;
    line-height: 1.35;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
    background: var(--kpi-icon-bg, var(--accent-blue-soft));
    color: var(--kpi-icon-fg, var(--accent-blue));
    position: relative;
    z-index: 1;
}

.kpi-card.tone-blue   { --kpi-glow: rgba(37, 99, 235, 0.15);  --kpi-icon-bg: rgba(37, 99, 235, 0.14);  --kpi-icon-fg: var(--accent-blue); }
.kpi-card.tone-amber  { --kpi-glow: rgba(217, 119, 6, 0.18);  --kpi-icon-bg: rgba(217, 119, 6, 0.14);  --kpi-icon-fg: var(--accent-amber); }
.kpi-card.tone-purple { --kpi-glow: rgba(124, 58, 237, 0.16); --kpi-icon-bg: rgba(124, 58, 237, 0.14); --kpi-icon-fg: var(--accent-purple); }
.kpi-card.tone-green  { --kpi-glow: rgba(22, 163, 74, 0.16);  --kpi-icon-bg: rgba(22, 163, 74, 0.14);  --kpi-icon-fg: var(--accent-green); }
.kpi-card.tone-red    { --kpi-glow: rgba(220, 38, 38, 0.16);  --kpi-icon-bg: rgba(220, 38, 38, 0.14);  --kpi-icon-fg: var(--accent-red); }

:root[data-theme="dark"] .kpi-card.tone-blue   { --kpi-icon-bg: rgba(96, 165, 250, 0.16); }
:root[data-theme="dark"] .kpi-card.tone-amber  { --kpi-icon-bg: rgba(251, 191, 36, 0.16); }
:root[data-theme="dark"] .kpi-card.tone-purple { --kpi-icon-bg: rgba(192, 132, 252, 0.16); }
:root[data-theme="dark"] .kpi-card.tone-green  { --kpi-icon-bg: rgba(52, 211, 153, 0.16); }
:root[data-theme="dark"] .kpi-card.tone-red    { --kpi-icon-bg: rgba(248, 113, 113, 0.16); }

/* Section header inside card */
.card-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: var(--tracking-tight);
    color: var(--text-primary);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--divider);
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.card-title i { color: var(--accent-blue); font-size: 1.1rem; }

/* -------------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------------- */

.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.87rem;
}

th {
    background-color: var(--bg-inset);
    color: var(--text-secondary);
    padding: 0.85rem 1rem;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
}

td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--divider);
    color: var(--text-primary);
    transition: background-color var(--dur-fast) var(--ease-out);
}

tr:last-child td { border-bottom: none; }

tbody tr {
    transition: background-color var(--dur-fast) var(--ease-out);
}

tbody tr:hover {
    background-color: var(--bg-inset);
}

/* -------------------------------------------------------------------------
   Badges
   ------------------------------------------------------------------------- */

.badge {
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid transparent;
    line-height: 1.4;
}

.badge-success { background-color: rgba(22, 163, 74, 0.12); color: var(--accent-green); border-color: rgba(22, 163, 74, 0.25); }
.badge-warning { background-color: rgba(217, 119, 6, 0.12); color: var(--accent-amber); border-color: rgba(217, 119, 6, 0.25); }
.badge-danger  { background-color: rgba(220, 38, 38, 0.12); color: var(--accent-red);   border-color: rgba(220, 38, 38, 0.25); }
.badge-info    { background-color: rgba(37, 99, 235, 0.12); color: var(--accent-blue);  border-color: rgba(37, 99, 235, 0.25); }
.badge-neutral { background-color: var(--bg-inset); color: var(--text-muted); border-color: var(--border-color); }

:root[data-theme="dark"] .badge-success { background-color: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.28); }
:root[data-theme="dark"] .badge-warning { background-color: rgba(251, 191, 36, 0.14); border-color: rgba(251, 191, 36, 0.28); }
:root[data-theme="dark"] .badge-danger  { background-color: rgba(248, 113, 113, 0.14); border-color: rgba(248, 113, 113, 0.28); }
:root[data-theme="dark"] .badge-info    { background-color: rgba(96, 165, 250, 0.14); border-color: rgba(96, 165, 250, 0.28); }

/* -------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------- */

.btn {
    padding: 0.62rem 1.15rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
    font-size: 0.87rem;
    font-family: var(--font-family);
    letter-spacing: var(--tracking-tight);
    position: relative;
    overflow: hidden;
    user-select: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:active { transform: translateY(1px); }

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
    gap: 0.35rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
    color: #fff;
    box-shadow: 0 4px 14px -6px rgba(37, 99, 235, 0.55);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--brand-400), var(--brand-500));
    box-shadow: 0 8px 18px -6px rgba(37, 99, 235, 0.6);
    transform: translateY(-1px);
    color: #fff;
    text-decoration: none;
}

.btn-secondary {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-highlight);
    transform: translateY(-1px);
    text-decoration: none;
}

.btn-danger {
    background-color: var(--accent-red);
    color: #fff;
    box-shadow: 0 4px 12px -6px rgba(220, 38, 38, 0.5);
}

.btn-danger:hover {
    background-color: #b91c1c;
    color: #fff;
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-inset);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-outline {
    background-color: transparent;
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.05);
}

.btn-outline:hover {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 16px -6px rgba(37, 99, 235, 0.55);
    transform: translateY(-1px);
    text-decoration: none;
}

.btn-outline:hover i { color: #fff; }

/* -------------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------------- */

.form-group { margin-bottom: 1.15rem; }

.form-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.95rem;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-family);
    transition: border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out);
}

.form-control::placeholder { color: var(--text-muted); }

.form-control:hover:not(:focus) { border-color: var(--border-strong); }

.form-control:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-focus);
    background-color: var(--bg-secondary);
}

.form-control[type="date"],
.form-control[type="time"],
.form-control[type="datetime-local"] {
    color-scheme: light dark;
}

.form-control::-webkit-calendar-picker-indicator {
    opacity: 0.7;
    cursor: pointer;
    filter: invert(30%);
    transition: opacity var(--dur-fast) var(--ease-out);
}

.form-control::-webkit-calendar-picker-indicator:hover { opacity: 1; }

:root[data-theme="dark"] .form-control::-webkit-calendar-picker-indicator {
    filter: invert(85%);
}

/* -------------------------------------------------------------------------
   Modals
   ------------------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(3, 7, 18, 0.78);
    backdrop-filter: blur(22px) saturate(130%);
    -webkit-backdrop-filter: blur(22px) saturate(130%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-med) var(--ease-out);
}

:root[data-theme="light"] .modal-backdrop {
    background-color: rgba(15, 23, 42, 0.5);
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lifted);
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    transition: transform var(--dur-med) var(--ease-emphatic),
                opacity var(--dur-med) var(--ease-out);
}

.modal-backdrop.active .modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* -------------------------------------------------------------------------
   Flash messages
   ------------------------------------------------------------------------- */

.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-subtle);
    animation: fadeInDown var(--dur-med) var(--ease-out) both;
}

.flash i { font-size: 1.1rem; flex-shrink: 0; }

.flash-error   { border-left: 3px solid var(--accent-red); }
.flash-error i { color: var(--accent-red); }
.flash-success { border-left: 3px solid var(--accent-green); }
.flash-success i { color: var(--accent-green); }
.flash-info    { border-left: 3px solid var(--accent-blue); }
.flash-info i  { color: var(--accent-blue); }

/* -------------------------------------------------------------------------
   Motion utilities
   ------------------------------------------------------------------------- */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes shimmerPulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.03); }
}

.reveal {
    opacity: 0;
    animation: fadeInUp var(--dur-slow) var(--ease-out) forwards;
}

.stagger > * {
    opacity: 0;
    animation: fadeInUp var(--dur-slow) var(--ease-out) forwards;
}

.stagger > *:nth-child(1) { animation-delay: 40ms; }
.stagger > *:nth-child(2) { animation-delay: 90ms; }
.stagger > *:nth-child(3) { animation-delay: 140ms; }
.stagger > *:nth-child(4) { animation-delay: 190ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 290ms; }
.stagger > *:nth-child(7) { animation-delay: 340ms; }
.stagger > *:nth-child(8) { animation-delay: 390ms; }
.stagger > *:nth-child(9) { animation-delay: 440ms; }
.stagger > *:nth-child(10) { animation-delay: 490ms; }

.pulse-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
    animation: shimmerPulse 2.2s var(--ease-out) infinite;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .stagger > * { opacity: 1; }
}

/* -------------------------------------------------------------------------
   Submenu lateral (accordion inline)
   ------------------------------------------------------------------------- */

.sidebar-item.has-submenu {
    position: relative;
    display: block;
    padding: 0;
}

.sidebar-item.has-submenu > .submenu-toggle {
    all: unset;
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.62rem 0.85rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.88rem;
    font-family: inherit;
    position: relative;
    transition: color var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out);
}

.sidebar-item.has-submenu > .submenu-toggle > i:first-child {
    font-size: 1.15rem;
    color: var(--text-muted);
    transition: color var(--dur-fast) var(--ease-out),
                transform var(--dur-med) var(--ease-out);
}

.sidebar-item.has-submenu > .submenu-toggle:hover,
.sidebar-item.has-submenu > .submenu-toggle:focus-visible {
    color: var(--text-primary);
    background-color: var(--bg-inset);
    outline: none;
}

.sidebar-item.has-submenu > .submenu-toggle:hover > i:first-child {
    color: var(--accent-blue);
    transform: translateX(1px);
}

.sidebar-item.has-submenu > .submenu-toggle .submenu-icon {
    margin-left: auto;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: transform var(--dur-fast) var(--ease-out);
}

.sidebar-item.has-submenu > .submenu-toggle[aria-expanded="true"] .submenu-icon {
    transform: rotate(180deg);
}

.sidebar-item.has-submenu.has-active > .submenu-toggle {
    color: var(--text-primary);
    font-weight: 600;
}

.sidebar-item.has-submenu.has-active > .submenu-toggle > i:first-child {
    color: var(--accent-blue);
}

.sidebar .submenu {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    transition: max-height var(--dur-med) var(--ease-out);
}

.sidebar .submenu.open {
    max-height: 600px;
    padding: 0.25rem 0 0.35rem;
}

.sidebar .submenu > .sidebar-item {
    margin-left: 0.85rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--divider);
    border-radius: 0;
}

.sidebar .submenu > .sidebar-item a {
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
}

.sidebar .submenu > .sidebar-item a i {
    font-size: 1rem;
}

.sidebar .submenu > .sidebar-item.active a::before {
    left: -0.75rem;
    top: 30%;
    bottom: 30%;
}

/* -------------------------------------------------------------------------
   Utility helpers
   ------------------------------------------------------------------------- */

.grid-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.15rem;
    margin-bottom: 1.75rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.4rem;
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--text-primary); }
.text-blue { color: var(--accent-blue); }
.text-amber { color: var(--accent-amber); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-purple { color: var(--accent-purple); }

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .sidebar { width: 220px; }
    .main-content { padding: 1.5rem; }
}

/* -------------------------------------------------------------------------
   Print — relatório da Matriz 9-box
   ------------------------------------------------------------------------- */

.print-only { display: none; }

@media print {
    @page { margin: 12mm; }
    html, body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        display: block !important;
    }
    .app-container, .main-content {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }
    .sidebar, .header-bar, .flash-stack { display: none !important; }
    .main-content > *:not(.modal-backdrop) { display: none !important; }
    .modal-backdrop:not(.active) { display: none !important; }
    .modal-backdrop.active .print-hide { display: none !important; }
    .modal-backdrop.active {
        position: static !important;
        background: #fff !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        display: block !important;
        opacity: 1 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .modal-backdrop.active .modal-content {
        position: static !important;
        transform: none !important;
        background: #fff !important;
        border: none !important;
        box-shadow: none !important;
        max-width: 100% !important;
        width: 100% !important;
        opacity: 1 !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .modal-backdrop.active .table-container {
        max-height: none !important;
        overflow: visible !important;
    }
    .modal-backdrop.active .print-9box-cabecalho {
        display: flex !important;
        justify-content: space-between;
        align-items: baseline;
        font-size: 0.75rem;
        color: #555;
        padding-bottom: 0.4rem;
        margin-bottom: 0.6rem;
        border-bottom: 1px solid #ccc;
    }
    .modal-backdrop.active .print-9box-cabecalho strong {
        color: #000;
        font-size: 0.85rem;
    }
    .modal-backdrop.active #modal-9box-resumo { color: #333 !important; }
    .modal-backdrop.active table {
        font-size: 0.8rem;
        border-collapse: collapse;
        width: 100%;
    }
    .modal-backdrop.active table tr { page-break-inside: avoid; }
    .modal-backdrop.active table th {
        background: #2563eb !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .modal-backdrop.active table th,
    .modal-backdrop.active table td {
        padding: 4px 6px;
        border: 1px solid #ccc;
    }
    .modal-backdrop.active table tbody tr:nth-child(even) {
        background: #f8fafc !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@media (max-width: 720px) {
    .app-container { flex-direction: column; height: auto; overflow: visible; }
    body { display: block; }
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--sidebar-border);
        padding: 1rem;
    }
    .sidebar-menu { flex-direction: row; overflow-x: auto; }
    .sidebar-item.active a::before { display: none; }
    .main-content { height: auto; padding: 1.25rem; }
}
