:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --line: #2a3138;
  --text: #e9edf2;
  --muted: #8d98a6;
  --accent: #4fc3f7;
  --rider-a: #4fc3f7;
  --rider-b: #ffab6b;
  --danger: #ff6b6b;
  --ok: #58d68d;
  --warn: #f5c451;
  --radius: 14px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --line: #dde3ea;
    --text: #161c22;
    --muted: #66727f;
    --rider-a: #0288d1;
    --rider-b: #d2691e;
  }
}

* { box-sizing: border-box; }

/* Several rules below set `display` on elements we also toggle with the
   `hidden` attribute, and a class selector outranks the browser's own
   `[hidden]` rule. Make hiding win. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 19px; letter-spacing: -0.2px; }
.strap { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------------- views */

.view { display: none; padding: 14px 14px 24px; }
.view.is-active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  font-weight: 600;
}

.status-line { margin: 0; font-size: 18px; font-weight: 600; }
.balance-line { margin: 0; font-size: 22px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 10px 2px 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; }

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

button, select, input { font: inherit; color: inherit; }

.primary-btn, .ghost-btn, .danger-btn {
  border-radius: 11px;
  padding: 12px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  min-height: 46px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn { background: var(--accent); color: #06121a; }
.ghost-btn { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.danger-btn { background: transparent; border-color: var(--danger); color: var(--danger); }
.primary-btn.big { width: 100%; font-size: 17px; min-height: 54px; margin-bottom: 12px; }
.ghost-btn.wide { flex: 1; }
button:disabled { opacity: 0.5; }

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  padding: 6px;
  cursor: pointer;
  line-height: 1;
}

.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .compact { flex: 0 0 auto; padding-left: 22px; padding-right: 22px; }

/* Buttons sitting directly on a view, outside a card, span the width. */
.view > .primary-btn, .view > .ghost-btn { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
  width: 100%;
  color: var(--text);
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------- calendar */

.week-nav { display: flex; gap: 8px; margin-bottom: 10px; }

.calendar {
  display: grid;
  grid-template-columns: 42px repeat(7, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  user-select: none;
}

.cal-head {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  text-align: center;
  padding: 6px 2px;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.2;
}

.cal-head strong { display: block; font-size: 14px; color: var(--text); }
.cal-head.is-today strong { color: var(--accent); }

.cal-hour {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  padding: 2px 5px 0 0;
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
  height: 34px;
}

.cal-cell {
  height: 34px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  position: relative;
  cursor: pointer;
}

.cal-cell.is-past { background: color-mix(in srgb, var(--bg) 45%, transparent); }
.cal-cell.is-selecting { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.cal-cell.busy-a { background: color-mix(in srgb, var(--rider-a) 42%, transparent); }
.cal-cell.busy-b { background: color-mix(in srgb, var(--rider-b) 42%, transparent); }
.cal-cell.is-start::after {
  content: attr(data-label);
  position: absolute;
  inset: 1px 2px auto 3px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------------------------------------------------------------- segmented */

.segmented { display: flex; gap: 6px; }

.segmented button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.segmented button.is-on { background: var(--accent); color: #06121a; border-color: var(--accent); }

/* ------------------------------------------------------------------- lists */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.list li:first-child { border-top: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; font-size: 14.5px; }
.list .sub { color: var(--muted); font-size: 12px; }
.list .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.pill {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.pill.ok { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
.pill.soon { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.pill.overdue { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }
.pill.unset { background: var(--surface-2); color: var(--muted); }

.mini-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  min-height: 36px;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.a { background: var(--rider-a); }
.dot.b { background: var(--rider-b); }

/* ------------------------------------------------------------------ tabbar */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  padding: 8px 2px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: var(--tabbar-h);
}

.tab span { font-size: 20px; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ------------------------------------------------------------------- sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
}

.sheet {
  background: var(--surface);
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 88vh;
  overflow-y: auto;
}

.sheet h2 { margin: 0; font-size: 17px; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  z-index: 50;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13.5px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.toast.is-error { border-color: var(--danger); color: var(--danger); }

@media (min-width: 720px) {
  main { max-width: 640px; margin: 0 auto; }
  .cal-cell, .cal-hour { height: 40px; }
}
