:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #6b7684;
  --accent: #2563eb;
  --its: #db2777;   /* 전주 ITS */
  --db: #2563eb;    /* 라이브버스 DB */
  --sev-high: #d7263d;
  --sev-mid: #e08700;
  --sev-low: #7a869a;
  --ok: #198754;
  --map-its: #d81b73;   /* 전주 ITS — 지도 전용 고정색 */
  --map-db: #1d4ed8;    /* 라이브버스 DB — 지도 전용 고정색 */
  --map-eq: #15803d;
  --map-far: #be123c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20,30,45,.07), 0 2px 8px rgba(20,30,45,.05);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181d; --surface: #1c2027; --surface-2: #21262e; --border: #333a45;
    --text: #e6eaf0; --muted: #98a2b3; --accent: #6ea8fe;
    --its: #f472b6; --db: #6ea8fe;
    --sev-high: #ff6b7f; --sev-mid: #f0b429; --sev-low: #98a2b3; --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 10px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #15181d; --surface: #1c2027; --surface-2: #21262e; --border: #333a45;
  --text: #e6eaf0; --muted: #98a2b3; --accent: #6ea8fe;
  --its: #f472b6; --db: #6ea8fe;
  --sev-high: #ff6b7f; --sev-mid: #f0b429; --sev-low: #98a2b3; --ok: #4ade80;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
        "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow); z-index: 500;
}
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand .arrow { color: var(--muted); font-weight: 400; margin: 0 2px; }
.sub { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.stat { text-align: right; }
.stat b { display: block; font-size: 17px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.high b { color: var(--sev-high); }
.stat.mid b { color: var(--sev-mid); }
.ghost {
  padding: 6px 11px; font: inherit; font-size: 12px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.caveat { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.caveat-inner {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px;
  padding: 14px 16px; max-width: 1400px;
}
.caveat h3 { margin: 0 0 5px; font-size: 12px; text-transform: uppercase;
             letter-spacing: .05em; color: var(--muted); }
.caveat p, .caveat li { margin: 0 0 5px; font-size: 13px; }
.caveat ul { margin: 0 0 10px; padding-left: 18px; }
.caveat ul li { list-style: none; margin-left: -18px; }
.caveat #caveat-list li { list-style: disc; margin-left: 0; color: var(--muted); }

/* ---------------------------------------------------------------- layout */
.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 1fr 300px;
  grid-template-areas: "panel map" "panel detail";
  gap: 1px; background: var(--border);
}
.panel { grid-area: panel; background: var(--surface); display: flex;
         flex-direction: column; min-height: 0; }
.mapwrap { grid-area: map; position: relative; background: var(--surface); }
.detail { grid-area: detail; background: var(--surface); overflow: auto; min-height: 0; }
#map { position: absolute; inset: 0; }

/* ---------------------------------------------------------------- panel */
.tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab {
  flex: 1; padding: 9px 6px; font: inherit; font-size: 12.5px; cursor: pointer;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted);
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabpane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.tabpane[hidden] { display: none; }

.filters { padding: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#q {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 13px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip {
  padding: 3px 9px; font-size: 11.5px; cursor: pointer; user-select: none;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 100px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip .n { opacity: .75; margin-left: 3px; font-variant-numeric: tabular-nums; }

.listcount { padding: 7px 10px; font-size: 11.5px; color: var(--muted);
             border-bottom: 1px solid var(--border); flex-shrink: 0; }
.note { margin: 0; padding: 10px; font-size: 12px; color: var(--muted);
        border-bottom: 1px solid var(--border); flex-shrink: 0; }

.routelist, .typelist { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.routelist li {
  padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: auto 1fr; gap: 2px 9px; align-items: start;
}
.routelist li:hover { background: var(--surface-2); }
.routelist li.sel { background: color-mix(in srgb, var(--accent) 13%, transparent);
                    box-shadow: inset 3px 0 0 var(--accent); }
.rno {
  grid-row: span 2; min-width: 42px; padding: 3px 6px; text-align: center;
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
}
.rno.s-높음 { background: color-mix(in srgb, var(--sev-high) 16%, transparent);
              border-color: var(--sev-high); color: var(--sev-high); }
.rno.s-중간 { background: color-mix(in srgb, var(--sev-mid) 16%, transparent);
              border-color: var(--sev-mid); color: var(--sev-mid); }
.rpath { font-size: 12.5px; line-height: 1.35; word-break: keep-all; }
.rmeta { font-size: 11px; color: var(--muted); display: flex; gap: 7px; flex-wrap: wrap; }
.tag { padding: 0 5px; border-radius: 3px; font-size: 10.5px; font-weight: 600;
       border: 1px solid currentColor; }
.tag.only-its { color: var(--its); }
.tag.only-db { color: var(--db); }
.tag.rescue { color: var(--sev-mid); }
.tag.lowconf { color: var(--sev-low); }
.tag.strong { color: var(--sev-high); }

.typelist li { padding: 9px 11px; border-bottom: 1px solid var(--border);
               display: flex; gap: 10px; align-items: baseline; }
.typelist .tn { font-family: var(--mono); font-size: 11.5px; flex: 1; }
.typelist .tc { font-weight: 700; font-variant-numeric: tabular-nums; }
.typelist .td { width: 100%; font-size: 11.5px; color: var(--muted); }
.typelist li { flex-wrap: wrap; }

/* ---------------------------------------------------------------- legend */
.legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 450;
  display: flex; gap: 11px; flex-wrap: wrap; align-items: center;
  padding: 6px 10px; font-size: 11.5px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.sw { display: inline-block; width: 15px; height: 3px; border-radius: 2px; vertical-align: middle; }
.sw.its { background: var(--map-its); }
.sw.db { background: var(--map-db); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%;
       border: 1.5px solid #fff; vertical-align: middle; }
.dot.eq { background: var(--map-eq); }
.dot.del { background: var(--map-its); }
.dot.ins { background: var(--map-db); }
.dot.far { background: var(--map-far); }

/* ---------------------------------------------------------------- detail */
.detail .empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.dhead { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap;
         gap: 10px 18px; align-items: baseline;
         padding: 9px 14px; background: var(--surface);
         border-bottom: 1px solid var(--border); }
.dhead h2 { margin: 0; font-size: 14px; }
.dhead .k { font-size: 11px; color: var(--muted); }
.dhead .k b { color: var(--text); font-variant-numeric: tabular-nums; }

.dcols { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(300px, 420px);
         gap: 0; align-items: start; }
@media (max-width: 1100px) { .dcols { grid-template-columns: 1fr; } }

table.seq { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.seq th {
  position: sticky; top: 0; z-index: 1; padding: 5px 8px; text-align: left;
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.seq td { padding: 3px 8px; border-bottom: 1px solid var(--border);
               vertical-align: top; }
table.seq td.n { width: 34px; color: var(--muted); font-family: var(--mono);
                 font-size: 11px; text-align: right; }
tr.r-del td { background: color-mix(in srgb, var(--its) 13%, transparent); }
tr.r-ins td { background: color-mix(in srgb, var(--db) 13%, transparent); }
tr.r-rep td { background: color-mix(in srgb, var(--sev-mid) 14%, transparent); }
tr.seqrow:hover td { background: color-mix(in srgb, var(--accent) 12%, transparent); cursor: pointer; }
td.gap { color: var(--muted); font-style: italic; }
td.farpos::after { content: " ⚠"; color: var(--sev-high); }

.findings { padding: 10px 14px; border-left: 1px solid var(--border); }
.findings h3 { margin: 0 0 7px; font-size: 11px; text-transform: uppercase;
               letter-spacing: .05em; color: var(--muted); }
.fitem { padding: 6px 0 6px 9px; border-left: 3px solid var(--sev-low);
         margin-bottom: 6px; font-size: 12.5px; }
.fitem.f-높음 { border-left-color: var(--sev-high); }
.fitem.f-중간 { border-left-color: var(--sev-mid); }
.fitem .ft { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.nofind { color: var(--ok); font-size: 13px; }

.leaflet-popup-content { margin: 9px 11px; font-size: 12.5px; line-height: 1.5; }
.leaflet-popup-content b { font-size: 13px; }
.leaflet-popup-content dl { margin: 5px 0 0; display: grid;
                            grid-template-columns: auto 1fr; gap: 1px 8px; }
.leaflet-popup-content dt { color: #6b7684; font-size: 11px; }
.leaflet-popup-content dd { margin: 0; font-family: var(--mono); font-size: 11px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 240px 320px 300px;
            grid-template-areas: "panel" "map" "detail"; }
  .stats { width: 100%; margin-left: 0; }
  .caveat-inner { grid-template-columns: 1fr; gap: 12px; }
}

/* ---------------------------------------------------------------- 다운로드 */
.dllist { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.dllist li { border-bottom: 1px solid var(--border); }
.dlcard { display: block; padding: 11px 12px; text-decoration: none; color: inherit; }
.dlcard:hover { background: var(--surface-2); }
.dlcard:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dlname { font-size: 13.5px; font-weight: 600; }
.dlname::before { content: "⬇ "; color: var(--accent); }
.dldesc { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: keep-all; }
.dlmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
          font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dlsize { margin-left: auto; font-family: var(--mono); }

/* 배경지도를 연한 흑백으로. Positron 에 남아 있는 색(물·녹지·도로 음영)까지 빼고
   살짝 밝혀서, 그 위에 올라가는 노선 선형과 정류장 점만 색으로 읽히게 한다. */
.leaflet-tile-pane { filter: grayscale(1) brightness(1.18) contrast(.82) opacity(.92); }

/* ---------------------------------------------------- 지도 정류장 라벨 */
/* 흰 테두리(paint-order)로 배경 없이 읽히게 한다. 배경 상자를 깔면 정류장이
   촘촘한 구간에서 상자끼리 겹쳐 지도가 안 보인다. */
.leaflet-tooltip.stoplabel {
  background: none; border: none; box-shadow: none; padding: 0;
  font: 600 11px/1.3 "Pretendard", -apple-system, "Malgun Gothic", sans-serif;
  color: #11161d; white-space: nowrap; pointer-events: none;
  -webkit-text-stroke: 3px rgba(255,255,255,.92);
  paint-order: stroke fill;
}
.leaflet-tooltip.stoplabel::before { display: none; }   /* 꼬리 화살표 제거 */
.leaflet-tooltip.stoplabel .lo {
  display: inline-block; min-width: 13px; margin-right: 3px;
  font-style: normal; font-weight: 700; font-variant-numeric: tabular-nums;
  text-align: right;
}
.stoplabel .lo-eq  { color: var(--map-eq); }
.stoplabel .lo-del { color: var(--map-its); }
.stoplabel .lo-ins { color: var(--map-db); }
.stoplabel .lo-far { color: var(--map-far); }

.labels-off .leaflet-tooltip.stoplabel { display: none; }

.lbltoggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
             padding-left: 9px; margin-left: 2px; border-left: 1px solid var(--border); }
.lbltoggle input { margin: 0; cursor: pointer; }

/* 멀리서는 순번만, 가까이 가면 이름까지 */
.names-off .leaflet-tooltip.stoplabel .nm { display: none; }
.names-off .leaflet-tooltip.stoplabel .lo { margin-right: 0; }
