:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1d1b;
  --muted: #62605a;
  --border: #d9d6cc;
  --accent: #b3261e;
  --accent-text: #ffffff;
  --ok: #1e6b3a;
  --warn-bg: #fff3d6;
  --warn-text: #6b4a00;
  --error-bg: #fde7e5;
  --error-text: #8a1c14;
  --focus: #1a5fb4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --surface: #211f1c;
    --surface-2: #2b2925;
    --text: #eceae4;
    --muted: #a6a39a;
    --border: #3d3a34;
    --accent: #e0594f;
    --accent-text: #1a0806;
    --ok: #6ccf8f;
    --warn-bg: #3a2e10;
    --warn-text: #f2d48a;
    --error-bg: #3d1a17;
    --error-text: #f6b3ad;
    --focus: #7cb0ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--focus); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 3px solid var(--accent);
}
.topbar .who { color: var(--muted); font-size: .9rem; display: flex; gap: .75rem; align-items: center; }

.page { max-width: 640px; margin: 0 auto; padding: 1rem; }
.page.wide { max-width: 1400px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; margin-bottom: 1rem;
}

label { display: block; font-weight: 600; margin: .9rem 0 .3rem; }
label .hint, .hint { font-weight: 400; color: var(--muted); font-size: .88rem; }
input, select, textarea, button {
  font: inherit; color: inherit;
}
input[type=text], input[type=tel], input[type=date], input[type=time], input[type=password],
input:not([type]), select, textarea {
  width: 100%; padding: .6rem .7rem; min-height: 44px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
textarea { min-height: 5rem; resize: vertical; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.row { display: flex; gap: .75rem; }
.row > * { flex: 1; min-width: 0; }

button {
  cursor: pointer; min-height: 44px; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
button:disabled { opacity: .6; cursor: default; }
button.small { min-height: 34px; padding: .25rem .6rem; font-size: .88rem; }
button.link { background: none; border: none; color: var(--focus); padding: 0; min-height: 0; text-decoration: underline; }

.needs { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.needs label {
  margin: 0; font-weight: 500; display: flex; align-items: center; gap: .5rem;
  padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer;
}
.needs label:has(input:checked) { border-color: var(--accent); outline: 2px solid var(--accent); }
.needs label:has(input:disabled) { opacity: .55; cursor: default; }
.needs input { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--accent); }

.notice { padding: .7rem .8rem; border-radius: 8px; margin: .75rem 0; }
.notice.error { background: var(--error-bg); color: var(--error-text); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.ok { color: var(--ok); border: 1px solid currentColor; }

.muted { color: var(--muted); }
.actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: 1.25rem; }

/* dashboard */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.toolbar label { margin: 0 0 .25rem; font-size: .85rem; }
.toolbar input, .toolbar select { width: auto; }
.counts { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .92rem; margin-bottom: .75rem; }
.counts b { color: var(--text); font-variant-numeric: tabular-nums; }


table.appts { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.appts th, table.appts td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.appts th { background: var(--surface-2); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.appts tr.overdue td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
table.appts tr.closed { opacity: .6; }
table.appts td .sub { color: var(--muted); font-size: .85rem; }
table.appts td input, table.appts td select { min-height: 36px; padding: .3rem .45rem; font-size: .92rem; }
table.appts td.assign { min-width: 11rem; }
table.appts td.status { min-width: 10rem; }
.tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.tag.overdue { background: var(--error-bg); color: var(--error-text); }
.tag.need-ride_to_polls { background: var(--warn-bg); color: var(--warn-text); }
.saved { color: var(--ok); font-size: .8rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* Phones: each row becomes a card. */
@media (max-width: 820px) {
  table.appts, table.appts tbody, table.appts tr, table.appts td { display: block; width: 100%; }
  table.appts thead { display: none; }
  table.appts { border: none; background: none; }
  table.appts tr { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: .75rem; padding: .25rem 0; }
  table.appts tr.overdue { border-left: 4px solid var(--accent); }
  table.appts tr.overdue td:first-child { box-shadow: none; }
  table.appts td { border: none; padding: .3rem .8rem; }
  table.appts td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
  .row { flex-direction: column; gap: 0; }
}
@media (max-width: 420px) { .needs { grid-template-columns: 1fr; } }

.intro { margin-top: 0; }
fieldset.plain { border: 0; padding: 0; margin: 0; }
fieldset.plain legend { font-weight: 600; margin: .4rem 0 .5rem; padding: 0; }
h2.section { margin-top: 1.5rem; }
.actions.tight { margin-top: .5rem; }
a.phone { white-space: nowrap; }
table.appts td.when { width: 10.5rem; }
table.appts td.when input { width: 100%; }
@media (max-width: 820px) { table.appts td.when { width: 100%; } }
@media (max-width: 820px) { table.appts td:empty, table.appts td.blank { display: none; } }
.topbar .who { flex-wrap: wrap; justify-content: flex-end; }
.linkbar input { font-family: ui-monospace, monospace; font-size: .85rem; }
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; }
  .topbar h1 { font-size: 1.1rem; }
}

/* admin nav */
.brand { display: flex; align-items: baseline; gap: 1.25rem; flex-wrap: wrap; }
.nav { display: flex; gap: .9rem; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 600; padding: .15rem 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); }
.nav a[aria-current=page] { color: var(--text); border-bottom-color: var(--accent); }
button.armed { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
button.danger { color: var(--error-text); }

/* photo gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem; }
.photo { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.photo .frame { display: block; aspect-ratio: 4 / 3; background: var(--surface-2); }
.photo .frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .frame .noimg { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--muted); font-size: .9rem; padding: 1rem; text-align: center; }
.photo .meta { padding: .6rem .7rem; font-size: .9rem; display: grid; gap: .15rem; }
.photo .meta .actions { margin-top: .4rem; }

/* team table */
table.team { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.team th, table.team td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.team th { background: var(--surface-2); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.team tr.off td { opacity: .55; }
.temp-pw { font-family: ui-monospace, monospace; font-size: 1.05rem; background: var(--warn-bg); color: var(--warn-text); padding: .1rem .4rem; border-radius: 4px; }
@media (max-width: 820px) {
  table.team, table.team tbody, table.team tr, table.team td { display: block; width: 100%; }
  table.team thead { display: none; }
  table.team { border: none; background: none; }
  table.team tr { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: .75rem; padding: .25rem 0; }
  table.team td { border: none; padding: .3rem .8rem; }
  table.team td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
}

/* field app */
body.field .page { padding-bottom: 3rem; }
.center { text-align: center; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.button {
  display: inline-flex; align-items: center; margin: 0; cursor: pointer; min-height: 44px; padding: .55rem 1rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600;
}
label.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
label.button:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }

.tabs { display: flex; gap: .25rem; align-items: stretch; margin: 0 0 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 2; }
.tabs button, .tabs a {
  border: none; background: none; border-radius: 0; padding: .6rem .7rem; font-weight: 700; color: var(--muted);
  border-bottom: 3px solid transparent; text-decoration: none; display: inline-flex; align-items: center; min-height: 44px;
}
.tabs a { margin-left: auto; font-weight: 600; color: var(--focus); }
.tabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }

.day-head { font-size: .95rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.day-head.overdue { color: var(--error-text); }
.assignment { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .85rem .95rem; margin-bottom: .75rem; }
.assignment.overdue { border-left: 4px solid var(--accent); }
.assignment.closed { opacity: .65; }
.assignment .top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.assignment .time { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.assignment .voter { font-size: 1.1rem; font-weight: 700; margin-top: .3rem; }
.assignment .addr { margin: .25rem 0; }
.assignment .notes { background: var(--surface-2); border-radius: 8px; padding: .45rem .6rem; margin: .5rem 0; font-size: .95rem; }
.assignment .quick { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .6rem; }
.assignment .quick a, .assignment .quick button {
  display: flex; justify-content: center; align-items: center; gap: .35rem; min-height: 44px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-decoration: none; font-weight: 600; padding: .4rem;
}
.assignment .quick .done { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.assignment .outcome { margin-top: .6rem; }
.assignment .status-line { margin-top: .5rem; font-weight: 700; }

.previews { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .6rem; }
.previews .thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.previews .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.previews .thumb span { display: flex; height: 100%; align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); text-align: center; padding: .3rem; }
.previews .thumb button { position: absolute; top: 4px; right: 4px; min-height: 28px; width: 28px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; border: none; }
.gallery.small { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.sub { color: var(--muted); font-size: .85rem; }
.inline-field { display: flex; gap: .5rem; align-items: center; }
.inline-field input { font-family: ui-monospace, monospace; font-size: .85rem; }

/* completed list (dashboard, under the table) */
.completed-section { margin-top: 1.75rem; }
.completed-section h2 { display: flex; align-items: baseline; gap: .5rem; }
ol.completed { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
ol.completed:empty { display: none; }
ol.completed li { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) auto; gap: .35rem 1rem; align-items: center; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
ol.completed li:last-child { border-bottom: none; }
ol.completed li.fresh { animation: fresh 2.5s ease-out; }
@keyframes fresh { from { background: var(--warn-bg); } to { background: transparent; } }
ol.completed .when { font-variant-numeric: tabular-nums; font-weight: 700; }
ol.completed .when .sub { display: block; font-weight: 400; }
ol.completed .what { min-width: 0; }
ol.completed .what .line { display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: baseline; }
ol.completed .thumbs { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.thumbs a { display: block; width: 52px; height: 52px; border-radius: 6px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.thumbs a img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .nophoto { color: var(--muted); font-size: .85rem; }
@media (max-width: 820px) {
  ol.completed li { grid-template-columns: 4.5rem minmax(0, 1fr); }
  ol.completed .thumbs { grid-column: 2; }
}

/* live photo pop-up */
.photo-toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50; width: min(440px, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28); animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { transform: translateY(1rem); opacity: 0; } to { transform: none; opacity: 1; } }
.photo-toast .close { position: absolute; top: .4rem; right: .4rem; z-index: 1; min-height: 32px; width: 32px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: none; font-size: 1.1rem; }
.toast-photos { display: grid; gap: 2px; background: #111; }
.toast-photos.n2 { grid-template-columns: 1fr 1fr; }
.toast-photos.n3, .toast-photos.many { grid-template-columns: 1fr 1fr 1fr; }
.toast-photos img { width: 100%; max-height: 52vh; object-fit: contain; display: block; background: #111; }
.toast-photos:not(.n1) img { height: 170px; object-fit: cover; }
.toast-photos .noimg { color: #ddd; padding: 2rem 1rem; text-align: center; }
.toast-body { padding: .7rem .9rem .8rem; display: grid; gap: .15rem; }
.toast-who { font-size: 1.2rem; font-weight: 800; }
.toast-timer { height: 4px; background: var(--surface-2); }
.toast-timer span { display: block; height: 100%; background: var(--accent); width: 100%; transform-origin: left; }
.toast-timer span.run { animation: toast-countdown linear forwards; }
@keyframes toast-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .photo-toast, ol.completed li.fresh { animation: none; } }

/* field: accept / on my way / arrived */
.assignment .steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-top: .7rem; }
.assignment .step {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .1rem; min-height: 52px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .35rem .3rem; font-size: .88rem; text-align: center; line-height: 1.2;
}
.assignment .step.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.assignment .step:disabled { opacity: .5; }
.assignment .step .sub { font-size: .76rem; }
.assignment .step.primary .sub { color: inherit; }
.assignment .step.done { background: none; border-style: dashed; color: var(--ok); }
.assignment.flash { animation: card-flash 1.6s ease-out; }
@keyframes card-flash { from { box-shadow: 0 0 0 4px var(--focus); } to { box-shadow: 0 0 0 4px transparent; } }
.card.notify { border-left: 4px solid var(--focus); }

/* dashboard: canvasser progress */
.progress { font-size: .85rem; font-weight: 600; }
.progress.waiting { color: var(--warn-text); background: var(--warn-bg); border-radius: 4px; padding: 0 .3rem; display: inline-block; }
.progress.accepted { color: var(--ok); }
.progress.en_route, .progress.arrived { color: var(--focus); }
@media (prefers-reduced-motion: reduce) { .assignment.flash { animation: none; } }
