/* Adjusted Health + Performance — the one token set and the shared base for
   every staff page: the engine, the hub, team, training, practice, analytics,
   the training report and the password pages.

   Two themes from the same tokens. Dark is the original engine look (charcoal,
   cream, bronze). Light is the same palette inverted onto cream paper, with a
   darker bronze for text so it still reads at 4.5:1. The theme is chosen by
   theme.js before first paint: a saved choice (localStorage "ahp-theme"), else
   the device's prefers-color-scheme. Without JS the media query below decides.

   Contrast (checked against every surface below, WCAG 2.x):
   - text, text-2, text-3, bronze-text, good, bad, warn ≥ 4.5:1 on bg, bg-deep,
     surface, surface-2 and surface-3 in both themes
   - control (input and button borders) ≥ 3:1 on bg and surface
   Overlays that tint a surface use the *-rgb channels: rgb(var(--ink-rgb) / .06). */

:root {
  color-scheme: dark;
  --bg: #14110e;            /* charcoal — the page */
  --bg-deep: #0e0c0a;       /* the sidebar */
  --surface: #1e1a16;       /* cards */
  --surface-2: #26211b;     /* raised: inputs, hover, wells */
  --surface-3: #2f2921;
  --text: #edebe5;          /* cream */
  --text-bright: #f7f5f0;
  --text-2: #c9c3b7;        /* secondary text */
  --text-3: #aaa397;        /* tertiary text — still 5.7:1 on surface-3 */
  --bronze: #baa682;        /* bronze for text, icons and rules */
  --bronze-fill: #baa682;   /* bronze for filled buttons and chips */
  --bronze-deep: #9c8a68;
  --bronze-ink: #baa682;    /* bronze text on a bronze wash */
  --on-accent: #14110e;     /* text on a bronze or green fill */
  --control: #7d7466;       /* input and button borders, 3:1+ */
  --steel: #a9c2d8;
  --chiro: #c9aee6;         /* calendar: chiropractic */
  --normatec: #7fcfc4;      /* calendar: Normatec */
  --good: #8fcaa2;
  --warn: #e3bd6f;
  --bad: #ec9f8c;
  --navy: #021c41;

  --ink-rgb: 237 235 229;   /* overlays: cream on charcoal */
  --bg-rgb: 20 17 14;
  --bronze-rgb: 186 166 130;
  --good-rgb: 143 202 162;
  --bad-rgb: 236 159 140;
  --warn-rgb: 227 189 111;
  --steel-rgb: 92 125 153;
  --chiro-rgb: 160 120 205;
  --normatec-rgb: 70 165 152;

  --line: rgb(var(--ink-rgb) / 0.10);
  --line-strong: rgb(var(--ink-rgb) / 0.18);
  --bronze-wash: rgb(var(--bronze-rgb) / 0.14);
  --good-wash: rgb(var(--good-rgb) / 0.13);
  --bad-wash: rgb(var(--bad-rgb) / 0.12);
  --warn-wash: rgb(var(--warn-rgb) / 0.14);
  --hover: rgb(var(--ink-rgb) / 0.05);
  --scrim: rgba(8, 6, 4, 0.66);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 18px 40px -24px rgba(0, 0, 0, 0.7);
  --shadow-pop: 0 40px 80px -30px rgba(0, 0, 0, 0.85);

  /* chart series, validated for colour blindness on --surface (dataviz) */
  --series-1: #b8892a;
  --series-2: #4a86d4;
  --series-3: #d0623e;
  --series-4: #9b7fd6;

  --font-display: 'Newsreader', Georgia, serif;
  --font-body: 'Hanken Grotesk', -apple-system, 'Helvetica Neue', sans-serif;
  --font-head: var(--font-display);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --radius: 22px;
  --tap: 44px;              /* touch target */
  --tap-sm: 40px;

  /* the older names some inline styles still use */
  --ahp-dark-blue: var(--text);
  --ahp-light-blue: var(--text-3);
  --ahp-white: var(--surface);
  --ahp-off-white: var(--surface-2);
  --ahp-gold: var(--bronze);
  --ahp-stone: var(--line-strong);
  --ahp-beige: var(--line);
  --ahp-black: #000;
  --gold: var(--bronze);
}

/* Light: cream paper, charcoal ink, deep bronze for text. Kept in one block and
   repeated for the no-JS media query (keep the two identical). */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f2ea; --bg-deep: #ebe5d9; --surface: #fffdf9; --surface-2: #f0eadf; --surface-3: #e6dfd1;
  --text: #1d1915; --text-bright: #110e0b; --text-2: #463f36; --text-3: #5c5448;
  --bronze: #6b5634; --bronze-fill: #baa682; --bronze-deep: #57462a; --bronze-ink: #57462a; --on-accent: #14110e;
  --control: #857b6c; --steel: #335a7a; --chiro: #6a4a8c; --normatec: #1d6a61; --good: #2c6a43; --warn: #7d5a10; --bad: #a3402c;
  --ink-rgb: 29 25 21; --bg-rgb: 246 242 234; --bronze-rgb: 140 114 72;
  --good-rgb: 44 106 67; --bad-rgb: 163 64 44; --warn-rgb: 125 90 16; --steel-rgb: 51 90 122; --chiro-rgb: 106 74 140; --normatec-rgb: 29 106 97;
  --line: rgb(var(--ink-rgb) / 0.12); --line-strong: rgb(var(--ink-rgb) / 0.22);
  --scrim: rgba(29, 25, 21, 0.45);
  --shadow: 0 1px 2px rgba(29, 25, 21, 0.06), 0 18px 40px -28px rgba(29, 25, 21, 0.35);
  --shadow-pop: 0 40px 80px -30px rgba(29, 25, 21, 0.45);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f6f2ea; --bg-deep: #ebe5d9; --surface: #fffdf9; --surface-2: #f0eadf; --surface-3: #e6dfd1;
    --text: #1d1915; --text-bright: #110e0b; --text-2: #463f36; --text-3: #5c5448;
    --bronze: #6b5634; --bronze-fill: #baa682; --bronze-deep: #57462a; --bronze-ink: #57462a; --on-accent: #14110e;
    --control: #857b6c; --steel: #335a7a; --chiro: #6a4a8c; --normatec: #1d6a61; --good: #2c6a43; --warn: #7d5a10; --bad: #a3402c;
    --ink-rgb: 29 25 21; --bg-rgb: 246 242 234; --bronze-rgb: 140 114 72;
    --good-rgb: 44 106 67; --bad-rgb: 163 64 44; --warn-rgb: 125 90 16; --steel-rgb: 51 90 122; --chiro-rgb: 106 74 140; --normatec-rgb: 29 106 97;
    --line: rgb(var(--ink-rgb) / 0.12); --line-strong: rgb(var(--ink-rgb) / 0.22);
    --scrim: rgba(29, 25, 21, 0.45);
    --shadow: 0 1px 2px rgba(29, 25, 21, 0.06), 0 18px 40px -28px rgba(29, 25, 21, 0.35);
    --shadow-pop: 0 40px 80px -30px rgba(29, 25, 21, 0.45);
  }
}

/* ---------- Base ---------- */
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--bronze); text-underline-offset: 3px; }
a:hover { color: var(--text-bright); }
::selection { background: rgb(var(--bronze-rgb) / 0.35); }
:focus-visible { outline: 2px solid var(--bronze); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 300; background: var(--bronze-fill); color: var(--on-accent); padding: 10px 16px; border-radius: 999px; font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 12px; }

/* ---------- Buttons — pills ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  font-family: var(--font-body); font-size: 13px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 10px 20px; border-radius: 999px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--control); background: var(--surface-2); color: var(--text);
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.12s var(--ease);
  white-space: nowrap;
}
.btn:hover { border-color: var(--bronze); color: var(--text-bright); }
.btn:active { transform: scale(0.97); }
.btn.primary, .btn.gold { background: var(--bronze-fill); border-color: var(--bronze-fill); color: var(--on-accent); }
.btn.primary:hover, .btn.gold:hover { background: var(--text-bright); border-color: var(--text-bright); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text-bright); }
.btn.danger { background: transparent; color: var(--bad); border-color: rgb(var(--bad-rgb) / 0.6); }
.btn.danger:hover { background: var(--bad-wash); color: var(--bad); border-color: var(--bad); }
.btn.sm { min-height: var(--tap-sm); padding: 7px 14px; font-size: 12px; letter-spacing: 0.08em; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap);
  border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text-bright); }

/* ---------- Forms ---------- */
input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="date"], input[type="number"],
input[type="datetime-local"], input[type="month"], input[type="search"], input[type="time"], input[type="url"], select, textarea {
  width: 100%; min-height: var(--tap); font-family: var(--font-body); font-size: 16px;
  padding: 10px 14px; border: 1px solid var(--control); border-radius: 12px;
  background: var(--surface-2); color: var(--text-bright);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23988562' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
select option, select optgroup { background: var(--surface-2); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--bronze); box-shadow: 0 0 0 3px rgb(var(--bronze-rgb) / 0.3); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--bronze-fill); width: 20px; height: 20px; vertical-align: middle; }
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }

/* ---------- Theme switch (in the user menu) ---------- */
.theme-switch { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 0; }
.theme-switch .track { width: 42px; height: 24px; border-radius: 999px; border: 1px solid var(--control); background: var(--surface-2); position: relative; flex: none; }
.theme-switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 999px; background: var(--bronze-fill); transition: transform 0.2s var(--ease); }
.theme-switch[aria-checked="true"] .track::after { transform: translateX(18px); }

/* ---------- Toast (aria-live) ---------- */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 400;
  background: var(--text-bright); color: var(--bg);
  padding: 13px 20px; border-radius: 16px; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
  font-size: 15px; font-weight: 500; opacity: 0; transform: translateY(10px) scale(0.98);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  pointer-events: none; max-width: 440px;
}
#toast.show { opacity: 1; transform: none; }
#toast.gold { background: var(--bronze-fill); color: var(--on-accent); }

@media (max-width: 720px) {
  #toast { left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}

/* The logo: white artwork on dark, black artwork on light. */
:root[data-theme="light"] img[src="/brand/logo-white.png"] { content: url("/brand/logo-black.png"); }
@media (prefers-color-scheme: light) { :root:not([data-theme]) img[src="/brand/logo-white.png"] { content: url("/brand/logo-black.png"); } }
