/* Design tokens, reset and typography.
 *
 * Every colour in the UI comes from a token below, so a palette only has to
 * redefine values, never rules. `:root` is the default dark palette, which
 * means a page with no data-theme attribute still looks right; the light and
 * black blocks only carry the values they change.
 *
 * The palette is picked in the header (see core/theme.js) and remembered in
 * localStorage; "System" follows prefers-color-scheme. */

:root {
  color-scheme: dark;

  --bg: #0f1117;
  --bg-glow: #141a2b;
  --panel: #171a23;
  --panel-alt: #1d2130;
  --border: #2a2f3a;
  --border-strong: #3a4152;
  --text: #e6e9ef;
  --muted: #8b93a7;

  --accent: #4f8cff;
  --accent-strong: #6ba1ff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --on-accent: #ffffff;

  --danger: #ff5f56;
  --danger-strong: #ff7b73;
  --danger-soft: rgba(255, 95, 86, 0.12);
  --on-danger: #2b0f0f;
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.13);

  /* Surfaces that a palette has to override as a group. */
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-lg: rgba(0, 0, 0, 0.45);
  /* One elevation for every raised surface (panels, dashboard tiles), a hair
     of contact shadow plus a soft ambient one. Indirect for the same reason
     as --input-bg: it re-resolves per palette. */
  --shadow-card: 0 1px 2px var(--shadow), 0 16px 32px -24px var(--shadow-lg);
  --header-bg: rgba(23, 26, 35, 0.86);
  --backdrop: rgba(6, 9, 16, 0.62);
  --row-hover: rgba(255, 255, 255, 0.04);
  --placeholder: #5f6779;
  --code-bg: #12151d;
  --scrollbar: #333a49;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;

  /* Inputs always sit inside a --panel surface, so they read better one step
     away from it (darker in the dark palettes, greyer in the light one).
     Indirect on purpose: the palettes below do not have to repeat it. */
  --input-bg: var(--bg);
}

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

  --bg: #f4f6fa;
  --bg-glow: #e3eaf7;
  --panel: #ffffff;
  --panel-alt: #f1f4f9;
  --border: #d8dee9;
  --border-strong: #b9c2d2;
  --text: #1b2333;
  --muted: #5f6b82;

  --accent: #2f6fed;
  --accent-strong: #1f5bd8;
  --accent-soft: rgba(47, 111, 237, 0.12);

  --danger: #d64545;
  --danger-strong: #c03a3a;
  --danger-soft: rgba(214, 69, 69, 0.1);
  --on-danger: #ffffff;
  --ok: #0f9d63;
  --ok-soft: rgba(15, 157, 99, 0.12);
  --warn: #9a6700;
  --warn-soft: rgba(154, 103, 0, 0.12);

  --shadow: rgba(23, 32, 51, 0.1);
  --shadow-lg: rgba(23, 32, 51, 0.16);
  --header-bg: rgba(255, 255, 255, 0.88);
  --backdrop: rgba(24, 31, 46, 0.3);
  --row-hover: rgba(43, 57, 84, 0.05);
  --placeholder: #98a2b6;
  --code-bg: #f4f6fa;
  --scrollbar: #c3cbd9;
}

html[data-theme="black"] {
  --bg: #000000;
  --bg-glow: #0a0c12;
  --panel: #070707;
  --panel-alt: #0d0d0d;
  --border: #1f1f1f;
  --border-strong: #303030;
  --muted: #8b93a3;

  --accent: #5b95ff;
  --accent-strong: #78a8ff;
  --accent-soft: rgba(91, 149, 255, 0.16);

  --shadow: rgba(0, 0, 0, 0.8);
  --shadow-lg: rgba(0, 0, 0, 0.85);
  --header-bg: rgba(0, 0, 0, 0.85);
  --backdrop: rgba(0, 0, 0, 0.72);
  --row-hover: rgba(255, 255, 255, 0.045);
  --code-bg: #0d0d0d;
  --scrollbar: #2a2a2a;
}

* {
  box-sizing: border-box;
  /* Thin, palette-coloured scrollbars beat the default OS chrome in a
     full-screen dark UI. */
  scrollbar-color: var(--scrollbar) transparent;
  scrollbar-width: thin;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 500px at 12% -10%, var(--bg-glow), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  transition: background-color 140ms ease, color 140ms ease;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

code,
kbd,
pre {
  font-family: var(--mono);
}

/* Native controls (checkboxes, scrollbars, date pickers) pick up the palette
   through `color-scheme`, but only if the accent is themed too. */
::selection {
  background: var(--accent-soft);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
  background-clip: content-box;
}

/* ---------------------------------------------------------------- utils */

/* !important on purpose: layout rules (e.g. `.auth-row { display: flex }`)
   would otherwise win on cascade order and keep hidden elements visible. */
.hidden {
  display: none !important;
}

/* Read-only accounts (role "user"): mutating controls are hidden rather than
   disabled - a viewer has no use for them, and the server rejects those
   requests anyway. Marked in index.html, or by core/dom.js for row buttons. */
html[data-role="user"] .admin-only {
  display: none !important;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

.hint code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.muted {
  color: var(--muted);
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
