/* RouteForge — 제도판(drafting table) 디자인 시스템
   종이 위 계측 도구. 모눈 격자·얇은 괘선·모노 수치·신호색 경로.
   이모지 쓰지 않는다. 기호는 전부 문자·선으로. */

:root {
  --paper:      #F2EEE4;
  --paper-2:    #FAF8F3;
  --paper-3:    #E9E4D7;
  --ink:        #16181C;
  --ink-2:      #434952;
  /* ⚠️ 보조 글자색. 예전 #8A9099 는 모눈 종이(--paper) 위에서 대비가 약 2.9:1 로
     WCAG AA(4.5:1)에 한참 못 미쳐 **화면에서 글씨가 배경에 묻혔다**(2026-08-13 JB 지적).
     제도판 느낌을 살리자고 읽히지 않으면 그건 디자인이 아니다. 지금은 약 5.0:1. */
  --ink-3:      #5F6670;
  --rule:       #D9D3C5;
  --rule-2:     #BCB4A2;
  --indigo:     #1F3B63;
  --indigo-2:   #2E5590;
  --signal:     #BE3E24;
  --ok:         #2E7D5B;
  --amber:      #B5820F;

  --grid-1: rgba(31, 59, 99, 0.055);
  --grid-2: rgba(31, 59, 99, 0.10);

  --sans: "IBM Plex Sans KR", "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --serif: "Gowun Batang", "IBM Plex Sans KR", serif;

  --rail-l: 336px;
  --rail-r: 352px;
  --bar-h: 58px;

  --shadow-1: 0 1px 0 rgba(22, 24, 28, .06), 0 2px 10px rgba(22, 24, 28, .05);
  --shadow-2: 0 2px 4px rgba(22, 24, 28, .08), 0 12px 32px rgba(22, 24, 28, .10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* 모눈 종이 — 8px 잔격자 + 48px 굵은 격자 */
.paper-grid {
  background-image:
    linear-gradient(var(--grid-1) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-1) 1px, transparent 1px),
    linear-gradient(var(--grid-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-2) 1px, transparent 1px);
  background-size: 8px 8px, 8px 8px, 48px 48px, 48px 48px;
}

a { color: var(--indigo); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--signal); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── 계측 라벨 (모든 소제목의 기본형) ─────────────────────────────── */
.meter-label {
  font-family: var(--mono);
  /* 자간을 넓게 준 소제목이라 작고 흐리면 글자가 흩어져 읽히지 않는다.
     크기·굵기를 올리고 자간은 조금 좁혔다(2026-08-13 가독성 보정). */
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 8px;
}
.meter-label::after {
  content: ""; flex: 1; height: 1px;
  background: repeating-linear-gradient(90deg, var(--rule) 0 3px, transparent 3px 6px);
}

/* ── 상단 바 ──────────────────────────────────────────────────────── */
.topbar {
  height: var(--bar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule-2);
  position: relative; z-index: 500;
  flex-wrap: nowrap; overflow: hidden;   /* 한 줄을 절대 안 넘긴다 — 넘치면 아래 화면을 밀어낸다 */
}
.topbar > * { flex: none; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-mark {
  font-family: var(--mono); font-weight: 600; font-size: 17px; letter-spacing: -.02em;
  border: 1.5px solid var(--ink); padding: 1px 7px 2px; flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.18; min-width: 0; }
.brand-name { font-size: 14.5px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.brand-sub {
  font-size: 11.5px; color: var(--ink-2); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30ch;
}
.topbar-spacer { flex: 1 1 auto; min-width: 0; }
@media (max-width: 1400px) { .brand-sub { display: none; } }

.chip {
  font-family: var(--mono); font-size: 11px; letter-spacing: .04em;
  border: 1px solid var(--rule-2); background: var(--paper);
  padding: 3px 9px; color: var(--ink-2); white-space: nowrap;
}
select.chip { max-width: 210px; text-overflow: ellipsis; }
.chip.live { border-color: var(--ok); color: var(--ok); }
.chip.warn { border-color: var(--amber); color: var(--amber); }
.chip.down { border-color: var(--signal); color: var(--signal); }

/* ── 버튼 ────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  border: 1px solid var(--ink); background: var(--paper-2); color: var(--ink);
  padding: 8px 14px; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  position: relative;
}
.btn:hover { background: #fff; box-shadow: var(--shadow-1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { border-color: var(--rule-2); background: transparent; }

/* ── 콘솔 레이아웃 ────────────────────────────────────────────────── */
.console {
  display: grid;
  grid-template-columns: var(--rail-l) minmax(0, 1fr) var(--rail-r);
  height: calc(100vh - var(--bar-h));
}
.rail {
  background: var(--paper-2);
  overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px 40px;
  animation: rail-in .5s cubic-bezier(.2,.7,.3,1) both;
}
.rail-left { border-right: 1px solid var(--rule-2); }
.rail-right { border-left: 1px solid var(--rule-2); animation-delay: .08s; }
@keyframes rail-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.stage { position: relative; background: var(--paper-3); }
/* ★ z-index:0 으로 쌓임 맥락을 만든다. 안 그러면 Leaflet 내부 레이어(마커 600)가
   KPI 스트립 위로 올라와 덮어버린다. */
#map { position: absolute; inset: 0; z-index: 0; }

.rail section { margin-bottom: 22px; }
.rail section > .meter-label { margin-bottom: 10px; }

/* ── 정책 계기판 ──────────────────────────────────────────────────── */
.axis { margin-bottom: 18px; }
.axis-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.axis-name { font-size: 13.5px; font-weight: 600; }
.axis-val { font-family: var(--mono); font-size: 12px; color: var(--indigo); }
.axis-help { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; line-height: 1.45; }

.axis-ends {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em;
  color: var(--ink-3); margin-top: 3px;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; margin: 6px 0 0; cursor: grab;
}
input[type="range"]:active { cursor: grabbing; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; background: var(--rule-2);
  background-image: repeating-linear-gradient(90deg, var(--rule-2) 0 1px, transparent 1px 10%);
}
input[type="range"]::-moz-range-track { height: 3px; background: var(--rule-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 18px; margin-top: -8px;
  background: var(--indigo); border: none;
  clip-path: polygon(50% 0, 100% 28%, 100% 100%, 0 100%, 0 28%);
  transition: transform .12s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scaleY(1.12); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 18px; border: none; border-radius: 0; background: var(--indigo);
}

/* 토글 (집중/분산 · 하드제약) */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.toggle-row + .toggle-row { border-top: 1px dashed var(--rule); }
.toggle-text { font-size: 13px; }
.toggle-note { font-size: 11px; color: var(--ink-3); }
.switch { position: relative; width: 42px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; background: var(--paper-3);
  border: 1px solid var(--rule-2); transition: background .15s ease, border-color .15s ease;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: var(--ink-3); transition: transform .18s cubic-bezier(.3,.8,.3,1), background .15s;
}
.switch input:checked + span { background: rgba(31,59,99,.12); border-color: var(--indigo); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--indigo); }
.switch input:disabled + span { opacity: .5; }

/* ── KPI 스트립 ───────────────────────────────────────────────────── */
.kpi-strip {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 450;
  display: flex; gap: 1px; background: var(--rule-2);
  border: 1px solid var(--rule-2); box-shadow: var(--shadow-2);
  overflow: hidden;
}
.kpi {
  flex: 1; min-width: 0; background: var(--paper-2); padding: 8px 12px 9px;
}
.kpi-k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .1em; color: var(--ink-3); text-transform: uppercase; }
.kpi-v { font-family: var(--mono); font-size: 21px; font-weight: 500; letter-spacing: -.02em; line-height: 1.15; }
.kpi-u { font-size: 11px; color: var(--ink-3); margin-left: 2px; }
.kpi.alarm .kpi-v { color: var(--signal); }
.kpi.good .kpi-v { color: var(--ok); }

/* ── 기사 카드 ────────────────────────────────────────────────────── */
.driver {
  border: 1px solid var(--rule); background: var(--paper);
  padding: 9px 11px; margin-bottom: 7px; cursor: pointer;
  transition: box-shadow .14s ease, transform .14s ease, border-color .14s;
  position: relative;
}
.driver::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c, var(--ink-3));
}
.driver:hover { box-shadow: var(--shadow-1); transform: translateX(2px); border-color: var(--rule-2); }
.driver.muted { opacity: .38; }
.driver.focus { border-color: var(--ink); box-shadow: var(--shadow-1); }
.driver-top { display: flex; align-items: baseline; gap: 8px; }
.driver-name { font-weight: 600; font-size: 13.5px; }
.driver-start { font-size: 11px; color: var(--ink-3); margin-left: auto; }
.driver-nums { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.load-bar { height: 3px; background: var(--paper-3); margin-top: 6px; }
.load-bar i { display: block; height: 100%; background: var(--c, var(--indigo)); transition: width .5s cubic-bezier(.2,.7,.3,1); }

/* ── 대기건 ──────────────────────────────────────────────────────── */
.waiting {
  border-left: 3px solid var(--signal); background: rgba(190, 62, 36, .05);
  padding: 8px 10px; margin-bottom: 6px; font-size: 12.5px;
}
.waiting b { font-weight: 600; }
.waiting .why { color: var(--signal); font-size: 11.5px; margin-top: 2px; }

/* ── 근거 패널 ────────────────────────────────────────────────────── */
.reason { border: 1px solid var(--rule-2); background: var(--paper); padding: 11px 12px; }
.reason dl { margin: 0; display: grid; grid-template-columns: 68px 1fr; gap: 4px 10px; font-size: 12.5px; }
.reason dt { color: var(--ink-3); font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; padding-top: 2px; }
.reason dd { margin: 0; }

/* ── 지도 마커 ────────────────────────────────────────────────────── */
.stop-pin {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10.5px; font-weight: 600; color: #fff;
  border: 1.5px solid rgba(255,255,255,.9);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  transition: transform .15s ease;
}
.stop-pin:hover { transform: scale(1.25); }
.depot-pin {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-2); border: 2px solid var(--ink);
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.unassigned-pin {
  width: 18px; height: 18px; background: var(--signal);
  border: 2px solid var(--paper-2);
  transform: rotate(45deg);
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
}
.leaflet-container { background: var(--paper-3); font-family: var(--sans); }
.leaflet-popup-content-wrapper { border-radius: 0; box-shadow: var(--shadow-2); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12.5px; }

/* 경로선 그려지는 모션 */
.route-line { stroke-dasharray: 1200; stroke-dashoffset: 1200; animation: draw 1.1s cubic-bezier(.25,.8,.35,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ── 계산 중 표시 ─────────────────────────────────────────────────── */
.working {
  position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 600;
  background: linear-gradient(90deg, transparent, var(--indigo), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: sweep 1s linear infinite; display: none;
}
.working.on { display: block; }
@keyframes sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* ── 각주·출처 ────────────────────────────────────────────────────── */
.footnote { font-size: 12.5px; color: var(--ink-3); line-height: 1.6; }
.footnote b { color: var(--ink-2); font-weight: 600; }

.notice {
  border: 1px solid var(--rule-2); border-left: 3px solid var(--amber);
  background: rgba(181, 130, 15, .06); padding: 9px 11px; font-size: 12px; color: var(--ink-2);
}
.notice.bad { border-left-color: var(--signal); background: rgba(190,62,36,.06); }
.notice.ok  { border-left-color: var(--ok);     background: rgba(46,125,91,.06); }

/* ── 표 ──────────────────────────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grid th, table.grid td { border: 1px solid var(--rule); padding: 6px 8px; text-align: left; vertical-align: top; }
table.grid th { background: var(--paper-3); font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; }
table.grid td.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }

/* ── 모달 ────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(22,24,28,.42); z-index: 1000;
  display: none; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-back.on { display: flex; }
.modal {
  background: var(--paper-2); border: 1px solid var(--ink); box-shadow: var(--shadow-2);
  width: min(620px, 100%); max-height: 82vh; overflow-y: auto; padding: 20px 22px;
  animation: pop .22s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal h3 { font-size: 16px; margin-bottom: 4px; }

textarea, input[type="text"], input[type="password"], input[type="file"], select {
  font-family: var(--sans); font-size: 13px; width: 100%;
  border: 1px solid var(--rule-2); background: var(--paper); color: var(--ink);
  padding: 8px 10px;
}
textarea:focus, input:focus, select:focus { outline: 2px solid rgba(31,59,99,.25); outline-offset: 1px; border-color: var(--indigo); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }

/* ── 투어 ────────────────────────────────────────────────────────── */
.tour-card {
  position: fixed; z-index: 1100; width: 330px;
  background: var(--paper-2); border: 1px solid var(--ink); box-shadow: var(--shadow-2);
  padding: 15px 17px; display: none;
}
.tour-card.on { display: block; animation: pop .22s cubic-bezier(.2,.8,.3,1) both; }
.tour-step { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; color: var(--ink-3); }
.tour-card h4 { font-size: 14.5px; margin: 3px 0 6px; }
.tour-card p { font-size: 12.5px; color: var(--ink-2); margin: 0 0 12px; line-height: 1.55; }
.tour-nav { display: flex; gap: 8px; justify-content: flex-end; }
.tour-spot { position: fixed; z-index: 1090; border: 2px solid var(--indigo); box-shadow: 0 0 0 9999px rgba(22,24,28,.35); pointer-events: none; display: none; }
.tour-spot.on { display: block; }

/* ── 반응형 ──────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .console { grid-template-columns: 300px minmax(0, 1fr); }
  .rail-right { display: none; }
  .rail-right.show { display: block; position: fixed; right: 0; top: var(--bar-h); bottom: 0; width: 320px; z-index: 700; box-shadow: var(--shadow-2); }
}
@media (max-width: 820px) {
  .console { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  .rail-left { border-right: none; border-top: 1px solid var(--rule-2); order: 2; }
  .stage { order: 1; }
  .kpi-strip { flex-wrap: wrap; }
  .kpi { min-width: 33%; }
}
