/* ----------------------------------------------------------------
   Typography — self-hosted Inter Variable (no CDN, no GDPR exposure).
   ---------------------------------------------------------------- */
@font-face {
    font-family: "InterVariable";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/InterVariable.woff2") format("woff2-variations"),
         url("/fonts/InterVariable.woff2") format("woff2");
}

@font-face {
    font-family: "InterVariable";
    font-style: italic;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/InterVariable-Italic.woff2") format("woff2-variations"),
         url("/fonts/InterVariable-Italic.woff2") format("woff2");
}

/* ----------------------------------------------------------------
   Design tokens — Vitality Dark.
   Translated from design/vitality_dark/DESIGN.md. Material 3 surface
   hierarchy with on-color pairs. Light theme to be layered later via
   [data-theme="light"] override of the same variables.
   ---------------------------------------------------------------- */
:root {
    /* Surface hierarchy (darkest → brightest) */
    --surface-lowest:   #0b0e14;
    --surface:          #101319;
    --surface-low:      #181c22;
    --surface-container:#1c2026;
    --surface-high:     #272a30;
    --surface-highest:  #32353b;
    --surface-bright:   #363940;

    /* Foreground */
    --on-surface:       #e0e2eb;
    --on-surface-muted: #c1c6d4;
    --outline:          #8b919e;
    --outline-variant:  #414752;

    /* Primary (corporate blue) */
    --primary:          #1173d4;
    --primary-hover:    #0f63b8;
    --primary-soft:     rgba(17, 115, 212, 0.15);
    --on-primary:       #faf9ff;

    /* Secondary / tertiary */
    --secondary:        #b5c9df;
    --on-secondary:     #1f3244;
    --tertiary:         #ffb68b;

    /* Semantic */
    --success:          #5dd1a3;
    --success-soft:     rgba(93, 209, 163, 0.10);
    --warning:          #ffb86b;
    --warning-soft:     rgba(255, 184, 107, 0.10);
    --danger:           #ffb4ab;
    --danger-soft:      rgba(255, 180, 171, 0.10);

    /* Aliases used throughout the app */
    --fg:               var(--on-surface);
    --fg-muted:         var(--on-surface-muted);
    --bg:               var(--surface);
    --bg-elevated:      var(--surface-container);
    --line:             var(--outline-variant);
    --line-strong:      var(--outline);
    --accent:           var(--primary);
    --accent-hover:     var(--primary-hover);
    --accent-soft:      var(--primary-soft);

    /* Shape */
    --radius-sm:    0.25rem;
    --radius:       0.5rem;
    --radius-lg:    0.75rem;
    --radius-full:  9999px;

    /* Spacing — 4 / 8 baseline */
    --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-12: 3rem;

    /* Subtle elevation (we mostly use tonal layering, not shadows) */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow:    0 4px 14px rgba(0, 0, 0, 0.35);

    /* Type scale */
    --font-sans: "InterVariable", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --fs-display: 2.25rem;   /* 36 */
    --fs-h1: 1.75rem;        /* 28 */
    --fs-h2: 1.25rem;        /* 20 */
    --fs-body: 1rem;         /* 16 */
    --fs-sm: 0.875rem;       /* 14 */
    --fs-xs: 0.75rem;        /* 12 */
}

/* ----------------------------------------------------------------
   Reset + base
   ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3 { margin: 0 0 var(--space-2); line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
p { margin: 0 0 var(--space-4); }

::selection { background: var(--primary-soft); color: var(--on-surface); }

/* ----------------------------------------------------------------
   Layout shell
   ---------------------------------------------------------------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-8);
    border-bottom: 1px solid var(--line);
    background: var(--surface-low);
    flex-wrap: wrap;
    gap: var(--space-2);
}

.brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--fg);
    letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; color: var(--fg); }

.app-nav {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    flex-wrap: wrap;
}
.app-nav a, .app-nav button {
    color: var(--fg-muted);
    font-size: var(--fs-sm);
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}
.app-nav a:hover, .app-nav button:hover { color: var(--accent); text-decoration: none; }

main {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

.app-footer {
    border-top: 1px solid var(--line);
    color: var(--fg-muted);
    font-size: var(--fs-xs);
    text-align: center;
    padding: var(--space-6);
    background: var(--surface-low);
}
.app-footer a { color: var(--fg-muted); }

/* ----------------------------------------------------------------
   Components
   ---------------------------------------------------------------- */
.lede {
    color: var(--fg-muted);
    font-size: 1.05rem;
    margin-bottom: var(--space-8);
}

/* Buttons --------------------------------------------------------- */
.btn {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; color: var(--on-primary); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--surface-high); color: var(--fg-muted); cursor: not-allowed; }
.btn-large { padding: 0.85rem 2rem; font-size: 1rem; }
.btn-quiet {
    background: var(--surface-container);
    color: var(--fg);
    border: 1px solid var(--line-strong);
}
.btn-quiet:hover { background: var(--surface-high); color: var(--fg); }

/* Cards ----------------------------------------------------------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-4);
}
.card {
    background: var(--surface-container);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}
.card h2 { margin-bottom: var(--space-2); font-size: 1rem; font-weight: 600; }
.card p { color: var(--fg-muted); font-size: var(--fs-sm); margin-bottom: var(--space-3); }

/* Chart cards ----------------------------------------------------- */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-4);
}
.chart-card {
    background: var(--surface-container);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    min-height: 280px;
}
.chart-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-3);
}
.chart-card .chart-canvas-wrap {
    flex: 1;
    position: relative;
    min-height: 180px;
}
.chart-card canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
    color: var(--fg-muted);
    font-size: var(--fs-sm);
    margin: auto 0;
    text-align: center;
    padding: var(--space-4);
}

/* Status chips (low-opacity background, high-contrast text) ------- */
.chip {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-danger  { background: var(--danger-soft);  color: var(--danger); }

/* Backwards-compat alias — the existing templates use ".tag" */
.tag { @extend .chip; } /* fallback if PostCSS — not used. Keep below. */

/* Documents ------------------------------------------------------- */
.doc {
    background: var(--surface-container);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
}
.doc h2 { margin-top: 0; }

/* Notices --------------------------------------------------------- */
.notice-success {
    color: var(--success);
    font-weight: 600;
    padding: var(--space-3);
    background: var(--success-soft);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
}

/* Misc ------------------------------------------------------------ */
.versions {
    color: var(--fg-muted);
    font-size: var(--fs-sm);
    margin-bottom: var(--space-8);
}

.center-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-8) var(--space-6);
}
.center-stage main { max-width: 520px; padding: 0; }

.fine-print {
    color: var(--fg-muted);
    font-size: var(--fs-xs);
    margin-top: var(--space-6);
}

/* ----------------------------------------------------------------
   Plain ".tag" alias (used by existing dashboard.html). Mirrors
   .chip styles so existing markup keeps working.
   ---------------------------------------------------------------- */
.tag {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ----------------------------------------------------------------
   App shell — sidebar layout for authenticated screens
   ---------------------------------------------------------------- */
.app-shell {
    flex: 1;
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-content > main {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

/* Sidebar shell --------------------------------------------------- */
.app-sidebar {
    flex: 0 0 288px;
    width: 288px;
    background: var(--surface-low);
    border-right: 1px solid var(--line);
    padding: var(--space-6) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-6);
    color: var(--fg);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.sidebar-brand:hover { text-decoration: none; color: var(--fg); }

.sidebar-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0.55rem var(--space-3);
    border-radius: var(--radius);
    color: var(--fg-muted);
    font-size: var(--fs-sm);
    font-weight: 500;
    transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-link:hover {
    background: var(--surface-container);
    color: var(--fg);
    text-decoration: none;
}
.sidebar-link.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}
.sidebar-link.is-disabled {
    color: var(--fg-muted);
    opacity: 0.55;
    cursor: not-allowed;
}
.sidebar-link.is-disabled:hover {
    background: transparent;
    color: var(--fg-muted);
}

/* Sidebar user footer -------------------------------------------- */
.sidebar-user {
    border-top: 1px solid var(--line);
    padding-top: var(--space-4);
    margin-top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-2);
}

.sidebar-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--surface-high);
    color: var(--fg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--fs-sm);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-user-text {
    min-width: 0;
    flex: 1;
}
.sidebar-user-name {
    color: var(--fg);
    font-size: var(--fs-sm);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-meta {
    color: var(--fg-muted);
    font-size: var(--fs-xs);
}

.sidebar-signout {
    width: 100%;
    padding: 0.5rem var(--space-3);
    font-size: var(--fs-sm);
}

/* ----------------------------------------------------------------
   Mobile — sidebar collapses to a horizontal top bar at < 768px
   ---------------------------------------------------------------- */
@media (max-width: 600px) {
    .app-header { padding: var(--space-3) var(--space-4); }
    main, .app-content > main { padding: var(--space-6) var(--space-4); }
    h1 { font-size: 1.5rem; }
    .app-nav { gap: var(--space-3); }
}

@media (max-width: 768px) {
    .app-shell { flex-direction: column; }
    .app-sidebar {
        flex: 0 0 auto;
        width: 100%;
        height: auto;
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: var(--space-3) var(--space-4);
    }
    .sidebar-brand { margin-bottom: var(--space-3); }
    .sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
        gap: var(--space-2);
        padding-bottom: var(--space-2);
    }
    .sidebar-link {
        flex-shrink: 0;
        white-space: nowrap;
    }
    .sidebar-link .chip { display: none; } /* Hide phase tags on mobile to save space */
    .sidebar-user {
        border-top: 1px solid var(--line);
        margin-top: var(--space-3);
        padding-top: var(--space-3);
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .sidebar-signout { width: auto; }
}
