/* ───────────────────────────────────────────────────────────────────────────
   RosterWarden — mobile-first stylesheet.

   The Sixth Day Studios dark palette shared with InvoiceWarden and RamWarden
   (near-black surfaces, teal accent). Dark-only: contrast is kept high so it
   stays readable on a phone outdoors. Everything is token-driven.

   System fonts throughout, deliberately: this is an offline-first installed app
   and a webfont request would block first paint on a bad connection.
   ─────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:        #121212;
  --surface:   #1a1a1a;
  --surface-2: #1f1f1f;
  --raised:    #272727;
  --line:      #2e2e2e;
  --ink:       #e8e8e8;
  --ink-dim:   #a8a8a8;
  --ink-faint: #919191;

  --accent:    #2cc4a8;
  --accent-in: #06201b;   /* text on an accent fill */
  --accent-lo: #123a33;

  --ok:        #5cc561;
  --warn:      #e8b04a;
  --bad:       #e86060;

  --radius:  10px;
  --radius-s: 7px;
  --tap:     44px;        /* minimum comfortable touch target */
  --maxw:    56rem;

  --shadow: 0 6px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
h4 { font-size: .9rem; font-weight: 650; }
p  { margin: 0 0 .75rem; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* ── app bar ─────────────────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.appbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .9rem;
}
.brand { display: flex; align-items: center; gap: .55rem; flex: none; }
/* Inline SVG shield-and-calendar mark, glowing teal like the sibling products. */
.brand-mark {
  width: 26px; height: 26px; flex: none;
  fill: none; stroke: var(--accent); stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(44,196,168,.55));
}
.brand-name {
  font-weight: 800; letter-spacing: .06em; font-size: .82rem;
  text-transform: uppercase; color: var(--accent);
  text-shadow: 0 0 10px rgba(44,196,168,.45);
}

.org-switch { margin-left: auto; min-width: 0; }
.org-switch select {
  width: 100%; max-width: 15rem;
  min-height: 36px; padding: .3rem 1.9rem .3rem .6rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font: inherit; font-size: .9rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1rem center, right .72rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

/* ── view area ───────────────────────────────────────────────────────── */
.view {
  max-width: var(--maxw); margin: 0 auto;
  padding: 1rem .9rem calc(5.5rem + env(safe-area-inset-bottom));
  outline: none;
}
.view > * + * { margin-top: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.card > * + * { margin-top: .8rem; }
.card-head { display: flex; align-items: center; gap: .6rem; }
.card-head h2 { flex: 1; min-width: 0; }

.muted { color: var(--ink-dim); font-size: .9rem; }
.faint { color: var(--ink-faint); font-size: .85rem; }
.label {
  display: block; font-size: .78rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: .35rem;
}

/* ── controls ────────────────────────────────────────────────────────── */
input[type="text"], input[type="date"], input[type="number"],
input[type="password"], input[type="time"], select, textarea {
  width: 100%; min-width: 0; min-height: var(--tap);
  padding: .55rem .7rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font: inherit; font-size: 1rem;   /* 16px stops iOS zooming on focus */
}
textarea { min-height: 5.5rem; resize: vertical; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .5rem 1rem;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font: inherit; font-size: .95rem; font-weight: 600;
  cursor: pointer; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
/* Teal edge on hover, only where a real pointer exists (not sticky on touch). */
@media (hover: hover) {
  .btn:hover:not(:disabled), .item:hover { border-color: var(--accent); }
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-in); border-color: transparent; }
.btn-danger  { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-ghost   { background: transparent; }
.btn-block   { width: 100%; }
.btn-sm      { min-height: 34px; padding: .25rem .6rem; font-size: .85rem; }
.btn-lg      { min-height: 52px; font-size: 1.05rem; }

.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-tight { display: flex; gap: .4rem; align-items: center; }
.grid-2 { display: grid; gap: .7rem; grid-template-columns: 1fr 1fr; }
/* Grid and flex children default to min-width:auto, which refuses to shrink
   below an input's intrinsic width - on a 375px phone that pushes date fields
   straight out of the card. */
.grid-2 > *, .row > *, .spread > * { min-width: 0; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }

/* ── weekday chips ───────────────────────────────────────────────────── */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.day-chip {
  min-height: var(--tap); padding: .35rem .1rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font-size: .78rem; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.day-chip[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-in); border-color: transparent;
}

/* ── calendar ────────────────────────────────────────────────────────── */
.cal { display: flex; flex-direction: column; gap: .55rem; }
.cal-head { display: flex; align-items: center; gap: .5rem; }
.cal-head .btn { flex: none; min-width: 44px; font-size: 1.15rem; line-height: 1; }
.cal-month { flex: 1; text-align: center; font-weight: 650; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow {
  text-align: center; font-size: .72rem; font-weight: 700;
  color: var(--ink-faint); padding-bottom: .15rem;
}
.cal-blank { aspect-ratio: 1; }
.cal-day {
  aspect-ratio: 1; min-height: 38px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font: inherit; font-size: .92rem; font-variant-numeric: tabular-nums;
  cursor: pointer; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.cal-day:active { transform: translateY(1px); }

/* Days the organisation is normally shut: recede into the background so the
   open days read as the obvious choice. Still tappable - opening specially for
   a market day is a real thing - so this stays a hint, not a disabled state. */
.cal-day.is-closed {
  background: transparent;
  border-color: transparent;
  color: var(--ink-faint);
}

/* Today gets a ring rather than a fill, so it never reads as "selected". */
.cal-day.is-today { border-color: var(--accent); border-width: 2px; }

/* Selection wins over everything, including the closed-day dimming. */
.cal-day[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-in);
  border-color: transparent; font-weight: 700;
}
/* A picked day that is normally closed is worth calling out - it's an
   exception the user deliberately made. */
.cal-day.is-closed[aria-pressed="true"] {
  background: var(--accent-lo); color: var(--accent);
  border: 1px dashed var(--accent);
}
.cal-bulk { flex-wrap: wrap; }

/* Bare monthGrid selection (away-date picker, "asked to work" card). The
   caller sets these classes; the grid itself has no aria-pressed state. */
.cal-day.in-range { background: var(--accent-lo); color: var(--accent); border-color: transparent; }
.cal-day.range-edge {
  background: var(--accent); color: var(--accent-in);
  border-color: transparent; font-weight: 700;
}
.cal-day.is-want {
  background: var(--ok); color: var(--accent-in);
  border-color: transparent; font-weight: 700;
}
.cal-day.is-away {
  color: var(--bad); border-color: var(--bad);
  border-style: dashed; text-decoration: line-through;
}

.cal-repeat {
  display: flex; flex-direction: column; gap: .3rem;
  padding-top: .55rem; border-top: 1px solid var(--line);
}
.cal-repeat .row-tight { flex-wrap: wrap; }
.cal-repeat label { font-size: .92rem; cursor: pointer; }
.cal-repeat input[type="checkbox"] {
  width: 20px; height: 20px; flex: none; accent-color: var(--accent); cursor: pointer;
}
.cal-repeat input:disabled + label { color: var(--ink-faint); cursor: default; }

.cal-repeat-fields { display: flex; flex-wrap: wrap; gap: .5rem .9rem; }
/* An author `display` beats the UA stylesheet's [hidden] rule, so the
   attribute has to be honoured explicitly or the fields never hide. */
.cal-repeat-fields[hidden] { display: none; }
.cal-repeat-fields .row-tight { flex: 1 1 9rem; }
.cal-repeat-fields input[type="number"] { width: 4.5rem; flex: none; min-height: 38px; }
.cal-repeat-fields input[type="date"] { flex: 1 1 8rem; min-height: 38px; }

/* ── lists ───────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: .5rem; }
.item {
  display: flex; align-items: center; gap: .7rem;
  min-height: var(--tap);
  padding: .6rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  cursor: pointer; text-align: left; width: 100%;
  font: inherit; color: var(--ink);
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { font-size: .84rem; color: var(--ink-dim); }
.item.inactive .item-title { color: var(--ink-faint); text-decoration: line-through; }
/* "Draft" marker on an unbuilt roster in the list. */
.item-tag {
  flex: none;
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: .15rem .4rem; border-radius: var(--radius-s);
  background: var(--accent-lo); color: var(--accent);
}

/* New Roster: Save draft and Build sit side by side at the foot of the page. */
.build-actions { display: flex; gap: .5rem; }
.build-actions > .btn { flex: 1; }

/* ── requests / days off ─────────────────────────────────────────────── */
.req-person { padding-top: .7rem; border-top: 1px solid var(--line); }
.req-person + .req-person { margin-top: .1rem; }
.req-name { font-weight: 650; font-size: .95rem; margin-bottom: .35rem; }
.req-dates { display: flex; flex-wrap: wrap; gap: .3rem; }
.req-chip {
  min-height: 34px; padding: .2rem .55rem;
  background: var(--surface-2); color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  font: inherit; font-size: .82rem; font-variant-numeric: tabular-nums;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
/* Wants and can't-work must be tellable apart without relying on colour
   alone, so each carries a mark as well as a fill. */
.req-chip.is-wants {
  background: var(--ok); color: var(--accent-in);
  border-color: transparent; font-weight: 650;
}
.req-chip.is-wants::before { content: '✓ '; }
.req-chip.is-cant,
.req-chip.is-cant-range {
  background: transparent; color: var(--bad);
  border-color: var(--bad); text-decoration: line-through;
}
.req-chip.is-cant::before,
.req-chip.is-cant-range::before { content: '✕ '; text-decoration: none; }
.req-chip.is-cant-range { opacity: .65; border-style: dashed; }

/* Settings menu rows: a chevron marks the ones that open a sub-screen. */
.item-chevron {
  flex: none; color: var(--ink-faint);
  font-size: 1.35rem; line-height: 1;
}

.install-steps { margin: .2rem 0 0; padding-left: 1.3rem; color: var(--ink-dim); }
.install-steps li { margin-bottom: .35rem; }

.empty {
  text-align: center; color: var(--ink-dim);
  padding: 2rem 1rem; border: 1px dashed var(--line);
  border-radius: var(--radius); background: var(--surface);
}
.empty strong { display: block; color: var(--ink); margin-bottom: .3rem; }

/* ── roster result ───────────────────────────────────────────────────── */
.day-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: .7rem .8rem;
}
.day-card + .day-card { margin-top: .5rem; }
.day-date { font-weight: 700; font-size: .95rem; }
.day-shift {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .3rem 0; border-top: 1px solid var(--line); margin-top: .4rem;
}
.day-shift .sname {
  flex: none; min-width: 5.5rem;
  font-size: .8rem; color: var(--ink-faint); font-weight: 600;
}
.day-shift .swho { flex: 1; }
.day-shift .swho.gap { color: var(--warn); font-style: italic; }

/* Manual edit: people become removable chips and each shift gets an add picker. */
.day-shift .swho.edit {
  display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; font-style: normal;
}
.edit-chip {
  display: inline-flex; align-items: center; gap: .15rem;
  padding: .1rem .15rem .1rem .5rem; border-radius: var(--radius-s);
  background: var(--accent-lo); color: var(--ink); font-size: .82rem;
}
.edit-x {
  border: 0; background: none; cursor: pointer; padding: 0 .3rem;
  color: var(--ink-dim); font-size: 1.05rem; line-height: 1;
}
.edit-x:hover { color: var(--bad); }
.edit-add {
  font: inherit; font-size: .82rem; padding: .2rem .3rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
}

.tally { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  padding: .2rem .6rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .85rem;
}
.chip b { font-variant-numeric: tabular-nums; }

.notice {
  border-left: 3px solid var(--warn);
  background: var(--surface-2);
  padding: .6rem .8rem; border-radius: 0 var(--radius-s) var(--radius-s) 0;
  font-size: .9rem;
}
.notice ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.notice li { margin-bottom: .2rem; }
.notice.bad { border-left-color: var(--bad); }

pre.roster-text {
  margin: 0; padding: .8rem;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s);
  overflow-x: auto; font-size: .8rem; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── tab bar ─────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .45rem .2rem .5rem;
  background: none; border: none; cursor: pointer;
  color: var(--ink-faint); font: inherit; font-size: .68rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab svg {
  width: 22px; height: 22px; fill: none;
  stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tab[aria-current="page"] { color: var(--accent); }

/* ── toast + modal ───────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(1rem);
  bottom: calc(5rem + env(safe-area-inset-bottom));
  z-index: 40; max-width: calc(100vw - 2rem);
  padding: .6rem 1rem; border-radius: 999px;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: .9rem; opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal {
  width: min(30rem, calc(100vw - 1.5rem));
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal-body { padding: 1rem; }
.modal-body > * + * { margin-top: .8rem; }
.modal h2 { font-size: 1.05rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 auto; min-width: 7rem; }

.err { color: var(--bad); font-size: .88rem; min-height: 1.1rem; }

/* ── wider screens: tabs move to the top, content breathes ───────────── */
@media (min-width: 46rem) {
  /* The wordmark stays on top and the sections sit directly beneath it -
     no `order`, so the bars follow document order. */
  .tabbar {
    position: static; bottom: auto;
    grid-template-columns: repeat(3, max-content);
    justify-content: center; gap: .3rem;
    border-top: none; border-bottom: 1px solid var(--line);
    padding: .3rem .5rem;
  }
  .tab { flex-direction: row; gap: .45rem; padding: .5rem .9rem; font-size: .85rem; border-radius: var(--radius-s); }
  .tab[aria-current="page"] { background: var(--accent-lo); }
  .appbar { position: static; }
  body { display: flex; flex-direction: column; }
  .view { padding-bottom: 3rem; width: 100%; }
  .toast { bottom: 2rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .btn:active { transform: none; }
}

/* The sync code: shown to be copied by hand, so it needs to be unambiguous
   and easy to read a group at a time. */
.sync-code {
  padding: .7rem .8rem;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-s);
  font-size: 1.05rem; letter-spacing: .06em;
  word-break: break-all; text-align: center;
  user-select: all;
}

/* ── export menu ─────────────────────────────────────────────────────── */
.export-row {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: .6rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-s);
}
.export-row .item-main { flex: 1 1 12rem; }
.export-row .row-tight { flex: none; }

/* ── printing a roster ───────────────────────────────────────────────────
   printRoster() adds #print-sheet and body.printing; everything else is
   hidden so the page is just the roster, black on white whatever the theme. */
#print-sheet { display: none; }
@media print {
  body.printing > :not(#print-sheet) { display: none !important; }
  body.printing { background: #fff; color: #000; display: block; }
  body.printing #print-sheet { display: block; font-size: 11pt; }
  #print-sheet h1 { font-size: 16pt; margin: 0 0 10pt; }
  #print-sheet table { width: 100%; border-collapse: collapse; }
  #print-sheet th, #print-sheet td {
    border: 1px solid #999; padding: 5pt 7pt; text-align: left; vertical-align: top;
  }
  #print-sheet th { background: #eee; }
  #print-sheet tr { break-inside: avoid; }
  #print-sheet .print-date { white-space: nowrap; font-weight: 600; }
  #print-sheet .print-times { font-weight: 400; font-size: 9pt; color: #444; }
  #print-sheet .print-gap { font-style: italic; color: #a33; font-size: 9pt; }
  #print-sheet .print-foot { margin-top: 10pt; font-size: 8pt; color: #666; }
}
