/* =========================================================================
   Dark theme: the palette and the theme button.

   partials/theme-boot sets data-theme="light" or "dark" on <html> before
   the page styles load: a choice saved on this device first (the button,
   or ?theme=dark / light / system in a link), else the system setting.
   Loaded on every page before its own styles; each stylesheet maps its own
   tokens and colors to the --dk-* values below under
   :root[data-theme="dark"], so the dark colors live here only.
   ========================================================================= */

:root {
  color-scheme: light;

  /* The footer switch (below), light values; dark ones further down. */
  --ts-track: rgba(17, 17, 17, 0.06);
  --ts-face: #fff;
  --ts-face-edge: rgba(17, 17, 17, 0.08);
  --ts-on: #111;
  --ts-off: rgba(17, 17, 17, 0.6);
}

/* A printout stays light, so the dark color scheme is for screens only. */
@media screen {
  :root[data-theme="dark"] { color-scheme: dark; }
}

:root[data-theme="dark"] {
  /* Surfaces, darkest first. */
  --dk-page: #0f0f11;       /* page background */
  --dk-surface: #18181b;    /* cards, bars, sheets, dialogs */
  --dk-surface-2: #212125;  /* fields, wells, chips, cards on cards */
  --dk-surface-3: #2b2b30;  /* hover and pressed, selected rows */

  /* Lines. */
  --dk-line: rgba(255, 255, 255, 0.1);    /* hairlines, dividers */
  --dk-line-2: rgba(255, 255, 255, 0.18); /* field borders, strong dividers */

  /* Text. --dk-muted keeps 4.5:1 or more on every surface above; --dk-faint
     is for decoration and disabled things only. */
  --dk-ink: #f4f4f5;
  --dk-ink-2: rgba(244, 244, 245, 0.8);
  --dk-muted: rgba(244, 244, 245, 0.64);
  --dk-faint: rgba(244, 244, 245, 0.4);
  --dk-on-ink: #0f0f11;     /* text on a light (inverted) button */

  /* Washes, scrims and shadows. */
  --dk-tint: rgba(255, 255, 255, 0.06);
  --dk-tint-2: rgba(255, 255, 255, 0.1);
  --dk-scrim: rgba(0, 0, 0, 0.62);
  --dk-shadow: rgba(0, 0, 0, 0.5);

  /* States. */
  --dk-danger: #ff7a70;
  --dk-danger-bg: rgba(255, 122, 112, 0.14);
  --dk-success: #5ad48a;
  --dk-success-bg: rgba(90, 212, 138, 0.14);
  --dk-warn: #f5c451;
  --dk-warn-bg: rgba(245, 196, 81, 0.14);
  --dk-link: #6aa8ff;
}

/* The black logo turns white on screen. */
@media screen {
  :root[data-theme="dark"] .g-logo img,
  :root[data-theme="dark"] img.app-logo { filter: invert(1); }
}

/* While the theme flips, nothing animates its colors. */
.theme-switching,
.theme-switching *,
.theme-switching *::before,
.theme-switching *::after { transition: none !important; }

/* ---------- The theme button (partials/theme-toggle) ---------- */

.g-top-end { display: flex; align-items: center; gap: 18px; }

.theme-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  cursor: pointer;
}
.theme-btn:hover { background: rgba(17, 17, 17, 0.06); }
:root[data-theme="dark"] .theme-btn:hover { background: var(--dk-tint-2); }
.theme-btn svg { width: 18px; height: 18px; display: block; }
/* The moon offers dark, the sun offers light. */
.theme-btn .theme-sun,
:root[data-theme="dark"] .theme-btn .theme-moon { display: none; }
:root[data-theme="dark"] .theme-btn .theme-sun { display: block; }

@media (pointer: coarse) {
  .theme-btn { width: 44px; height: 44px; }
}

/* ---------- The footer switch (partials/theme-switch) ---------- */

:root[data-theme="dark"] {
  --ts-track: var(--dk-tint);
  --ts-face: var(--dk-surface-3);
  --ts-face-edge: var(--dk-line-2);
  --ts-on: var(--dk-ink);
  --ts-off: var(--dk-muted);
}

.theme-switch {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--ts-track);
}
.theme-switch [data-theme-set] {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ts-off);
  cursor: pointer;
}
.theme-switch [data-theme-set]:hover { color: var(--ts-on); }
.theme-switch [data-theme-set][aria-pressed="true"] {
  background: var(--ts-face);
  color: var(--ts-on);
  box-shadow: 0 0 0 1px var(--ts-face-edge), 0 1px 2px var(--ts-face-edge);
  cursor: default;
}
.theme-switch svg { width: 14px; height: 14px; display: block; }

/* Touch: a 44px tall target around the small face. */
@media (pointer: coarse) {
  .theme-switch [data-theme-set] { width: 44px; }
  .theme-switch [data-theme-set]::after { content: ""; position: absolute; inset: -10px 0; }
}

