:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5e6b7a;
  --line: #d9dee5;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --accent: #2f6fb0;
  --ok: #1e7b4d;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e7ebf0;
    --muted: #9aa6b4;
    --line: #2f3843;
    --brand: #173a5c;
    --accent: #6aa7e6;
    --ok: #6fd3a0;
    --ok-bg: #173527;
    --warn: #f2bd5c;
    --warn-bg: #3a2c10;
    --bad: #ff8a80;
    --bad-bg: #3b1b18;
  }
}

* { 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(--accent); }
h1 { font-size: 1.5rem; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.muted { color: var(--muted); }
.prewrap { white-space: pre-wrap; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  padding: 0.6rem 1rem; background: var(--brand); color: var(--brand-ink);
}
.topbar a { color: var(--brand-ink); text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; flex: 1; }
.topbar nav a { padding: 0.35rem 0; }
.account { position: relative; }
.account summary { cursor: pointer; list-style: none; padding: 0.35rem 0; }
.account summary::-webkit-details-marker { display: none; }
.account .menu {
  position: absolute; right: 0; top: 2.2rem; z-index: 10; min-width: 12rem;
  display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}
.account .menu a { color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
main.narrow { max-width: 420px; }
main.medium { max-width: 720px; }
main.phone { max-width: 560px; }

/* Messages */
.flash, .error, .saved {
  padding: 0.6rem 0.8rem; border-radius: var(--radius); margin: 0 0 1rem;
}
.flash { background: var(--ok-bg); color: var(--ok); }
.error { background: var(--bad-bg); color: var(--bad); }
.saved { background: var(--ok-bg); color: var(--ok); margin: 0.5rem 0 0; padding: 0.3rem 0.6rem; }
.warn-text { color: var(--warn); }

/* Cards and layout */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.columns { display: grid; gap: 1rem; }
@media (min-width: 960px) { .columns { grid-template-columns: 1fr 1fr; align-items: start; } }
.heading-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.row { display: grid; gap: 0.75rem; }
@media (min-width: 560px) { .row { grid-template-columns: 1fr 1fr; } }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

/* Forms: large tap targets for phones */
input, select, textarea, button, .button {
  font: inherit; color: inherit;
}
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: 44px; padding: 0.55rem 0.7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
textarea { min-height: auto; }
label { display: block; font-weight: 600; }
label input, label select, label textarea { margin-top: 0.3rem; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.grid-form { display: grid; gap: 0.75rem; }
@media (min-width: 900px) { .grid-form { grid-template-columns: repeat(4, 1fr) auto; align-items: end; } }
form.inline { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
form.inline input, form.inline select { width: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.filters input[type=search] { flex: 1 1 14rem; width: auto; }
.filters select { width: auto; }
fieldset.choices { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; margin: 0; }
fieldset.choices legend { font-weight: 600; padding: 0 0.25rem; }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; min-height: 40px; }
label.check input { width: 1.25rem; height: 1.25rem; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: auto; text-decoration: underline; }
button:disabled { opacity: 0.6; cursor: wait; }

/* Segmented choice buttons (status, photo stage) */
.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.segmented label { flex: 1 1 30%; font-weight: 400; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 0.4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.segmented input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { font-size: 0.85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.inactive td { color: var(--muted); }
table.grid td.cell { text-align: center; white-space: nowrap; font-size: 0.85rem; }
.cell.job { background: rgba(47, 111, 176, 0.14); }
.cell.activity { background: rgba(94, 107, 122, 0.14); }
.cell.gap { color: var(--warn); background: var(--warn-bg); }
.cell.dimmed { opacity: 0.3; }
.legend .cell { display: inline-block; padding: 0.1rem 0.4rem; border-radius: 4px; }

/* Badges */
.badge, .status {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
  background: var(--bg); border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.type { background: var(--brand); color: #fff; border-color: transparent; }
.status.s-ready_to_invoice { background: var(--warn-bg); color: var(--warn); }
.status.s-complete, .status.s-invoiced { background: var(--ok-bg); color: var(--ok); }
.status.s-closed { color: var(--muted); }

/* Technician screens */
.type-banner {
  margin: 0 0 0.25rem; padding: 0.4rem 0.7rem; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 700; display: inline-block;
}
.day-banner {
  display: block; padding: 0.8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; text-decoration: none;
}
.day-banner.warn { background: var(--warn-bg); color: var(--warn); }
.day-banner.ok { background: var(--ok-bg); color: var(--ok); }
.job-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.job-list a {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 0.9rem 1rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.job-list .badge, .job-list .status { align-self: flex-start; }
.job-list .addr { color: var(--muted); }
.map { font-weight: 600; }

.blocks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; }
.block.gap { border-left: 5px solid var(--warn); }
.block form { display: grid; gap: 0.5rem; }
.block-head { display: flex; justify-content: space-between; font-weight: 700; }
.block .done { color: var(--ok); }
.block details summary { cursor: pointer; display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: baseline; }
.block .time { font-variant-numeric: tabular-nums; font-weight: 700; }
.block .detail { padding-top: 0.5rem; }

.photo-pick input { padding: 0.8rem; }
.preview { max-width: 100%; border-radius: 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
.photo-grid figure { margin: 0; }
.photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; }
.photo-grid figcaption { font-size: 0.85rem; margin-top: 0.3rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.timeline .meta { font-size: 0.82rem; color: var(--muted); }
.timeline .thumb { max-width: 120px; border-radius: 6px; margin-top: 0.3rem; }
.add-tech { margin-top: 0.75rem; }
