/* Bike Tracker – mobile-first stylesheet. No build step, no framework. */

:root {
  --bg: #f2f4f7; --surface: #fff; --surface-2: #f7f8fa; --text: #151a23; --muted: #5f6b7d;
  --border: #e1e5ec; --accent: #3b5bdb; --accent-soft: #e8edff; --accent-text: #fff;
  --ok: #2b8a3e; --ok-soft: #e6f4ea; --warn: #b35c00; --warn-soft: #fff3e0;
  --err: #d6336c; --err-soft: #fde8ef;
  --radius: 14px; --radius-sm: 10px; --tap: 44px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 1px 3px rgb(16 24 40 / .06);
  --tabbar-h: 62px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1016; --surface: #171b23; --surface-2: #1d222c; --text: #e8ebf1; --muted: #9aa4b5;
    --border: #2a303b; --accent: #7c95ff; --accent-soft: #232b48; --accent-text: #0d1016;
    --ok: #51cf66; --ok-soft: #1c2e22; --warn: #ffa94d; --warn-soft: #33261a;
    --err: #ff6b9a; --err-soft: #3a1e29;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 1rem);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: .25rem 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; line-height: 1.25; margin: 0; }
h2 a { color: inherit; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.km, .num { font-variant-numeric: tabular-nums; }
.km { font-weight: 700; }
.lead { margin: 0 0 1rem; }

/* --- top bar + navigation ---------------------------------------------------------- */
.topbar {
  /* no backdrop-filter here: it would become the containing block of the fixed tab bar */
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top, 0px);
}
.topbar .bar { max-width: 960px; margin: 0 auto; padding: 0 1rem; height: 54px; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text); margin-right: auto; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 28px; height: 28px; color: var(--accent); }
form.user { display: flex; align-items: center; gap: .4rem; }
.user .name { font-size: .85rem; color: var(--muted); }
.icon { width: 22px; height: 22px; flex: none; }
.chev { width: 18px; height: 18px; flex: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-b);
}
.tabbar a {
  flex: 1; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar .icon { width: 24px; height: 24px; }

@media (min-width: 760px) {
  body { padding-bottom: 2rem; }
  .tabbar {
    position: static; background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
    border: 0; padding: 0; gap: .25rem; order: 0;
  }
  .topbar .bar { height: 60px; }
  .tabbar a { flex: none; height: 38px; flex-direction: row; gap: .4rem; padding: 0 .8rem; border-radius: 999px; font-size: .92rem; }
  .tabbar a[aria-current="page"] { background: var(--accent-soft); }
  .tabbar .icon { width: 18px; height: 18px; }
}

main { max-width: 960px; margin: 0 auto; padding: 1rem; }

/* --- cards ------------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card > h2 { margin-bottom: .6rem; }
.card-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.card-head h1, .card-head h2 { margin: 0; }
.page-head { margin: .25rem 0 1rem; }
.title-badges { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.empty { padding: 1rem 0; text-align: center; }

/* --- badges ------------------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: .25rem; font-size: .72rem; font-weight: 600; line-height: 1.6;
  padding: 0 .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); vertical-align: middle; white-space: nowrap;
}
.badge.default { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge.err { background: var(--err-soft); border-color: transparent; color: var(--err); }
a.badge:hover { text-decoration: none; filter: brightness(.97); }

/* --- buttons ----------------------------------------------------------------------- */
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .95rem; font-weight: 600; min-height: var(--tap); padding: 0 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; line-height: 1.2; text-align: center; touch-action: manipulation;
}
.btn:hover, button:hover { text-decoration: none; border-color: var(--accent); }
.btn:active, button:active { transform: translateY(1px); }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
.btn.danger, button.danger { color: var(--err); }
.btn.danger:hover, button.danger:hover { border-color: var(--err); }
.btn.small, button.small { font-size: .85rem; min-height: 36px; padding: 0 .75rem; }
.btn.ghost, button.ghost { border-color: transparent; background: none; }
button.icon-btn { min-height: 40px; width: 40px; padding: 0; border-color: transparent; background: none; color: var(--muted); }
button.icon-btn:hover { color: var(--text); background: var(--surface-2); }
form.inline { display: inline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Full-width primary actions on phones. */
@media (max-width: 759px) {
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions > * { width: 100%; }
  .stack-sm { flex-direction: column; align-items: stretch; }
  .stack-sm > * { width: 100%; }
}

/* --- chips (add component) ----------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }
.chip {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 36px; padding: 0 .8rem;
  border-radius: 999px; border: 1px dashed var(--border); color: var(--accent); font-size: .88rem; font-weight: 600;
}
.chip:hover { text-decoration: none; border-color: var(--accent); background: var(--accent-soft); }

/* --- sync status --------------------------------------------------------------------- */
.status { display: grid; gap: .75rem; }
.status .line { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; }
.status .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; width: 100%; }
.status .alerts { display: flex; flex-wrap: wrap; gap: .4rem; }
.alert-link {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: var(--tap);
  padding: .5rem .9rem; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: .92rem;
  flex: 1 1 14rem;
}
.alert-link.info { background: var(--accent-soft); color: var(--accent); }
.alert-link:hover { text-decoration: none; filter: brightness(.98); }
@media (min-width: 760px) {
  .status { grid-template-columns: 1fr auto; align-items: center; }
  .status .alerts { grid-column: 1 / -1; }
}

/* --- component tiles ----------------------------------------------------------------- */
.comp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.comp {
  display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; align-items: start;
  padding: .85rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border);
}
.comp-title { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.comp-km { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.comp-km .km { font-size: 1.35rem; line-height: 1.1; }
.comp-km .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.comp-km .sub strong { color: var(--text); }
.comp .actions { grid-column: 1 / -1; margin-top: .55rem; }
.comp .actions .btn { flex: 1 1 0; }
@media (min-width: 760px) {
  .comp { grid-template-columns: 1fr auto auto; align-items: center; }
  .comp .actions { grid-column: auto; margin-top: 0; flex-wrap: nowrap; }
  .comp .actions .btn { flex: none; }
}

/* --- stats ------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 760px) {
  .stats { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
  .stats .stat:last-child:nth-child(odd) { grid-column: auto; }
}
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; box-shadow: var(--shadow); }
.stat .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat .value.small { font-size: 1rem; }
.stat .hint { font-size: .8rem; color: var(--muted); }

/* --- generic lists ------------------------------------------------------------------ */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .primary-line { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.list .right { text-align: right; white-space: nowrap; }
.list .chev { color: var(--muted); }

a.row-link { display: flex; align-items: center; gap: .75rem; color: inherit; width: 100%; min-height: var(--tap); }
a.row-link:hover { text-decoration: none; }
a.row-link:hover .primary-line > .name { color: var(--accent); }

/* --- segmented tabs ----------------------------------------------------------------- */
.segmented {
  display: flex; gap: .25rem; padding: .25rem; margin: 0 0 1rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented a {
  flex: 1 0 auto; display: flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 .8rem;
  border-radius: 9px; font-size: .88rem; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- rides -------------------------------------------------------------------------- */
.ride-list > li { padding: 0; }
.ride-list label.ride-row { display: flex; margin: 0; font-weight: 400; font-size: 1rem; align-items: center; gap: .8rem; width: 100%; padding: .7rem 0; cursor: pointer; }
.ride-row .meta { font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .3rem .5rem; align-items: center; }
.ride-row .dist { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card label.select-all { display: flex; margin: 0; align-items: center; gap: .6rem; padding: .25rem 0 .6rem; border-bottom: 1px solid var(--border); font-size: .88rem; color: var(--muted); font-weight: 600; cursor: pointer; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 0; }

.assign-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + .5rem); z-index: 10;
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1rem; padding: .6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 24px rgb(16 24 40 / .14);
}
.assign-bar label { font-size: .85rem; font-weight: 600; color: var(--muted); width: 100%; margin: 0 !important; }
.assign-bar select { flex: 1 1 10rem; }
@media (min-width: 760px) {
  .assign-bar { bottom: 1rem; }
  .assign-bar label { width: auto; }
}

.filter { margin: 0 0 1rem; }

.pagination { margin-top: 1rem; display: flex; gap: .5rem; align-items: center; justify-content: space-between; }

/* --- duplicates --------------------------------------------------------------------- */
.dup-grid { display: grid; grid-template-columns: 1fr; gap: .6rem; }
.dup-grid > div { display: flex; flex-direction: column; gap: .15rem; padding: .8rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.dup-grid > div.suspect { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.dup-grid .badge { align-self: flex-start; margin-bottom: .3rem; }
.dup-actions { margin-top: .8rem; }
@media (min-width: 760px) { .dup-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 759px) { .dup-actions { flex-direction: column; align-items: stretch; } }

/* --- messages ----------------------------------------------------------------------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .4rem; }
.messages li { padding: .7rem .9rem; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); font-size: .95rem; }
.messages li.success { background: var(--ok-soft); }
.messages li.warning { background: var(--warn-soft); }
.messages li.error { background: var(--err-soft); }

/* --- forms -------------------------------------------------------------------------- */
.form .field, .form p { margin: 0 0 1rem; }
.form label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .3rem; }
.form .check label { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); font-weight: 600; cursor: pointer; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; max-width: 32rem; font: inherit; font-size: 16px; /* >=16px: no iOS zoom on focus */
  min-height: var(--tap); padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 2.2rem; background-repeat: no-repeat; background-position: right .75rem center; background-size: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23889' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
}
input:focus, select, textarea:focus { outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form .helptext { display: block; color: var(--muted); font-size: .84rem; margin-top: .3rem; }
.errorlist { list-style: none; color: var(--err); margin: .3rem 0 0; padding: 0; font-size: .88rem; font-weight: 600; }
.form > .errorlist { margin-bottom: 1rem; padding: .6rem .8rem; background: var(--err-soft); border-radius: var(--radius-sm); }
fieldset.component-fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .4rem 1rem 0; margin: 0 0 1rem; background: var(--surface-2); }
fieldset.component-fieldset legend { font-weight: 700; padding: 0 .4rem; }
.section-title { margin: 1.5rem 0 .4rem; }
.danger-zone { margin-top: 1.5rem; text-align: center; }

.login { max-width: 24rem; margin: 2rem auto; }
.login .logo { width: 48px; height: 48px; color: var(--accent); display: block; margin: 0 auto .5rem; }
.login h1 { text-align: center; }
.login button { width: 100%; }
