/* ESFD EMS shift calendar — shared styles for the volunteer and officer views.
   Deliberately mirrors the printed Wiki Calendar the chief is using today:
   a 7-column month grid with sub-boxes per shift block. Below 900px the grid
   collapses to a stacked day list, because most volunteers will open this on a
   phone. Print styles keep the desktop grid so it can still go on the wall. */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #cfd4dc;
  --border-strong: #1d2430;
  --text: #161d29;
  --text-dim: #5c6675;
  --text-faint: #8b95a3;

  --accent: #a3231f;          /* fire-service red */
  --accent-text: #ffffff;
  --mine: #1c6b4a;            /* shifts you hold */
  --mine-soft: #e3f3ec;
  --other-soft: #eceff4;
  --closed: #e3e6eb;
  --warn: #8a5a00;
  --warn-soft: #fdf3dd;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 22, 32, 0.06), 0 4px 12px rgba(16, 22, 32, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151b;
    --surface: #1a1f27;
    --surface-2: #212831;
    --border: #333c48;
    --border-strong: #7d8896;
    --text: #e8ecf1;
    --text-dim: #a3adba;
    --text-faint: #6f7a88;

    --accent: #e0524d;
    --accent-text: #1a0f0e;
    --mine: #5fd39b;
    --mine-soft: #163025;
    --other-soft: #252d38;
    --closed: #1e232b;
    --warn: #e8b45c;
    --warn-soft: #2e2617;
  }
}

:root[data-theme="dark"] {
  --bg: #11151b;
  --surface: #1a1f27;
  --surface-2: #212831;
  --border: #333c48;
  --border-strong: #7d8896;
  --text: #e8ecf1;
  --text-dim: #a3adba;
  --text-faint: #6f7a88;
  --accent: #e0524d;
  --accent-text: #1a0f0e;
  --mine: #5fd39b;
  --mine-soft: #163025;
  --other-soft: #252d38;
  --closed: #1e232b;
  --warn: #e8b45c;
  --warn-soft: #2e2617;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand { display: flex; flex-direction: column; gap: 2px; }

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.brand .sub { color: var(--text-dim); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.field { display: flex; flex-direction: column; gap: 4px; }

.field > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

select, button, input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
}

button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--border-strong); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.monthnav { display: flex; align-items: center; gap: 8px; }
.monthnav .label { min-width: 9.5em; text-align: center; font-weight: 600; }

/* ---------- status line ---------- */

.notice {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
}
.notice[hidden] { display: none; }
.notice.err { border-color: var(--accent); background: var(--warn-soft); color: var(--text); }

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { display: flex; flex-direction: column; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.stat .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--text-dim); }

/* ---------- month grid ---------- */

.dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.dow span {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 2px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.day.pad { background: transparent; border: none; min-height: 0; }
.day.weekend { background: var(--surface-2); }

.day > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.daynum { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dayname { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }

/* Officer on Duty — admin view only. */
.ood { display: flex; align-items: center; gap: 4px; }
.ood select { padding: 1px 4px; font-size: 11px; border-radius: 5px; }
.ood .tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid currentColor;
}

/* ---------- shift blocks ---------- */

.block {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 5px;
  background: var(--surface);
}
.block.closed { background: var(--closed); border-style: dashed; }
.block.full { border-color: var(--mine); }

.block > .head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.block .time { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.block .credit { font-size: 10px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.block .why { font-size: 10px; color: var(--text-faint); font-style: italic; }

.seats { display: flex; flex-direction: column; gap: 3px; }

.seat {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 3px 6px;
  font-size: 12px;
  line-height: 1.3;
  border-radius: 5px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-faint);
  min-height: 24px;
}
.seat.taken {
  border-style: solid;
  background: var(--other-soft);
  color: var(--text);
  font-weight: 500;
}
.seat.self {
  border-color: var(--mine);
  background: var(--mine-soft);
  color: var(--mine);
  font-weight: 700;
}
.seat .r {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 3px;
  border: 1px solid currentColor;
  opacity: 0.75;
}
.seat.disabled { cursor: not-allowed; }
.seat select { width: 100%; padding: 2px 4px; font-size: 11px; border-radius: 4px; }

/* ---------- payroll table (admin) ---------- */

.panel {
  margin-top: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel > header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.panel > header h2 { margin: 0; font-size: 16px; }
.panel .body { padding: 0; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: var(--surface-2);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--other-soft);
  color: var(--text-dim);
}
.pill.res { background: var(--mine-soft); color: var(--mine); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-dim);
}
.legend i {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
  border: 1px solid var(--border);
}
.legend .k-self { background: var(--mine-soft); border-color: var(--mine); }
.legend .k-other { background: var(--other-soft); }
.legend .k-closed { background: var(--closed); border-style: dashed; }

.foot { margin-top: 28px; font-size: 13px; color: var(--text-dim); }
.foot code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  word-break: break-all;
}
.foot a { color: var(--accent); }

/* ---------- responsive: stacked day list on phones ---------- */

@media (max-width: 900px) {
  .dow { display: none; }
  .grid { grid-template-columns: 1fr; gap: 8px; }
  .day { min-height: 0; }
  .day.pad { display: none; }
  .day > header { border-bottom: 1px solid var(--border); padding-bottom: 5px; }
  /* The stacked list needs the weekday spelled out next to the date; the
     right-aligned .dayname that the desktop grid uses becomes redundant. */
  .daynum::after { content: attr(data-long); font-size: 12px; font-weight: 500; color: var(--text-dim); margin-left: 7px; }
  .dayname { display: none; }
  .block .time { font-size: 13px; }
  .seat { font-size: 14px; min-height: 34px; }
}

@media print {
  body { background: #fff; }
  .controls, .panel, .foot, .notice, .legend { display: none !important; }
  .grid { grid-template-columns: repeat(7, 1fr); }
  .day { break-inside: avoid; border-color: #000; }
}
