:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --card2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --zak: #38bdf8;   /* zakelijk - blauw */
  --pri: #a78bfa;   /* privé - paars */
  --ww: #34d399;    /* woon-werk - groen */
  --danger: #f87171;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(72px + var(--safe-b));
  overscroll-behavior-y: contain;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px calc(14px + env(safe-area-inset-top, 0px));
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, var(--bg), rgba(15,23,42,.85));
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -.3px; }
.logo { margin-right: 4px; }
.icon-btn { background: none; border: none; font-size: 22px; cursor: pointer; }

main { padding: 8px 16px 24px; max-width: 640px; margin: 0 auto; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card-title { font-weight: 700; margin-bottom: 12px; font-size: 15px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.section-label { margin-top: 4px; }
.opt { color: var(--muted); font-weight: 400; }
.row { margin-bottom: 14px; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type=date], input[type=number], input[type=text] {
  width: 100%; padding: 14px; font-size: 17px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input:focus { border-color: var(--accent); }

.distance {
  text-align: center; font-size: 30px; font-weight: 800;
  margin: 6px 0 16px; color: var(--accent); letter-spacing: -1px;
}

.typebtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.typebtn {
  padding: 14px 6px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all .12s;
}
.typebtn.active[data-type=zakelijk]  { border-color: var(--zak); color: var(--zak); background: rgba(56,189,248,.12); }
.typebtn.active[data-type=prive]     { border-color: var(--pri); color: var(--pri); background: rgba(167,139,250,.12); }
.typebtn.active[data-type=woon-werk] { border-color: var(--ww);  color: var(--ww);  background: rgba(52,211,153,.12); }

button.primary {
  width: 100%; padding: 16px; font-size: 17px; font-weight: 700;
  background: var(--accent); color: #06283a; border: none; border-radius: 14px; cursor: pointer;
}
button.primary:active { transform: scale(.99); }
button.ghost {
  width: 100%; padding: 14px; font-size: 15px; font-weight: 600; margin-top: 10px;
  background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 14px; cursor: pointer;
}
.hidden { display: none !important; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0 0; min-height: 16px; }
.hint.err { color: var(--danger); }

/* ritten lijst */
.trips { display: flex; flex-direction: column; gap: 10px; }
.month-head { color: var(--muted); font-size: 13px; font-weight: 700; margin: 12px 4px 2px; text-transform: capitalize; }
.trip {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.trip .ticon { font-size: 22px; }
.trip .tmain { flex: 1; min-width: 0; }
.trip .tdist { font-weight: 700; font-size: 16px; }
.trip .tmeta { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip .ttype { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.ttype.zakelijk { color: var(--zak); background: rgba(56,189,248,.14); }
.ttype.prive { color: var(--pri); background: rgba(167,139,250,.14); }
.ttype.woonwerk { color: var(--ww); background: rgba(52,211,153,.14); }
.trip .tact { display: flex; gap: 4px; }
.trip .tact button { background: none; border: none; font-size: 16px; cursor: pointer; padding: 6px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* stats */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg-btn { flex: 1; padding: 10px; border: none; background: none; color: var(--muted); font-weight: 700; font-size: 13px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #06283a; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; text-align: center; }
.stat.big { grid-column: 1 / -1; }
.stat-val { font-size: 30px; font-weight: 800; letter-spacing: -1px; }
.stat.big .stat-val { font-size: 40px; }
.stat-val.zak { color: var(--zak); } .stat-val.pri { color: var(--pri); } .stat-val.ww { color: var(--ww); }
.stat-lbl { color: var(--muted); font-size: 12px; margin-top: 4px; font-weight: 600; }

.vergoeding { display: flex; align-items: center; justify-content: space-between; }
.verg-lbl { font-weight: 700; }
.verg-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.verg-amount { font-size: 26px; font-weight: 800; color: var(--ww); }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; margin: 6px 0 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-stack { width: 100%; max-width: 26px; display: flex; flex-direction: column-reverse; border-radius: 5px; overflow: hidden; }
.bar-seg { width: 100%; }
.bar-seg.zak { background: var(--zak); } .bar-seg.pri { background: var(--pri); } .bar-seg.ww { background: var(--ww); }
.bar-label { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.dot.zak { background: var(--zak); } .dot.pri { background: var(--pri); } .dot.ww { background: var(--ww); }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: rgba(15,23,42,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; padding: 10px 0 12px; background: none; border: none; color: var(--muted);
  font-size: 11px; font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab span { font-size: 22px; }
.tab.active { color: var(--accent); }

/* dialog + toast */
dialog { border: none; border-radius: 20px; padding: 0; background: transparent; color: var(--text); max-width: 90vw; width: 360px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions button { flex: 1; margin-top: 0; }
.dialog-actions .primary { color: #06283a; }

/* auth */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #0ea5e9, #0f172a 60%);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-overlay.hidden { display: none; }
.auth-box { width: 100%; max-width: 340px; text-align: center; }
.auth-logo { font-size: 56px; }
.auth-box h2 { margin: 8px 0 6px; font-size: 26px; }
.auth-sub { color: #cbd5e1; margin: 0 0 22px; font-size: 15px; line-height: 1.4; }
#auth-form input { margin-bottom: 12px; }
#auth-form .hint { color: #fecaca; }
.divider { border: none; border-top: 1px solid var(--line); margin: 16px 0 12px; }
.logout { color: var(--danger); border-color: rgba(248,113,113,.4); }
#pw-dialog .hint { text-align: left; }

.toast {
  position: fixed; bottom: calc(84px + var(--safe-b)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: #0b1220; border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
