/* Driver Trips — mobile-first styles (no external dependencies). */

:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --text: #172033;
  --muted: #5b6578;
  --border: #dbe1ea;
  --primary: #1f56c3;
  --primary-hover: #1a49a6;
  --primary-ink: #ffffff;
  --primary-soft: #e8effc;
  --ok: #157f3b;
  --ok-bg: #e5f5ea;
  --warn: #8a4b06;
  --warn-bg: #fff3d6;
  --warn-border: #f2c86b;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --danger-border: #f5b5ae;
  --topbar: #1f4fa3;
  --topbar-ink: #ffffff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.06);
  --tap: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #18202b;
    --surface-2: #1e2834;
    --text: #e8edf4;
    --muted: #9aa6b7;
    --border: #2c3846;
    --primary: #5b8dee;
    --primary-hover: #7aa3f2;
    --primary-ink: #0b1220;
    --primary-soft: #1c2b47;
    --ok: #6fd391;
    --ok-bg: #143021;
    --warn: #f5c56b;
    --warn-bg: #33270f;
    --warn-border: #6b5220;
    --danger: #ff8a80;
    --danger-bg: #3a1716;
    --danger-border: #6e2a26;
    --topbar: #142a52;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.5rem; }
a { color: var(--primary); }
code { font-size: 0.9em; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.lead { font-size: 1.05rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.6rem; }

/* ---------- layout ---------- */

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}
.container-wide { max-width: 1400px; }

/* 100vh on mobile is the height with the browser's address bar hidden, so while the bar is
   visible the page overflows and scrolls. dvh tracks the visible height; 100vh is the fallback. */
.page-center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar);
  color: var(--topbar-ink);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-wide { max-width: 1400px; }
.who { display: flex; flex-direction: column; min-width: 0; }
.who-label { font-size: 0.75rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.04em; }
.who-name { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.topbar-actions form { margin: 0; }
.topbar .link-btn { color: var(--topbar-ink); }

.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.link-btn:hover { background: rgba(127, 127, 127, 0.15); }
.link-btn.back { padding-left: 0; }

.netbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 6px 16px;
}
.netbar .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.netbar-online { background: var(--ok-bg); color: var(--ok); }
.netbar-pending, .netbar-syncing { background: var(--warn-bg); color: var(--warn); }
.netbar-syncing .dot { animation: pulse 1s ease-in-out infinite; }
.netbar-offline { background: #5c6473; color: #fff; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 58px; font-size: 1.1rem; }
.btn-sm { min-height: 44px; padding: 8px 14px; font-size: 0.95rem; }
.btn + .btn-block, .btn-block + .btn-block { margin-top: 10px; }

.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost-danger { background: transparent; color: var(--danger); }
.btn-ghost-danger:hover { background: var(--danger-bg); }
.btn-google { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-google:hover { border-color: var(--primary); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn-danger { color: var(--danger); }

/* ---------- forms ---------- */

/* display:block so <label class="field"> (inline by default) gets its spacing too */
.field { display: block; margin: 0 0 18px; border: 0; padding: 0; min-width: 0; }
.label { display: block; font-weight: 650; margin-bottom: 6px; padding: 0; }
.label.question { font-size: 1.1rem; margin-bottom: 12px; }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem; /* >= 16px prevents iOS zoom */
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { min-height: 96px; resize: vertical; }
select.input { appearance: auto; }
.input-plate { text-transform: uppercase; font-weight: 700; letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.input-plate::placeholder { text-transform: none; letter-spacing: normal; font-weight: 400; }

.error { color: var(--danger); font-weight: 600; font-size: 0.95rem; margin: 6px 0 0; }
.input.is-invalid { border-color: var(--danger); }
.form-errors {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 600;
}
.form-errors p { margin: 0; }
.form-errors p + p { margin-top: 4px; }
.hint-warn { color: var(--warn); margin: 8px 0 0; font-weight: 600; }

.form-head { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 12px; }
.form-head h2 { margin: 0; }

.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 48px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.chip strong { letter-spacing: 0.05em; }
.chip span { font-size: 0.8rem; color: var(--muted); }

/* points editor */
.points { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.point-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  grid-template-areas: "num input" ". actions";
  align-items: center;
  gap: 6px 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.point-num {
  grid-area: num;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
  font-size: 0.875rem;
  display: flex; align-items: center; justify-content: center;
}
.point-input { grid-area: input; min-height: 48px; }
.point-actions { grid-area: actions; display: flex; gap: 6px; justify-content: flex-end; }
@media (min-width: 480px) {
  .point-row { grid-template-columns: 28px 1fr auto; grid-template-areas: "num input actions"; }
}

.add-point { display: flex; gap: 8px; flex-wrap: wrap; }
.add-point .input { flex: 1 1 200px; }
.add-point .btn { flex: 1 0 auto; }

.choice-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  min-height: 64px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}
.choice-yes.is-selected { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.choice-no.is-selected { border-color: var(--warn-border); background: var(--warn-bg); color: var(--warn); }

/* ---------- trip display ---------- */

.card-head { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.trip-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 16px; }
.trip-meta dt { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.trip-meta dd { margin: 2px 0 0; font-weight: 650; }

.plate {
  display: inline-block;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border: 2px solid var(--text);
  border-radius: 6px;
  background: var(--surface);
}
.plate-sm { font-size: 0.85rem; padding: 0 6px; border-width: 1.5px; white-space: nowrap; }

.section-title { font-size: 0.95rem; color: var(--muted); margin: 0 0 8px; }
.route { margin: 0 0 18px; padding: 0; list-style: none; counter-reset: route; }
.route li {
  counter-increment: route;
  position: relative;
  padding: 6px 0 6px 40px;
  min-height: 36px;
}
.route li::before {
  content: counter(route);
  position: absolute; left: 0; top: 4px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
}
.route li:not(:last-child)::after {
  content: "";
  position: absolute; left: 13px; top: 32px; bottom: -4px;
  width: 2px; background: var(--border);
}
.route-compact li { padding: 2px 0 2px 26px; min-height: 0; font-size: 0.9rem; }
.route-compact li::before { width: 18px; height: 18px; font-size: 0.7rem; top: 3px; }
.route-compact li:not(:last-child)::after { left: 8px; top: 22px; bottom: -2px; }

.hero { text-align: center; padding: 26px 18px; }
.hero .btn { margin-top: 10px; }

.confirm-box {
  margin-top: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
}

.recent summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
.recent summary::-webkit-details-marker { display: none; }
.recent summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform 0.2s; }
.recent[open] summary::after { transform: rotate(180deg); }
.recent[open] summary { margin-bottom: 10px; }
.count { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 0.85rem; }
.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-item { padding: 12px 0; border-top: 1px solid var(--border); }
.recent-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.recent-route { margin: 6px 0; }
.recent-badges { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- badges, banners, notices ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: normal;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge-progress, .badge-status-in_progress { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-status-completed { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-status-cancelled { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge-muted { color: var(--muted); }

.banner {
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid;
}
.banner p:last-child { margin-bottom: 0; }
.banner .btn { margin-top: 10px; }
.banner-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.banner-warn .banner-text { flex: 1 1 220px; }
.banner-warn .btn { margin-top: 0; }
.banner-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.banner details { margin-top: 8px; }
.banner summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.failed-list { padding-left: 18px; font-size: 0.875rem; }

.notice { border-radius: var(--radius-sm); padding: 10px 12px; margin: 0 0 14px; font-weight: 600; }
.notice-error { background: var(--danger-bg); color: var(--danger); }
.notice-info { background: var(--primary-soft); color: var(--primary); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #172033;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
  max-width: calc(100% - 32px);
  text-align: center;
}

.footer-note { text-align: center; margin-top: 8px; }
.auth-footer { text-align: center; margin: 12px 0 0; font-size: 0.875rem; }

/* Long-form text pages (privacy policy) */
.doc { line-height: 1.55; }
.doc h1 { margin-top: 12px; }
.doc h2 { font-size: 1.1rem; margin: 1.6rem 0 0.5rem; }
.doc ul { padding-left: 1.2rem; margin: 0 0 0.6rem; }
.doc li { margin: 0.35rem 0; }
.doc-nav { display: flex; justify-content: space-between; gap: 12px; }
.doc-nav a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- auth pages ---------- */

.auth-wrap { width: 100%; max-width: 440px; padding: 16px; }
.auth-card { text-align: center; padding: 28px 22px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .btn-block { margin-top: 14px; }
.auth-logo { display: block; margin: 0 auto 12px; border-radius: 16px; }
.forbidden-icon { font-size: 44px; margin-bottom: 8px; }
.dev-login { margin-top: 24px; padding-top: 18px; border-top: 1px dashed var(--border); }
.dev-login form { margin: 0; }
.dev-login-title { font-weight: 700; margin-bottom: 0; }
.dev-login-title span { font-weight: 400; color: var(--muted); font-size: 0.875rem; }

/* ---------- admin ---------- */

.page-title { margin: 4px 0 14px; }
.filters { display: grid; grid-template-columns: 1fr; gap: 12px; }
.filters .field { margin: 0; }
.filters-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters-actions .btn { flex: 1 1 auto; }
@media (min-width: 720px) {
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters-actions { grid-column: 1 / -1; }
  .filters-actions .btn { flex: 0 0 auto; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.stat-value { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.875rem; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.trips-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.trips-table th, .trips-table td { text-align: left; vertical-align: top; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.trips-table th { background: var(--surface-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); position: sticky; top: 0; }
.trips-table tr:last-child td { border-bottom: 0; }
.trips-table .badge { margin: 0 4px 4px 0; }
.note { margin: 6px 0 0; font-size: 0.85rem; color: var(--muted); }

@media (max-width: 860px) {
  .table-wrap { border: 0; background: none; overflow: visible; }
  .trips-table thead { display: none; }
  .trips-table, .trips-table tbody, .trips-table tr, .trips-table td { display: block; width: 100%; }
  .trips-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 6px 0;
  }
  .trips-table td { border: 0; padding: 6px 14px; display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
  .trips-table td::before { content: attr(data-label); color: var(--muted); font-size: 0.8rem; font-weight: 600; padding-top: 2px; }
}
.trips-table .route { margin: 0; }

/* route-point suggestions (driver's previously used places) */
.point-suggest { margin-top: 10px; }
.suggest-label { width: 100%; font-size: 0.85rem; color: var(--muted); }
.chip-point { flex-direction: row; align-items: center; gap: 6px; min-height: 44px; font-weight: 600; }
.chip-plus { color: var(--primary); font-weight: 800; font-size: 1.1rem; line-height: 1; }

/* trip time (now / manually set) */
.time-now { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.time-now-value { font-weight: 650; }
.time-field input[type="datetime-local"] { margin-bottom: 6px; }
.manual-mark { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--warn-bg); color: var(--warn); }
.manual-note { font-size: 0.8rem; color: var(--warn); }

/* Manual trip time: day select + time input side by side */
.time-inputs { display: flex; gap: 8px; }
.time-inputs .time-day { flex: 1 1 auto; min-width: 0; }
.time-inputs .time-clock { flex: 0 0 7.5em; }

/* Route doesn't return to its first point: a hint, never a blocker */
.route-notice {
  margin: 14px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.9rem;
}
.route-notice p { margin: 0 0 8px; font-weight: 600; }

/* ---------- admin: sections, users and vehicles ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.break { overflow-wrap: anywhere; }
.notice-ok { background: var(--ok-bg); color: var(--ok); }
.admin-nav { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.admin-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  color: var(--muted); font-weight: 650; text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.admin-nav a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.card-title { font-size: 1.1rem; margin: 0 0 14px; }
.page-subtitle { font-size: 1rem; font-weight: 500; margin-left: 8px; }
.admin-forms { display: grid; gap: 0 16px; align-items: start; }
@media (min-width: 900px) { .admin-forms { grid-template-columns: 1fr 1fr; } }
.bulk summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.bulk[open] summary { margin-bottom: 8px; }
.bulk-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; }
@media (min-width: 720px) {
  .filters.filters-compact { grid-template-columns: 2fr 1fr auto; align-items: end; }
  .filters-compact .filters-actions { grid-column: auto; }
}
.users-table tr.is-inactive td > div { opacity: 0.65; }
.users-table td:last-child { text-align: right; }
@media (max-width: 860px) {
  .users-table td:last-child { display: block; text-align: left; }
  .users-table td:last-child::before { content: none; }
}
