/* Team Roster: calm utilitarian tool. Warm monochrome, one ink accent,
   status colours only where they carry meaning (ok / gap-sick / warn).
   Shape rule: 8px radius for controls and cards, full pill only for badges and chips. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeeea;
  --ink: #1d1f1e;
  --muted: #656966;
  --line: #e2e0da;
  --line-strong: #c9c6be;
  --accent: #1f4f46;          /* single accent: focus rings, selected states */
  --accent-soft: #e3eeea;
  --on-ink: #ffffff;
  --ok: #2f7d4f;
  --ok-soft: #e4f1e8;
  --ok-ink: #1f5a37;
  --bad: #c0392b;
  --bad-soft: #fbe7e4;
  --bad-ink: #8f2a1f;
  --warn: #b7791f;
  --warn-soft: #fbf0d9;
  --warn-ink: #7a4f0c;
  --radius: 8px;
  --gutter: 16px;
  --tap: 44px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151716;
    --surface: #1e2120;
    --surface-2: #272b29;
    --ink: #ecebe7;
    --muted: #9ea29e;
    --line: #2f3331;
    --line-strong: #444a47;
    --accent: #7fc4b2;
    --accent-soft: #223a34;
    --on-ink: #151716;
    --ok: #52b37a;
    --ok-soft: #1c3226;
    --ok-ink: #8fd6ac;
    --bad: #e5675a;
    --bad-soft: #3a211e;
    --bad-ink: #f0a59c;
    --warn: #d9a441;
    --warn-soft: #35291a;
    --warn-ink: #e8c27a;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.error { color: var(--bad-ink); }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.time { font-family: var(--mono); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.login { width: 100%; max-width: 380px; }
.view { max-width: 1200px; margin: 0 auto; padding: var(--gutter); display: grid; gap: var(--gutter); align-content: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px var(--gutter);
}
.card h2 { margin-bottom: .75rem; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 8px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1rem; letter-spacing: -0.01em; margin-right: auto; }
.bar nav { display: flex; gap: 4px; order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
.bar nav::-webkit-scrollbar { display: none; }
.who { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.tab {
  min-height: var(--tap); padding: 0 14px; white-space: nowrap;
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--muted); cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }

@media (min-width: 721px) {
  .bar { flex-wrap: nowrap; padding: 0 24px; gap: 16px; }
  .brand { margin-right: 8px; }
  .bar nav { order: 0; width: auto; margin-right: auto; }
}

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
  transition: background-color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; background: var(--ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--bad-ink); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.add {
  width: 100%; min-height: var(--tap); font-size: .85rem; color: var(--muted);
  background: transparent; border-style: dashed;
}
.btn.add:hover { color: var(--ink); background: var(--surface-2); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 auto; }

/* ---------- Forms ---------- */
input, select, textarea {
  min-height: var(--tap); padding: 0 12px; width: 100%;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
textarea { padding: 10px 12px; min-height: 88px; }
input::placeholder { color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: 20px; min-height: 20px; height: 20px; padding: 0; accent-color: var(--accent); flex: none; }

.field { display: grid; gap: 6px; margin: 0 0 14px; padding: 0; border: 0; font-size: .9rem; color: var(--muted); min-width: 0; }
.field legend { padding: 0; margin-bottom: 6px; }
.field input, .field select, .field textarea { color: var(--ink); font-size: 1rem; }
.field.row { grid-template-columns: 1fr 1fr; gap: 12px; }
.field.row label { display: grid; gap: 6px; min-width: 0; }

.check {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 0 12px; color: var(--ink); font-size: 1rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.checks { display: grid; gap: 8px; }

/* ---------- Login and PIN pad ---------- */
.login h1 { margin-bottom: .25rem; }
.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.name {
  min-height: 52px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  cursor: pointer; font-weight: 500;
}
.name:hover { background: var(--surface-2); }
.name.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.pin {
  min-height: 56px; margin-bottom: 12px;
  font-family: var(--mono); font-size: 1.5rem; letter-spacing: .5em; text-align: center;
}
.pin::placeholder { font-family: var(--font); font-size: 1rem; letter-spacing: 0; }
.login .btn { width: 100%; }

/* ---------- Week bar and coverage ---------- */
.weekbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.weekbar strong { flex: 1 1 auto; text-align: center; order: -1; width: 100%; }
@media (min-width: 480px) { .weekbar strong { order: 0; width: auto; } }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: .85rem; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; }
.swatch.ok { background: var(--ok); }
.swatch.bad { background: var(--bad); }

.cover {
  position: relative; height: 8px; border-radius: 4px; overflow: hidden;
  background: var(--ok); margin: 4px 0 12px;
}
.cover .gap { position: absolute; top: 0; bottom: 0; background: var(--bad); }

/* ---------- Week grid ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(7, minmax(150px, 1fr)); overflow-x: auto; padding-bottom: 4px; align-items: start; }
.day {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: grid; gap: 8px; min-width: 0;
}
.day h3 { margin: 0; }

.shift {
  display: grid; gap: 2px; width: 100%; text-align: left;
  padding: 10px 12px; min-height: var(--tap);
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: var(--radius);
}
button.shift { cursor: pointer; }
button.shift:hover { border-color: var(--line-strong); border-left-color: var(--ok); }
.shift.sick { background: var(--bad-soft); border-left-color: var(--bad); }
.shift.open { background: var(--warn-soft); border-left-color: var(--warn); border-style: dashed; border-left-style: solid; }
.who-line { font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: .8rem; }
.chip {
  padding: 2px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-strong); font-size: .8rem;
}

.badge {
  display: inline-block; padding: 2px 10px; margin-left: 6px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; vertical-align: middle;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.shift .badge { margin-left: 0; justify-self: start; }
.badge.ok { background: var(--ok-soft); color: var(--ok-ink); border-color: transparent; }
.badge.sick { background: var(--bad-soft); color: var(--bad-ink); border-color: transparent; }
.warn { color: var(--warn-ink); background: var(--warn-soft); padding: 2px 8px; border-radius: 4px; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; overflow: visible; }
}

/* ---------- Hours panel and tables ---------- */
.hours table { width: 100%; border-collapse: collapse; }
.hours td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.hours tr:last-child td { border-bottom: 0; }
.hours td.num { width: 1%; white-space: nowrap; }

.row-form { display: grid; gap: 8px; grid-template-columns: 1fr; align-items: end; }
@media (min-width: 721px) { .row-form { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); } }

/* People: stacked per-person rows (name + role, then actions) */
ul.people { list-style: none; margin: 0 0 12px; padding: 0; }
.person { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.person-name { flex: 1 1 auto; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.person-main select { width: 130px; min-height: var(--tap); flex: 0 0 130px; }
.person-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 721px) { .person-actions { grid-template-columns: repeat(2, max-content); } }

ul.plain { list-style: none; margin: 0 0 12px; padding: 0; }
ul.plain li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }

/* ---------- Availability rows ---------- */
.avail-row {
  display: grid; grid-template-columns: 1fr; gap: 8px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.avail-row:last-child { border-bottom: 0; }
.day-label { font-weight: 600; }
.times { display: flex; align-items: center; gap: 8px; }
.times[hidden] { display: none; }
.times input { flex: 1 1 0; min-width: 0; }
@media (min-width: 721px) {
  .avail-row { grid-template-columns: 180px 220px 1fr; }
}

/* ---------- Dialog sheet ---------- */
dialog.sheet {
  width: min(480px, calc(100vw - 2 * var(--gutter))); max-height: calc(100dvh - 2 * var(--gutter));
  margin: auto; padding: 20px var(--gutter);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: auto;
}
dialog.sheet::backdrop { background: rgba(20, 22, 21, .5); }
dialog.sheet form { margin: 0; }
dialog.sheet h2 { margin-bottom: 1rem; }
dialog.sheet .actions { margin-top: 8px; }
@media (max-width: 720px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; left: var(--gutter); right: var(--gutter); bottom: var(--gutter); z-index: 30;
  display: grid; gap: 8px; justify-items: center; pointer-events: none;
}
.toast {
  max-width: 420px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--ink); color: var(--on-ink); font-size: .95rem;
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@media (prefers-color-scheme: dark) {
  .toast.error, .toast.ok { color: #151716; }
}

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
