/* Driver Assistant: dark-first, big targets, one-handed cab use */
:root {
  --bg: #0e1524;
  --card: #1a2436;
  --card2: #212e46;
  --line: #2c3a57;
  --text: #eef2f9;
  --dim: #9fb0cc;
  --accent: #4da3ff;
  --accent-ink: #06111f;
  --good: #43d17c;
  --bad: #ff6b6b;
  --warn: #ffc861;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5fa;
    --card: #ffffff;
    --card2: #eef2f8;
    --line: #d9e0ec;
    --text: #16213a;
    --dim: #5b6b86;
    --accent: #1461c4;
    --accent-ink: #ffffff;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
.topbtns { display: flex; gap: 8px; align-items: center; }
.linepill {
  border: 1px solid var(--accent); color: var(--accent); background: none;
  font-size: 12px; font-weight: 700; letter-spacing: 0.3px;
  border-radius: 14px; padding: 8px 12px; min-height: 32px; line-height: 1;
  white-space: nowrap;
}
.iconbtn {
  background: none; border: 1px solid var(--line); color: var(--dim);
  font-size: 18px; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- search overlay ---------- */
.searchwrap {
  position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 35; background: var(--bg);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.searchwrap.hidden { display: none; }
.searchbar {
  display: flex; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.searchbar input {
  flex: 1; min-width: 0;
  background: var(--card2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-size: 17px; padding: 12px 14px; min-height: 48px;
  -webkit-appearance: none; appearance: none;
}
.searchbar .btn { flex: 0 0 auto; padding: 0 16px; }
.searchres {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 14px calc(24px + env(safe-area-inset-bottom));
}
.searchres .grouphead { margin-top: 16px; }

/* ---------- layout ---------- */
main { padding: 12px 14px calc(96px + env(safe-area-inset-bottom)); }
.grouphead {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim); margin: 22px 2px 10px;
}
.grouphead:first-child { margin-top: 6px; }
.parked {
  font-size: 12px; font-weight: 600; color: var(--dim);
  margin: 2px 2px 0; padding: 0 2px;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 { font-size: 16.5px; font-weight: 700; margin-bottom: 4px; }
.hint { font-size: 13px; color: var(--dim); margin-bottom: 10px; }
.preview {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 17px;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 10px 0 12px;
  min-height: 44px;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card2); color: var(--text);
  font-size: 16px; font-weight: 600;
  padding: 14px 18px; min-height: 50px;
}
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  font-weight: 700; width: 100%;
}
.btn.copied { background: var(--good); border-color: var(--good); color: #04120a; }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row .btn { flex: 1; }

/* ---------- switch (iOS style) ---------- */
.switchrow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0 10px;
}
.switchrow span { font-size: 15px; font-weight: 600; }
input.switch {
  appearance: none; -webkit-appearance: none;
  width: 54px; height: 32px; border-radius: 16px;
  background: var(--line); position: relative; flex: 0 0 auto;
  transition: background 0.15s;
}
input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 28px; height: 28px; border-radius: 50%; background: #fff;
  transition: left 0.15s;
}
input.switch:checked { background: var(--good); }
input.switch:checked::after { left: 24px; }

/* ---------- text inputs / steppers ---------- */
.fieldrow { display: flex; gap: 8px; margin-bottom: 10px; }
.fieldrow label {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--dim);
}
.fieldrow input {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 16px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.fieldrow select.field {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 16px; padding: 10px 12px; min-height: 44px; width: 100%;
  -webkit-appearance: none; appearance: none;
}
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button {
  width: 48px; height: 44px; font-size: 22px; font-weight: 700;
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
}
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper output {
  min-width: 64px; text-align: center; font-size: 17px; font-weight: 700;
  background: var(--bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  height: 44px; line-height: 44px;
}

/* ---------- gate (5-star) ---------- */
.gate {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 14.5px;
}
.gate input { width: 24px; height: 24px; accent-color: var(--good); flex: 0 0 auto; margin-top: 1px; }
.denied {
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.45);
  border-radius: 10px; padding: 10px 12px;
  font-size: 14px; color: var(--bad); margin-bottom: 12px;
}

/* ---------- chips (filters, sticky under the top bar) ---------- */
.chips {
  position: sticky; top: calc(env(safe-area-inset-top) + 57px);
  z-index: 15; background: var(--bg);
  display: flex; gap: 8px; overflow-x: auto;
  margin: 0 -14px 12px; padding: 6px 14px 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--dim);
  font-size: 13.5px; font-weight: 600; padding: 8px 14px; min-height: 38px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- produce cards ---------- */
.pcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.pcard h3 { font-size: 16px; margin-bottom: 2px; }
.askbadge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--warn); border: 1px solid rgba(255, 200, 97, 0.5);
  border-radius: 8px; padding: 2px 8px; margin: 2px 0 8px;
}
.pline { font-size: 14px; margin-bottom: 6px; }
.pline b {
  display: inline-block; min-width: 74px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.5px; margin-right: 2px;
}
.pline.look b { color: var(--good); }
.pline.avoid b { color: var(--bad); }
.pline.today b { color: var(--accent); }
.pline.week b { color: var(--accent); }
.pline.def b { color: var(--dim); }
.askbtn { width: 100%; margin-top: 8px; padding: 10px 14px; min-height: 44px; font-size: 15px; }
.mistakes { padding-left: 20px; font-size: 14px; }
.mistakes li { margin-bottom: 8px; }

/* ---------- never send ---------- */
.nevercard {
  background: var(--card); border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
}
.nevercard h3 { font-size: 15.5px; color: var(--bad); margin-bottom: 4px; }
.nevercard p { font-size: 14px; color: var(--dim); }

/* ---------- habits ---------- */
.habit {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
}
.habit input { width: 26px; height: 26px; accent-color: var(--good); flex: 0 0 auto; margin-top: 1px; }
.habit .htext { font-size: 15px; }
.habit .htext b { display: block; font-size: 15.5px; }
.habit .htext span { color: var(--dim); font-size: 13.5px; }
.habit.done .htext { opacity: 0.45; text-decoration: line-through; }
.resetrow { margin-top: 16px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 20;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; appearance: none; background: none; border: none;
  color: var(--dim); font-size: 11px; font-weight: 600;
  padding: 8px 0 10px; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button .ti { font-size: 20px; line-height: 1; }
.tabbar button.on { color: var(--accent); }

/* ---------- settings overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay.hidden { display: none; }
.sheet {
  width: 100%; max-width: 560px;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}
.sheet h2 { font-size: 17px; margin-bottom: 4px; }
.small { font-size: 13px; margin-bottom: 12px; }
.dim { color: var(--dim); }
.setfield {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 700; color: var(--dim);
  margin-bottom: 12px;
}
.setfield input {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 16px; padding: 12px; min-height: 48px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(78px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--good); color: #04120a;
  font-size: 14px; font-weight: 700;
  padding: 10px 18px; border-radius: 20px; z-index: 40;
  transition: opacity 0.2s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
