:root {
  --ink: #0F2A30;
  --ink2: #48646B;
  --paper: #EAEFEF;
  --panel: #FFFFFF;
  --line: #D2DBDC;
  --rail: #0B2A2F;
  --rail-ink: #C9DCDD;
  --rail-line: #3C6A70;
  --signal: #F2B705;
  --live: #1B9A66;
  --stale: #B9820A;
  --off: #8B999C;
  --bad: #C0402B;
  --blue: #1F5FA8;
  --font: "Hind Siliguri", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.2; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
code { font: 600 .92em ui-monospace, Consolas, monospace; background: #E0E9E9; padding: 1px 6px; border-radius: 4px; }
.block { display: block; }
.strong { font-weight: 600; color: var(--ink); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--rail); }
.login form { width: 100%; max-width: 360px; background: var(--panel); border-radius: 10px; padding: 28px; }
.login .brand { color: var(--ink); margin-bottom: 22px; }
.login .brand small { color: var(--ink2); }
.wide { width: 100%; padding: 11px 16px; }

/* ---------- shell: the nav is drawn as a transit line ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100dvh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 24px 20px 20px 26px; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; line-height: 1.1; color: #fff; }
.brand small { display: block; font-weight: 500; font-size: 13px; color: var(--rail-ink); }
.line { list-style: none; margin: 0; padding: 0; position: relative; }
.line::before { content: ""; position: absolute; left: 7px; top: 22px; bottom: 22px; width: 3px; background: var(--rail-line); }
.line a { position: relative; display: block; padding: 11px 0 11px 34px; color: var(--rail-ink); text-decoration: none; font-weight: 500; }
.line a::before { content: ""; position: absolute; left: 0; top: 50%; width: 17px; height: 17px; margin-top: -8.5px; border-radius: 50%; background: var(--rail); border: 3px solid var(--rail-ink); }
.line a:hover { color: #fff; }
.line a[aria-current="page"] { color: #fff; font-weight: 700; }
.line a[aria-current="page"]::before { background: var(--signal); border-color: var(--signal); box-shadow: 0 0 0 4px rgba(242, 183, 5, .25); }
.rail-foot { margin-top: auto; font-size: 13.5px; }
.rail-foot .who { display: block; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.linkbtn { background: none; border: 0; padding: 0; color: #fff; text-decoration: underline; }
.mobbar { display: none; }

.main { padding: 24px 28px 40px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { font-size: 26px; font-weight: 700; }
.head p { color: var(--ink2); margin-top: 2px; }

/* ---------- lists ---------- */
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: left; }
.row:last-child { border-bottom: 0; }
button.row:hover { background: #F3F7F7; }
.row.sel { background: #FFF6D6; }
.grow { flex: 1; min-width: 0; }
.sub { color: var(--ink2); font-size: 13.5px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns.tight { margin-top: 6px; gap: 6px; }
.time { font-size: 20px; font-weight: 700; min-width: 64px; font-variant-numeric: tabular-nums; }
.num { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.empty { padding: 36px 20px; text-align: center; color: var(--ink2); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty.small { padding: 20px; }
.pad { padding: 14px 2px 0; }
.hint { font-size: 13px; color: var(--ink2); }

.btn { background: var(--ink); color: #fff; border: 1px solid var(--ink); border-radius: 6px; padding: 9px 16px; font-weight: 600; text-decoration: none; display: inline-block; }
.btn:hover { background: #1C4650; }
.btn.ghost { background: transparent; color: var(--ink); border-color: #9DB0B3; }
.btn.ghost:hover { background: #DDE6E7; }
.btn.danger { background: transparent; color: var(--bad); border-color: #DDA79D; }
.btn.danger:hover { background: #FBECE9; }
.btn.sm { padding: 4px 11px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip::before, .dot { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot { display: inline-block; }
.chip.on::before, .dot.live { background: var(--live); }
.dot.stale { background: var(--stale); }
.dot.off, .dot.none { background: var(--off); }

.days { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.d { font-size: 12px; font-weight: 600; padding: 0 7px; border-radius: 4px; background: #E3EAEB; color: #8A9A9D; }
.d.on { background: var(--ink); color: #fff; }

/* ---------- forms and dialog ---------- */
.field { display: block; margin-bottom: 14px; border: 0; padding: 0; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; }
.field small { display: block; margin-top: 4px; }
input, select { width: 100%; padding: 9px 11px; border: 1px solid #9DB0B3; border-radius: 6px; font: inherit; background: #fff; color: var(--ink); }
input[type="checkbox"] { width: auto; }
dialog { border: 0; border-radius: 10px; padding: 0; width: min(440px, calc(100vw - 24px)); color: var(--ink); box-shadow: 0 20px 60px rgba(8, 30, 35, .35); }
dialog::backdrop { background: rgba(8, 30, 35, .55); }
.dlg-body { padding: 24px; }
.dlg-body h2 { font-size: 20px; margin-bottom: 14px; }
.dlg-body p { margin-bottom: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.err { color: var(--bad); font-weight: 600; margin: 0 0 8px; }
.steps { margin: 0 0 10px; padding-left: 20px; }
.cred { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; margin: 14px 0; padding: 14px; background: #F1F6F6; border-radius: 8px; }
.cred dt { color: var(--ink2); }
.cred dd { margin: 0; }
.big { font-size: 26px; letter-spacing: .12em; }
fieldset.days-pick { border: 0; padding: 0; margin: 0 0 6px; }
fieldset.days-pick legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.daypick { display: inline-block; margin: 0 6px 6px 0; }
.daypick input { position: absolute; opacity: 0; }
.daypick span { display: inline-block; padding: 5px 11px; border: 1px solid #9DB0B3; border-radius: 6px; font-weight: 600; cursor: pointer; }
.daypick input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.daypick input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------- maps ---------- */
.map { width: 100%; height: 100%; min-height: 320px; border-radius: 8px; }
.livewrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; height: calc(100dvh - 128px); min-height: 440px; }
.mapbox { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.maptools { position: absolute; top: 10px; right: 10px; z-index: 500; display: flex; gap: 12px; align-items: center; background: #fff; padding: 6px 10px; border-radius: 6px; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.maptools label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.side { display: flex; flex-direction: column; gap: 14px; overflow: auto; min-height: 0; }
.summary { font-weight: 600; }
.tools { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.tools h3 { font-size: 16px; margin-bottom: 4px; }
.tools .btn { margin: 8px 0 12px; }
.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.split .map { height: calc(100dvh - 190px); min-height: 380px; }
.split .sheet { max-height: calc(100dvh - 190px); overflow: auto; }

.basesw { display: flex; overflow: hidden; }
.basesw button { border: 0; border-right: 1px solid var(--line); background: #fff; padding: 6px 12px; font: 600 13px var(--font); color: var(--ink); }
.basesw button:last-child { border-right: 0; }
.basesw button:hover { background: #F3F7F7; }
.basesw button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.basesw button:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }

.pin-wrap { background: none; border: 0; }
.bus-pin { min-width: 40px; height: 26px; padding: 0 8px; border-radius: 7px; background: var(--signal); border: 2px solid var(--ink); color: var(--ink); font: 700 12px/22px var(--font); text-align: center; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
.bus-pin.stale { background: #F6E2A0; border-style: dashed; }
.bus-pin.off, .bus-pin.none { background: #C9D2D4; color: #4A5B5F; border-color: #6E8084; }
.stop-pin { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 3px solid var(--blue); color: var(--ink); font: 700 12px/20px var(--font); text-align: center; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }

.stop-pin.sel { background: var(--signal); border-color: var(--ink); }
.listbar { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.stopedit { padding: 16px; }
.stopedit h2 { font-size: 18px; margin-bottom: 12px; }
.stopedit .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stopedit .hint { margin-bottom: 8px; }
.stopedit .dlg-actions { margin-top: 14px; }

/* ---------- brand mark and toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 3000; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

@media (max-width: 1000px) {
  .livewrap { grid-template-columns: 1fr; height: auto; }
  .mapbox { height: 52dvh; }
  .side { overflow: visible; }
  .split { grid-template-columns: 1fr; }
  .split .map { height: 50dvh; }
  .split .sheet { max-height: none; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .rail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 1000; gap: 0; }
  .rail .brand, .rail-foot { display: none; }
  .line { display: flex; width: 100%; }
  .line li { flex: 1; }
  .line::before { left: 10%; right: 10%; top: 13px; bottom: auto; width: auto; height: 3px; }
  .line a { padding: 28px 0 4px; text-align: center; font-size: 12.5px; }
  .line a::before { left: 50%; top: 6px; margin: 0 0 0 -8.5px; }
  .mobbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--rail); color: #fff; padding-top: calc(10px + env(safe-area-inset-top)); }
  .main { padding: 18px 16px 32px; }
  .head h1 { font-size: 22px; }
  .row { flex-wrap: wrap; }
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- schedule direction ---------- */
fieldset.dir-pick { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.dir-pick legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.dir-opts { display: flex; gap: 8px; flex-wrap: wrap; }
.dirpick { display: inline-block; }
.dirpick input { position: absolute; opacity: 0; }
.dirpick span { display: inline-block; padding: 8px 16px; border: 1px solid #9DB0B3; border-radius: 6px; font-weight: 600; cursor: pointer; }
.dirpick input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.dirpick input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
fieldset.dir-pick .hint { display: block; margin-top: 6px; }
.dirtag { display: inline-block; font-size: 12px; font-weight: 600; padding: 0 7px; border-radius: 4px; background: var(--ink); color: #fff; margin-right: 4px; }
.dirtag.backward { background: #8A6D00; }


/* ---------- guest mode (logged out: live map only) ---------- */
.guest { min-height: 100dvh; }
.gbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--rail); padding: 10px 24px; padding-top: calc(10px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 1100; }
.gbar .btns { display: flex; align-items: center; gap: 8px; }
.gbar .btn.ghost { color: #fff; border-color: var(--rail-line); background: transparent; }
.guest .livewrap { height: calc(100dvh - 190px); }
.login .back { margin-top: 10px; }
@media (max-width: 1000px) {
  .guest .livewrap { height: auto; }
}
@media (max-width: 760px) {
  .gbar { padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); }
  #toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}
