/* StudioSaaS shared brand language.
 *
 * Surfaces keep their own layout, while typography, colour roles, controls,
 * date/time fields and status output share these semantic tokens. Tenant
 * branding may override --brand / --tenant-primary at runtime.
 */
:root {
  --brand-accent: var(--tenant-primary, var(--brand, var(--ui-primary, #835D33)));
  --brand-accent-strong: var(--tenant-secondary, var(--brand-2, var(--ui-secondary, #4C6877)));
  --brand-accent-2-soft: var(--accent-2-soft, var(--brand-paper-raised));
  --brand-on-accent-2-soft: var(--on-accent-2-soft, var(--brand-accent-strong));
  --brand-accent-2-border: var(--accent-2-border, var(--brand-line));
  --brand-on-accent: #ffffff;
  --brand-paper: var(--bg, var(--ui-bg, #F3EFEA));
  --brand-paper-raised: var(--surface, var(--panel, var(--ui-surface, #FDFDFD)));
  --brand-ink: var(--ink, var(--ui-text, #221E1A));
  --brand-ink-soft: var(--muted, var(--ink2, var(--ui-muted, #6C635A)));
  --brand-line: var(--line, var(--ui-border, #DFDAD5));
  --brand-success: var(--ui-success, #2F7951);
  --brand-warning: var(--ui-warning, #5B421F);
  --brand-danger: var(--ui-error, #76332A);
  --brand-info: var(--info, #396F95);
  --brand-font-body: "Noto Sans SC", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --brand-font-display: "Noto Serif SC", "Cormorant Garamond", "Songti SC", Georgia, serif;
  --brand-reading-measure: var(--ui-reading-measure, 55ch);
  --brand-golden-columns: var(--ui-golden-columns, minmax(0, 1.618fr) minmax(0, 1fr));
  --brand-golden-columns-reverse: var(--ui-golden-columns-reverse, minmax(0, 1fr) minmax(0, 1.618fr));
  --brand-space-xs: var(--ui-space-2, 8px);
  --brand-space-sm: var(--ui-space-3, 13px);
  --brand-space-md: var(--ui-space-4, 21px);
  --brand-space-lg: var(--ui-space-5, 34px);
  --brand-space-xl: var(--ui-space-6, 55px);
  --brand-radius-control: 10px;
  --brand-radius-card: 18px;
  --brand-control-height: var(--ui-control-height, 46px);
  --brand-focus-ring: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 24%, transparent);
  --brand-shadow-card: 0 18px 46px rgba(55, 44, 34, .09);
}

:where(body) {
  font-family: var(--brand-font-body);
  color: var(--brand-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:where(h1, h2, .brand-display) {
  text-wrap: balance;
}

:where(p, li) {
  text-wrap: pretty;
}

:where(input, select, textarea, button) {
  font: inherit;
}

:where(input, select, textarea) {
  color: var(--brand-ink);
  accent-color: var(--brand-accent);
}

/* ── the surfaces a palette cannot reach ──────────────────────────────────
 *
 * `color-scheme` is the only way to tell the browser which set of NATIVE
 * colours to draw: scrollbars, the `<select>` popup, checkbox and radio
 * chrome, the autofill wash, spin buttons, the caret, the default
 * `::placeholder`, and the rubber-band overscroll. None of them are styleable
 * and none of them read a custom property.
 *
 * Until v8.4.0 this was declared on date and time inputs only. Measured on
 * production, `getComputedStyle(:root).colorScheme` was `normal` on a tenant
 * portal carrying a dark theme — so that page had 11 text inputs, 2 selects,
 * 2 checkboxes, a textarea and a scrollbar all rendering light native chrome
 * on a #15120D page, and not one contrast assertion could see it, because
 * none of those colours is in the palette.
 *
 * It follows the STUDIO's chosen scheme, not the visitor's OS. When an owner
 * opts into following the visitor, index.html writes data-brand-scheme from
 * prefers-color-scheme, so this still tracks the scheme actually rendered.
 */
:root { color-scheme: light; }
:root[data-brand-scheme="dark"] { color-scheme: dark; }

:where(input[type="date"], input[type="time"], input[type="datetime-local"]) {
  min-height: var(--brand-control-height);
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

/* Selection and placeholder are drawn by the browser from its own defaults
   unless told otherwise, and both land on theme surfaces. */
::selection {
  background: color-mix(in srgb, var(--brand-accent) 26%, transparent);
  color: var(--brand-ink);
}

:where(input, textarea)::placeholder {
  color: var(--muted, var(--brand-ink-soft));
  opacity: 1;   /* Firefox dims placeholders by default, below the 4.5 target */
}

/* Chrome paints autofilled fields a fixed pale yellow and ignores
   `background-color`. The inset shadow is the documented way to override it,
   and it has to carry the field's own ink with it. */
:where(input, textarea, select):-webkit-autofill,
:where(input, textarea, select):-webkit-autofill:hover,
:where(input, textarea, select):-webkit-autofill:focus {
  -webkit-text-fill-color: var(--brand-ink);
  -webkit-box-shadow: 0 0 0 40rem var(--brand-paper-raised) inset;
  caret-color: var(--brand-ink);
}

:where(.brand-action-primary) { background: var(--brand-accent); color: var(--brand-on-accent); }
/* The secondary action is a TINT, not a second filled button. Design_
   Constraints 1.1: the accent is the only role that fills, because that is
   what lets a semantic chip and a brand chip be told apart by shape before
   hue. A page with two filled buttons has two primary actions. */
:where(.brand-action-secondary) {
  background: var(--brand-accent-2-soft, var(--brand-paper-raised));
  color: var(--brand-on-accent-2-soft, var(--brand-accent-strong));
  border: 1px solid var(--brand-accent-2-border, var(--brand-line));
}

:where(input[type="date"], input[type="time"], input[type="datetime-local"])::-webkit-date-and-time-value {
  min-height: 1.4em;
  text-align: left;
}

:where(output, .numeric, [data-number]) {
  font-variant-numeric: tabular-nums;
}

/* summary and [tabindex] join the list — see ui-tokens.css. */
:where(input, select, textarea, button, a, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-accent);
  outline-offset: 2px;
  box-shadow: var(--brand-focus-ring);
}

:where(.brand-card) {
  border: 1px solid var(--brand-line);
  border-radius: var(--brand-radius-card);
  background: var(--brand-paper-raised);
  box-shadow: var(--brand-shadow-card);
}

:where(.brand-status) {
  border-left: 3px solid var(--brand-info);
  border-radius: var(--brand-radius-control);
  padding: 12px 14px;
  background: color-mix(in srgb, var(--brand-info) 8%, var(--brand-paper-raised));
  color: var(--brand-ink);
}

:where(.brand-status[data-tone="success"]) { border-left-color: var(--brand-success); }
:where(.brand-status[data-tone="warning"]) { border-left-color: var(--brand-warning); }
:where(.brand-status[data-tone="danger"]) { border-left-color: var(--brand-danger); }

@media (max-width: 1279px) {
  :where(input, select, textarea) { font-size: max(16px, 1em); }
}

/* v8.3.0 removed a `@media (prefers-color-scheme: dark)` block here that
 * reassigned --brand-paper / --brand-paper-raised / --brand-ink /
 * --brand-ink-soft / --brand-line to a fixed dark set.
 *
 * It never took effect anywhere. The tenant surfaces get 34 tokens written
 * inline on :root by /brand, and an inline style beats a stylesheet rule, so
 * the block was overridden on exactly the pages it was written for. On the two
 * admin surfaces it was inert for the opposite reason: neither uses a --brand-*
 * token for its own paper or ink (measured: all 62 fields in Studio Admin stay
 * #0E1729 on #FFFFFF with the OS in dark mode).
 *
 * Dead, but not harmless: any page that later styled itself from --brand-paper
 * without writing tokens inline would have had its paper and ink flipped out
 * from under it by the visitor's OS setting, while its accents — which this
 * block did not touch — stayed solved for light. A studio's chosen theme
 * decides light or dark; the visitor's OS does not get a vote.
 *
 * Per-theme dark variants live in backend/studiosaas/presets.py and are
 * generated and checked by docs/design/palette_gen.py.
 */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  /* One carve-out, and it is not cosmetic. `animation-iteration-count: 1`
     stops every looping animation after a single pass, which turns a busy
     indicator into a frozen glyph — the CMS boot spinner sits beside
     "连接中…" and is the only thing distinguishing "connecting" from "hung".
     Reduce-motion is about vestibular triggers, and the trigger there is the
     rotation, not the fact of animating: so the rotation is replaced by an
     opacity pulse rather than removed. `[data-motion="essential"]` is the
     hook for anything else that means "still working". */
  .sp, [role="progressbar"], [data-motion="essential"] {
    animation: essential-pulse 1.2s ease-in-out infinite !important;
    animation-iteration-count: infinite !important;
  }
}

@keyframes essential-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
