:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1f1c;
  --muted: #6b6e68;
  --line: #dedbd2;
  --accent: #0e6b70;
  --accent-ink: #ffffff;
  --fresh: #2e8b57;
  --aging: #c98a12;
  --stale: #8d918a;
  --danger: #b3372c;
  --danger-bg: #fbeceb;
  --warn-bg: #fdf4e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141614;
    --surface: #1c1f1c;
    --surface-2: #252925;
    --text: #e9ebe6;
    --muted: #9ca19a;
    --line: #333833;
    --accent: #5cc4c8;
    --accent-ink: #0b1a1b;
    --fresh: #5fbf8f;
    --aging: #e0a93a;
    --stale: #7d827b;
    --danger: #ef7a6e;
    --danger-bg: #3a201d;
    --warn-bg: #3a3020;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 1px 6px; margin-right: 2px; }
/* Gmail-style beta tag: small, gray, raised beside the name */
.beta {
  margin-left: 4px; position: relative; top: -7px;
  font-size: 9px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}
/* Terms popup: scrolls inside the dialog, close button stays reachable */
#terms-dialog { max-height: calc(100dvh - 32px); display: none; flex-direction: column; }
#terms-dialog[open] { display: flex; }
.terms { overflow-y: auto; font-size: 14px; line-height: 1.5; }
.terms h4 { margin: 16px 0 4px; font-size: 14px; }
.terms p { margin: 0 0 8px; }
#terms-dialog .dlg-actions { padding-top: 12px; border-top: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; min-height: 34px;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* Layout: map on top on phones, side by side on wide screens */
.layout { flex: 1; min-height: 0; display: grid; grid-template-rows: 40vh 1fr; }
#map { min-height: 0; background: var(--surface-2); }
.panel { min-height: 0; overflow-y: auto; padding: 12px 16px 0; background: var(--bg); }
/* Data credit: pinned to the bottom of the panel on every tab */
.credit {
  position: sticky; bottom: 0; z-index: 1;
  margin: 20px -16px 0; padding: 9px 16px calc(9px + env(safe-area-inset-bottom));
  background: var(--surface-2); border-top: 1px solid var(--line);
  font-size: 12px; line-height: 1.4; color: var(--muted); text-align: center;
}
.credit a { font-weight: 600; white-space: nowrap; }
@media (min-width: 900px) {
  .layout { grid-template-rows: none; grid-template-columns: 420px 1fr; }
  .panel { order: -1; border-right: 1px solid var(--line); }
}

/* Controls */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.stack > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters label, label.inline { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
input, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 44px;
}
input { flex: 1; min-width: 0; }
.filters select, label.inline select { font-size: 14px; min-height: 36px; padding: 4px 8px; }
.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.bike-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.bike-bar label { font-size: 13px; color: var(--muted); }
.bike-bar select { font-size: 14px; min-height: 36px; padding: 4px 8px; }

.status { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }

/* Station rows: one inset list with hairline dividers */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start;
  padding: 11px 12px; cursor: pointer; border-top: 1px solid var(--line);
}
.list > .card:first-child { border-top: 0; }
.card:hover { background: var(--surface-2); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.card .sign.flat { margin: 2px 0 0; box-shadow: none; border-width: 1.5px; font-size: 12px; }
.card .sign.flat::after { display: none; }
.card .sign.flat:hover { transform: none; }
.card .sign.flat .l, .card .sign.flat .r { padding: 4px 5px; }
.card-body { min-width: 0; }
.card-name { font-weight: 600; font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { color: var(--muted); font-size: 13px; line-height: 1.3; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-fresh { font-size: 12px; margin-top: 3px; color: var(--muted); }
.card-fresh .f-fresh { color: var(--fresh); }
.card-fresh .f-aging { color: var(--aging); }
.card-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.card-main { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.25; }
.card-subside { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .03em; }
.card-actions { display: flex; gap: 8px; margin-top: 5px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text); text-decoration: none; position: relative;
}
.icon-btn::before { content: ''; position: absolute; inset: -5px; } /* 44px tap target */
.icon-btn.go { background: var(--accent); color: var(--accent-ink); }
.chip { font-size: 12px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.chip.oct { font-variant-numeric: tabular-nums; font-weight: 600; }
.fresh-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.f-fresh .fresh-dot, .fresh-dot.f-fresh { background: var(--fresh); } .fresh-dot.f-aging { background: var(--aging); } .fresh-dot.f-stale { background: var(--stale); }

/* Route plan */
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 12px 0; }
.summary-nums { display: flex; gap: 16px; flex-wrap: wrap; }
.summary-nums div { display: flex; flex-direction: column; }
.summary-nums b { font-size: 20px; font-variant-numeric: tabular-nums; }
.summary-nums span { font-size: 12px; color: var(--muted); }
.alert { border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.alert.gap { background: var(--danger-bg); color: var(--danger); }
.alert.warn { background: var(--warn-bg); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.timeline > li { position: relative; }
.timeline > li::before {
  content: attr(data-n); position: absolute; left: -27px; top: 10px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.timeline > li.endpoint::before { background: var(--text); color: var(--bg); content: ''; width: 12px; height: 12px; left: -22px; top: 6px; }
.timeline > li.endpoint { font-size: 14px; color: var(--muted); }
.leg { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.leg.over { color: var(--danger); font-weight: 600; }
details.backups { margin-top: 6px; font-size: 13px; }
details.backups summary { cursor: pointer; color: var(--muted); }
details.backups ul { padding-left: 18px; margin: 6px 0 0; }
.plan-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

/* Settings: bikes */
.bike-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.bike-card .full { grid-column: 1 / -1; }
.bike-card label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.bike-card input { min-height: 38px; font-size: 15px; }
.bike-card .bike-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }

/* Station dialog */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-body { padding: 16px; }
.dlg-body h3 { margin: 0 0 2px; font-size: 18px; }
.dlg-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 12px 0; }
.dlg-body dt { color: var(--muted); }
.dlg-body dd { margin: 0; }
.dlg-note { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; white-space: pre-wrap; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 16px 16px; }
.dlg-actions .full { grid-column: 1 / -1; }

/* Overlay + toast */
#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 2000; }
#overlay[hidden] { display: none; }
.overlay-card { background: var(--surface); border-radius: 14px; padding: 20px; width: min(360px, calc(100vw - 32px)); text-align: center; }
.overlay-card progress { width: 100%; }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 2100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

/* Map markers */
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #2a7de1; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(42,125,225,.35); }
/* Station "price sign" pin (anchored at the pointer tip) */
.sign { position: relative; display: flex; align-items: stretch; border-radius: 7px; border: 2px solid #fff; cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,.45); font: 800 13px/1 -apple-system, BlinkMacSystemFont, sans-serif; color: #fff; margin-bottom: 8px; }
.sign .l { padding: 5px 6px; letter-spacing: .02em; border-radius: 5px 0 0 5px; }
.sign .r { padding: 5px 6px; background: #111; border-radius: 0 5px 5px 0; font-variant-numeric: tabular-nums; }
.sign::after { content: ''; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: #fff; border-bottom: 0; }
.sign.stale { border-style: dashed; opacity: .85; }
.sign:hover { transform: scale(1.08); }
/* Group of stations when zoomed out */
.cluster { width: 46px; height: 46px; border-radius: 50%; background: #1d1f1c; color: #fff; border: 3px solid #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; transform: translateY(50%); cursor: pointer;
  box-shadow: 0 0 0 4px rgba(46,139,87,.55), 0 2px 6px rgba(0,0,0,.4); font: 800 15px/1 -apple-system, sans-serif; }
.cluster small { font-size: 8px; font-weight: 700; opacity: .85; margin-top: 2px; letter-spacing: .04em; }
/* Planned fuel stop */
.stop-pin { filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); cursor: pointer; }
.stop-pin svg { display: block; }
.me-dot { transform: translateY(50%); }
.map-off { padding: 24px; color: var(--muted); text-align: center; }
.filters input[type="checkbox"] { min-height: auto; flex: none; width: 18px; height: 18px; }
