:root {
  --ink: #0f172a;
  --ink-2: #1e293b;
  --ink-3: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #ffffff;
  --bg-2: #f8fafc;
  --bg-3: #f1f5f9;
  --accent: #10b981;
  --accent-ink: #052e1f;
  --warn: #f59e0b;
  --danger: #e11d48;
  --ok: #059669;
  --radius: 16px;
  --shadow: 0 10px 26px -6px rgba(15, 23, 42, .25), 0 3px 8px -2px rgba(15, 23, 42, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sheet-peek: 210px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overflow: clip; background: var(--ink); -webkit-tap-highlight-color: transparent; }
body { position: fixed; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }
[hidden] { display: none !important; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

#map { position: fixed; inset: 0; z-index: 1; background: #e5e7eb; }
.leaflet-control-attribution { font-size: 9px !important; }
/* Calmer basemap so markers stand out (OSM default colours are busy). */
.leaflet-tile-pane { filter: saturate(.55) brightness(1.04) contrast(.95); }

/* ---------- Top bar ---------- */
.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; padding: max(10px, var(--safe-top)) 12px 0; pointer-events: none; display: flex; flex-direction: column; gap: 8px; max-width: 640px; margin: 0 auto; }
.topbar > * { pointer-events: auto; }
.bar { background: rgba(15, 23, 42, .96); color: #fff; border-radius: var(--radius); padding: 8px 8px 8px 12px; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.bar-actions { display: flex; gap: 6px; }
.pill-btn { height: 36px; padding: 0 10px; border-radius: 12px; background: var(--ink-2); border: 1px solid var(--ink-3); font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 6px; color: #fff; }
.pill-btn b { font-weight: 700; color: #94a3b8; }
.pill-btn b.on { color: #fff; }
.pill-btn span { color: #475569; }
.pill-btn.accent { background: rgba(16, 185, 129, .16); border-color: rgba(52, 211, 153, .4); color: #6ee7b7; }
.pill-btn.accent span { color: inherit; }

.layers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: rgba(255, 255, 255, .96); padding: 4px; border-radius: var(--radius); box-shadow: var(--shadow); }
.layer-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px; border-radius: 12px; font-size: 13px; font-weight: 700; color: var(--ink-3); }
.layer-btn.active { background: var(--ink); color: #fff; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, .96); border: 1px solid var(--line); font-size: 12px; font-weight: 700; box-shadow: 0 2px 6px rgba(15, 23, 42, .08); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip .n { font-size: 11px; color: var(--muted); }
.chip.off { opacity: .5; text-decoration: line-through; }

.banner { background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; font-size: 12px; padding: 8px 12px; border-radius: 12px; box-shadow: var(--shadow); }

/* ---------- FABs ---------- */
.fabs { position: fixed; left: 12px; right: 12px; z-index: 15; bottom: calc(var(--sheet-peek) + 12px + var(--safe-bottom)); display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; max-width: 616px; margin: 0 auto; transition: bottom .3s ease; }
.fabs > * { pointer-events: auto; }
.fab-report { height: 44px; padding: 0 16px 0 10px; border-radius: 16px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); }
.warn-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--warn); color: var(--ink); display: grid; place-items: center; font-weight: 700; }
.fab-round { width: 44px; height: 44px; border-radius: 16px; background: #fff; display: grid; place-items: center; box-shadow: var(--shadow); color: var(--ink); }
.fab-round.active { color: #2563eb; }

/* ---------- Sheet ---------- */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-width: 640px; margin: 0 auto; background: var(--bg); border-radius: 24px 24px 0 0; box-shadow: 0 -12px 36px -6px rgba(15, 23, 42, .25); display: flex; flex-direction: column; height: calc(var(--sheet-peek) + var(--safe-bottom)); transition: height .3s cubic-bezier(.22, 1, .36, 1); }
.sheet.half { height: 55vh; }
.sheet.full { height: 85vh; }
.sheet-head { padding: 8px 16px 6px; touch-action: none; }
.grip { width: 40px; height: 5px; background: #cbd5e1; border-radius: 99px; margin: 0 auto 8px; }
.sheet-title-row { display: flex; align-items: center; gap: 8px; }
.sheet-title-row h2 { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow { flex: 1; }
.count { background: var(--bg-3); color: var(--muted); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.count:empty { display: none; }
.sheet-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); min-height: 0; }
.sheet-sub:empty { display: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 12px; background: var(--bg-3); display: grid; place-items: center; color: var(--ink-3); flex-shrink: 0; }
.icon-btn.dark { background: var(--ink-2); color: #cbd5e1; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 10px calc(12px + var(--safe-bottom)); overscroll-behavior: contain; }

.row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 14px; text-align: left; }
.row:hover, .row:focus-visible { background: var(--bg-2); }
.row + .row { border-top: 1px solid var(--bg-3); }
.row .stripe { width: 5px; align-self: stretch; border-radius: 9px; flex-shrink: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t1 { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { text-align: right; flex-shrink: 0; }
.row .side b { display: block; font-size: 14px; }
.row .side small { font-size: 11px; color: var(--muted); }
.op-name { font-size: 12px; font-weight: 600; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); font-size: 13px; }
.empty b { display: block; color: var(--ink-3); font-size: 14px; margin-bottom: 4px; }

.lines { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.line { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; color: #fff; background: var(--ink-3); min-width: 22px; text-align: center; }
.line.metroA { background: #00a562; } .line.metroB { background: #f8b322; color: var(--ink); } .line.metroC { background: #cf003d; }
.line.tram { background: #7a0603; } .line.bus { background: #007da8; } .line.train { background: #0f4c81; } .line.night { background: #1e1b4b; }
.line.ferry { background: #0891b2; } .line.funicular { background: #6b21a8; } .line.trolleybus { background: #0d9488; }

.dep { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-top: 1px solid var(--bg-3); }
.dep:first-child { border-top: 0; }
.dep .line { font-size: 13px; min-width: 38px; padding: 3px 6px; }
.dep .head { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep .head small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.dep .when { text-align: right; font-size: 15px; font-weight: 700; }
.dep .when small { display: block; font-size: 11px; font-weight: 700; }
.late { color: var(--danger); } .ontime { color: var(--ok); }
.dep.canceled .head, .dep.canceled .when { text-decoration: line-through; opacity: .6; }
.infotext { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; font-size: 12px; padding: 8px 10px; border-radius: 12px; margin: 6px 4px; }
.btn-row { display: flex; gap: 8px; padding: 8px 4px; flex-wrap: wrap; }

.btn { min-height: 44px; padding: 10px 14px; border-radius: 14px; font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; background: var(--bg-3); color: var(--ink); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 12px; border-radius: 12px; }
.btn-row .btn { flex: 1; }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card + .card { margin-top: 8px; }
.tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #fef3c7; color: #92400e; }
.tag.bio { background: #d1fae5; color: #065f46; }
.tag.msd { background: #e0e7ff; color: #3730a3; }
.section-h { font-size: 14px; font-weight: 600; color: var(--ink); margin: 14px 4px 8px; }
.section-h:first-child { margin-top: 4px; }

/* ---------- Detail ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(2, 6, 23, .4); }
.detail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 640px; margin: 0 auto; background: #fff; border-radius: 24px 24px 0 0; padding: 10px 18px calc(18px + var(--safe-bottom)); box-shadow: var(--shadow); }
.detail-top { display: flex; align-items: center; gap: 12px; }
.badge-ic { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.badge-ic .ic { width: 24px; height: 24px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.stat span { font-size: 11px; color: var(--muted); }
.stat b { display: block; font-size: 16px; margin-top: 2px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(2, 6, 23, .6); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: #fff; width: 100%; max-width: 560px; max-height: 94vh; border-radius: 24px 24px 0 0; display: flex; flex-direction: column; overflow: hidden; }
@media (min-width: 640px) { .modal { align-items: center; padding: 16px; } .modal-card { border-radius: 24px; } }
.modal-head { background: var(--ink); color: #fff; padding: 14px 16px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 2px 0 0; font-size: 12px; color: #94a3b8; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: calc(16px + var(--safe-bottom)); }
.box { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.box .label { margin: 0; }
.input { width: 100%; padding: 11px 12px; font: inherit; font-size: 15px; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; color: var(--ink); }
.input:focus { outline: 2px solid var(--ink); outline-offset: 0; }
.input.dark { background: var(--ink-2); border-color: var(--ink-3); color: #fff; }
.input.dark::placeholder { color: #94a3b8; }
.link-btn { color: #0284c7; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tiny { font-size: 11px; color: var(--muted); margin: 0; }
.tiny.light { color: #94a3b8; margin-top: 6px; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cat { text-align: left; padding: 10px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-size: 13px; font-weight: 700; line-height: 1.25; }
.cat.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.route-card { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: var(--radius); padding: 12px; font-size: 13px; }
.route-card b { display: block; font-size: 14px; margin-bottom: 2px; }
.route-card p { margin: 4px 0 0; color: #065f46; }
.preview summary { font-size: 12px; font-weight: 700; color: var(--ink-3); cursor: pointer; }
.preview pre { white-space: pre-wrap; font-size: 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 8px 0 0; }
.actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: 100%; max-width: 440px; background: var(--bg-2); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer-head { background: var(--ink); color: #fff; padding: max(14px, var(--safe-top)) 16px 14px; }
.drawer-head h2 { margin: 0; font-size: 17px; }
.muted-light { margin: 2px 0 0; font-size: 12px; color: #94a3b8; }
.home-form { display: flex; gap: 8px; margin-top: 12px; }
.home-form .btn { flex-shrink: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 14px calc(20px + var(--safe-bottom)); }
.kv { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.kv a { color: #0369a1; font-weight: 600; word-break: break-word; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-decoration: none; display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 13px; }
.tile span { font-size: 11px; color: var(--muted); }

/* ---------- Map markers ---------- */
.stop-mk { width: 26px; height: 26px; border-radius: 8px; background: #fff; border: 2px solid var(--ink); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--ink); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.stop-mk.metroA { border-color: #00a562; color: #00a562; } .stop-mk.metroB { border-color: #e9a210; color: #b57b00; } .stop-mk.metroC { border-color: #cf003d; color: #cf003d; }
.stop-mk.tram { border-color: #7a0603; color: #7a0603; } .stop-mk.bus { border-color: #007da8; color: #007da8; } .stop-mk.train { border-color: #0f4c81; color: #0f4c81; }
.stop-mk.sel { transform: scale(1.25); background: var(--ink); color: #fff; }
.vok-mk { padding: 3px 7px; border-radius: 9px; background: var(--warn); color: var(--ink); font-size: 11px; font-weight: 700; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); border: 2px solid #fff; }
.vok-mk.bio { background: #34d399; }
.yard-mk { width: 28px; height: 28px; border-radius: 9px; background: var(--ink); color: #6ee7b7; display: grid; place-items: center; border: 2px solid #6ee7b7; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(37, 99, 235, .22); }
.home-mk { width: 26px; height: 26px; border-radius: 8px; background: var(--ink); color: #6ee7b7; display: grid; place-items: center; border: 2px solid #6ee7b7; }
.center-cross { position: fixed; z-index: 5; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; pointer-events: none; opacity: .5; }

.toast { position: fixed; z-index: 90; top: calc(max(10px, var(--safe-top)) + 110px); left: 50%; transform: translateX(-50%) translateY(-8px); background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 14px; font-size: 13px; font-weight: 700; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- v2 additions ---------- */
.pill-btn.square { width: 36px; padding: 0; justify-content: center; }
.search { display: flex; gap: 6px; background: rgba(255, 255, 255, .97); padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow); }
.search input { flex: 1; min-width: 0; border: 0; font: inherit; font-size: 15px; padding: 6px 8px; background: transparent; color: var(--ink); }
.search input:focus { outline: none; }

.veh-mk { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .35); }
.veh-mk.car { border-radius: 8px; }
.veh-mk .ic { width: 14px; height: 14px; stroke-width: 2.4; }

.bin-mk { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: #fff; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .35); font-size: 10px; font-weight: 700; }
.bin-mk .ic { width: 13px; height: 13px; stroke-width: 2.4; }
.fill-ok { background: #059669; } .fill-mid { background: #d97706; } .fill-full { background: #e11d48; } .fill-na { background: #64748b; }

.cont { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--bg-3); }
.cont:first-child { border-top: 0; }
.cont .main { flex: 1; min-width: 0; }
.cont .t1 { font-size: 14px; font-weight: 700; }
.cont .t2 { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bar-wrap { width: 72px; flex-shrink: 0; text-align: right; }
.bar-wrap b { font-size: 13px; }
.fillbar { height: 6px; background: var(--bg-3); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.fillbar > i { display: block; height: 100%; border-radius: 99px; }
.swatch { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0, 0, 0, .1); }

.cat-grid { grid-template-columns: repeat(2, 1fr); }
.cat { display: flex; align-items: center; gap: 8px; }
.cat .ic { width: 20px; height: 20px; }
.cat.featured { grid-column: span 1; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); padding: 2px 6px 8px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.chip.cls { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip.cls.off { background: rgba(255, 255, 255, .96); color: var(--ink-3); border-color: var(--line); text-decoration: none; opacity: .75; }
.chip.cls .n { color: #94a3b8; }
.ev { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: #dcfce7; color: #166534; margin-left: 4px; vertical-align: 1px; }
.cls-tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--bg-3); color: var(--ink-3); }
.layer-btn { font-size: 12.5px; padding: 8px 4px; gap: 5px; }
@media (max-width: 460px) { .layer-btn .ic { display: none; } }

@media (max-width: 380px) {
  .layer-btn .ic { display: none; }
  #areaBtnLabel { display: none; }
}

button, input, select, textarea { font-family: inherit; }
