:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #17213a;
  --surface-3: #1f2c4a;
  --border: #263352;
  --text: #e8eefc;
  --muted: #93a1c4;
  --brand: #14b8a6;
  --brand-ink: #032420;
  --ok: #22c55e;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #ef4444;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --tap: 0.15s ease;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(20, 184, 166, 0.14), transparent 60%),
    var(--bg);
  min-height: 100dvh;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 96px);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .spacer { flex: 1; }
.topbar h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brandmark {
  width: 30px; height: 30px;
  flex: 0 0 auto;
}
.iconbtn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform var(--tap), background var(--tap);
}
.iconbtn:active { transform: scale(0.92); background: var(--surface-2); }

.backbtn {
  appearance: none;
  border: none;
  background: none;
  color: var(--brand);
  font-size: 16px;
  font-weight: 600;
  padding: 6px 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }

.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  margin: 22px 4px 10px;
}

/* ---------- Bike list ---------- */
.bike-card {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform var(--tap), border-color var(--tap);
  text-align: left;
  width: 100%;
  appearance: none;
  color: inherit;
  font: inherit;
}
.bike-card:active { transform: scale(0.98); border-color: var(--brand); }
.bike-emoji {
  font-size: 26px;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--surface-2);
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.bike-card .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.bike-card .name { font-weight: 700; font-size: 17px; }
.bike-card .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.bike-card .chev { color: var(--muted); font-size: 20px; align-self: center; }

/* At-a-glance stat chips on the bike cards */
.glance { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px; }
.gstat { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.gstat b { color: var(--text); font-weight: 700; }
.gstat .status-dot { width: 8px; height: 8px; box-shadow: none; }
.gtag {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 7px; border-radius: 999px;
}
.g-ok { color: var(--ok); }
.g-yellow { color: var(--yellow); }
.g-orange { color: var(--orange); }
.g-red { color: var(--red); }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.04);
}
.dot-ok { background: var(--ok); }
.dot-yellow { background: var(--yellow); }
.dot-orange { background: var(--orange); }
.dot-red { background: var(--red); box-shadow: 0 0 0 4px rgba(239,68,68,0.18); }

/* ---------- Detail header ---------- */
.detail-head {
  display: flex; align-items: center; gap: 14px; margin: 6px 4px 4px;
}
.detail-head .bike-emoji { width: 60px; height: 60px; font-size: 30px; }
.detail-head h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.detail-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ---------- Wax action buttons ---------- */
.wax-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.wax-btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform var(--tap), background var(--tap), border-color var(--tap);
  text-align: center;
}
.wax-btn:active { transform: scale(0.96); }
.wax-btn .emoji { font-size: 30px; }
.wax-btn .label { font-weight: 800; font-size: 16px; }
.wax-btn .hint { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.wax-dip {
  background: linear-gradient(180deg, rgba(20,184,166,0.18), rgba(20,184,166,0.05));
  border-color: rgba(20,184,166,0.5);
}
.wax-dip:active { background: rgba(20,184,166,0.28); }
.wax-drip {
  background: linear-gradient(180deg, rgba(96,165,250,0.15), rgba(96,165,250,0.04));
  border-color: rgba(96,165,250,0.45);
}
.wax-drip:active { background: rgba(96,165,250,0.24); }

/* ---------- Key/value rows ---------- */
.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); font-size: 14px; }
.kv .v { font-weight: 600; font-size: 15px; text-align: right; }
.kv .v.editable { color: var(--brand); cursor: pointer; }
.kv .v a { color: var(--brand); text-decoration: none; }

.card-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 6px;
}
.card-title h3 { margin: 0; font-size: 16px; font-weight: 800; }
.card-title .edit { font-size: 14px; color: var(--brand); cursor: pointer; background: none; border: none; padding: 4px; }

/* ---------- Master-link status banner ---------- */
.ml-status {
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.ml-count {
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  min-width: 58px;
  text-align: center;
}
.ml-status .txt { flex: 1; }
.ml-status .txt .h { font-weight: 800; font-size: 16px; }
.ml-status .txt .s { font-size: 13px; color: var(--muted); margin-top: 3px; }

.ml-ok     { background: rgba(34,197,94,0.10);  border-color: rgba(34,197,94,0.35); }
.ml-ok .ml-count { color: var(--ok); }
.ml-yellow { background: rgba(234,179,8,0.12);  border-color: rgba(234,179,8,0.45); }
.ml-yellow .ml-count { color: var(--yellow); }
.ml-orange { background: rgba(249,115,22,0.13); border-color: rgba(249,115,22,0.5); }
.ml-orange .ml-count { color: var(--orange); }
.ml-red    { background: rgba(239,68,68,0.15);  border-color: rgba(239,68,68,0.6); animation: pulse 2s ease-in-out infinite; }
.ml-red .ml-count { color: var(--red); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0.10); } }

.replace-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  margin-top: 4px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--tap), filter var(--tap);
}
.replace-btn:active { transform: scale(0.97); filter: brightness(1.05); }

.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.stepper button {
  appearance: none; border: none; background: none; color: var(--text);
  width: 40px; height: 40px; font-size: 22px; cursor: pointer;
  display: grid; place-items: center;
}
.stepper button:active { background: var(--surface-3); }
.stepper .val { min-width: 34px; text-align: center; font-weight: 800; font-size: 18px; }

/* ---------- Service log ---------- */
.log-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.log-row:last-child { border-bottom: none; }
.log-badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 4px 9px; border-radius: 999px; flex: 0 0 auto;
}
.badge-dip { background: rgba(20,184,166,0.18); color: #5eead4; }
.badge-drip { background: rgba(96,165,250,0.18); color: #93c5fd; }
.log-row .when { flex: 1; font-size: 14px; }
.log-row .rel { color: var(--muted); font-size: 12px; }
.log-row .del { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px; }

/* ---------- Buttons / forms ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 14px;
  padding: 13px 16px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  transition: transform var(--tap), background var(--tap);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn-ghost { background: none; }
.btn-danger { color: var(--red); border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.08); }
.btn-row { display: flex; gap: 10px; }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty .big { font-size: 46px; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin: 0 0 6px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(20px + var(--safe-bottom));
  width: 58px; height: 58px;
  border-radius: 20px;
  background: var(--brand);
  color: var(--brand-ink);
  border: none;
  font-size: 30px;
  font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 12px 26px rgba(20,184,166,0.4);
  cursor: pointer;
  z-index: 30;
  transition: transform var(--tap);
}
.fab:active { transform: scale(0.9); }

/* ---------- Modal / sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(5, 10, 20, 0.6);
  backdrop-filter: blur(4px);
  z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 640px;
  padding: 8px 18px calc(24px + var(--safe-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,0.5);
  animation: slideup 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 90dvh;
  overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet .grabber { width: 40px; height: 4px; border-radius: 999px; background: var(--border); margin: 8px auto 14px; }
.sheet h2 { margin: 0 0 16px; font-size: 20px; font-weight: 800; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px; /* >=16px prevents iOS zoom */
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
}
.field .help { font-size: 12px; color: var(--muted); margin-top: 5px; }
.pass-hint { font-weight: 600; }
.pass-hint.weak { color: var(--red); }
.pass-hint.ok { color: var(--yellow); }
.pass-hint.strong { color: var(--ok); }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-picker button {
  width: 46px; height: 46px; border-radius: 12px; font-size: 24px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer;
}
.emoji-picker button.sel { border-color: var(--brand); background: rgba(20,184,166,0.15); }

/* ---------- Sync status pill ---------- */
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface);
}
.sync-pill .d { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sync-pill.on .d { background: var(--ok); }
.sync-pill.err .d { background: var(--red); }
.sync-pill.busy .d { background: var(--yellow); animation: blink 0.9s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

hr.div { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
