:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #18211c;
  --muted: #5d6b63;
  --line: #e1e6e2;
  --brand: #146c43;
  --brand-ink: #ffffff;
  --brand-soft: #e5f3eb;
  --cyc: #1864ab;
  --cyc2: #4c9be8;
  --cyc3: #74b4f0;
  --walk: #9c36b5;
  --walk2: #cc5de8;
  --alt: #d9480f;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --ok: #146c43;
  --danger: #c92a2a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613; --panel: #1a211d; --ink: #e8ede9; --muted: #9aa8a0; --line: #2c3530;
    --brand: #3fb07a; --brand-ink: #08130d; --brand-soft: #1d3327; --cyc: #4dabf7; --cyc2: #74c0fc; --cyc3: #a5d8ff;
    --walk: #da77f2; --walk2: #e599f7; --alt: #ff8a4c; --warn: #ffc56b; --warn-bg: #3a2c12; --ok: #3fb07a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111613; --panel: #1a211d; --ink: #e8ede9; --muted: #9aa8a0; --line: #2c3530;
  --brand: #3fb07a; --brand-ink: #08130d; --brand-soft: #1d3327; --cyc: #4dabf7; --cyc2: #74c0fc; --cyc3: #a5d8ff;
  --walk: #da77f2; --walk2: #e599f7; --alt: #ff8a4c; --warn: #ffc56b; --warn-bg: #3a2c12; --ok: #3fb07a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 400px 1fr; height: 100dvh; }
.side { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; z-index: 2; }
#map { height: 100%; width: 100%; background: #dfe5e1; }
.brandbar { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.brandbar .kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); }
.brandbar h1 { margin: 2px 0 2px; font-size: 20px; line-height: 1.2; letter-spacing: -.01em; }
.brandbar p { margin: 0; color: var(--muted); font-size: 13px; }
.controls { padding: 12px 18px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input:not([type]), input[type=text], input[type=search], input[type=password], input[type=number], input[type=url], textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
textarea { min-height: 70px; resize: vertical; }
select:focus, input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 13px; user-select: none; }
.chip input { margin: 0; accent-color: var(--brand); }
.chip .sw { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 10px; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 6px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--brand); }
.scroll { overflow: auto; flex: 1; min-height: 0; }
.foot { padding: 10px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.foot strong { color: var(--ink); }

/* ---------- route list ---------- */
.group-h { position: sticky; top: 0; background: var(--panel); padding: 10px 18px 6px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); z-index: 1; }
.ritem { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line);
  cursor: pointer; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.ritem:hover { background: var(--bg); }
.code { min-width: 38px; height: 26px; padding: 0 6px; border-radius: 6px; display: inline-grid; place-items: center;
  font-weight: 800; font-size: 12px; color: #fff; background: var(--cyc); letter-spacing: .02em; }
.code.walking { background: var(--walk); }
.code.secondary { background: var(--cyc2); }
.code.walking.secondary { background: var(--walk2); }
.code.link, .code.longlist { background: transparent; color: var(--cyc); box-shadow: inset 0 0 0 2px var(--cyc); }
.code.walking.link { color: var(--walk); box-shadow: inset 0 0 0 2px var(--walk); }
.code.alt { background: var(--alt); }
.rname { font-weight: 600; line-height: 1.3; }
.rmeta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.tag.unmapped { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag.ok { background: var(--brand-soft); color: var(--ok); border-color: transparent; }
.empty { padding: 30px 18px; color: var(--muted); text-align: center; }

/* ---------- detail ---------- */
.detail { padding: 14px 18px 24px; }
.back { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font-weight: 600; margin-bottom: 10px; }
.detail h2 { margin: 6px 0 4px; font-size: 19px; line-height: 1.25; }
.detail dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 14px 0; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail .block { margin: 12px 0; }
.detail .block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 4px; }
.detail .block p { margin: 0; white-space: pre-line; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 13px; margin: 10px 0; }
.note.info { background: var(--brand-soft); color: var(--ok); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* docs / about */
.doc { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.doc .t { font-weight: 600; }
.doc .m { font-size: 12.5px; color: var(--muted); }
.prose { padding: 14px 18px; }
.prose h3 { margin: 16px 0 6px; font-size: 15px; }
.prose p, .prose li { color: var(--ink); }
.prose .muted { color: var(--muted); }

/* legend + map ui */
.legend { background: var(--panel); color: var(--ink); padding: 10px 12px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 12.5px; line-height: 1.7; }
.legend .ln { display: inline-block; width: 26px; height: 0; border-top: 4px solid var(--cyc); vertical-align: middle; margin-right: 6px; }
.legend .zn { display: inline-block; width: 18px; height: 12px; background: color-mix(in srgb, var(--walk) 20%, transparent); border: 2px solid var(--walk); vertical-align: middle; margin-right: 10px; margin-left: 4px; border-radius: 3px; }
.leaflet-popup-content { font: 13.5px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.leaflet-popup-content h4 { margin: 0 0 4px; font-size: 14px; }
.leaflet-popup-content .pop-desc { white-space: pre-line; max-height: 180px; overflow: auto; }
.leaflet-container a.btn { color: var(--ink); }
.mobile-toggle { display: none; }
.legend.compact { font-size: 11px; line-height: 1.5; padding: 6px 8px; }
.legend.compact .ln { width: 18px; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .side { position: fixed; left: 0; right: 0; bottom: 0; height: 52dvh; z-index: 1100; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.15); transition: height .2s ease; }
  .side.collapsed { height: 116px; overflow: hidden; }
  .side { overflow-y: auto; overscroll-behavior: contain; }
  .side .scroll { flex: none; overflow: visible; min-height: 40vh; }
  .side .tabs { position: sticky; top: 0; background: var(--panel); z-index: 3; }
  .group-h { top: 43px; }
  .brandbar { padding: 8px 16px 8px; }
  .brandbar p { display: none; }
  .brandbar h1 { font-size: 17px; }
  .controls { padding: 10px 16px; }
  .mobile-toggle { display: block; margin: 6px auto 0; width: 44px; height: 5px; border-radius: 3px; background: var(--line); border: 0; cursor: pointer; }
  #map { height: 100dvh; }
  .ritem, .doc, .detail, .group-h, .prose, .foot { padding-left: 16px; padding-right: 16px; }
}

/* ---------- admin ---------- */
.admin { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .title { font-weight: 800; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav button { background: none; border: 0; padding: 7px 11px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.topbar nav button[aria-selected=true] { background: var(--brand-soft); color: var(--ink); }
.topbar .spacer { flex: 1; }
.view { overflow: auto; padding: 18px; }
.view.split { display: grid; grid-template-columns: minmax(340px, 460px) 1fr; gap: 0; padding: 0; overflow: hidden; }
.view.split > .pane { overflow: auto; padding: 16px 18px; border-right: 1px solid var(--line); background: var(--panel); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; max-width: 980px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.card h3 { margin: 14px 0 6px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.f > * { color: var(--ink); font-weight: 400; }
label.cb { display: flex; gap: 8px; align-items: center; font-size: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; background: var(--panel); }
tr.sel td { background: var(--brand-soft); }
tbody tr { cursor: pointer; }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); z-index: 9999; max-width: 420px; }
.toast.err { background: var(--danger); color: #fff; }
.login { max-width: 400px; margin: 10vh auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 4px; }
.editor-map { height: 100%; min-height: 400px; }
.maptools { position: absolute; z-index: 500; top: 10px; left: 56px; display: flex; gap: 6px; flex-wrap: wrap; }
.maptools .btn { box-shadow: var(--shadow); }
.rel { position: relative; height: 100%; }
@media (max-width: 900px) {
  .view.split { grid-template-columns: 1fr; grid-template-rows: auto 60vh; overflow: auto; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
