/*
 * One screen at a time, thumb-sized targets, and nothing on the page that is
 * not either a vehicle, a trip, or the button that starts or stops one.
 */
:root {
  --bg: #f2f3f6;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --ink: #101623;
  --muted: #6b7787;
  --line: #e3e6eb;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --brand-soft: #e9efff;
  --green: #0f7a45;
  --green-soft: #e2f5ea;
  --amber: #97540a;
  --amber-soft: #fdf0da;
  --red: #b3251b;
  --red-soft: #fdebe9;
  --danger: #b3251b;
  --danger-ink: #ffffff;
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 26px -14px rgba(16, 24, 40, .22);
  --shadow-lift: 0 -8px 30px -10px rgba(16, 24, 40, .28);
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --panel: #161d26; --panel-2: #1d2531; --ink: #e9edf3; --muted: #97a3b4;
    --line: #26303c; --brand: #6f9bff; --brand-ink: #0b1220; --brand-soft: #1b2740;
    --green: #4fd694; --green-soft: #12312a; --amber: #eeb35c; --amber-soft: #2f2614;
    --red: #ff8f84; --red-soft: #341d1c; --danger: #d0392b; --danger-ink: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px -16px rgba(0, 0, 0, .8);
    --shadow-lift: 0 -10px 34px -8px rgba(0, 0, 0, .75);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161d26; --panel-2: #1d2531; --ink: #e9edf3; --muted: #97a3b4;
  --line: #26303c; --brand: #6f9bff; --brand-ink: #0b1220; --brand-soft: #1b2740;
  --green: #4fd694; --green-soft: #12312a; --amber: #eeb35c; --amber-soft: #2f2614;
  --red: #ff8f84; --red-soft: #341d1c; --danger: #d0392b; --danger-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px -16px rgba(0, 0, 0, .8);
  --shadow-lift: 0 -10px 34px -8px rgba(0, 0, 0, .75);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 650; }
h1 { font-size: 26px; letter-spacing: -.4px; }
p { margin: 0; }
a { color: var(--brand); text-underline-offset: 2px; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ------------------------------------------------------------------ inputs */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 13px 14px; width: 100%; min-height: var(--tap);
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 49%, var(--muted) 50%),
                    linear-gradient(-45deg, transparent 49%, var(--muted) 50%);
  background-size: 6px 6px, 6px 6px;
  background-position: right 18px center, right 12px center;
  background-repeat: no-repeat; padding-right: 34px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent;
}
/* A tick box has to look like one: stripping the native appearance from every
   input would leave it an empty rounded rectangle with no visible state. */
input[type="checkbox"], input[type="radio"] {
  appearance: auto; -webkit-appearance: auto;
  width: 22px; height: 22px; min-height: 0; padding: 0; flex: none;
  accent-color: var(--brand); border: 0; background: none;
}
input[type="file"] {
  appearance: auto; -webkit-appearance: auto; padding: 10px 12px;
  background: var(--panel-2);
}
/* A tick box with its words next to it, big enough for a thumb. */
.check {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  font-size: 16px; font-weight: 500; color: var(--ink);
  min-height: var(--tap); margin: 0;
}
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 > * { min-width: 0; }
input[type="date"], input[type="datetime-local"] { min-width: 0; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  min-height: var(--tap); padding: 12px 18px; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); font-weight: 650;
  white-space: nowrap; transition: transform .08s ease, filter .12s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--danger); color: var(--danger-ink); }
.btn.danger.ghost { background: transparent; color: var(--red); border-color: var(--red); }
.btn.sm { min-height: 38px; padding: 8px 14px; font-size: 14px; border-radius: 9px; }
.btn.hero {
  width: 100%; min-height: 60px; font-size: 19px; border-radius: var(--r);
  box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--brand) 70%, transparent);
}
.btn.hero.stop { background: var(--danger); color: var(--danger-ink); box-shadow: none; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; border-radius: 50%;
  width: 42px; height: 42px; display: grid; place-items: center; font-size: 19px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 14px;
  display: grid; place-items: center;
}

/* ------------------------------------------------------------------- shell */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brandmark { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.3px; }
.brandmark .glyph { font-size: 20px; }
main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(104px + env(safe-area-inset-bottom));
}
.page-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: transparent; cursor: pointer;
  display: grid; gap: 2px; justify-items: center; padding: 6px 4px;
  font-size: 11px; font-weight: 600; color: var(--muted); min-height: 52px;
  border-radius: 12px;
}
.tabbar button .ico { font-size: 21px; line-height: 1; }
.tabbar button.active { color: var(--brand); }

.empty {
  text-align: center; color: var(--muted); padding: 48px 16px;
  background: var(--panel); border-radius: var(--r); border: 1px dashed var(--line);
}
.section-label {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); margin: 24px 4px 10px;
}

/* ------------------------------------------------------------- active trip */
.active-card {
  background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow);
  overflow: hidden; margin-bottom: 8px;
  border: 2px solid color-mix(in srgb, var(--green) 45%, transparent);
}
.active-card .head { display: flex; gap: 14px; padding: 16px 16px 12px; align-items: center; }
.active-card .thumb { width: 62px; height: 62px; border-radius: 14px; flex: none; }
.active-card h2 { font-size: 20px; }
.active-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  color: var(--green); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 4px;
}
.pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }
.active-card .clock { flex: none; text-align: right; }
.active-card .clock .k {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--muted); margin-top: 2px;
}
.stopwatch {
  font-variant-numeric: tabular-nums; font-size: 28px; font-weight: 700;
  letter-spacing: -1px; line-height: 1;
}
.active-facts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.active-facts > div { background: var(--panel); padding: 12px 16px; min-width: 0; }
.active-facts > div.wide { grid-column: 1 / -1; overflow: hidden; }
.active-facts .loc-line { margin-top: 0; }
.active-facts .k { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.active-facts .v { font-weight: 600; margin-top: 2px; }
.active-card .foot { padding: 14px 16px 16px; }
.warn-line {
  background: var(--amber-soft); color: var(--amber); font-size: 14px; font-weight: 600;
  padding: 10px 16px;
}

/* --------------------------------------------------------------- vehicles */
.v-list { display: grid; gap: 8px; }
.v-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .08s ease;
}
.v-row:active { transform: scale(.99); }
.thumb {
  width: 52px; height: 52px; border-radius: 12px; flex: none; overflow: hidden;
  background: var(--panel-2); display: grid; place-items: center; font-size: 24px;
  border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.big { width: 76px; height: 76px; border-radius: 16px; font-size: 32px; }
.sheet-hero { display: flex; align-items: center; gap: 14px; }
.sheet-info {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  display: grid; gap: 4px;
}
.v-main { flex: 1; min-width: 0; }
.v-main h3 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.v-sub.strong { color: var(--ink); font-weight: 600; }
.plate {
  display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; margin-top: 4px;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 13px; font-weight: 700; border-radius: 999px; padding: 6px 12px;
  background: var(--panel-2); color: var(--muted);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.available { background: var(--green-soft); color: var(--green); }
.pill.inuse { background: var(--amber-soft); color: var(--amber); }
.loc-line {
  font-size: 13px; color: var(--muted); margin-top: 3px;
  display: flex; gap: 6px; align-items: center; min-width: 0;
}
.loc-line > .tag, .loc-line > a { flex: none; }
.loc-line .sep { flex: none; opacity: .5; }
.loc-line .loc-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc-line.detail { flex-wrap: wrap; }
.loc-line.detail .loc-text { overflow: visible; white-space: normal; }
.loc-line .loc-age { flex: none; white-space: nowrap; opacity: .85; }
.loc-line .loc-text.live { color: var(--green); font-weight: 600; }

.loc-line .tag { font-size: 12px; border-radius: 5px; padding: 1px 6px; }
.loc-line .tag.live { background: var(--green-soft); color: var(--green); }
.tag.live { background: var(--green-soft); color: var(--green); }

/* ---------------------------------------------------------------- history */
.day-head {
  font-size: 13px; font-weight: 700; color: var(--muted);
  padding: 18px 4px 8px; position: sticky; top: 52px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.t-row {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; margin-bottom: 8px; width: 100%; text-align: left; cursor: pointer;
}
.t-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; white-space: nowrap; }
.t-dur { font-size: 13px; color: var(--muted); }
.t-row.open { border-color: color-mix(in srgb, var(--green) 50%, transparent); }
.filters {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; margin-bottom: 14px;
}
.filters summary {
  list-style: none; cursor: pointer; font-weight: 650; color: var(--muted);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 30px;
}
.filters summary::-webkit-details-marker { display: none; }
.filters[open] summary { color: var(--ink); margin-bottom: 12px; }
.filters .body { display: grid; }
.segmented {
  display: inline-flex; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; gap: 2px; width: 100%;
}
.segmented button {
  flex: 1; border: 0; background: transparent; cursor: pointer; border-radius: 999px;
  padding: 9px 12px; font-size: 14px; font-weight: 650; color: var(--muted); min-height: 40px;
}
.segmented button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.lookup {
  background: var(--brand-soft); border-radius: var(--r); padding: 14px; margin-bottom: 14px;
}
.lookup summary {
  list-style: none; cursor: pointer; font-weight: 700; color: var(--brand);
  display: flex; align-items: center; gap: 8px; min-height: 28px;
}
.lookup summary::-webkit-details-marker { display: none; }
.lookup .body { margin-top: 12px; }
.lookup .hit {
  background: var(--panel); border-radius: var(--r-sm); padding: 14px; margin-top: 12px;
}
.lookup .hit .who { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }

/* ------------------------------------------------------------------ admin */
.admin-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 10px; margin-bottom: 8px; cursor: pointer; text-align: left;
}
.admin-row .chev { color: var(--muted); font-size: 22px; flex: none; padding: 0 4px; }
.admin-open {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  border: 0; background: transparent; cursor: pointer; padding: 4px 0; text-align: left;
}
.admin-row .avatar { flex: none; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 600;
  border-radius: 6px; padding: 1px 7px; background: var(--panel-2); color: var(--muted);
}
.tag.warn { background: var(--amber-soft); color: var(--amber); }
.tag.bad { background: var(--red-soft); color: var(--red); }
.tag.ok { background: var(--brand-soft); color: var(--brand); }

/* ------------------------------------------------------------ sheet/modal */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 12, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--panel); box-shadow: var(--shadow-lift);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: rise .22s cubic-bezier(.22, .9, .3, 1);
}
@keyframes rise { from { transform: translateY(14%); } }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 8px 16px 12px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body { padding: 0 16px 16px; }
.sheet-foot { padding: 4px 16px 8px; display: grid; gap: 8px; }
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: var(--r-lg); max-height: 88vh; }
}

/* A big row that shows the current choice and opens a picker when tapped. */
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; cursor: pointer; min-height: 64px;
}
.choice .name { font-weight: 650; font-size: 17px; }
.choice .change { color: var(--brand); font-weight: 650; font-size: 14px; }
.pick-list { display: grid; gap: 4px; max-height: 54vh; overflow: auto; margin-top: 12px; }
.pick-list button {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; background: transparent; cursor: pointer; padding: 11px 10px;
  border-radius: var(--r-sm); min-height: var(--tap); font-size: 16px;
}
.pick-list button:hover { background: var(--panel-2); }
.pick-list button.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.status-line { font-size: 13px; color: var(--muted); margin-top: 10px; text-align: center; min-height: 20px; }
.status-line.ok { color: var(--green); }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 28px 22px; width: 100%; max-width: 400px;
}
.login-card .brandmark { font-size: 21px; justify-content: center; margin-bottom: 6px; }
.login-card .brandmark .glyph { font-size: 26px; }
.login-card .help { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 20px; }
.notice { border-radius: var(--r-sm); padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
.notice.error { background: var(--red-soft); color: var(--red); }
.notice.info { background: var(--brand-soft); color: var(--brand); }
.access-banner {
  background: var(--amber-soft); color: var(--amber); font-size: 14px; font-weight: 600;
  padding: 10px 16px; text-align: center;
}

/* ------------------------------------------------------------------ toast */
#toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 90;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); color: #fff; }

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