:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1d2330; --muted: #657083; --line: #dfe3ea;
  --accent: #1f5fae; --accent-text: #ffffff; --warn-bg: #fff1d6; --warn-text: #7a4b00;
  --ok-bg: #e2f4e6; --ok-text: #1e6b32; --bad-bg: #fbe3e3; --bad-text: #8f1d1d; --gray-bg: #eceff3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --surface: #1d2129; --text: #e6e9ef; --muted: #98a2b3; --line: #313744;
    --accent: #6ea8ff; --accent-text: #0b1220; --warn-bg: #3d3013; --warn-text: #ffd27a;
    --ok-bg: #173523; --ok-text: #8fe0a8; --bad-bg: #3f1d1d; --bad-text: #ffb1b1; --gray-bg: #2a2f39;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h1 .sub { font-weight: 400; color: var(--muted); font-size: 1.1rem; margin-left: .4rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.card h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1.1rem; flex: 1; }
.topbar nav a { text-decoration: none; font-weight: 600; }
.signout { display: flex; align-items: center; gap: .6rem; margin: 0; }
.who { color: var(--muted); }
.page { max-width: 1280px; margin: 0 auto; padding: 1.2rem; }

.heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; color: var(--muted); }
.stats strong { color: var(--text); }

input, select, button { font: inherit; color: inherit; }
input, select { padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0; }
button { padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 1rem; align-items: center; }
.filters input[name=Q] { flex: 1 1 260px; }
.check { display: flex; gap: .35rem; align-items: center; }
.inline { display: flex; gap: .4rem; margin: 0; }
.inline input { width: 10rem; }
.stack { display: grid; gap: .8rem; }
.stack label, .login label { display: grid; gap: .3rem; font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.compact th, table.compact td { padding: .3rem .4rem; }
tr.inactive td { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 460px; margin-top: 1.5rem; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.notes { white-space: pre-wrap; margin: 0; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 600; text-decoration: none; }
.badge.small { font-size: .72rem; padding: .05rem .4rem; margin-left: .3rem; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.status { display: inline-block; padding: .1rem .5rem; border-radius: 4px; font-size: .85rem; font-weight: 600; background: var(--gray-bg); }
.status.active { background: var(--ok-bg); color: var(--ok-text); }
.status.inshop { background: var(--warn-bg); color: var(--warn-text); }
.status.sold, .status.retired { background: var(--gray-bg); color: var(--muted); }

.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin: 1rem 0; }
.notice { background: var(--ok-bg); color: var(--ok-text); padding: .6rem .8rem; border-radius: 6px; }
.error { background: var(--bad-bg); color: var(--bad-text); padding: .6rem .8rem; border-radius: 6px; }

.login { max-width: 360px; margin: 10vh auto; display: grid; gap: .8rem; background: var(--surface); padding: 1.6rem; border: 1px solid var(--line); border-radius: 10px; }
.login form { display: grid; gap: .9rem; }
.login h1 { margin: 0; }

@media (max-width: 640px) {
  .page { padding: .8rem; }
  th, td { padding: .45rem .5rem; }
  .inline input { width: 7rem; }
}

/* ---- milestone 2 ---- */
h3 { font-size: .95rem; margin: 1.1rem 0 .5rem; }
.button { display: inline-block; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
          text-decoration: none; color: var(--text); font-weight: 600; }
.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.small-btn { font-size: .85rem; padding: .25rem .6rem; vertical-align: middle; margin-left: .5rem; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.actions-cell { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
button.danger { background: var(--bad-bg); color: var(--bad-text); border-color: var(--bad-text); }
.danger-text { color: var(--bad-text) !important; }
.inline.wrap { flex-wrap: wrap; margin-top: .8rem; }
.inline .grow { flex: 1 1 220px; width: auto; }
.inline select { width: auto; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem 1rem; }
.form-grid label, .inline-label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid.tight { margin-top: 1rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.inline-label { max-width: 260px; margin-top: .6rem; }
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); }
textarea { font: inherit; color: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); width: 100%; }
.full { width: 100%; }
input.money { width: 8rem; text-align: right; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .45rem .8rem; }
.checks .check { font-weight: 400; }
.check input { width: 1.1rem; height: 1.1rem; }
.table-wrap.plain { border: none; background: none; }
#lines input { width: 100%; }
#lines td.num input { width: 8rem; }

.priority { display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .8rem; font-weight: 700; background: var(--gray-bg); }
.priority.high { background: var(--bad-bg); color: var(--bad-text); }
.priority.low { color: var(--muted); }
.log { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.log li { border-left: 3px solid var(--line); padding-left: .6rem; }

@media (max-width: 640px) {
  .checks { grid-template-columns: 1fr; }
  .check input { width: 1.4rem; height: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---- milestone 3 ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: .5rem 0 1rem; }
.tile { display: grid; gap: .1rem; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
        text-decoration: none; color: var(--text); }
.tile strong { font-size: 1.8rem; line-height: 1.1; }
.tile span { color: var(--muted); font-size: .9rem; }
.tile.bad strong { color: var(--bad-text); }
.tile.warn strong { color: var(--warn-text); }
.tabs { display: flex; gap: .3rem; margin: .8rem 0; flex-wrap: wrap; }
.tabs a { padding: .4rem .8rem; border-radius: 6px; text-decoration: none; font-weight: 600; color: var(--muted); }
.tabs a.on { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.due { display: inline-block; padding: .1rem .5rem; border-radius: 4px; font-size: .82rem; font-weight: 700; white-space: nowrap; background: var(--gray-bg); }
.due.overdue { background: var(--bad-bg); color: var(--bad-text); }
.due.duesoon { background: var(--warn-bg); color: var(--warn-text); }
.due.ok { background: var(--ok-bg); color: var(--ok-text); }
.due.neverrecorded, .due.noreading { color: var(--muted); }
details summary { cursor: pointer; color: var(--accent); }
.schedule-form { display: grid; gap: .5rem; margin-top: .5rem; min-width: 220px; }
.schedule-form label { display: grid; grid-template-columns: 4rem 1fr; align-items: center; gap: .4rem; }
.schedule-form label.check { display: flex; }
.schedule-form input:not([type=checkbox]) { width: 6rem; }
.num-input { width: 6rem; }
details.add { margin-top: 1rem; }
details.add[open] summary { margin-bottom: .6rem; }
pre.code { background: var(--gray-bg); padding: .7rem .9rem; border-radius: 6px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; font-size: .85rem; }
.warn-text { color: var(--warn-text); }

/* ---- milestone 4: driver check-in (phone first) ---- */
.driver { max-width: 560px; margin: 0 auto; }
.driver h1 { margin-top: .4rem; }
.driver .vehicle { font-size: 1.05rem; margin: 0 0 .3rem; }
.driver label { display: grid; gap: .35rem; font-weight: 600; margin-top: .8rem; }
.driver label.big input { font-size: 1.4rem; padding: .6rem .7rem; }
.driver textarea, .driver input[type=file] { width: 100%; }
fieldset.choice { border: none; padding: 0; margin: 0 0 .9rem; }
fieldset.choice legend { font-weight: 600; margin-bottom: .4rem; }
.pill { display: inline-flex !important; align-items: center; gap: .4rem; margin: 0 .4rem .4rem 0 !important; padding: .55rem .9rem;
        border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 500 !important; cursor: pointer; }
.pill input { width: 1.2rem; height: 1.2rem; margin: 0; }
.pill:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.big-button { width: 100%; padding: .9rem; font-size: 1.1rem; }
.error ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.ci { display: inline-block; padding: .1rem .5rem; border-radius: 4px; font-size: .82rem; font-weight: 700; background: var(--gray-bg); white-space: nowrap; }
.ci.submitted { background: var(--ok-bg); color: var(--ok-text); }
.ci.overdue, .ci.emailfailed { background: var(--bad-bg); color: var(--bad-text); }
.ci.reminded, .ci.notsent { background: var(--warn-bg); color: var(--warn-text); }
.ci.notincluded { color: var(--muted); }
.tire { font-weight: 700; }
.tire.fair { color: var(--warn-text); }
.tire.replace { color: var(--bad-text); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .6rem; }
.photos img { width: 100%; height: 180px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photo-file { display: block; padding: 1rem; border: 1px dashed var(--line); border-radius: 6px; }
.inline-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .4rem 0 .8rem; }
.tile strong small { font-size: 1rem; color: var(--muted); font-weight: 600; }
