/* =====================================================================
   Pesco Innovation Hub · design tokens (#959 system, #960 phase 2)
   ---------------------------------------------------------------------
   <html data-theme="auto|light|dark" data-accent="saetta|aglianico|ulivo|ofanto">
   is rendered by base.html from the context (ui_theme, ui_accent). «auto»
   follows prefers-color-scheme in pure CSS, so the first paint is right.

   Dark = today's site, value for value: the legacy names of style.css
   (--primary-bg, --accent-color, --text-secondary, ...) are aliases of these
   tokens, and in dark + Saetta every alias resolves to the colour it had
   before. Pages not migrated yet render their <main>/<footer> with
   data-theme="dark" (base.html, {% block content_theme %}), so in light
   mode they stay dark until their area is migrated (docs/design/system.md §9).

   Theme differences live ONLY in the token blocks below (light is written
   twice: explicit and «auto» on a light device; keep them in sync).
   Loaded after style.css. Spec: docs/design/system.md.
   ===================================================================== */

/* ---------- 1. Foundations (theme-independent) ---------- */
:root {
    --font-display: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-text: 'Roboto', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
    --fs-xs: 0.78rem;
    --fs-sm: 0.875rem;
    --fs-base: 1rem;
    --fs-md: 1.125rem;
    --fs-lg: 1.375rem;
    --fs-xl: 1.75rem;
    --fs-2xl: clamp(2rem, 1.4rem + 2.2vw, 2.75rem);
    --fs-display: clamp(2.4rem, 1.3rem + 4.2vw, 4.25rem);
    --lh-tight: 1.15;
    --lh-text: 1.6;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-pill: 999px;

    --hairline: 1px;
    --focus-width: 3px;

    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --dur-fast: 120ms;
    --dur: 180ms;

    /* Accent pairs, default «Saetta». -l = light theme, -d = dark theme,
       -ink = text on a filled accent. */
    --acc-l: #0A7263;  --acc-l-ink: #FFFFFF;  --acc-l-rgb: 10, 114, 99;
    --acc-d: #39D3BB;  --acc-d-ink: #0D1117;  --acc-d-rgb: 57, 211, 187;
}

/* ---------- 2. Accent palettes ---------- */
[data-accent="saetta"] {     /* Lago Saetta: today's teal */
    --acc-l: #0A7263;  --acc-l-ink: #FFFFFF;  --acc-l-rgb: 10, 114, 99;
    --acc-d: #39D3BB;  --acc-d-ink: #0D1117;  --acc-d-rgb: 57, 211, 187;
}
[data-accent="aglianico"] {  /* Aglianico del Vulture: wine red */
    --acc-l: #8C1D3B;  --acc-l-ink: #FFFFFF;  --acc-l-rgb: 140, 29, 59;
    --acc-d: #E58A9E;  --acc-d-ink: #2B0A13;  --acc-d-rgb: 229, 138, 158;
}
[data-accent="ulivo"] {      /* olive groves: olive / sage */
    --acc-l: #4E6B2C;  --acc-l-ink: #FFFFFF;  --acc-l-rgb: 78, 107, 44;
    --acc-d: #AFC982;  --acc-d-ink: #18220C;  --acc-d-rgb: 175, 201, 130;
}
[data-accent="ofanto"] {     /* the Ofanto river: stone / river blue */
    --acc-l: #2C5A88;  --acc-l-ink: #FFFFFF;  --acc-l-rgb: 44, 90, 136;
    --acc-d: #93B9E6;  --acc-d-ink: #0B1A2B;  --acc-d-rgb: 147, 185, 230;
}

/* ---------- 3. Themes ---------- */
/* Dark: the default and today's look (values = the old :root of style.css). */
:root,
[data-theme="dark"],
[data-theme="auto"] {
    color-scheme: dark;
    --is-light: 0;
    --fx: 1;                       /* decorative glows/gradients on (today) */

    --bg: #0A0F18;            --bg-rgb: 10, 15, 24;
    --surface: #1A202C;       --surface-rgb: 26, 32, 44;
    --surface-2: #222A37;
    --text: #E2E8F0;
    --text-muted: #A0AEC0;
    --border: #2D3748;
    --border-strong: #3B4555;
    --scrim: rgba(10, 15, 24, 0.72);

    --accent: var(--acc-d);
    --accent-rgb: var(--acc-d-rgb);
    --accent-contrast: var(--acc-d-ink);
    --accent-soft: rgba(var(--acc-d-rgb), 0.14);
    --accent-hover: color-mix(in srgb, var(--acc-d) 85%, #000000);

    --ok: #5DD39A;     --ok-soft: rgba(93, 211, 154, 0.12);
    --warn: #F2B84B;   --warn-soft: rgba(242, 184, 75, 0.12);
    --danger: #FC8181; --danger-soft: rgba(252, 129, 129, 0.12);
    --info: #7FB6F0;   --info-soft: rgba(127, 182, 240, 0.12);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.45);

    /* component tokens: today's dark effects */
    --hairline-color: rgba(255, 255, 255, 0.08);
    --ctrl-bg: rgba(255, 255, 255, 0.03);
    --hover-bg: rgba(255, 255, 255, 0.05);
    --menu-bg: color-mix(in srgb, var(--surface) 88%, transparent);
    --menu-shadow: 0 18px 48px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --menu-shadow-sm: 0 12px 32px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
    --elev-header: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.28);
    --shadow-card-hover: 0 16px 40px rgba(0, 0, 0, 0.4);
    --title-fade-end: var(--acc-d);   /* the home title's gradient end */
    --thumb-bg: #0D1420;
    --theme-color: #0A0F18;
    /* membership tiers and roles (badges): today's colours */
    --tier-member: #39D3BB;
    --tier-member-plus: #818CF8;
    --tier-advisor: #F59E0B;
    --tier-guest: #A0AEC0;
    --tier-partner: #EC4899;
    --tier-staff: #3B82F6;
    --tier-admin: #EF4444;
}

[data-theme="light"] {
    color-scheme: light;
    --is-light: 1;
    --fx: 0;                       /* no glows or decorative gradients */

    --bg: #FAFAF8;            --bg-rgb: 250, 250, 248;
    --surface: #FFFFFF;       --surface-rgb: 255, 255, 255;
    --surface-2: #F3F2EE;
    --text: #16191D;
    --text-muted: #5A6069;
    --border: #E3E1DB;
    --border-strong: #CFCCC4;
    --scrim: rgba(250, 250, 248, 0.78);

    --accent: var(--acc-l);
    --accent-rgb: var(--acc-l-rgb);
    --accent-contrast: var(--acc-l-ink);
    --accent-soft: rgba(var(--acc-l-rgb), 0.10);
    --accent-hover: color-mix(in srgb, var(--acc-l) 85%, #000000);

    --ok: #18703F;     --ok-soft: rgba(24, 112, 63, 0.12);
    --warn: #8A5A00;   --warn-soft: rgba(138, 90, 0, 0.12);
    --danger: #B42318; --danger-soft: rgba(180, 35, 24, 0.10);
    --info: #1D5FA6;   --info-soft: rgba(29, 95, 166, 0.10);

    --shadow-1: 0 1px 2px rgba(22, 25, 29, 0.06), 0 1px 3px rgba(22, 25, 29, 0.06);
    --shadow-2: 0 12px 32px rgba(22, 25, 29, 0.12);

    --hairline-color: var(--border);
    --ctrl-bg: var(--surface);
    --hover-bg: var(--surface-2);
    --menu-bg: var(--surface);
    --menu-shadow: var(--shadow-2);
    --menu-shadow-sm: var(--shadow-2);
    --elev-header: var(--shadow-1);
    --shadow-card: var(--shadow-1);
    --shadow-card-hover: var(--shadow-2);
    --title-fade-end: var(--text);
    --thumb-bg: var(--surface-2);
    --theme-color: #FAFAF8;
    --tier-member: #086357;
    --tier-member-plus: #4F46E5;
    --tier-advisor: #8A5A00;
    --tier-guest: #5A6069;
    --tier-partner: #A3154F;
    --tier-staff: #1D4ED8;
    --tier-admin: #B91C1C;
}
/* «auto» on a light device: the same values as [data-theme="light"]. */
@media (prefers-color-scheme: light) {
    [data-theme="auto"] {
        color-scheme: light;
        --is-light: 1;
        --fx: 0;
        --bg: #FAFAF8;            --bg-rgb: 250, 250, 248;
        --surface: #FFFFFF;       --surface-rgb: 255, 255, 255;
        --surface-2: #F3F2EE;
        --text: #16191D;
        --text-muted: #5A6069;
        --border: #E3E1DB;
        --border-strong: #CFCCC4;
        --scrim: rgba(250, 250, 248, 0.78);
        --accent: var(--acc-l);
        --accent-rgb: var(--acc-l-rgb);
        --accent-contrast: var(--acc-l-ink);
        --accent-soft: rgba(var(--acc-l-rgb), 0.10);
        --accent-hover: color-mix(in srgb, var(--acc-l) 85%, #000000);
        --ok: #18703F;     --ok-soft: rgba(24, 112, 63, 0.12);
        --warn: #8A5A00;   --warn-soft: rgba(138, 90, 0, 0.12);
        --danger: #B42318; --danger-soft: rgba(180, 35, 24, 0.10);
        --info: #1D5FA6;   --info-soft: rgba(29, 95, 166, 0.10);
        --shadow-1: 0 1px 2px rgba(22, 25, 29, 0.06), 0 1px 3px rgba(22, 25, 29, 0.06);
        --shadow-2: 0 12px 32px rgba(22, 25, 29, 0.12);
        --hairline-color: var(--border);
        --ctrl-bg: var(--surface);
        --hover-bg: var(--surface-2);
        --menu-bg: var(--surface);
        --menu-shadow: var(--shadow-2);
        --menu-shadow-sm: var(--shadow-2);
        --elev-header: var(--shadow-1);
        --shadow-card: var(--shadow-1);
        --shadow-card-hover: var(--shadow-2);
        --title-fade-end: var(--text);
        --thumb-bg: var(--surface-2);
        --theme-color: #FAFAF8;
        --tier-member: #086357;
        --tier-member-plus: #4F46E5;
        --tier-advisor: #8A5A00;
        --tier-guest: #5A6069;
        --tier-partner: #A3154F;
        --tier-staff: #1D4ED8;
        --tier-admin: #B91C1C;
    }
}

/* ---------- 4. Legacy aliases (until the last area is migrated) ----------
   Declared on every theme root, so a nested data-theme="dark" (unmigrated
   <main>) resolves them again with dark values. */
:root,
[data-theme] {
    --primary-bg: var(--bg);
    --primary-bg-rgb: var(--bg-rgb);
    --secondary-bg: var(--surface);
    --header-bg: var(--surface);
    --footer-bg: var(--surface);
    --glass-bg: rgba(var(--surface-rgb), 0.6);
    --accent-color: var(--accent);
    --accent-color-rgb: var(--accent-rgb);
    --text-primary: var(--text);
    --text-secondary: var(--text-muted);
    --text-on-accent: var(--accent-contrast);
    --border-color: var(--border);
}
/* base.html's .page-shell wraps <main> and <footer>; display: contents keeps
   them flex items of <body>. When it carries data-theme (unmigrated page),
   main paints its own background and text colour from the nested theme. */
.page-shell { display: contents; }
.page-shell[data-theme] > main { background: var(--bg); color: var(--text); }
/* Any other nested theme root (e.g. the Hub rail, moved to <body> by its
   script) re-starts the inherited text colour from its own theme. */
[data-theme]:not(html):not(.page-shell) { color: var(--text); }

/* ---------- 5. Components of the system (opt-in classes) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0 1.15rem;
    border: var(--hairline) solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-text);
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn--sm { min-height: 36px; padding: 0 0.85rem; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn--primary   { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }
.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover { border-color: var(--text-muted); color: var(--text); }
.btn--ghost     { background: transparent; color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger    { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: var(--surface); }
.btn:focus-visible {
    outline: var(--focus-width) solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 2px;
}
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.chip {
    display: inline-flex; align-items: center; gap: 0.3rem;
    min-height: 26px; padding: 0 0.6rem;
    border: var(--hairline) solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); color: var(--text-muted);
    font-size: var(--fs-xs); font-weight: 500;
}
.chip--accent { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.chip--ok     { border-color: transparent; background: var(--ok-soft); color: var(--ok); }
.chip--warn   { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.chip--danger { border-color: transparent; background: var(--danger-soft); color: var(--danger); }

.card {
    background: var(--surface);
    border: var(--hairline) solid var(--border);
    border-radius: var(--radius-md);
}
.input {
    min-height: 44px; padding: 0 0.85rem;
    border: var(--hairline) solid var(--border-strong); border-radius: var(--radius-md);
    background: var(--surface); color: var(--text); font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 var(--focus-width) var(--accent-soft); }

/* An accent swatch: the element carries its own data-accent, so --acc-l and
   --acc-d are that palette's; --is-light (from the theme) picks the variant. */
.accent-swatch {
    display: inline-block;
    flex: none;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--acc-l) calc(var(--is-light) * 100%), var(--acc-d));
    box-shadow: 0 0 0 1px var(--border);
}

@media (prefers-reduced-motion: reduce) {
    .btn, .chip, .input { transition: none; }
}
