/* ==========================================================================
   Grandus — Aurora Glass Design System
   ========================================================================== */

@layer reset, tokens, base, components, utilities;

/* --------------------------------------------------------------------------
   Inter Variable — self-hosted, single woff2 for all weights
   -------------------------------------------------------------------------- */
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/assets/fonts/inter-variable.woff2") format("woff2-variations"),
         url("/assets/fonts/inter-variable.woff2") format("woff2");
}

/* ==========================================================================
   Reset
   ========================================================================== */
@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    body, h1, h2, h3, h4, h5, h6, p, ul, ol, dl, dd, figure, blockquote { margin: 0; }
    ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
    img, svg, video, canvas, audio, iframe, embed, object { display: block; max-width: 100%; }
    button { font: inherit; cursor: pointer; }
    input, button, textarea, select { font: inherit; color: inherit; }
    a { color: inherit; text-decoration: none; }
    :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
}

/* ==========================================================================
   Tokens — colours, scales, motion. Themed via [data-theme].
   ========================================================================== */
@layer tokens {
    :root {
        /* Aurora gradient stops — shared between themes */
        --aurora-1: #5b4cff;
        --aurora-2: #22d3ee;
        --aurora-3: #a855f7;
        --aurora-4: #ec4899;

        /* Scale */
        --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
        --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
        --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem; --space-16: 4rem;

        --radius-xs: 4px; --radius-sm: 6px; --radius: 10px;
        --radius-lg: 14px; --radius-xl: 20px; --radius-pill: 999px;

        --motion-instant: 80ms;
        --motion-fast: 140ms;
        --motion-base: 240ms;
        --motion-slow: 380ms;
        --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
        --ease-in-out: cubic-bezier(0.5, 0, 0.2, 1);

        --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
        --font-mono: ui-monospace, "JetBrains Mono", SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

        --container: 1240px;
        --header-h: 64px;

        color-scheme: dark light;
    }

    :root,
    [data-theme="dark"] {
        --bg: #07080F;
        --bg-veil: rgba(7, 8, 15, 0.6);
        --surface: hsl(228 22% 9%);
        --surface-2: hsl(228 20% 12%);
        --surface-3: hsl(228 18% 15%);
        --surface-glass: hsla(228, 22%, 10%, 0.62);
        --surface-glass-strong: hsla(228, 22%, 8%, 0.86);

        --text: #ECEFF8;
        --text-strong: #FFFFFF;
        --muted: #8E97AE;
        --subtle: #5C6378;

        --border: hsla(230, 18%, 65%, 0.12);
        --border-strong: hsla(230, 18%, 70%, 0.22);
        --hairline: hsla(230, 18%, 90%, 0.06);

        --accent: #8B9CFF;
        --accent-hover: #A6B3FF;
        --accent-soft: hsla(232, 100%, 75%, 0.16);
        --accent-glow: 0 0 0 1px hsla(232, 100%, 75%, 0.4), 0 6px 30px -8px hsla(232, 100%, 70%, 0.6);
        --accent-fg: #0A0B12;

        --success: #4ADE80;
        --success-soft: hsla(142, 70%, 60%, 0.15);
        --warn: #FBBF24;
        --warn-soft: hsla(43, 95%, 56%, 0.16);
        --danger: #F87171;
        --danger-soft: hsla(0, 90%, 71%, 0.16);
        --info: #38BDF8;
        --info-soft: hsla(199, 92%, 60%, 0.16);

        --status-aberta: #93B4F2;
        --status-andamento: #FBBF24;
        --status-concluida: #4ADE80;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px 1px rgba(0, 0, 0, 0.15);
        --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.4), 0 2px 6px -2px rgba(0, 0, 0, 0.25);
        --shadow-lg: 0 18px 50px -16px rgba(0, 0, 0, 0.55), 0 8px 20px -8px rgba(0, 0, 0, 0.4);
        --shadow-glow: 0 0 80px -20px hsla(232, 100%, 70%, 0.35);

        --chart-grid: hsla(230, 18%, 65%, 0.08);

        --aurora-opacity: 0.55;
        --aurora-blur: 90px;
    }

    [data-theme="light"] {
        --bg: #F6F7FB;
        --bg-veil: rgba(246, 247, 251, 0.72);
        --surface: #FFFFFF;
        --surface-2: #F1F3F9;
        --surface-3: #E6E9F2;
        --surface-glass: hsla(0, 0%, 100%, 0.72);
        --surface-glass-strong: hsla(0, 0%, 100%, 0.92);

        --text: #0E1428;
        --text-strong: #05071A;
        --muted: #5B647A;
        --subtle: #8B92A6;

        --border: hsla(230, 22%, 28%, 0.1);
        --border-strong: hsla(230, 22%, 28%, 0.2);
        --hairline: hsla(230, 22%, 28%, 0.06);

        --accent: #5B4CFF;
        --accent-hover: #4B3CEC;
        --accent-soft: hsla(245, 100%, 65%, 0.1);
        --accent-glow: 0 0 0 1px hsla(245, 100%, 65%, 0.35), 0 8px 26px -10px hsla(245, 100%, 60%, 0.55);
        --accent-fg: #FFFFFF;

        --success: #10A968;
        --success-soft: hsla(150, 82%, 36%, 0.1);
        --warn: #D97706;
        --warn-soft: hsla(28, 92%, 44%, 0.1);
        --danger: #DC2626;
        --danger-soft: hsla(0, 73%, 50%, 0.08);
        --info: #0284C7;
        --info-soft: hsla(199, 96%, 39%, 0.08);

        --status-aberta: #3B72D8;
        --status-andamento: #D97706;
        --status-concluida: #10A968;

        --shadow-sm: 0 1px 2px rgba(13, 18, 40, 0.05);
        --shadow-md: 0 4px 16px -4px rgba(13, 18, 40, 0.08), 0 2px 6px -2px rgba(13, 18, 40, 0.05);
        --shadow-lg: 0 18px 50px -16px rgba(13, 18, 40, 0.16), 0 8px 20px -8px rgba(13, 18, 40, 0.08);
        --shadow-glow: 0 0 80px -20px hsla(245, 100%, 65%, 0.18);

        --chart-grid: hsla(230, 22%, 28%, 0.07);

        --aurora-opacity: 0.4;
        --aurora-blur: 110px;
    }
}

/* ==========================================================================
   Base
   ========================================================================== */
@layer base {
    html {
        font-family: var(--font-sans);
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        font-feature-settings: "cv11", "ss01", "ss03";
        text-rendering: optimizeLegibility;
    }

    html { overflow-x: clip; }
    body {
        margin: 0;
        min-height: 100vh;
        background: var(--bg);
        color: var(--text);
        line-height: 1.5;
        font-size: 15px;
        position: relative;
    }

    h1, h2, h3, h4 {
        color: var(--text-strong);
        letter-spacing: -0.02em;
        line-height: 1.2;
    }
    h1 { font-size: clamp(1.75rem, 1.4rem + 1vw, 2.25rem); font-weight: 700; letter-spacing: -0.03em; }
    h2 { font-size: 1.2rem; font-weight: 650; }
    h3 { font-size: 1.05rem; font-weight: 600; }

    a { color: var(--accent); transition: color var(--motion-fast) var(--ease-out); }
    a:hover { color: var(--accent-hover); }

    code, kbd, samp, pre {
        font-family: var(--font-mono);
        font-size: 0.875em;
    }
    code {
        padding: 0.12em 0.4em;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: var(--radius-xs);
        font-size: 0.85em;
    }
    kbd {
        padding: 0.1em 0.45em;
        background: var(--surface-2);
        border: 1px solid var(--border-strong);
        border-bottom-width: 2px;
        border-radius: var(--radius-xs);
        font-size: 0.78em;
        font-weight: 500;
        color: var(--muted);
    }

    p { margin: 0; }
    p + p { margin-top: var(--space-3); }

    hr {
        border: 0;
        height: 1px;
        background: var(--border);
        margin: var(--space-6) 0;
    }

    ::selection {
        background: var(--accent-soft);
        color: var(--text-strong);
    }

    /* Scrollbar */
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--border-strong) transparent;
    }
    *::-webkit-scrollbar { width: 10px; height: 10px; }
    *::-webkit-scrollbar-track { background: transparent; }
    *::-webkit-scrollbar-thumb {
        background: var(--border-strong);
        border-radius: 8px;
        border: 2px solid transparent;
        background-clip: padding-box;
    }
    *::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; border: 2px solid transparent; }
}

/* ==========================================================================
   Aurora background — camada fixa, pintada UMA vez, sem animação, sem blur.
   (Tudo isto era caríssimo em GPU: blur(90px) animado + backdrop-filter
   em N cards = scroll lag.) Mantemos o efeito estético via radial-gradients
   numa camada fixed que nunca repinta.
   ========================================================================== */
@layer base {
    .aurora {
        position: fixed;
        inset: 0;
        z-index: -1;
        pointer-events: none;
        background:
            radial-gradient(ellipse 80vmax 60vmax at 12% 8%,  hsla(232, 100%, 65%, var(--aurora-a, 0.20)), transparent 55%),
            radial-gradient(ellipse 70vmax 55vmax at 88% 18%, hsla(189, 90%, 55%, var(--aurora-b, 0.15)), transparent 60%),
            radial-gradient(ellipse 75vmax 60vmax at 50% 110%, hsla(272, 100%, 65%, var(--aurora-c, 0.17)), transparent 60%);
    }
    .aurora > span { display: none; } /* legado */

    [data-theme="light"] {
        --aurora-a: 0.10;
        --aurora-b: 0.08;
        --aurora-c: 0.09;
    }

    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            transition-duration: 0.01ms !important;
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
        }
    }
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
@layer components {
    /* ---- Header ---- */
    .site-header {
        position: sticky;
        top: 0;
        z-index: 50;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: 0 var(--space-6);
        height: var(--header-h);
        background: var(--surface-glass-strong);
        border-bottom: 1px solid var(--border);
    }

    .brand {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        font-weight: 700;
        letter-spacing: -0.025em;
        font-size: 1.05rem;
        color: var(--text-strong);
        padding: var(--space-2) var(--space-2) var(--space-2) 0;
    }
    .brand__mark {
        display: inline-block;
        width: 28px;
        height: 28px;
        background: url("/assets/grandus-mark.svg") center/contain no-repeat;
        flex-shrink: 0;
    }
    .brand:hover { color: var(--text-strong); }

    .nav-pill {
        display: flex;
        align-items: center;
        gap: 2px;
        padding: 4px;
        background: var(--surface-2);
        border: 1px solid var(--hairline);
        border-radius: var(--radius-pill);
        margin: 0 auto 0 var(--space-4);
    }
    .nav-item {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border-radius: var(--radius-pill);
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--muted);
        transition: color var(--motion-fast) var(--ease-out),
                    background-color var(--motion-fast) var(--ease-out);
        position: relative;
        white-space: nowrap;
    }
    .nav-item__icon {
        width: 16px;
        height: 16px;
        opacity: 0.85;
        flex-shrink: 0;
    }
    .nav-item:hover { color: var(--text); background: var(--surface-3); }
    .nav-item.is-active {
        color: var(--accent-fg);
        background: linear-gradient(135deg, var(--accent), color-mix(in oklab, var(--accent), var(--aurora-3) 35%));
        box-shadow: 0 4px 20px -6px hsla(232, 100%, 70%, 0.5);
    }
    .nav-item.is-active .nav-item__icon { opacity: 1; }

    .header-right {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        margin-left: auto;
    }

    @media (max-width: 1100px) {
        .nav-item span { display: none; }
        .nav-item { padding: 6px 10px; }
    }
    @media (max-width: 720px) {
        .site-header { padding: 0 var(--space-3); gap: var(--space-2); }
        .brand__name { display: none; }
        .nav-pill { margin: 0 auto; padding: 3px; }
        .nav-item__icon { width: 18px; height: 18px; }
        .user-menu > summary { padding: 3px 3px 3px 8px; font-size: 0.78rem; }
        .user-menu__email { font-size: 0.75rem; }
    }

    .icon-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        padding: 0;
        background: transparent;
        border: 1px solid var(--hairline);
        border-radius: var(--radius);
        color: var(--muted);
        transition: all var(--motion-fast) var(--ease-out);
    }
    .icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }
    .icon-btn svg { width: 18px; height: 18px; }
    .icon-btn.theme-toggle .icon-sun,
    .icon-btn.theme-toggle .icon-moon { display: none; }
    [data-theme="dark"] .icon-btn.theme-toggle .icon-sun { display: block; }
    [data-theme="light"] .icon-btn.theme-toggle .icon-moon { display: block; }

    /* ---- User menu (popover via <details>) ---- */
    .user-menu { position: relative; }
    .user-menu > summary {
        list-style: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        padding: 4px 4px 4px 10px;
        background: var(--surface-2);
        border: 1px solid var(--hairline);
        border-radius: var(--radius-pill);
        font-size: 0.85rem;
        font-weight: 500;
        color: var(--text);
        transition: all var(--motion-fast) var(--ease-out);
    }
    .user-menu > summary::-webkit-details-marker,
    .user-menu > summary::marker { display: none; }
    .user-menu > summary:hover { border-color: var(--border); background: var(--surface-3); }
    .user-menu[open] > summary { border-color: var(--accent); }

    .avatar {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--aurora-1), var(--aurora-3));
        color: #fff;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0;
        text-transform: uppercase;
        flex-shrink: 0;
    }
    .avatar--lg { width: 40px; height: 40px; font-size: 0.95rem; }

    .user-menu__panel {
        position: absolute;
        right: 0;
        top: calc(100% + 8px);
        min-width: 240px;
        padding: var(--space-2);
        background: var(--surface-glass-strong);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
        z-index: 60;
        animation: pop-in var(--motion-base) var(--ease-out);
    }
    @keyframes pop-in {
        from { opacity: 0; transform: translateY(-6px) scale(0.98); }
        to   { opacity: 1; transform: translateY(0) scale(1); }
    }
    .user-menu__header {
        padding: var(--space-3) var(--space-3) var(--space-2);
        border-bottom: 1px solid var(--hairline);
        margin-bottom: var(--space-2);
    }
    .user-menu__email {
        font-size: 0.78rem;
        color: var(--muted);
        word-break: break-all;
    }
    .menu-item {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        width: 100%;
        padding: var(--space-2) var(--space-3);
        height: auto;
        border-radius: var(--radius-sm);
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--text);
        background: none;
        border: 0;
        text-align: left;
        box-shadow: none;
        cursor: pointer;
        transition: background var(--motion-fast) var(--ease-out);
    }
    button.menu-item, button.menu-item:hover { box-shadow: none; transform: none; }
    .menu-item svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
    .menu-item:hover { background: var(--surface-2); color: var(--text-strong); }
    .menu-item:hover svg { color: var(--accent); }
    .menu-item--danger:hover { background: var(--danger-soft); color: var(--danger); }
    .menu-item--danger:hover svg { color: var(--danger); }

    /* ---- Main container ---- */
    .main {
        max-width: 980px;
        margin: 0 auto;
        padding: var(--space-8) var(--space-5) var(--space-12);
    }
    .main--wide { max-width: var(--container); }
    .main--narrow { max-width: 460px; padding-top: var(--space-16); }
    .main--auth {
        max-width: none;
        padding: 0;
        min-height: 100vh;
        display: grid;
        place-items: center;
    }

    /* ---- Page header ---- */
    .page-header {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-4);
        margin-bottom: var(--space-6);
        padding-bottom: var(--space-4);
        border-bottom: 1px solid var(--hairline);
    }
    .page-header h1 {
        margin: 0;
        display: flex;
        align-items: center;
        gap: var(--space-3);
    }
    .page-header h1 svg {
        width: 28px;
        height: 28px;
        color: var(--accent);
        opacity: 0.9;
    }
    .page-header__subtitle {
        display: block;
        margin-top: var(--space-2);
        color: var(--muted);
        font-size: 0.9rem;
        font-weight: 400;
        letter-spacing: 0;
    }
    .page-header__actions {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        flex-wrap: wrap;
    }
}

/* ==========================================================================
   Buttons
   ========================================================================== */
@layer components {
    button, .button {
        --btn-bg: var(--accent);
        --btn-fg: var(--accent-fg);
        --btn-border: var(--accent);

        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 0 14px;
        height: 36px;
        background: var(--btn-bg);
        color: var(--btn-fg);
        border: 1px solid var(--btn-border);
        border-radius: var(--radius);
        font-size: 0.875rem;
        font-weight: 550;
        letter-spacing: -0.005em;
        cursor: pointer;
        text-decoration: none;
        transition: background-color var(--motion-fast) var(--ease-out),
                    border-color var(--motion-fast) var(--ease-out),
                    color var(--motion-fast) var(--ease-out),
                    transform var(--motion-instant) var(--ease-out),
                    box-shadow var(--motion-fast) var(--ease-out);
        white-space: nowrap;
        box-shadow: var(--accent-glow);
    }
    button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
    button:active, .button:active { transform: translateY(1px); }
    button:disabled, .button:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

    button svg, .button svg { width: 15px; height: 15px; flex-shrink: 0; }

    /* Variants */
    button.secondary, .button.secondary,
    button.subtle, .button.subtle {
        --btn-bg: var(--surface-2);
        --btn-fg: var(--text);
        --btn-border: var(--border);
        box-shadow: none;
    }
    button.secondary:hover, .button.secondary:hover,
    button.subtle:hover, .button.subtle:hover {
        background: var(--surface-3);
        border-color: var(--border-strong);
        color: var(--text-strong);
    }

    button.ghost, .button.ghost,
    button.button--ghost, .button.button--ghost {
        --btn-bg: transparent;
        --btn-fg: var(--muted);
        --btn-border: transparent;
        box-shadow: none;
    }
    button.ghost:hover, .button.ghost:hover,
    .button.button--ghost:hover {
        background: var(--surface-2);
        color: var(--text);
    }

    button.danger, .button.danger {
        --btn-bg: transparent;
        --btn-fg: var(--danger);
        --btn-border: var(--danger-soft);
        box-shadow: none;
    }
    button.danger:hover, .button.danger:hover {
        background: var(--danger-soft);
        border-color: var(--danger);
        color: var(--danger);
    }

    button.primary, .button.primary {
        --btn-bg: var(--success);
        --btn-fg: #052e1a;
        --btn-border: var(--success);
        box-shadow: 0 0 0 1px hsla(142, 70%, 60%, 0.35), 0 8px 24px -10px hsla(142, 70%, 50%, 0.4);
    }
    button.primary:hover, .button.primary:hover {
        background: color-mix(in oklab, var(--success), white 8%);
        border-color: color-mix(in oklab, var(--success), white 8%);
    }

    .button--sm { height: 28px; padding: 0 10px; font-size: 0.8rem; border-radius: var(--radius-sm); }
    .button--lg { height: 44px; padding: 0 20px; font-size: 0.95rem; }
    .button--block { width: 100%; }

    .link-button {
        background: none; border: 0; padding: 0;
        color: var(--accent);
        cursor: pointer;
        text-decoration: underline;
        text-underline-offset: 2px;
        height: auto;
        box-shadow: none;
    }
    .link-button:hover { color: var(--accent-hover); background: none; transform: none; }
    .link-button:active { transform: none; }
}

/* ==========================================================================
   Cards
   ========================================================================== */
@layer components {
    .card {
        position: relative;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        padding: var(--space-5);
        margin-bottom: var(--space-5);
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    .card--bare { background: transparent; box-shadow: none; border-color: transparent; }
    .card--flush { padding: 0; overflow: hidden; }

    .card > h2:first-child,
    .card > h3:first-child {
        margin-top: 0;
        margin-bottom: var(--space-3);
    }

    .card-hero {
        position: relative;
        border-radius: var(--radius-xl);
        padding: var(--space-8) var(--space-6);
        background:
            radial-gradient(circle at 0% 0%, hsla(232, 100%, 70%, 0.18) 0, transparent 50%),
            radial-gradient(circle at 100% 100%, hsla(272, 100%, 70%, 0.18) 0, transparent 50%),
            var(--surface);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        overflow: hidden;
    }

    /* KPI cards */
    .kpi-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: var(--space-4);
        margin-bottom: var(--space-6);
    }
    .dashboard-refresh-badge {
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }
    .kpi-card {
        position: relative;
        padding: var(--space-5);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        overflow: hidden;
        transition: transform var(--motion-base) var(--ease-out),
                    box-shadow var(--motion-base) var(--ease-out),
                    border-color var(--motion-fast) var(--ease-out);
    }
    .kpi-card:hover {
        transform: translateY(-2px);
        border-color: var(--border-strong);
        box-shadow: var(--shadow-md);
    }
    .kpi-card::before {
        content: "";
        position: absolute;
        inset: 0 0 auto 0;
        height: 2px;
        background: linear-gradient(90deg, var(--accent), var(--aurora-2));
        opacity: 0.8;
    }
    .kpi-card--warn::before { background: linear-gradient(90deg, var(--warn), var(--aurora-4)); }
    .kpi-card--danger::before { background: linear-gradient(90deg, var(--danger), var(--aurora-3)); }
    .kpi-card--success::before { background: linear-gradient(90deg, var(--success), var(--aurora-2)); }

    .kpi-card__label {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        font-size: 0.78rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
        margin: 0 0 var(--space-3);
    }
    .kpi-card__label svg { width: 14px; height: 14px; opacity: 0.8; }
    .kpi-card__value {
        font-size: clamp(2rem, 1.7rem + 1vw, 2.75rem);
        font-weight: 700;
        line-height: 1;
        letter-spacing: -0.03em;
        color: var(--text-strong);
        font-feature-settings: "tnum" 1, "cv11" 1;
        margin: 0;
    }
    .kpi-card__hint {
        margin-top: var(--space-2);
        font-size: 0.8rem;
        color: var(--muted);
    }
    .kpi-card__value-suffix {
        font-size: 1.1rem;
        font-weight: 500;
        color: var(--muted);
        margin-left: 2px;
    }

    .kpi-progress {
        position: relative;
        min-width: 7rem;
        height: 22px;
        background: var(--surface-2);
        border-radius: var(--radius-pill);
        overflow: hidden;
        border: 1px solid var(--hairline);
    }
    .kpi-progress__bar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        background: linear-gradient(90deg, var(--success), color-mix(in oklab, var(--success), var(--aurora-2) 40%));
        border-radius: var(--radius-pill);
        transition: width var(--motion-base) var(--ease-out);
    }
    .kpi-progress__label {
        position: relative;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        font-size: 0.72rem;
        font-weight: 600;
        color: var(--text);
        text-shadow: 0 0 4px var(--surface);
    }

    .table--kpi th.right,
    .table--kpi td.right {
        text-align: right;
        white-space: nowrap;
    }
    .table--kpi .kpi-progress {
        min-width: 5.5rem;
    }
}

/* ==========================================================================
   Tables
   ========================================================================== */
@layer components {
    .table-wrap {
        width: 100%;
        overflow-x: auto;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }

    .table {
        width: 100%;
        border-collapse: collapse;
        font-size: 0.875rem;
        margin: 0;
    }
    .table th,
    .table td {
        text-align: left;
        padding: 12px 14px;
        vertical-align: middle;
        border-bottom: 1px solid var(--hairline);
    }
    .table th:first-child, .table td:first-child { padding-left: 20px; }
    .table th:last-child, .table td:last-child { padding-right: 20px; }
    .table th {
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        color: var(--muted);
        background: var(--surface-2);
    }
    .table tbody tr {
        transition: background-color var(--motion-fast) var(--ease-out);
    }
    .table tbody tr:hover { background: var(--accent-soft); }
    .table tbody tr:last-child td { border-bottom: 0; }
    .table--align-top td { vertical-align: top; }
    .summary-table th, .summary-table td { padding: 10px 14px; font-size: 0.85rem; }

    /* Sticky first column — mantém o título/utilizador visível ao fazer
       scroll horizontal em tabelas largas. Sombra subtil indica overflow. */
    .table--sticky-first th:first-child,
    .table--sticky-first td:first-child {
        position: sticky;
        left: 0;
        background: var(--surface);
        z-index: 2;
        box-shadow: 1px 0 0 var(--hairline);
    }
    .table--sticky-first thead th:first-child {
        background: var(--surface-2);
        z-index: 3;
    }
    .table--sticky-first tbody tr:hover td:first-child {
        background: color-mix(in oklab, var(--surface), var(--accent-soft) 60%);
    }
}

/* ==========================================================================
   Forms
   ========================================================================== */
@layer components {
    label {
        display: flex;
        flex-direction: column;
        gap: 6px;
        font-size: 0.85rem;
        color: var(--text);
    }
    label > span { font-weight: 500; color: var(--text); letter-spacing: -0.005em; }

    label.inline-label {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: var(--space-2);
        font-size: 0.85rem;
    }
    label.checkbox-label {
        flex-direction: row;
        align-items: center;
        gap: var(--space-2);
        cursor: pointer;
        font-weight: 400;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    input[type="url"],
    input[type="tel"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        width: 100%;
        max-width: 100%;
        padding: 0 12px;
        height: 38px;
        background: var(--surface);
        color: var(--text);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        font-size: 0.9rem;
        transition: border-color var(--motion-fast) var(--ease-out),
                    box-shadow var(--motion-fast) var(--ease-out),
                    background-color var(--motion-fast) var(--ease-out);
        appearance: none;
        -webkit-appearance: none;
    }
    [data-theme="dark"] input,
    [data-theme="dark"] select,
    [data-theme="dark"] textarea {
        background: var(--surface-2);
    }

    textarea {
        min-height: 120px;
        padding: 10px 12px;
        resize: vertical;
        line-height: 1.55;
        height: auto;
    }

    input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
    input:focus, select:focus, textarea:focus {
        outline: none;
        border-color: var(--accent);
        box-shadow: 0 0 0 4px var(--accent-soft);
        background: var(--surface);
    }

    /* Native select arrow */
    select {
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238E97AE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
        background-repeat: no-repeat;
        background-position: right 10px center;
        background-size: 16px;
        padding-right: 36px;
    }

    input[type="checkbox"], input[type="radio"] {
        appearance: none;
        -webkit-appearance: none;
        width: 16px;
        height: 16px;
        padding: 0;
        margin: 0;
        border: 1.5px solid var(--border-strong);
        border-radius: 4px;
        background: var(--surface);
        cursor: pointer;
        transition: all var(--motion-fast) var(--ease-out);
        position: relative;
        flex-shrink: 0;
    }
    input[type="radio"] { border-radius: 50%; }
    input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--accent); }
    input[type="checkbox"]:checked, input[type="radio"]:checked {
        background: var(--accent);
        border-color: var(--accent);
    }
    input[type="checkbox"]:checked::after {
        content: "";
        position: absolute;
        inset: 0;
        background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><path d='M20 6L9 17l-5-5'/></svg>") center/12px no-repeat;
    }
    input[type="radio"]:checked::after {
        content: "";
        position: absolute;
        inset: 3px;
        background: white;
        border-radius: 50%;
    }
    input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
        box-shadow: 0 0 0 4px var(--accent-soft);
    }

    input::placeholder, textarea::placeholder {
        color: var(--subtle);
        opacity: 1;
    }

    input[type="search"]::-webkit-search-cancel-button {
        -webkit-appearance: none;
        appearance: none;
        height: 14px;
        width: 14px;
        background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238E97AE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M18 6L6 18'/><path d='M6 6l12 12'/></svg>") center/contain no-repeat;
        cursor: pointer;
    }

    /* Datetime calendar icon (Firefox/Edge) */
    input[type="datetime-local"]::-webkit-calendar-picker-indicator,
    input[type="date"]::-webkit-calendar-picker-indicator,
    input[type="time"]::-webkit-calendar-picker-indicator {
        filter: var(--cal-filter, none);
        opacity: 0.7;
        cursor: pointer;
    }
    [data-theme="dark"] {
        --cal-filter: invert(1) brightness(1.2);
    }

    /* Input with leading icon */
    .input-icon {
        position: relative;
        display: block;
    }
    .input-icon > svg {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: 16px;
        height: 16px;
        color: var(--muted);
        pointer-events: none;
    }
    .input-icon > input { padding-left: 36px; }

    /* Field grids / filter rows */
    .filters {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
        gap: var(--space-3);
        align-items: end;
    }
    .filters .filters__actions {
        display: flex;
        gap: var(--space-2);
        align-items: flex-end;
    }
    .filters label { font-size: 0.78rem; }
    .filters label > span {
        font-size: 0.72rem;
        color: var(--muted);
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    /* Tag toggle chips */
    .tag-field {
        border: 1px dashed var(--border-strong);
        border-radius: var(--radius-lg);
        padding: var(--space-4);
        margin: 0;
        background: var(--surface-2);
    }
    .tag-field legend {
        font-size: 0.85rem;
        font-weight: 600;
        padding: 0 var(--space-2);
        color: var(--text);
    }
    .tag-toggle-list {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        margin-top: var(--space-3);
    }
    label.tag-toggle {
        display: inline-flex;
        flex-direction: row;
        align-items: center;
        margin: 0;
        cursor: pointer;
    }
    .tag-toggle .tag-toggle__text {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 6px 12px;
        border-radius: var(--radius-pill);
        border: 1px solid var(--border-strong);
        background: var(--surface);
        color: var(--muted);
        font-size: 0.82rem;
        font-weight: 500;
        transition: all var(--motion-fast) var(--ease-out);
    }
    .tag-toggle:hover .tag-toggle__text { color: var(--text); border-color: var(--accent); }
    .tag-toggle input:checked + .tag-toggle__text {
        background: var(--accent-soft);
        border-color: var(--accent);
        color: var(--accent);
        font-weight: 600;
    }
    .tag-toggle input:focus-visible + .tag-toggle__text { box-shadow: 0 0 0 3px var(--accent-soft); }
}

/* ==========================================================================
   Badges & tags
   ========================================================================== */
@layer components {
    .badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 3px 8px;
        border-radius: var(--radius-pill);
        font-size: 0.72rem;
        font-weight: 600;
        line-height: 1.3;
        letter-spacing: 0;
        border: 1px solid transparent;
        background: var(--surface-2);
        color: var(--muted);
        white-space: nowrap;
    }
    .badge::before {
        content: "";
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: currentColor;
        opacity: 0.85;
    }
    .badge--aberta, .badge--bxstatus,
    .badge--info {
        background: var(--info-soft);
        color: var(--info);
        border-color: hsla(199, 92%, 60%, 0.3);
    }
    .badge--em_andamento, .badge--warn {
        background: var(--warn-soft);
        color: var(--warn);
        border-color: hsla(43, 95%, 56%, 0.35);
    }
    .badge--concluida, .badge--success {
        background: var(--success-soft);
        color: var(--success);
        border-color: hsla(142, 70%, 60%, 0.35);
    }
    .badge--danger {
        background: var(--danger-soft);
        color: var(--danger);
        border-color: hsla(0, 90%, 71%, 0.35);
    }
    .badge--neutral {
        background: var(--surface-3);
        color: var(--muted);
    }
    .badge--neutral::before { display: none; }

    /* Used in logs view */
    .tag {
        display: inline-flex;
        align-items: center;
        padding: 2px 8px;
        border-radius: var(--radius-pill);
        font-size: 0.7rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        background: var(--surface-3);
        color: var(--muted);
    }
    .tag--outbound { background: var(--info-soft); color: var(--info); }
    .tag--inbound { background: var(--warn-soft); color: var(--warn); }
    .tag--ok { background: var(--success-soft); color: var(--success); }
    .tag--err { background: var(--danger-soft); color: var(--danger); }
}

/* ==========================================================================
   Flash / Toast
   ========================================================================== */
@layer components {
    .flash-stack {
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        margin-bottom: var(--space-5);
    }
    .flash {
        position: relative;
        display: flex;
        align-items: flex-start;
        gap: var(--space-3);
        padding: 12px 16px;
        border-radius: var(--radius);
        font-size: 0.875rem;
        line-height: 1.5;
        background: var(--surface);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-sm);
        animation: flash-in var(--motion-base) var(--ease-out);
    }
    @keyframes flash-in {
        from { opacity: 0; transform: translateY(-6px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .flash::before {
        content: "";
        position: absolute;
        left: 0; top: 0; bottom: 0;
        width: 3px;
        border-radius: 3px 0 0 3px;
    }
    .flash-error::before, .flash-error.flash-banner::before { background: var(--danger); }
    .flash-success::before, .flash-success.flash-banner::before { background: var(--success); }
    .flash-warn::before, .flash-warn.flash-banner::before { background: var(--warn); }
    .flash-error { color: var(--text); background: color-mix(in oklab, var(--surface), var(--danger-soft) 35%); }
    .flash-success { color: var(--text); background: color-mix(in oklab, var(--surface), var(--success-soft) 35%); }
    .flash-warn { color: var(--text); background: color-mix(in oklab, var(--surface), var(--warn-soft) 35%); }

    .temp-password-reveal {
        margin-bottom: var(--space-5);
        border-color: color-mix(in oklab, var(--success), var(--border) 70%);
        background: color-mix(in oklab, var(--surface), var(--success-soft) 28%);
        box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in oklab, var(--success), transparent 75%);
    }
    .temp-password-reveal__head {
        display: flex;
        align-items: flex-start;
        gap: var(--space-3);
        margin-bottom: var(--space-4);
    }
    .temp-password-reveal__title {
        margin: 0 0 var(--space-1);
        font-size: 1.05rem;
        color: var(--text-strong);
    }
    .temp-password-reveal__row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-3);
    }
    .temp-password-reveal__secret {
        flex: 1;
        min-width: 12rem;
        padding: 12px 16px;
        font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
        font-size: 1.25rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        color: var(--text-strong);
        background: var(--surface);
        border: 1px dashed var(--border-strong);
        border-radius: var(--radius);
        user-select: all;
    }
}

/* ==========================================================================
   Modal
   ========================================================================== */
@layer components {
    .modal-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-4);
        background: var(--bg-veil);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        animation: modal-fade var(--motion-base) var(--ease-out);
    }
    @keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

    .modal {
        width: 100%;
        max-width: 28rem;
        padding: var(--space-6);
        background: var(--surface-glass-strong);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
        color: var(--text);
        animation: modal-pop var(--motion-base) var(--ease-out);
    }
    @keyframes modal-pop {
        from { transform: scale(0.96) translateY(8px); opacity: 0; }
        to   { transform: scale(1) translateY(0); opacity: 1; }
    }
    .modal h2 { margin: 0 0 var(--space-2) 0; font-size: 1.05rem; color: var(--text-strong); }
    .modal p { margin: 0 0 var(--space-2) 0; color: var(--text); font-size: 0.9rem; }
    .modal .modal__hint { color: var(--muted); font-size: 0.825rem; }
    .modal .modal__actions {
        display: flex;
        gap: var(--space-2);
        justify-content: flex-end;
        flex-wrap: wrap;
        margin-top: var(--space-5);
    }
    .modal .modal__actions--stacked { flex-direction: column; align-items: stretch; }
    .modal .modal__actions--stacked button { width: 100%; }
}

/* ==========================================================================
   Loading overlay
   ========================================================================== */
@layer components {
    .loading-overlay {
        position: fixed;
        inset: 0;
        z-index: 2000;
        display: none;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: var(--space-4);
        background: var(--bg-veil);
        color: var(--text);
    }
    .loading-overlay.is-active { display: flex; }
    .loading-overlay__spinner {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 3px solid var(--border-strong);
        border-top-color: var(--accent);
        animation: spin 0.8s linear infinite;
    }
    .loading-overlay__label {
        font-size: 0.85rem;
        color: var(--muted);
        font-weight: 500;
        letter-spacing: 0.01em;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    .loading-overlay__bar {
        position: absolute;
        top: 0; left: 0; right: 0;
        height: 2px;
        background: linear-gradient(90deg, transparent, var(--accent), var(--aurora-3), transparent);
        background-size: 40% 100%;
        background-repeat: no-repeat;
        animation: loading-bar 1.2s ease-in-out infinite;
    }
    @keyframes loading-bar {
        0%   { background-position: -40% 0; }
        100% { background-position: 140% 0; }
    }
}

/* ==========================================================================
   Dashboard & charts
   ========================================================================== */
@layer components {
    .dashboard-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-5);
        margin-bottom: var(--space-8);
    }
    @media (max-width: 900px) {
        .dashboard-grid { grid-template-columns: 1fr; }
    }

    .chart-card {
        position: relative;
        padding: var(--space-5);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        min-height: 300px;
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        overflow: hidden;
    }
    .chart-card h2 {
        font-size: 0.95rem;
        font-weight: 600;
        margin: 0;
        display: flex;
        align-items: center;
        gap: var(--space-2);
    }
    .chart-card h2 svg {
        width: 16px;
        height: 16px;
        color: var(--accent);
        opacity: 0.85;
    }
    .chart-canvas-wrap {
        flex: 1;
        position: relative;
        min-height: 220px;
    }
    .chart-card canvas { max-height: 280px; }
    .chart-card--wide {
        grid-column: 1 / -1;
    }
    .chart-canvas-wrap--tall {
        min-height: clamp(220px, 40vh, 420px);
    }

    .dashboard-section-title {
        font-size: 0.95rem;
        font-weight: 600;
        margin: 0 0 var(--space-4);
        color: var(--text-strong);
        display: flex;
        align-items: center;
        gap: var(--space-2);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        font-size: 0.78rem;
        color: var(--muted);
    }
}

/* ==========================================================================
   Auth (login & required pages)
   ========================================================================== */
@layer components {
    .auth-shell {
        position: relative;
        display: grid;
        grid-template-columns: 1.05fr 1fr;
        min-height: 100vh;
        width: 100%;
        overflow: hidden;
    }
    @media (max-width: 900px) {
        .auth-shell { grid-template-columns: 1fr; }
        .auth-shell__side { display: none; }
    }

    .auth-shell__side {
        position: relative;
        padding: var(--space-12);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        background:
            radial-gradient(circle at 20% 30%, hsla(232, 100%, 70%, 0.45), transparent 40%),
            radial-gradient(circle at 80% 70%, hsla(189, 90%, 60%, 0.4), transparent 45%),
            radial-gradient(circle at 50% 100%, hsla(272, 100%, 70%, 0.4), transparent 50%),
            linear-gradient(180deg, #0A0B14, #06070D);
        color: #fff;
        overflow: hidden;
    }
    .auth-shell__brand {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        font-size: 1.3rem;
        font-weight: 700;
        letter-spacing: -0.025em;
    }
    .auth-shell__brand .brand__mark {
        width: 36px;
        height: 36px;
    }
    .auth-shell__tagline {
        position: relative;
        max-width: 28rem;
    }
    .auth-shell__tagline h2 {
        color: #fff;
        font-size: clamp(1.8rem, 1.4rem + 1.2vw, 2.6rem);
        font-weight: 700;
        letter-spacing: -0.035em;
        line-height: 1.1;
        margin-bottom: var(--space-4);
    }
    .auth-shell__tagline p {
        color: hsla(0, 0%, 100%, 0.75);
        font-size: 1rem;
        line-height: 1.55;
        max-width: 30rem;
    }
    .auth-shell__footer {
        position: relative;
        font-size: 0.78rem;
        color: hsla(0, 0%, 100%, 0.55);
    }

    .auth-shell__main {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-10) var(--space-6);
        background: var(--bg);
    }
    .auth-card {
        width: 100%;
        max-width: 380px;
    }
    .auth-card h1 {
        font-size: 1.65rem;
        margin-bottom: var(--space-2);
    }
    .auth-card__lede {
        color: var(--muted);
        font-size: 0.9rem;
        margin-bottom: var(--space-6);
    }
    .auth-card form {
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
    }
    .auth-card .button { height: 44px; font-size: 0.95rem; }
}

/* ==========================================================================
   Approvals / approval-card / diff
   ========================================================================== */
@layer components {
    .approval-card {
        position: relative;
        padding: var(--space-5);
        background: var(--surface);
        border: 1px solid var(--border);
        border-left: 3px solid var(--warn);
        border-radius: var(--radius-lg);
        margin-bottom: var(--space-4);
    }
    .approval-card__title {
        font-size: 1.1rem;
        font-weight: 650;
        margin: 0 0 var(--space-1);
        color: var(--text-strong);
    }
    .diff-table { font-size: 0.85rem; }
    .diff-table td:first-child { color: var(--muted); width: 28%; font-weight: 500; }
}

/* ==========================================================================
   Logs (live)
   ========================================================================== */
@layer components {
    .logs-filters {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
        gap: var(--space-3);
        align-items: end;
    }
    #logs-table tbody tr.is-new {
        animation: logs-flash 1.6s ease-out;
    }
    @keyframes logs-flash {
        from { background: var(--accent-soft); }
        to   { background: transparent; }
    }
    .logs-live {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--space-3);
        margin-top: var(--space-6);
        margin-bottom: var(--space-3);
    }
    .logs-live__indicator {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-weight: 600;
        font-size: 0.85rem;
        color: var(--success);
    }
    .logs-live__indicator::before {
        content: "";
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--success);
        box-shadow: 0 0 10px var(--success);
        animation: pulse 1.6s ease-in-out infinite;
    }
    .logs-live__indicator[data-state="paused"] { color: var(--warn); }
    .logs-live__indicator[data-state="paused"]::before {
        background: var(--warn);
        box-shadow: none;
        animation: none;
    }
    @keyframes pulse {
        0%, 100% { opacity: 1; transform: scale(1); }
        50% { opacity: 0.4; transform: scale(0.8); }
    }

    /* Native <dialog> for log detail */
    dialog#log-detail-dialog {
        max-width: 960px;
        width: 90vw;
        max-height: 85vh;
        padding: 0;
        background: var(--surface);
        color: var(--text);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
    }
    dialog#log-detail-dialog::backdrop {
        background: var(--bg-veil);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
    dialog#log-detail-dialog > div:first-child {
        padding: var(--space-4) var(--space-5);
        border-bottom: 1px solid var(--border);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    dialog#log-detail-dialog pre {
        padding: var(--space-4) var(--space-5);
        max-height: 70vh;
        overflow: auto;
        font-family: var(--font-mono);
        font-size: 0.78rem;
        margin: 0;
        white-space: pre-wrap;
        word-break: break-word;
    }
}

/* ==========================================================================
   Misc / utilities
   ========================================================================== */
@layer components {
    .stack {
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
    }
    .stack.tight { gap: var(--space-2); }
    .stack.loose { gap: var(--space-5); }

    .row {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-3);
        align-items: flex-start;
    }
    .inline-row {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        align-items: center;
    }
    .inline-form { display: inline; margin: 0; }

    .narrow { max-width: 480px; }
    .wide { width: 100%; }
    textarea.wide, input.wide { max-width: 100%; }

    .grid-stats {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: var(--space-4);
        margin-bottom: var(--space-6);
    }

    .list-inline {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-3);
    }
    .kv {
        display: grid;
        grid-template-columns: max-content 1fr;
        gap: var(--space-2) var(--space-5);
        margin: 0;
    }
    .kv dt {
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--muted);
        font-weight: 600;
        align-self: center;
    }
    .kv dd { margin: 0; color: var(--text); }
}

@layer utilities {
    .muted { color: var(--muted); }
    .subtle { color: var(--subtle); }
    .small { font-size: 0.8rem; }
    .tiny { font-size: 0.72rem; }
    .strong { font-weight: 600; color: var(--text-strong); }
    .center { text-align: center; }
    .right { text-align: right; }
    .mb-0 { margin-bottom: 0 !important; }
    .mb-2 { margin-bottom: var(--space-2); }
    .mb-3 { margin-bottom: var(--space-3); }
    .mb-4 { margin-bottom: var(--space-4); }
    .mt-2 { margin-top: var(--space-2); }
    .mt-3 { margin-top: var(--space-3); }
    .mt-4 { margin-top: var(--space-4); }
    .mt-6 { margin-top: var(--space-6); }
    .nowrap { white-space: nowrap; }

    .sr-only {
        position: absolute;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    /* Empty state */
    .empty-state {
        text-align: center;
        padding: var(--space-12) var(--space-6);
        color: var(--muted);
    }
    .empty-state__icon {
        width: 56px;
        height: 56px;
        margin: 0 auto var(--space-4);
        padding: var(--space-3);
        border-radius: var(--radius-lg);
        background: var(--accent-soft);
        color: var(--accent);
    }
    .empty-state h3 {
        color: var(--text);
        margin: 0 0 var(--space-2);
        font-size: 1rem;
    }
    .empty-state p { font-size: 0.875rem; max-width: 32rem; margin: 0 auto; }
}

/* ==========================================================================
   Command palette (Cmd+K)
   ========================================================================== */
@layer components {
    .cmdk-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1500;
        background: var(--bg-veil);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        display: none;
        align-items: flex-start;
        justify-content: center;
        padding: 12vh var(--space-4) var(--space-4);
    }
    .cmdk-backdrop.is-open { display: flex; }

    .cmdk {
        width: 100%;
        max-width: 36rem;
        background: var(--surface-glass-strong);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg), 0 0 60px -20px hsla(232, 100%, 70%, 0.4);
        overflow: hidden;
        animation: modal-pop var(--motion-base) var(--ease-out);
    }
    .cmdk__input-wrap {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--hairline);
    }
    .cmdk__icon {
        width: 18px;
        height: 18px;
        color: var(--muted);
        flex-shrink: 0;
    }
    .cmdk__input {
        flex: 1;
        background: transparent;
        border: 0;
        height: 28px;
        padding: 0;
        font-size: 1rem;
        color: var(--text);
        outline: none;
    }
    .cmdk__input:focus { box-shadow: none; }
    .cmdk__kbd { font-size: 0.7rem; }

    .cmdk__list {
        list-style: none;
        padding: var(--space-2);
        margin: 0;
        max-height: 50vh;
        overflow-y: auto;
    }
    .cmdk__item {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) var(--space-3);
        border-radius: var(--radius-sm);
        cursor: pointer;
        color: var(--text);
        font-size: 0.9rem;
    }
    .cmdk__item-icon {
        width: 18px;
        height: 18px;
        color: var(--muted);
        flex-shrink: 0;
    }
    .cmdk__item-label { flex: 1; }
    .cmdk__item-hint {
        font-size: 0.72rem;
        color: var(--subtle);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    .cmdk__item.is-active {
        background: var(--accent-soft);
        color: var(--text-strong);
    }
    .cmdk__item.is-active .cmdk__item-icon { color: var(--accent); }
    .cmdk__empty {
        padding: var(--space-6);
        color: var(--muted);
        text-align: center;
        font-size: 0.875rem;
        list-style: none;
    }
    .cmdk__footer {
        display: flex;
        gap: var(--space-4);
        padding: var(--space-2) var(--space-4);
        border-top: 1px solid var(--hairline);
        font-size: 0.75rem;
        color: var(--muted);
    }
    .cmdk__footer kbd { margin-right: 4px; }
}

/* ==========================================================================
   Pagination
   ========================================================================== */
@layer components {
    .pagination {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: var(--space-5);
        gap: var(--space-3);
        flex-wrap: wrap;
        font-size: 0.85rem;
    }
    .pagination__info { color: var(--muted); }
    .pagination__nav {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        padding: 4px;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
    .pagination__nav .button,
    .pagination__nav button {
        height: 30px;
        padding: 0 10px;
        background: transparent;
        color: var(--muted);
        border: 0;
        border-radius: var(--radius-sm);
        box-shadow: none;
        font-weight: 500;
    }
    .pagination__nav .button:hover,
    .pagination__nav button:hover {
        background: var(--surface-3);
        color: var(--text);
        transform: none;
    }
    .pagination__nav .pagination__current {
        padding: 0 12px;
        color: var(--text);
        font-weight: 600;
    }
}
