/* ================================================================
   MI Lab theme: the shared light palette and the theme toggle.

   Loaded after each page's own stylesheet. The dark theme lives in each
   page's existing :root tokens and is the default; every page family maps
   its tokens onto these light colours in its own
   :root[data-theme="light"] block. One light palette, several token
   families: the same token name means different things in different
   files (history's --mi-text-muted is everyone else's "secondary").

   Every light text colour below meets WCAG AA (4.5:1) on --lt-card and on
   --lt-page; tinted backgrounds take the -ink shades, never the -700s.
   ================================================================ */

:root {
  /* Surfaces */
  --lt-page: #f4f6fa;
  --lt-surface: #f8fafc;
  --lt-card: #ffffff;
  --lt-card-hover: #f1f5f9;
  --lt-card-selected: #eff6ff;
  --lt-border: #e2e8f0;
  --lt-border-strong: #cbd5e1;
  --lt-border-input: #8492a6;      /* form controls: 3.1:1 on white (WCAG 1.4.11) */
  --lt-card-ring: 0 0 0 1px #e2e8f0, 0 1px 2px rgba(15, 23, 42, 0.05);

  /* Text */
  --lt-ink: #0f172a;               /* 17.85:1 on white */
  --lt-ink-2: #1e293b;
  --lt-ink-secondary: #475569;     /* 7.58:1 */
  --lt-ink-muted: #5b6b80;         /* 5.44:1; #64748b fails on the page (4.40) */

  /* Accents */
  --lt-accent: #2563eb;            /* white on it 5.17:1 */
  --lt-accent-hover: #1d4ed8;
  --lt-link: #1d4ed8;
  --lt-accent-glow: rgba(37, 99, 235, 0.14);
  --lt-teal: #0f766e;              /* white on it 5.47:1 */
  --lt-teal-strong: #115e59;
  --lt-success: #15803d;
  --lt-success-2: #047857;
  --lt-warn-ink: #92400e;
  --lt-warn-solid: #d97706;        /* takes dark text */
  --lt-danger: #b91c1c;
  --lt-danger-solid: #dc2626;      /* white on it 4.83:1 */

  /* Status/tone text on white and on light tints of the same hue */
  --lt-green-ink: #166534;
  --lt-emerald-ink: #065f46;
  --lt-teal-ink: #115e59;
  --lt-blue-ink: #1d4ed8;
  --lt-indigo-ink: #3730a3;
  --lt-violet-ink: #6d28d9;
  --lt-purple-ink: #7e22ce;
  --lt-orange-ink: #9a3412;
  --lt-amber-ink: #92400e;
  --lt-red-ink: #b91c1c;
  --lt-sky-ink: #0369a1;
  --lt-slate-ink: #334155;

  /* Data-visualisation hues: AA as text, at least 3:1 as fills */
  --lt-hue-blue: #2563eb;
  --lt-hue-green: #047857;
  --lt-hue-purple: #9333ea;
  --lt-hue-orange: #c2410c;
  --lt-hue-red: #dc2626;
  --lt-hue-teal: #0f766e;
  --lt-hue-amber: #b45309;
  --lt-hue-slate: #64748b;
  --lt-hue-slate-dim: #5b6b80;

  /* Overlays */
  --lt-scrim: rgba(15, 23, 42, 0.45);
  --lt-shadow-pop: 0 10px 30px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.08);
  --lt-shadow-modal: 0 24px 60px rgba(15, 23, 42, 0.18);

  /* Theme toggle (dark) */
  --mt-pop-bg: #151c28;
  --mt-pop-border: #1e293b;
  --mt-seg-bg: rgba(148, 163, 184, 0.1);   /* reads on the page and on cards */
  --mt-on-bg: #1e293b;
  --mt-ink: #f1f5f9;
  --mt-ink-muted: #94a3b8;
  --mt-focus: #60a5fa;
  --mt-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --mt-on-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --mt-pop-bg: var(--lt-card);
  --mt-pop-border: var(--lt-border);
  --mt-seg-bg: color-mix(in srgb, var(--lt-ink) 6%, transparent);
  --mt-on-bg: var(--lt-card);
  --mt-ink: var(--lt-ink);
  --mt-ink-muted: var(--lt-ink-secondary);
  --mt-focus: var(--lt-accent);
  --mt-shadow: var(--lt-shadow-pop);
  --mt-on-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

/* Browser-drawn parts follow the theme: scrollbars, native form controls
   (date pickers, selects, checkboxes) and the canvas past the end of the page.
   Without it the browser draws them for a light page, so every page that
   scrolls showed a white scrollbar down its side in the dark theme, and a
   white strip along the foot of anything that scrolls sideways. Dark is the
   default, as for the tokens; print is always paper. A page that is paper in
   both themes (the CPD record, the quote) sets color-scheme on its sheet. */
:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
@media print { :root { color-scheme: light; } }

/* Switching themes: no per-component fades. */
:root.mt-switching,
:root.mt-switching *,
:root.mt-switching *::before,
:root.mt-switching *::after {
  transition: none !important;
}

/* ─── Toggle ─────────────────────────────────────────────────────── */

.mt-mount { display: contents; }

.mt-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.mt-trigger .mt-icon { flex-shrink: 0; }

/* The trigger borrows the host header's button class for its look; these
   fill in what some host classes lack. :where() keeps them at zero
   specificity so a host rule hiding header items at some width still wins. */
:where(.mt-trigger) { display: inline-flex; align-items: center; gap: 6px; }
:where(.mt-trigger):focus-visible { outline: 2px solid var(--mt-focus); outline-offset: 2px; }

/* Headers laid out with space-between: sit beside Log out, not mid-bar. */
:where(.mh-header, .rc-header, .toolbar) > .mt-mount > .mt-trigger {
  margin-left: auto;
  margin-right: 10px;
}

/* Headers that are already tight on a phone: a compact icon-only square, so
   the toggle fits the gap the header already leaves and nothing else wraps. */
@media (max-width: 640px) {
  :where(.toolbar, .mh-header, .rc-header) .mt-trigger > span { display: none; }
  .mh-header > .mt-mount > .mt-trigger,
  .rc-header > .mt-mount > .mt-trigger,
  .toolbar > .mt-mount > .mt-trigger,
  .toolbar-actions > .mt-mount > .mt-trigger {
    justify-content: center;
    min-width: 30px;
    padding-left: 7px;
    padding-right: 7px;
    margin-right: 6px;
  }
  .toolbar-actions > .mt-mount > .mt-trigger { margin-right: 0; }
}

/* Phones: these secondary pages' headers have no room left (their own items
   already wrap at 360px). The choice is per browser and stays one tap away
   in the MI Lab header and on the sign-in pages, and "Device" already
   follows the phone's own setting. */
@media (max-width: 480px) {
  :where(.mh-header, .rc-header, .toolbar, .toolbar-actions) > .mt-mount { display: none; }
}
/* The Trainer Hub header only just fits a tablet as it is (and overflows a
   phone already): its toggle shows from desktop widths up. */
@media (max-width: 1023px) {
  :where(.th-header-right) > .mt-mount { display: none; }
}

.mt-pop {
  position: fixed;
  z-index: 1200;
  min-width: 240px;
  padding: 8px;
  border: 1px solid var(--mt-pop-border);
  border-radius: 12px;
  background: var(--mt-pop-bg);
  box-shadow: var(--mt-shadow);
  color: var(--mt-ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
.mt-pop[hidden] { display: none; }

.mt-seg {
  display: flex;
  gap: 2px;
  margin: 0;
  padding: 3px;
  min-width: 0;
  border: 0;
  border-radius: 9px;
  background: var(--mt-seg-bg);
}

.mt-opt {
  position: relative;
  flex: 1 1 0;
  display: flex;
  cursor: pointer;
}

.mt-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.mt-opt__body {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--mt-ink-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.mt-opt:hover .mt-opt__body { color: var(--mt-ink); }

.mt-opt input:checked + .mt-opt__body {
  background: var(--mt-on-bg);
  color: var(--mt-ink);
  box-shadow: var(--mt-on-shadow);
}

.mt-opt input:focus-visible + .mt-opt__body {
  outline: 2px solid var(--mt-focus);
  outline-offset: 1px;
}

.mt-hint {
  margin: 8px 4px 2px;
  color: var(--mt-ink-muted);
  font-size: 12px;
  line-height: 1.4;
}

.mt-inline {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.mt-inline .mt-seg { max-width: 320px; flex: 1; }

@media (forced-colors: active) {
  .mt-opt input { position: static; opacity: 1; width: auto; height: auto; }
  .mt-opt input:checked + .mt-opt__body { outline: 2px solid CanvasText; }
}
