/* MPS Group — Resource Schedule
   Sizes here are deliberately small: the grid has to fit a fortnight of a
   410-day roster on a phone, so type steps down to 7px in the reference
   gutters. Colours come from two palettes swapped by [data-theme]. */

:root {
  --navy: #003667;
  --navy-dark: #00294e;
  --orange: #D88027;

  --c-bg: #ffffff;
  --c-bg2: #f3f5f8;
  --c-bg3: #eef1f5;
  --c-tx: #0f1722;
  --c-tx2: #5a6474;
  --c-bd: #c6ccd6;
  --c-bd2: #e4e8ee;
  --c-nv: #003667;

  --shell-max: 520px;
  --search-min: 42%;
  --cell-w: 64px;
  --row-h: 42px;
  --pad-y: 5px;
  --name-w: 128px;
  --ref-disp: block;
  --ref-disp-f: flex;
  --roster-cols: 1fr;

  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

[data-theme="dark"] {
  --c-bg: #131a24;
  --c-bg2: #1a2330;
  --c-bg3: #1e2a3a;
  --c-tx: #e8ecf1;
  --c-tx2: #9aa8ba;
  --c-bd: #34415a;
  --c-bd2: #263246;
  --c-nv: #9ec7ea;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #e8ecf1;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}
[data-theme="dark"] body { background: #0b1119; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.shell {
  height: 100dvh;
  max-width: var(--shell-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  overflow: hidden;
  position: relative;
}

/* ── top bar ─────────────────────────────────────────────────────── */
/* Safe-area padding matters once installed: in standalone the app owns the
   full screen, including the notch and the home indicator. */
.topbar {
  background: var(--navy);
  padding: calc(7px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
           7px calc(12px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.brand { font-size: 15px; font-weight: 800; letter-spacing: .02em; color: #fff; line-height: 1; }
.brand span { color: var(--orange); }
.topbar-meta { margin-left: auto; text-align: right; }
.topbar-title { color: #fff; font-weight: 700; font-size: 10px; letter-spacing: .1em; }
.topbar-sub { color: rgba(255, 255, 255, .7); font-size: 8.5px; margin-top: 1px; }
.icon-btn {
  flex: none; width: 28px; height: 28px;
  border: 1px solid rgba(255, 255, 255, .4);
  background: transparent; color: #fff;
  border-radius: 3px; padding: 0;
  display: flex; align-items: center; justify-content: center;
}

.state-msg {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--c-tx2); font-size: 13px;
  padding: 20px; text-align: center;
}
.state-error { color: #a33; font-size: 12px; }
.state-error .btn { margin-top: 14px; }

.signin { max-width: 300px; text-align: center; }
.signin-title { font-size: 15px; font-weight: 700; color: var(--c-nv); }
.signin-sub { font-size: 11.5px; color: var(--c-tx2); line-height: 1.5; margin: 8px 0 18px; }
.signin .btn { padding: 0 22px; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ── toolbar ─────────────────────────────────────────────────────── */
.toolbar {
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-bd);
  padding: 5px 8px;
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  flex: none;
}
.btn {
  flex: none; height: 30px;
  border: 1px solid var(--c-bd);
  background: var(--c-bg);
  color: var(--c-nv);
  border-radius: 3px;
  padding: 0 8px;
  font-size: 10px; font-weight: 700;
}
.btn.tight { padding: 0 7px; font-size: 9.5px; }
.btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.accent { background: var(--orange); color: #fff; border-color: var(--orange); padding: 0 9px; }
.btn.accent.on { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn.sq { width: 30px; padding: 0; font-size: 14px; }
.btn.lg { height: 34px; font-size: 15px; }
.btn.sq.lg { width: 34px; }
.btn.accent.lg { padding: 0 10px; font-size: 10px; }
.btn.ghost { border-color: rgba(255, 255, 255, .4); background: transparent; color: #fff; padding: 0 10px; height: 28px; }

.search {
  flex: 1; min-width: var(--search-min); height: 30px;
  border: 1px solid var(--c-bd); border-radius: 3px;
  padding: 0 8px; font-size: 12px;
  color: var(--c-tx); background: var(--c-bg);
}

.stepper {
  flex: none; display: inline-flex; align-items: center;
  border: 1px solid var(--c-bd); border-radius: 3px; overflow: hidden;
}
.stepper button {
  width: 28px; height: 28px; border: none;
  background: var(--c-bg); color: var(--c-nv);
  font-size: 14px; font-weight: 700; padding: 0;
}
.stepper button:first-child { border-right: 1px solid var(--c-bd2); }
.stepper button:last-child { border-left: 1px solid var(--c-bd2); }
.stepper-val {
  width: 36px; text-align: center;
  font-size: 9.5px; font-weight: 700; color: var(--c-nv);
}

.chips {
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-bd);
  padding: 4px 8px;
  display: flex; flex-wrap: wrap; gap: 3px;
  flex: none;
}
.chips.flat { border: none; padding: 0; gap: 4px; }
.chip {
  flex: none;
  border: 1px solid var(--c-bd);
  background: var(--c-bg); color: var(--c-nv);
  border-radius: 3px; padding: 4px 6px;
  font-size: 9.5px; font-weight: 600; line-height: 1;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chips.flat .chip { padding: 5px 8px; font-size: 10px; }

/* ── grid ────────────────────────────────────────────────────────── */
.grid-scroll { flex: 1; overflow: auto; background: var(--c-bg); min-height: 0; }
.grid-head { display: flex; width: max-content; position: sticky; top: 0; z-index: 6; }

.head-name {
  width: var(--name-w); flex: none;
  position: sticky; left: 0; z-index: 7;
  background: var(--navy); color: #fff;
  border-right: 2px solid var(--orange);
  display: flex; flex-direction: column;
}
.head-ref {
  display: var(--ref-disp);
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-bd2);
  padding: 1px;
  font-size: 7px; line-height: 1.2;
  color: var(--c-tx2); text-align: center;
}
.head-name-body { flex: 1; padding: 4px 8px; display: flex; flex-direction: column; justify-content: center; }
.head-people { font-size: 8.5px; letter-spacing: .08em; color: rgba(255, 255, 255, .7); }
.head-count { font-size: 11px; font-weight: 700; }

.head-day {
  width: var(--cell-w); flex: none;
  padding: 0; text-align: center;
  background: var(--navy); color: #fff;
  border-bottom: 3px solid var(--navy);
  border-right: 1px solid rgba(255, 255, 255, .15);
  overflow: hidden;
}
.head-day.weekend { background: var(--navy-dark); }
.head-day.today { background: var(--orange); border-bottom-color: var(--orange); }
.head-day .head-ref { font-weight: 600; letter-spacing: .05em; }
.head-day-body { padding: 2px; }
.head-dow { font-size: 8.5px; letter-spacing: .06em; opacity: .75; }
.head-dm { font-size: 11.5px; font-weight: 700; }

.group-row {
  display: flex; width: max-content; min-width: 100%;
  background: var(--c-bg3);
  border-bottom: 1px solid var(--c-bd);
}
.group-label {
  position: sticky; left: 0; z-index: 4;
  padding: 4px 8px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .08em;
  color: var(--c-tx2); text-transform: uppercase;
  white-space: nowrap; background: var(--c-bg3); max-width: 100vw;
}
.group-label.pinned { color: var(--orange); }

.person-row { display: flex; width: max-content; border-bottom: 1px solid var(--c-bd2); }
.name-cell {
  width: var(--name-w); flex: none;
  position: sticky; left: 0; z-index: 4;
  background: var(--c-bg);
  padding: 0;
  border-right: 2px solid var(--c-bd);
  cursor: pointer;
  min-height: var(--row-h);
  display: flex; align-items: stretch;
}
.name-rn {
  display: var(--ref-disp-f);
  width: 16px; flex: none;
  background: var(--c-bg);
  border-right: 1px solid var(--c-bd2);
  font-size: 7px; color: var(--c-tx2);
  align-items: center; justify-content: center; text-align: center;
}
.name-body {
  flex: 1; min-width: 0;
  padding: var(--pad-y) 6px;
  display: flex; flex-direction: column; justify-content: center;
}
.name-main { font-size: 11.5px; font-weight: 700; color: var(--c-nv); line-height: 1.15; }
.name-sub { font-size: 9px; color: var(--c-tx2); line-height: 1.2; margin-top: 2px; }

.cell {
  width: var(--cell-w); flex: none;
  padding: var(--pad-y) 2px;
  font-size: 9.5px; line-height: 1.15;
  display: flex; align-items: center; justify-content: center; text-align: center;
  border-right: 1px solid var(--c-bd2);
  color: var(--c-tx);
  overflow: hidden; min-height: var(--row-h);
  position: relative; cursor: pointer;
}
.cell.weekend { background: var(--c-bg2); }
.cell.today { box-shadow: inset 2px 0 0 0 var(--orange), inset -2px 0 0 0 var(--orange); }
.cell-text { max-height: 34px; overflow: hidden; }
.flag {
  position: absolute; top: 0; right: 0;
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-top: 7px solid var(--orange);
}

.empty { padding: 32px 16px; text-align: center; color: var(--c-tx2); font-size: 13px; }

.foot {
  flex: none;
  background: var(--c-bg);
  border-top: 1px solid var(--c-bd);
  padding: 4px calc(12px + env(safe-area-inset-right))
           calc(4px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  font-size: 9px; color: var(--c-tx2); text-align: center;
}

/* ── person roster ───────────────────────────────────────────────── */
.person-head {
  flex: none;
  background: var(--c-bg);
  border-bottom: 2px solid var(--orange);
  padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
}
.person-id { flex: 1; min-width: 0; }
.person-name { font-size: 14px; font-weight: 700; color: var(--c-nv); line-height: 1.15; }
.person-sub { font-size: 10px; color: var(--c-tx2); margin-top: 2px; }

.roster-scroll { flex: 1; overflow: auto; background: var(--c-bg); min-height: 0; }
.roster-cols {
  display: grid;
  grid-template-columns: var(--roster-cols);
  align-items: start;
  column-gap: 1px;
}
.month { border-right: 1px solid var(--c-bd2); }
.month-label {
  position: sticky; top: 0; z-index: 3;
  background: var(--navy); color: #fff;
  padding: 4px 12px;
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.day-row {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--c-bd2);
  cursor: pointer;
}
.day-row.weekend { background: var(--c-bg2); }
.day-row.today { background: #fdf3e7; }
[data-theme="dark"] .day-row.today { background: #3a2712; }
.day-date { width: 58px; flex: none; }
.day-dow { font-size: 9px; color: var(--c-tx2); letter-spacing: .05em; }
.day-dm { font-size: 12px; font-weight: 700; color: var(--c-nv); }
.day-row.today .day-dm { color: var(--orange); }
.day-val {
  flex: 1; min-width: 0;
  background: var(--c-bg); color: var(--c-tx);
  border: 1px solid var(--c-bd2); border-radius: 3px;
  padding: 5px 9px;
  font-size: 11.5px; line-height: 1.25;
  min-height: 29px;
  display: flex; align-items: center;
  position: relative;
}

/* ── popup ───────────────────────────────────────────────────────── */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(0, 22, 44, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.popup-card {
  background: var(--c-bg);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 10, 25, .4);
  max-width: 340px; min-width: 220px; max-height: 70dvh;
  overflow: auto;
  border-top: 2px solid var(--orange);
}
.popup-head { padding: 12px 14px 8px; display: flex; align-items: flex-start; gap: 10px; }
.popup-who { flex: 1; min-width: 0; }
.popup-name { font-size: 13px; font-weight: 700; color: var(--c-nv); line-height: 1.2; }
.popup-date { font-size: 10.5px; color: var(--c-tx2); margin-top: 2px; }
.popup-ref {
  flex: none;
  background: var(--c-bg3);
  border: 1px solid var(--c-bd2); border-radius: 3px;
  padding: 3px 7px;
  font-size: 10px; font-weight: 700; color: var(--c-nv);
  font-family: var(--font-mono);
}
.popup-body { padding: 0 14px 12px; }
.popup-val {
  background: var(--c-bg3); color: var(--c-tx);
  border: 1px solid var(--c-bd2); border-radius: 3px;
  padding: 8px 10px;
  font-size: 13px; font-weight: 600; line-height: 1.3;
  white-space: pre-wrap;
}
.popup-comment { border-top: 1px solid var(--c-bd2); padding: 10px 14px 12px; }
.popup-comment-label {
  font-size: 9px; font-weight: 700; letter-spacing: .1em;
  color: var(--orange); margin-bottom: 6px;
}
.popup-comment-text { font-size: 11.5px; color: var(--c-tx); line-height: 1.45; white-space: pre-wrap; }
.popup-foot {
  border-top: 1px solid var(--c-bd2);
  padding: 8px 14px; text-align: center;
  font-size: 10px; color: var(--c-tx2);
}

/* ── settings ────────────────────────────────────────────────────── */
.settings {
  position: absolute; inset: 0; z-index: 50;
  background: var(--c-bg);
  display: flex; flex-direction: column;
}
.settings-bar {
  background: var(--navy);
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
           10px calc(14px + env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px;
  flex: none;
}
.settings-title { color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .1em; flex: 1; }
.settings-body {
  flex: 1; overflow: auto;
  padding: 14px calc(14px + env(safe-area-inset-right))
           calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 18px;
}
.btn[disabled] { opacity: .55; cursor: default; }
.row-end { display: flex; align-items: center; justify-content: flex-end; }
.row-toggle { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px 16px;
  align-items: end;
}
.field-label {
  font-size: 12px; font-weight: 700; color: var(--c-nv);
  margin-bottom: 6px; min-height: 28px;
  display: flex; align-items: flex-end;
}
.field-label.plain { min-height: 0; display: block; margin-bottom: 6px; }
.field-cap { font-size: 9px; color: var(--c-tx2); margin-top: 3px; }
.field-cap.spaced { margin: 2px 0 8px; font-size: 10px; }
.settings .stepper button { width: 30px; height: 30px; }
.settings .stepper .stepper-val { width: 34px; font-size: 12px; }

.pad-chips { display: flex; gap: 4px; }
.pad-chips .chip { padding: 6px 10px; font-size: 10.5px; }
.pad-range { display: block; width: 100%; max-width: 280px; margin-top: 10px; accent-color: var(--orange); }

.text-input {
  width: 100%; height: 32px;
  border: 1px solid var(--c-bd); border-radius: 3px;
  padding: 0 9px; font-size: 12px;
  color: var(--c-tx); background: var(--c-bg);
}
.pin-matches { border: 1px solid var(--c-bd2); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.pin-match {
  display: block; width: 100%; text-align: left;
  border: none; border-bottom: 1px solid var(--c-bd2);
  background: var(--c-bg); color: var(--c-tx);
  padding: 7px 9px; font-size: 11.5px;
}
.pin-match b { font-weight: 700; color: var(--c-nv); }
.pin-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.pin-item {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--c-bd2); border-radius: 3px;
  padding: 5px 8px; background: var(--c-bg3);
}
.pin-n { flex: none; font-size: 10px; font-weight: 700; color: var(--orange); width: 14px; }
.pin-name { flex: 1; min-width: 0; font-size: 11.5px; font-weight: 700; color: var(--c-nv); }
.pin-name span { font-weight: 400; color: var(--c-tx2); }
.pin-btn {
  flex: none; width: 26px; height: 26px;
  border: 1px solid var(--c-bd); background: var(--c-bg); color: var(--c-nv);
  border-radius: 3px; font-size: 11px; padding: 0;
}
.pin-btn.danger { color: #a33; }
.settings-note {
  font-size: 9.5px; color: var(--c-tx2);
  border-top: 1px solid var(--c-bd2); padding-top: 10px;
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .icon-btn { transition: background-color .12s, color .12s, border-color .12s; }
}
