/*
 * Design tokens (plan.md §8).
 *
 * Every colour, size, radius, shadow and timing the components use is a
 * custom property here. Components never use raw values, so each screen is
 * designed for both themes from the start.
 *
 * Themes: light by default. Dark follows the device setting, unless the
 * person picked a theme by hand (data-theme="light" | "dark" on <html>,
 * set before the first paint by static/js/theme.js).
 *
 * The dark values appear twice below (once for the device setting, once for
 * the manual choice) because plain CSS cannot share one block between a media
 * query and an attribute selector. tests/test_design_system.py fails if the
 * two blocks ever differ, and checks the contrast of every colour pair.
 */

:root {
  color-scheme: light;

  /* --- Neutrals (direction D, 18/11/2026): grey page, white cards, hairlines,
     everything black and grey; one blue only where time is booked. */
  --bg: #e7e7e9;
  --surface: #ffffff;
  --surface-2: #f4f4f5;       /* secondary buttons, segmented track */
  --surface-3: #e9e9ec;       /* hover on surface-2 */
  --text: #171717;
  --text-muted: #525252;
  --text-disabled: #8b8b90;
  --border: #dcdce0;          /* decorative: cards, dividers */
  --border-strong: #85858b;   /* fields: at least 3:1 against the card */
  --primary: #171717;         /* the black pill */
  --primary-hover: #333336;
  --on-primary: #ffffff;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #15803d;

  /* Free time (soft green) and unavailable time (hatched), as in docs/reference-calendar.png */
  --free-bg: #f4f4f5;
  --free-bg-hover: #e9e9ec;
  --free-border: #d4d4d8;
  --free-text: #3f3f46;
  --closed-a: #efeff1;
  --closed-b: #e4e4e7;
  /* Behind QR codes: white in both themes, so every camera reads them. */
  --qr-bg: #ffffff;
  /* The platform panel's bar charts (one series each): the honey of the
     panel, at least 3:1 against the card in both themes, and inside the
     lightness band the dataviz checks ask for (L 0.43-0.77 light, 0.48-0.67
     dark), so dark mode has its own, deeper step. */
  --chart-bar: #b07a10;

  /* --- The platform's own colour (D: one blue): the logo's filled time and
     the landing page's main button. Decoration only:
     text never sits on them alone (it uses --accent and --primary). */
  --brand-1: #ecae36;   /* violet */
  --brand-2: #d9961a;   /* cyan */
  --brand-3: #ecae36;   /* pink */
  /* Fills that carry white text (the landing's main button): deep ends of
     the same gradient, white on both at least 4.5:1 (tests). */
  --brand-ink-1: #8a5d00;
  --brand-ink-2: #8a5d00;

  --shadow-rgb: 0 0 0;
  --shadow-card: 0 1px 2px rgb(var(--shadow-rgb) / 0.05);
  --shadow-float: 0 1px 2px rgb(var(--shadow-rgb) / 0.06), 0 12px 32px -12px rgb(var(--shadow-rgb) / 0.18);
  --scrim: rgb(22 22 20 / 0.34);   /* behind sheets */

  /* --- Accent: 8 presets, one per shop (Business.accent_color) ---------- *
   * Light theme: dark enough for white text on them and for use as text on
   * the page (both at least 4.5:1).                                        */
  --acc-terracotta: #a8461f;
  --acc-pomegranate: #b02e4f;
  --acc-plum: #7e3a84;
  --acc-honey: #8a5d00;
  --acc-sea: #1f64a3;
  --acc-cypress: #19705f;
  --acc-olive: #5a6a1e;
  --acc-ochre: #8f5d00;
  --accent: var(--acc-honey);
  /* How strongly the accent tints the page background. Text placed directly on
     the page stays AA over the strongest point (checked by the tests). */
  --glow-strength: 0%;

  /* --- Glass (floating controls only, never content) --------------------- *
   * Fill is the theme's tint at --glass-alpha. The alpha never drops below
   * the floor that keeps --text at WCAG AA over a pure black (light theme)
   * or pure white (dark theme) background, sheen included: 0.50 light,
   * 0.68 dark. tests/test_design_system.py checks every preset.            */
  --glass-tint: 255 255 255;
  --glass-alpha: var(--glass-alpha-light);
  --glass-edge: rgb(0 0 0 / 0.06);      /* thin bright top edge */
  --glass-rim: rgb(0 0 0 / 0.06);        /* hairline all round */
  --glass-sheen: rgb(255 255 255 / 0);     /* light falling on the top half */
  --glass-solid: #ffffff;                     /* fallback without blur */

  /* Intensity preset (data-glass on <html>). Default: "bold". */
  --glass-blur: 0px;
  --glass-saturate: 100%;
  --glass-alpha-light: 1;
  --glass-alpha-dark: 1;
  --glass-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));

  /* --- Type --------------------------------------------------------------- */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  /* Direction D: one family on screen. The two names stay for the
     components that ask for them; both are Inter now. */
  --font-display: var(--font-sans);
  --font-serif: var(--font-sans);

  /* Nothing on screen is smaller than 16px (plan.md §7.4). */
  --text-sm: 1rem;            /* 16px: labels, captions, buttons */
  --text-md: 1.0625rem;       /* 17px: body */
  --text-lg: 1.25rem;         /* 20px */
  --text-xl: 1.5rem;          /* 24px */
  --text-2xl: clamp(1.75rem, 1.35rem + 1.6vw, 2.25rem);
  --text-3xl: clamp(2.375rem, 1.6rem + 3.4vw, 3.75rem);
  --leading-tight: 1.06;
  --leading-snug: 1.25;
  --leading-body: 1.55;
  --tracking-display: -0.03em;

  /* --- Space, size, shape ------------------------------------------------- */
  --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;

  --control-h: 3rem;          /* 48px: buttons and fields */
  --touch-min: 2.75rem;       /* 44px: nothing tappable is smaller */
  --page-max: 72rem;
  --topbar-h: 3.75rem;

  --radius-sm: 0.625rem;
  --radius-md: 0.75rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.125rem;
  /* "A touch more square" (18/11/2026): what was a pill (buttons, chips,
     segmented controls) has small corners now; --radius-round stays for
     what must be round (a switch, a progress dot). */
  --radius-pill: 0.625rem;
  --radius-xs: 0.375rem;
  --radius-round: 999px;

  /* --- Motion (all of it switched off for prefers-reduced-motion) -------- */
  --dur-fast: 160ms;
  --dur: 240ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);   /* soft, no bounce */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* --- Dark theme, following the device ----------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f10;
    --surface: #19191b;
    --surface-2: #232325;
    --surface-3: #2c2c2f;
    --text: #ededed;
    --text-muted: #a1a1a6;
    --text-disabled: #6e6e73;
    --border: #2a2a2d;
    --border-strong: #707076;
    --primary: #ededed;
    --primary-hover: #d4d4d8;
    --on-primary: #0f0f10;
    --on-accent: #0f0f10;
    --danger: #ff8a80;
    --danger-soft: #3a1d1d;
    --success: #4cc38a;
    --free-bg: #1e1e21;
    --free-bg-hover: #26262a;
    --free-border: #36363b;
    --free-text: #c7c7cc;
    --closed-a: #141416;
    --closed-b: #1b1b1e;
    --qr-bg: #ffffff;
    --chart-bar: #ecae36;
    --shadow-rgb: 0 0 0;
    --shadow-card: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-float: 0 8px 24px -8px rgb(0 0 0 / 0.6);
    --scrim: rgb(0 0 0 / 0.55);
    --acc-terracotta: #f0956b;
    --acc-pomegranate: #f28da7;
    --acc-plum: #d5a0df;
    --acc-honey: #ecae36;
    --acc-sea: #7fb9ef;
    --acc-cypress: #6fcdb6;
    --acc-olive: #b9c773;
    --acc-ochre: #e6b55c;
    --glow-strength: 0%;
    --glass-tint: 25 25 27;
    --glass-alpha: var(--glass-alpha-dark);
    --glass-edge: rgb(255 255 255 / 0.06);
    --glass-rim: rgb(255 255 255 / 0.06);
    --glass-sheen: rgb(255 255 255 / 0);
    --glass-solid: #19191b;
    --brand-1: #ecae36;
    --brand-2: #d9961a;
    --brand-3: #ecae36;
    --brand-ink-1: #8a5d00;
    --brand-ink-2: #8a5d00;
  }
}

/* --- Dark theme, chosen by hand (keep identical to the block above) ------ */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f10;
  --surface: #19191b;
  --surface-2: #232325;
  --surface-3: #2c2c2f;
  --text: #ededed;
  --text-muted: #a1a1a6;
  --text-disabled: #6e6e73;
  --border: #2a2a2d;
  --border-strong: #707076;
  --primary: #ededed;
  --primary-hover: #d4d4d8;
  --on-primary: #0f0f10;
  --on-accent: #0f0f10;
  --danger: #ff8a80;
  --danger-soft: #3a1d1d;
  --success: #4cc38a;
  --free-bg: #1e1e21;
  --free-bg-hover: #26262a;
  --free-border: #36363b;
  --free-text: #c7c7cc;
  --closed-a: #141416;
  --closed-b: #1b1b1e;
  --qr-bg: #ffffff;
  --chart-bar: #ecae36;
  --shadow-rgb: 0 0 0;
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-float: 0 8px 24px -8px rgb(0 0 0 / 0.6);
  --scrim: rgb(0 0 0 / 0.55);
  --acc-terracotta: #f0956b;
  --acc-pomegranate: #f28da7;
  --acc-plum: #d5a0df;
  --acc-honey: #ecae36;
  --acc-sea: #7fb9ef;
  --acc-cypress: #6fcdb6;
  --acc-olive: #b9c773;
  --acc-ochre: #e6b55c;
  --glow-strength: 0%;
  --glass-tint: 25 25 27;
  --glass-alpha: var(--glass-alpha-dark);
  --glass-edge: rgb(255 255 255 / 0.06);
  --glass-rim: rgb(255 255 255 / 0.06);
  --glass-sheen: rgb(255 255 255 / 0);
  --glass-solid: #19191b;
  --brand-1: #ecae36;
  --brand-2: #d9961a;
  --brand-3: #ecae36;
  --brand-ink-1: #8a5d00;
  --brand-ink-2: #8a5d00;
}

:root[data-theme="light"] {
  color-scheme: light;
}

/* --- Glass intensity presets --------------------------------------------- *
 * The owner approves one on a real phone (plan.md §12); it then becomes the
 * default above and the other two go away.                                 */
:root[data-glass="calm"] {
  --glass-blur: 30px;
  --glass-saturate: 130%;
  --glass-alpha-light: 0.8;
  --glass-alpha-dark: 0.86;
}

:root[data-glass="max"] {
  --glass-blur: 12px;
  --glass-saturate: 240%;
  --glass-alpha-light: 0.52;
  --glass-alpha-dark: 0.7;
}

/* --- Shop accent ----------------------------------------------------------- *
 * data-accent works on <html> (the whole page) and on any element (a preview
 * of one colour), because each rule resolves the theme's value where it is
 * declared.                                                                 */
[data-accent="terracotta"] { --accent: var(--acc-terracotta); }
[data-accent="pomegranate"] { --accent: var(--acc-pomegranate); }
[data-accent="plum"] { --accent: var(--acc-plum); }
[data-accent="honey"] { --accent: var(--acc-honey); }
[data-accent="sea"] { --accent: var(--acc-sea); }
[data-accent="cypress"] { --accent: var(--acc-cypress); }
[data-accent="olive"] { --accent: var(--acc-olive); }
[data-accent="ochre"] { --accent: var(--acc-ochre); }

:root,
[data-accent] {
  /* What the accent fills (a chosen time, the "Next" chip, a booked entry)
     and the text on it: the accent itself, except for honey (below). */
  --accent-fill: var(--accent);
  --on-accent-fill: var(--on-accent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --accent-glow: color-mix(in srgb, var(--accent) var(--glow-strength), transparent);
}

/* Honey as a fill is the bright one, with dark text on it (18/11/2026):
   --acc-honey is its deep tone, for text and lines on the light page. In
   the dark theme both are the bright one. After the block above, which it
   overrides. */
[data-accent="honey"] {
  --accent-fill: #ecae36;
  --on-accent-fill: #101820;
}

/* --- The light behind the page (body::before in base.css) ----------------- *
 * data-glow on <html>: "accent" on a shop's pages (its own colour, three
 * soft spots); "brand" on the platform's own pages (templates/base.html's
 * default): the Aurora colours, violet, cyan and pink.                     */
:root {
  --glow-a: var(--accent-glow);
  --glow-b: color-mix(in srgb, var(--accent-glow) 60%, transparent);
  --glow-c: color-mix(in srgb, var(--accent-glow) 70%, transparent);
}

:root[data-glow="brand"] {
  --glow-a: color-mix(in srgb, var(--brand-1) var(--glow-strength), transparent);
  --glow-b: color-mix(in srgb, var(--brand-2) var(--glow-strength), transparent);
  --glow-c: color-mix(in srgb, var(--brand-3) var(--glow-strength), transparent);
}

/* --- Reduced motion: every duration becomes zero ------------------------- */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur: 0ms;
    --dur-slow: 0ms;
  }
}
