:root { color-scheme: light; }

/* Existing declarations keep their original light colors as token fallbacks. */
html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e2ece7;
  --muted: #a1b5ab;
  --line: #354b40;
  --paper: #192922;
  --bg: #101c17;
  --nav: #102d24;
  --green: #78d8b3;
  --green-soft: #233f32;
  --yellow: #edc778;
  --yellow-soft: #3c3422;
  --red: #ff9e9e;
  --red-soft: #422a2e;
  --shadow: 0 18px 50px rgba(0, 0, 0, .3);
  --theme-ink: var(--ink);
  --theme-muted: var(--muted);
  --theme-line: var(--line);
  --theme-surface: var(--paper);
  --theme-surface-muted: #21332a;
  --theme-green: var(--green);
  --theme-green-soft: var(--green-soft);
  --theme-green-border: #4c7f65;
  --theme-yellow: var(--yellow);
  --theme-yellow-soft: var(--yellow-soft);
  --theme-yellow-border: #816c3d;
  --theme-red: var(--red);
  --theme-red-soft: var(--red-soft);
  --theme-red-border: #875258;
  --theme-info: #9dcaf4;
  --theme-info-soft: #263b4c;
  --theme-focus-warning: #edc77855;
  --theme-primary: #24765c;
  --theme-chart-green: #78d8b3;
  --theme-chart-reference: #e0b77c;
  --theme-chart-grid: #354b40;
}

/* Native controls and overlays also need readable foregrounds in dark mode. */
html[data-theme="dark"] :is(input, select, textarea) {
  color: var(--ink);
}
html[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
html[data-theme="dark"] .modal { background: rgba(0, 0, 0, .65); }
html[data-theme="dark"] .toast { background: #dcece3; color: #162b20; }
html[data-theme="dark"] .bar { background: linear-gradient(#78d8b3, #348d6d); }

.sidebar-tools { margin-top: auto; display: grid; gap: 10px; padding-top: 24px; }
.sidebar-tools .version-refresh { margin-top: 0; }
.theme-toggle {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 54px; padding: 12px 14px; border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 10px; background: rgba(255, 255, 255, .07); color: #d7ebe5;
  text-align: left;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .3); }
.theme-toggle:focus-visible { outline: 2px solid #9be0c7; outline-offset: 3px; }
.theme-icon { flex: 0 0 22px; width: 22px; height: 22px; }
.theme-label { flex: 1; font-size: 13px; font-weight: 700; white-space: nowrap; }
.theme-track {
  flex: 0 0 32px; height: 19px; padding: 3px; border-radius: 20px;
  background: #59766a; transition: background .15s;
}
.theme-track::before {
  content: ""; display: block; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.theme-toggle[aria-checked="true"] .theme-track { background: #428c6e; }
.theme-toggle[aria-checked="true"] .theme-track::before { transform: translateX(13px); }
.theme-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

@media (min-width: 721px) {
  aside { overflow-y: auto; }
}
@media (max-width: 1000px) and (min-width: 721px) {
  .theme-toggle { gap: 7px; padding: 12px 9px; }
  .theme-icon { flex-basis: 18px; width: 18px; height: 18px; }
}
@media (max-width: 720px) {
  aside { grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; }
  .sidebar-tools { grid-column: 2; grid-row: 1; margin: 0; padding: 0; display: block; }
  .sidebar-tools .version-refresh { display: none; }
  .theme-toggle { width: 40px; min-height: 44px; justify-content: center; padding: 8px; }
  .theme-label, .theme-track { display: none; }
  .theme-toggle[aria-checked="true"] { background: rgba(120, 216, 179, .2); color: #a7e8cc; }
  aside .side-footer { grid-column: 3; grid-row: 1; }
  aside .side-footer button { min-width: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .theme-track, .theme-track::before { transition: none; }
}
