/* Drive Notes: minimal, high-contrast, readable outdoors.
   Palette: sage #E3E7D3, slate #757780, aubergine #32213A, lavender #DCCCFF, brick #A52422. */
:root {
  --bg: #E3E7D3;          /* sage */
  --field: #F3F5EC;       /* inputs, cards: a lighter sage so they stand out */
  --surface: #D7DCC4;
  --surface-2: #CAD0B4;
  --line: #757780;        /* slate grey */
  --text: #32213A;        /* aubergine */
  --muted: #4E4558;       /* darker than #757780 so small text stays readable on sage */
  --accent: #32213A;
  --accent-ink: #DCCCFF;
  --accent-soft: #DCCCFF; /* lavender */
  --danger: #A52422;      /* brick red */
  --ok: #5B5D66;          /* "Fixed" = resolved, deliberately quiet */
  --mark: #DCCCFF;
  --focus: #32213A;
  --radius: 8px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1120; --field: #24182B; --surface: #32213A; --surface-2: #3E2C48; --line: #757780;
    --text: #E3E7D3; --muted: #B9BBAE; --accent: #DCCCFF; --accent-ink: #32213A;
    --accent-soft: #3E2C48; --danger: #F07C78; --ok: #B9BBAE; --mark: #5A4479; --focus: #DCCCFF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1A1120; --field: #24182B; --surface: #32213A; --surface-2: #3E2C48; --line: #757780;
    --text: #E3E7D3; --muted: #B9BBAE; --accent: #DCCCFF; --accent-ink: #32213A;
    --accent-soft: #3E2C48; --danger: #F07C78; --ok: #B9BBAE; --mark: #5A4479; --focus: #DCCCFF;
  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 var(--font); font-variant-numeric: tabular-nums;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
  font: 12px var(--mono); padding: 1px 5px; border: 1px solid var(--line);
  border-radius: 4px; color: var(--muted); background: var(--surface);
}
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 56px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 750; text-decoration: none; letter-spacing: -0.01em; }
.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border-radius: var(--radius); text-decoration: none; color: var(--muted); font-weight: 550;
}
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.save-status { margin-left: auto; font-size: 14px; color: var(--muted); white-space: nowrap; }
.save-status.err { color: var(--danger); font-weight: 600; }
.icon-btn {
  min-width: var(--tap); min-height: 40px; border: 1px solid var(--line); background: var(--field);
  border-radius: var(--radius); cursor: pointer; font-size: 18px;
}
@media (max-width: 560px) { .nav a kbd { display: none; } .brand { display: none; } }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 120px; outline: none; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 28px 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--field); cursor: pointer; font-weight: 600;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { min-height: 56px; font-size: 17px; padding: 0 22px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }

input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], textarea, select {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--field); width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 76px; resize: vertical; line-height: 1.4; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span { text-transform: uppercase; letter-spacing: .04em; }
.req::after { content: " *"; color: var(--danger); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--field); cursor: pointer; font-weight: 550; white-space: nowrap;
}
.chip:hover { background: var(--surface); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.add { border-style: dashed; color: var(--muted); }
.chip.suggest { min-height: 32px; font-size: 13px; padding: 0 10px; color: var(--muted); font-weight: 500; }
.chip.suggest:hover { color: var(--text); }
.chip-input { display: inline-flex; gap: 6px; }
.chip-input input { min-height: 40px; width: 160px; border-radius: 999px; }
.missing .chips { padding: 4px; border-radius: 12px; outline: 2px dashed var(--danger); outline-offset: 1px; }

/* ---------- session list ---------- */
.start-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: var(--surface);
  display: grid; gap: 12px;
}
.start-card .chips .chip { min-height: 52px; font-size: 16px; padding: 0 20px; }
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list > li { border-bottom: 1px solid var(--line); }
.row-link {
  display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center;
  padding: 12px 8px; text-decoration: none; min-height: 56px;
}
.row-link:hover { background: var(--surface); }
.row-link .date { font-weight: 650; }
.row-link .meta { color: var(--muted); font-size: 14px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650; border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.open { color: var(--danger); border-color: currentColor; }
.badge.fixed { color: var(--ok); border-color: currentColor; }
.badge.flag { color: var(--accent); border-color: currentColor; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- session header ---------- */
.session-head { display: grid; gap: 14px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.session-head .grid { display: grid; grid-template-columns: 170px 1fr; gap: 14px; }
.surface-note { font-size: 14px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
@media (max-width: 640px) { .session-head .grid { grid-template-columns: 1fr; } .row-link { grid-template-columns: 1fr auto; } .row-link .date { grid-column: 1 / -1; } }

/* ---------- runs ---------- */
.runs { list-style: none; padding: 0; margin: 0; }
.run { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--field); }
.run.open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.run-summary {
  width: 100%; display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center;
  min-height: 56px; padding: 8px 12px; border: 0; background: none; cursor: pointer; text-align: left;
}
.run-summary:hover { background: var(--surface); border-radius: 10px; }
.run-num { font-weight: 750; font-size: 18px; }
.run-line { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; min-width: 0; }
.run-line b { font-weight: 650; }
.run-line .sep { color: var(--line); }
.run-preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2 / 3; }
.run-body { padding: 4px 14px 16px; display: grid; gap: 18px; border-top: 1px solid var(--line); }
.timer { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; padding-top: 12px; }
.timer .btn.big { min-width: 170px; }
.timer.running .btn.primary { background: var(--danger); border-color: var(--danger); color: #fff; }
.timer label.field { width: 120px; }
.nums { display: grid; grid-template-columns: repeat(3, minmax(0, 160px)); gap: 12px; }
@media (max-width: 560px) { .nums { grid-template-columns: repeat(2, 1fr); } }
.note-field { display: grid; gap: 6px; }
.note-head { display: flex; align-items: center; gap: 8px; }
.note-head > span { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mic {
  margin-left: auto; min-height: 36px; min-width: 44px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--field); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 14px;
}
.mic svg { width: 16px; height: 16px; }
.mic.rec { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.mic.busy { opacity: .7; cursor: progress; }
@keyframes pulse { 50% { opacity: .65; } }

.issues { display: grid; gap: 10px; }
.issue { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; background: var(--surface); }
.issue-row { display: flex; gap: 8px; align-items: center; }
.issue-row input { flex: 1; }
.status-toggle { min-width: 92px; }
.status-toggle[data-status="Open"] { color: var(--danger); border-color: var(--danger); }
.status-toggle[data-status="Fixed"] { color: var(--ok); border-color: var(--ok); }

details.tires > summary {
  list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: center; min-height: var(--tap);
  font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
details.tires > summary::-webkit-details-marker { display: none; }
details.tires > summary::before { content: "▸"; }
details.tires[open] > summary::before { content: "▾"; }
details.tires > summary .tire-sum { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); }
.tire-grid { display: grid; grid-template-columns: 64px repeat(4, minmax(0, 110px)); gap: 6px; align-items: center; }
.tire-grid .h { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; }
.tire-grid .corner { font-weight: 650; }
.tire-grid .all { color: var(--accent); font-weight: 700; }
.tire-grid input { min-height: 40px; padding: 6px 8px; }
.tire-grid .all-row input { border-color: var(--accent); }

.flags { border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; background: var(--accent-soft); font-size: 14px; }
.flags ul { margin: 6px 0; padding-left: 18px; }
.run-foot { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.run-foot .spacer { flex: 1; }
.new-run-bar { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); display: flex; gap: 10px; align-items: center; }

/* ---------- search & shitlist ---------- */
.searchbar { display: flex; gap: 8px; }
.searchbar input { min-height: 52px; font-size: 18px; }
.filters { display: grid; gap: 10px; margin: 14px 0; }
.filter-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; }
.filter-row > span { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filter-row .chip { min-height: 34px; font-size: 14px; }
.daterange { display: flex; gap: 8px; align-items: center; }
.daterange input { width: 170px; min-height: 36px; }
@media (max-width: 560px) { .filter-row { grid-template-columns: 1fr; gap: 4px; } }
.results { list-style: none; padding: 0; margin: 0; }
.result { border-bottom: 1px solid var(--line); }
.result a { display: block; padding: 12px 8px; text-decoration: none; }
.result a:hover { background: var(--surface); }
.result .ctx { font-size: 14px; color: var(--muted); }
.result .ctx b { color: var(--text); }
.result .snip { margin-top: 4px; font-size: 15px; white-space: pre-wrap; }
.result .snip i { font-style: normal; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; margin-right: 6px; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.count { font-size: 14px; color: var(--muted); margin: 6px 0 10px; }

.shit-row { display: grid; grid-template-columns: 110px 120px 1fr auto; gap: 12px; align-items: center; padding: 10px 8px; min-height: 60px; }
.shit-row .desc { font-weight: 550; }
.shit-row .ctx { font-size: 13px; color: var(--muted); }
.shit-row .ctx a { color: var(--muted); }
.shit-row.fixed .desc { color: var(--muted); text-decoration: line-through; }
@media (max-width: 640px) { .shit-row { grid-template-columns: 1fr auto; } .shit-row > :nth-child(2) { order: -1; } }

.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-weight: 600;
  transition: .15s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.hint { font-size: 13px; color: var(--muted); }
.hint kbd { margin: 0 2px; }

/* ---------- car / year switcher ---------- */
.car-switch { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.car-btn {
  min-height: 40px; min-width: 52px; padding: 0 12px; border: 0; background: var(--field); cursor: pointer;
  font-weight: 650; color: var(--muted);
}
.car-btn + .car-btn { border-left: 1px solid var(--line); }
.car-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.past-car .topbar { box-shadow: inset 0 -3px 0 var(--accent); }
.past-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 14px; padding: 10px 14px;
  border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent-soft); font-weight: 600;
}

/* ---------- runs header + view toggle ---------- */
.runs-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.runs-head h2 { margin-bottom: 10px; }
.chips.mode { margin-bottom: 8px; }
.chips.mode .chip { min-height: 34px; font-size: 14px; }

/* ---------- spreadsheet (Excel template layout) ---------- */
main:has(.grid-wrap) { max-width: none; }
.grid-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: var(--radius); }
table.sheet { border-collapse: separate; border-spacing: 0; table-layout: fixed; min-width: max-content; font-size: 14px; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; vertical-align: top; background: var(--field); }
.sheet thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; padding: 8px;
  font-size: 12px; font-weight: 700; white-space: normal; line-height: 1.2;
}
.sheet .rowhead { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: center; padding: 4px; }
.sheet thead .rowhead { z-index: 3; background: var(--surface-2); }
.sheet .rownum { border: 0; background: none; font-weight: 750; font-size: 15px; cursor: pointer; min-height: 32px; min-width: 32px; color: var(--text); }
.sheet .rownum:hover { text-decoration: underline; }
.sheet .rowhead .badge { padding: 0 5px; }
.sheet .rowhead .gf { display: inline-block; text-decoration: none; color: var(--accent); font-weight: 700; padding: 0 3px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 2px; vertical-align: middle; }
.dot.open { background: var(--danger); }
.sheet input, .sheet textarea {
  display: block; width: 100%; min-height: 40px; border: 0; border-radius: 0; padding: 9px 8px; background: transparent;
  font-size: 14px; line-height: 1.35;
}
.sheet textarea { resize: none; overflow: hidden; height: 40px; }
.sheet input:focus, .sheet textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.sheet input.bad { outline: 2px solid var(--danger); outline-offset: -2px; }
.sheet input::placeholder, .sheet textarea::placeholder { color: var(--muted); opacity: .6; }
.sheet tr.new-row td, .sheet tr.new-row th { background: var(--surface); }
.issue-tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 6px 6px; }
.issue-tag { font-size: 12px; }
.issue-tag select {
  min-height: 26px; width: auto; padding: 0 4px; font-size: 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-weight: 600;
}
.issue-tag.fixed select { color: var(--ok); }
.new-run-bar { z-index: 5; }
.sheet textarea:not(:focus) { overflow: hidden; text-overflow: ellipsis; }

/* Event / subsystem dropdowns in the run editor */
.run-body > label.field { max-width: 340px; }
.run-body select, .issue-row select.subsystem {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--field); font-weight: 600; cursor: pointer;
}
.issue-row select.subsystem { flex: 0 0 150px; }
.missing select { outline: 2px dashed var(--danger); outline-offset: 1px; }
@media (max-width: 560px) { .issue-row { flex-wrap: wrap; } .issue-row select.subsystem { flex: 1 1 100%; } }

/* Search highlights: lavender with an underline so they show on any background */
mark { box-shadow: inset 0 -2px 0 var(--accent); }

/* Delete-run "−" on every run row (cards and spreadsheet) */
.run-head { display: flex; align-items: stretch; }
.run-head .run-summary { flex: 1; min-width: 0; }
.run-del {
  flex: 0 0 auto; align-self: center; width: 40px; height: 40px; margin-right: 8px; border-radius: 50%;
  border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 22px; line-height: 1;
  cursor: pointer;
}
.run-del:hover, .run-del:focus-visible { color: var(--danger); border-color: var(--danger); background: var(--field); }
.run-del.small { width: 28px; height: 28px; margin: 2px auto 0; font-size: 18px; display: block; }

/* ---------- filter dropdowns ---------- */
.filter-picks { display: flex; flex-wrap: wrap; gap: 10px; }
.filter-pick { display: inline-flex; flex-direction: column; gap: 2px; }
.filter-pick > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.filter-select {
  min-height: 40px; min-width: 170px; padding: 0 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--field); color: var(--text); font: inherit; font-size: 15px;
}
.filter-select.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }

/* ---------- save day ---------- */
.saved-line { margin: 4px 0 10px; font-size: 13px; color: var(--muted); }
.saved-line code { font-size: 12px; }
.new-run-bar { flex-wrap: wrap; }

/* ---------- accounts ---------- */
.account { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.account .who { font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.badge.role-pending { color: var(--danger); border-color: currentColor; }
.badge.role-admin { background: var(--accent-soft); }
.login-card {
  max-width: 460px; margin: 40px auto; padding: 28px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); display: grid; gap: 12px;
}
.login-actions { display: grid; gap: 10px; }
.login-actions .btn { justify-content: center; text-decoration: none; }
.login-roles { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: grid; gap: 4px; }
.login-error, .pending-note { margin: 0; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--danger); color: var(--danger); background: var(--field); }
.readonly-note { display: block; }
.user-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 12px 8px; }
.user-actions { display: flex; gap: 6px; }
@media (max-width: 560px) { .user-row { grid-template-columns: 1fr; } .account .who { display: none; } }

/* View only (guest / awaiting approval): hide the controls that would only be refused. */
html.readonly .new-run-bar, html.readonly .run-del, html.readonly tr.new-row, html.readonly .mic,
html.readonly .chip-input, html.readonly [data-k="add-issue"], html.readonly .chip.suggest,
html.readonly .run-foot .danger, html.readonly .flags .btn { display: none !important; }
html.readonly .run-body :is(input, textarea, select):is([readonly], :disabled) { background: transparent; }

/* ---------- connection / sync icon ---------- */
.net {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--field); color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.net[hidden] { display: none; }
.net[data-tone="bad"] { color: var(--danger); border-color: var(--danger); }
.net[data-tone="busy"] { color: var(--text); }
.net[data-tone="busy"] svg { animation: net-pulse 1.2s ease-in-out infinite; }
@keyframes net-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .net[data-tone="busy"] svg { animation: none; } }
@media (max-width: 720px) { .net-label { display: none; } .net { padding: 0 8px; } }
