/* PIP — look and feel carried over from the PSC PIP reference build.
   Tokens, three themes and component styles match the prototype. */

:root {
  --bg: #172433; --panel: #223348; --panel2: #293c54; --nav: #102033; --border: #3f5877;
  --text: #eaf6ff; --muted: #a9c5dc; --accent: #69b7ff; --accent2: #91d3ff;
  --gold: #f4c84a; --green: #35d39a; --yellow: #f4c84a; --red: #ff7474;
  --font-base: 14px;
}

/* ── light: full warm cream ─────────────────────────────────────────────── */
body.theme-light {
  --bg: #f2ead8; --panel: #faf4e6; --panel2: #e8dfc8; --nav: #d4c9ae; --border: #b8aa8a;
  --text: #1e1608; --muted: #5a4a28; --accent: #6b3d0a; --accent2: #6b3d0a;
  --gold: #7a5500; --green: #1e4e1e; --yellow: #7a5500; --red: #7a1010;
}
body.theme-light aside { background: #cfc4a8; border-right: 2px solid #b8aa8a; }
body.theme-light .nav button { color: #2a1c08; background: transparent; border-color: transparent; font-weight: 500; }
body.theme-light .nav button:hover, body.theme-light .nav button.active { background: #bdb09a; border-color: #9a8c70; color: #0e0a04; }
body.theme-light .brand { background: #c4b898; border-color: #a89870; }
body.theme-light .brand .tag { color: #6b3d0a; letter-spacing: 6px; font-weight: bold; }
body.theme-light .brand h1, body.theme-light h1, body.theme-light h2, body.theme-light h3 { color: #4a2a08; }
body.theme-light .card { background: #faf4e6; border-color: #b8aa8a; box-shadow: 0 4px 18px rgba(60, 40, 10, .13); }
body.theme-light .metric { background: #ede4ce; border-color: #b8aa8a; }
body.theme-light table th { background: #c8bc9e; color: #2a1c08; }
body.theme-light .notice { background: #ede4c0; border-left-color: #7a5500; color: #2a1c08; }
body.theme-light .sub, body.theme-light .label { color: #5a4a28; }
body.theme-light input, body.theme-light select, body.theme-light textarea { background: #faf4e6; color: #1e1608; border-color: #b8aa8a; }
body.theme-light button { background: #e8dfc8; color: #1e1608; border-color: #b8aa8a; }
body.theme-light button:hover { border-color: #6b3d0a; color: #4a2a08; }
body.theme-light .tabs button.active { background: #b8aa8a; border-color: #6b3d0a; color: #0e0a04; }
body.theme-light .good { color: #1e4e1e; } body.theme-light .warn { color: #7a5500; } body.theme-light .bad { color: #7a1010; }
body.theme-light .pill { border-color: #b8aa8a; color: #5a4a28; background: #ede4ce; }
body.theme-light .navhead { color: #6b3d0a; }

/* ── midnight: pure black, max contrast for night shift ─────────────────── */
body.theme-midnight {
  --bg: #000; --panel: #0a0a0a; --panel2: #161616; --nav: #000; --border: #2e2e2e;
  --text: #fff; --muted: #b8c4cc; --accent: #69b7ff; --accent2: #91d3ff;
  --gold: #f4c84a; --green: #35d39a; --yellow: #f4c84a; --red: #ff7474;
}
body.theme-midnight aside { border-right: 1px solid #2e2e2e; }
body.theme-midnight .card { box-shadow: 0 0 0 1px #1c1c1c; }

body.font-lg { --font-base: 16px; }
body.font-xl { --font-base: 18px; }

/* ── skip link: first tab stop, visible only when focused ───────────────── */
.skiplink {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--panel); color: var(--accent2); border: 1px solid var(--accent);
  border-radius: 0 0 10px 0; padding: 10px 16px; font-size: 13px; text-decoration: none;
}
.skiplink:focus { left: 0; }
body.login-mode .skiplink { display: none; }

* { box-sizing: border-box; }
html, body { font-size: var(--font-base); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Arial, Helvetica, sans-serif; display: flex; min-height: 100vh;
}
body.login-mode { display: block; }

aside {
  width: 285px; background: var(--nav); border-right: 1px solid var(--border);
  padding: 16px; position: fixed; height: 100vh; overflow: auto; z-index: 5;
}
main { margin-left: 285px; width: calc(100% - 285px); min-height: 100vh; padding: 20px; }
h1, h2, h3 { color: var(--accent2); margin-top: 0; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.sub { color: var(--muted); }

.brand { border: 1px solid var(--border); background: var(--nav); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.brand .tag { letter-spacing: 6px; color: var(--accent2); font-weight: bold; font-size: 11px; }
.brand h1 { font-size: 22px; margin: 8px 0 4px; color: var(--accent2); }
.brand .who { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

.nav button {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--text); border-radius: 12px; padding: 10px 12px; margin: 4px 0; cursor: pointer;
  font-size: 13px; font-family: inherit;
}
.nav button:hover, .nav button.active { background: var(--panel2); border-color: var(--border); }
.navsec { border-top: 1px solid #1a1a2e; margin-top: 2px; }
.navhead {
  cursor: pointer; display: flex; align-items: center; justify-content: space-between;
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: #4a9eff; padding: 10px 10px 4px 12px; user-select: none;
  width: 100%; background: transparent; border: 1px solid transparent;
  border-radius: 8px; margin: 0; font-family: inherit; text-align: left;
}
.navhead:hover { color: var(--accent2); }
.navhead:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, th:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.navbadge {
  display: inline-block; min-width: 16px; text-align: center; font-size: 10px; font-weight: 700;
  background: #2b4b6e; color: var(--accent2); border-radius: 999px; padding: 1px 5px; margin-left: 6px;
}
.devpill {
  font-size: 9px; background: #2d1a00; color: #f59e0b; border: 1px solid #f59e0b;
  border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: middle;
}

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar select, .toolbar button, .toolbar input {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 10px; font-family: inherit; font-size: 13px;
  width: auto; margin-top: 0;
}
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; margin: 3px; cursor: pointer;
  font-family: inherit; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.primary { background: #1d344d; border-color: var(--accent); color: var(--accent2); font-weight: 700; }
button.danger { border-color: var(--red); color: var(--red); }
button:disabled { opacity: .45; cursor: not-allowed; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 16px; margin-bottom: 14px; box-shadow: 0 12px 34px rgba(0, 0, 0, .22);
}
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.col-2 { grid-column: span 2 } .col-3 { grid-column: span 3 } .col-4 { grid-column: span 4 }
.col-6 { grid-column: span 6 } .col-8 { grid-column: span 8 } .col-12 { grid-column: span 12 }
.metric { background: var(--panel2); border: 1px solid var(--border); border-radius: 16px; padding: 14px; }
.label { color: var(--muted); font-size: 12px; }
.value { font-size: 28px; font-weight: bold; margin-top: 8px; }
.value.sm { font-size: 20px; }

input, select, textarea {
  width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px; margin-top: 4px; font-family: inherit; font-size: 13px;
}
label { font-size: 12px; color: var(--muted); }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: auto; margin-right: 6px; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
th, td { border-bottom: 1px solid var(--border); padding: 9px; text-align: left; vertical-align: top; }
th { background: var(--nav); color: var(--accent2); position: sticky; top: 0; cursor: pointer; white-space: nowrap; }
tbody tr:hover { background: var(--panel2); }
.tablewrap { max-height: 68vh; overflow: auto; border-radius: 10px; }

.good { color: var(--green); font-weight: bold } .warn { color: var(--yellow); font-weight: bold } .bad { color: var(--red); font-weight: bold }
.pill { display: inline-block; border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px; margin: 2px; color: var(--muted); font-size: 12px; }
.pill.on { border-color: var(--green); color: var(--green); }
.pill.off { border-color: var(--red); color: var(--red); }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tabs button.active { background: #2b4b6e; border-color: var(--accent); }
.notice { border-left: 4px solid var(--gold); background: #26364a; padding: 12px; border-radius: 10px; color: #fff5c7; margin-bottom: 12px; }
.small { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--panel2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 46px; margin-top: 8px; }
.spark > i {
  flex: 1 1 auto; max-width: 22px; background: var(--accent); border-radius: 2px 2px 0 0;
  min-height: 3px; opacity: .85;
}

/* ── modal ──────────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .62); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; overflow: auto; padding: 40px 16px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 860px; padding: 20px; box-shadow: 0 30px 70px rgba(0, 0, 0, .55);
}
.modal h2 { margin-bottom: 4px; }
.formgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.formgrid .wide { grid-column: 1 / -1; }
@media (max-width: 700px) { .formgrid { grid-template-columns: 1fr; } }

/* ── toast ──────────────────────────────────────────────────────────────── */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--accent); color: var(--text);
  border-radius: 12px; padding: 11px 14px; font-size: 13px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  max-width: 380px;
}
.toast.err { border-color: var(--red); }
.toast.ok { border-color: var(--green); }

/* ── login ──────────────────────────────────────────────────────────────── */
/* The login card is intentionally theme-independent: the theme is a signed-in
   preference, and inheriting the light palette here left pale accent text on a
   cream background (unreadable demo buttons and hints). */
#login {
  --bg: #172433; --panel: #223348; --panel2: #293c54; --nav: #102033; --border: #3f5877;
  --text: #eaf6ff; --muted: #a9c5dc; --accent: #69b7ff; --accent2: #91d3ff;
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 25% 20%, #1d3b5a, transparent), #172433;
  padding: 24px; color: #eaf6ff;
}
#login .loginwrap { background: #223348; border-color: #3f5877; }
#login input {
  background: #293c54; color: #eaf6ff; border: 1px solid #3f5877;
}
#login input::placeholder { color: #7f9cb8; }
#login button.primary { background: #1d344d; border-color: #69b7ff; color: #91d3ff; }
#login label { color: #a9c5dc; }
#login h2 { color: #e8f6ff; }
#login .hint { color: #a9c5dc; }
#login .notice { background: #12261e; color: #35d39a; border-left-color: #35d39a; }
.loginwrap {
  display: flex; flex-wrap: wrap; gap: 0; background: var(--panel);
  border: 1px solid var(--border); border-radius: 22px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55); max-width: 900px; width: 100%;
}
.loginbrand {
  flex: 1 1 380px; min-width: 300px; padding: 44px 36px; background: linear-gradient(160deg, #0e1c2c, #17324d);
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
}
.loginbrand .mark { font-size: 40px; font-weight: 900; letter-spacing: 6px; color: #e8f6ff; }
.loginbrand .sub2 { font-size: 10px; letter-spacing: 2px; color: #4ab8f4; font-weight: 600; line-height: 1.7; }
.loginbrand .tagline { font-size: 12px; color: #6688aa; font-style: italic; margin-top: 6px; }
.loginform { flex: 1 1 360px; min-width: 300px; max-width: 440px; padding: 38px 36px; }
.loginform h2 { font-size: 19px; color: #e8f6ff; text-align: center; margin-bottom: 2px; }
.loginform .hint { font-size: 12px; color: #a9c5dc; text-align: center; margin-bottom: 20px; }
.demo-btn {
  width: 100%; margin-bottom: 6px; border-radius: 4px; padding: 9px; font-size: 13px;
  font-weight: 600; cursor: pointer; text-align: center; user-select: none; border: 1px solid;
  background: transparent;
}
.build {
  font-size: 9px; color: #556677; letter-spacing: 1px; margin-top: 12px; line-height: 1.6;
  border-top: 1px solid #1a3a5a; padding-top: 10px;
}
.err { color: var(--red); font-size: 12px; min-height: 18px; }

@media (max-width: 950px) {
  body { display: block; }
  aside {
    position: relative; width: 100%; height: auto; max-height: 46vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  main { margin-left: 0; width: 100%; padding: 14px; }
  .grid { grid-template-columns: repeat(6, 1fr); }
  .col-3, .col-4 { grid-column: span 3; }
  .col-6, .col-8, .col-12 { grid-column: span 6; }
  .toolbar { gap: 6px; }
  .value { font-size: 24px; }
  /* tables scroll horizontally rather than forcing the page wide */
  .tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 620px; }
  .modal { max-width: 100%; padding: 16px; }
  .modal-back { padding: 16px 10px; }
}

/* the toggle only exists on small screens (base rule must precede the media query) */
.navtoggle {
  display: none; width: 100%; margin: 10px 0 0; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
}

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .col-2, .col-3, .col-4, .col-6, .col-8, .col-12 { grid-column: span 1; }
  aside { max-height: none; padding: 12px; }
  .brand { padding: 12px; border-radius: 14px; margin-bottom: 8px; }
  .brand h1 { font-size: 19px; }
  main { padding: 10px; }
  .card { padding: 12px; border-radius: 14px; }
  .value { font-size: 21px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > div { display: flex; flex-wrap: wrap; gap: 6px; }
  .toolbar select, .toolbar button, .toolbar input { flex: 1 1 auto; }
  .formgrid { grid-template-columns: 1fr; }
  /* nav collapses behind a toggle so the page starts at the top of the screen */
  .navtoggle { display: block; }
  #aside .nav { display: none; }
  body.nav-open #aside .nav { display: block; max-height: 60vh; overflow: auto; }
  #aside > div:last-child { display: none; }         /* sign-out moves into the menu */
  body.nav-open #aside > div:last-child { display: block; }
}

/* ── charts ────────────────────────────────────────────────────────────── */
.chart { margin: 12px 0; }
.charttitle { font-weight: 700; font-size: 13px; color: var(--accent2); margin-bottom: 6px; }
.chartsvg { width: 100%; height: auto; display: block; overflow: visible; }
.chartsvg.donut { max-width: 200px; margin: 0 auto; }
.chartgrid { stroke: var(--border); stroke-width: 1; opacity: .5; }
.charttarget { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chartaxis { fill: var(--muted); font-size: 10px; }
.chartval { fill: var(--text); font-size: 10px; font-weight: 700; }
.chartrail { fill: var(--panel2); stroke: var(--border); }
.chartline { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chartarea { opacity: .14; }
.donuttotal { fill: var(--text); font-size: 22px; font-weight: 800; }
.chartlegend { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; justify-content: center; }
.charttable { margin-top: 6px; }
.charttable summary {
  cursor: pointer; font-size: 11px; color: var(--accent);
  padding: 2px 0; user-select: none;
}
.charttable summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.charttable table { margin-top: 6px; font-size: 12px; }
.charttable th, .charttable td { padding: 4px 8px; }
.chartgrid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }

@media (max-width: 620px) {
  .chartgrid2 { grid-template-columns: 1fr; }
  .chartaxis { font-size: 9px; }
}
@media print {
  .chart { break-inside: avoid; }
  .charttable { display: none; }   /* the graphic prints; the fallback table would duplicate it */
}

/* ── meaning that survives monochrome and colour blindness ─────────────── */
.statemark { font-size: .78em; opacity: .85; margin-left: 1px; }
/* visible only to assistive technology */
.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;
}

/* ── month calendar widget ─────────────────────────────────────────────── */
.calhead { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.calnav { display: flex; gap: 6px; }
.callegend { margin: 8px 0 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.calgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.caldow {
  text-align: center; font-weight: 700; color: var(--accent2);
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding-bottom: 2px;
}
.calcell {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 10px;
  min-height: 104px; padding: 6px 6px 8px; overflow: hidden;
  display: flex; flex-direction: column; gap: 3px;
}
.calcell.calpad { background: transparent; border-color: transparent; min-height: 0; }
.calcell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.calcell[tabindex]:hover { border-color: var(--accent); }
.calweekend { background: color-mix(in srgb, var(--panel2) 82%, var(--bg)); }
.caltoday { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.caltoday .caldate { color: var(--accent2); }
.calgap { border-color: var(--red); }
.caldate { font-size: 12px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.calgapdot { color: var(--red); font-size: 9px; }
.calbar {
  font-size: 11px; line-height: 1.35; padding: 2px 5px; border-radius: 5px;
  border-left: 3px solid var(--accent); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--text);
}
/* a run of days reads as one continuous bar */
.calbar-start { border-radius: 5px 0 0 5px; }
.calbar-mid { border-radius: 0; border-left-style: dotted; }
.calbar-end { border-radius: 0 5px 5px 0; border-left-style: dotted; }
.calmore { color: var(--muted); font-size: 10px; }

@media (max-width: 950px) {
  .calcell { min-height: 84px; }
  .calbar { font-size: 10px; }
}
@media (max-width: 620px) {
  /* a 7-column month grid is unreadable on a phone — stack into a day list */
  .calgrid { grid-template-columns: 1fr; }
  .caldow { display: none; }
  .calcell.calpad { display: none; }
  .calcell { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .caldate { min-width: 34px; }
  .calbar { flex: 1 1 100%; white-space: normal; }
}
@media print {
  .calcell { min-height: 70px; break-inside: avoid; }
  .calnav { display: none !important; }
  aside, .toolbar, #toasts, .noprint { display: none !important; }
  main { margin: 0; width: 100%; }
  body { background: #fff; color: #000; display: block; }
  .card { box-shadow: none; border-color: #999; }
}
