/* ==========================================================================
   한산 — 스타일
   디자인 시스템: design.md (toss.im / TDS 추출)
   흰 바탕 · 파란 액센트 하나 · 네이비 틴트 그림자 · 자간 0.
   ========================================================================== */

@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");

:root {
  color-scheme: light;

  /* Brand — 단 하나 */
  --blue50:  #e8f3ff;
  --blue100: #c9e2ff;
  --blue200: #90c2ff;
  --blue300: #64a8ff;
  --blue400: #4593fc;
  --blue500: #3182f6;   /* canonical */
  --blue600: #2272eb;
  --blue700: #1b64da;
  --blue900: #194aa6;

  /* Neutral — 전 구간 푸른기, 순흑 없음 */
  --grey50:  #f9fafb;
  --grey100: #f2f4f6;
  --grey200: #e5e8eb;
  --grey300: #d1d6db;
  --grey400: #b0b8c1;
  --grey500: #8b95a1;
  --grey600: #6b7684;
  --grey700: #4e5968;
  --grey800: #333d4b;
  --grey900: #191f28;

  /* 역할 alias */
  --bg-page:    #ffffff;
  --surface:    var(--grey100);
  --surface-subtle: var(--grey50);
  --text:       var(--grey900);
  --text-2:     var(--grey700);
  --text-muted: var(--grey500);
  --border:     var(--grey200);
  --brand:      var(--blue500);
  --brand-hover:var(--blue600);
  --brand-weak: var(--blue50);

  /* 네이비 틴트 알파 — rgba(0,0,0,…) 로 바꾸면 화면이 탁해진다 */
  --greyOpacity50:  rgba(0, 23, 51, 0.02);
  --greyOpacity100: rgba(2, 32, 71, 0.05);
  --greyOpacity200: rgba(0, 27, 55, 0.10);
  --greyOpacity300: rgba(0, 29, 58, 0.18);

  --shadow-s: 0 0 4px 0 var(--greyOpacity100), 0 4px 16px 0 var(--greyOpacity100);
  --shadow-m: 0 8px 16px 0 var(--greyOpacity200), 0 4px 8px 0 var(--greyOpacity100);
  --shadow-l: 0 24px 40px 0 var(--greyOpacity50), 0 16px 24px 0 var(--greyOpacity200),
              0 0 8px 0 var(--greyOpacity100);

  /* Semantic (토스 램프) */
  --green500: #03b26c;
  --orange50: #fff3e0;
  --orange500: #fe9800;
  --red500: #f04452;
  --red900: #a51926;

  /* 혼잡도 status — 토스 semantic. 색 단독 사용 금지: 항상 글리프 + 라벨 동반 */
  --lvl-1: #03b26c;   /* 여유    green500 */
  --lvl-2: #fe9800;   /* 보통    orange500 */
  --lvl-3: #f04452;   /* 약간붐빔 red500 */
  --lvl-4: #a51926;   /* 붐빔    red900 */

  /* 차트 — emphasis 패턴 */
  --series-past: var(--grey500);
  --series-future: var(--blue500);

  --r-sm: 6px;
  --r-md: 8px;      /* 기본 */
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 100px;

  --ease-standard: cubic-bezier(.4, 0, .2, 1);
  --ease-press:    cubic-bezier(.1, .76, .55, .9);

  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
          "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

/* 색약 모드 — 토스 blue 300/500/700/900 순차 램프 (검증 전 항목 PASS) */
:root[data-cvd="on"] {
  --lvl-1: #64a8ff;
  --lvl-2: #3182f6;
  --lvl-3: #1b64da;
  --lvl-4: #194aa6;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;          /* 토스 본문은 400이 아니라 500 */
  line-height: 1.5;
  letter-spacing: 0;         /* 전 구간 자간 보정 없음 */
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: var(--brand); text-underline-offset: 3px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  background: var(--grey900); color: #fff;
  padding: 10px 16px; border-radius: 0 0 var(--r-md) 0;
  font-size: 13px;
}
.skip-link:focus { left: 0; }

/* 포커스는 outline이 아니라 inset 그림자 — 레이아웃을 밀지 않는다 */
:where(button, select, input, a):focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--brand);
}

/* ---------- 상단바 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--bg-page);
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
  box-shadow: 0 1px 0 0 var(--greyOpacity100);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 32px; height: 32px;
  border-radius: 10px;
  box-shadow: 0 4px 12px 0 rgba(49, 130, 246, .28);
  flex: none;
  display: block;
}

.brand-text h1 {
  margin: 0; font-size: 19px; font-weight: 700; line-height: 1.3;
}
.brand-text p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.topbar-stats { display: flex; align-items: center; gap: 24px; margin-left: auto; }

.hero-stat { display: flex; flex-direction: column; align-items: flex-end; }
.hero-figure {
  font-size: 40px; font-weight: 700; line-height: 1.3; color: var(--brand);
}
.hero-label { font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.mini-stats { display: flex; gap: 20px; }
.mini-stat { display: flex; flex-direction: column; align-items: flex-end; }
.mini-stat span { font-size: 22px; font-weight: 700; line-height: 1.3; }
.mini-stat small { font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* 버튼 — press 시 border-radius가 스프링 이징으로 변형된다 */
.btn {
  background: var(--surface);
  color: var(--text-2);
  border: 0;
  border-radius: var(--r-md);
  padding: 9px 14px;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .2s ease, color .2s ease,
              border-radius .2s var(--ease-press);
}
.btn:hover { background: var(--grey200); color: var(--text); }
.btn:active { border-radius: var(--r-lg); }
.btn[aria-pressed="true"] { background: var(--brand-weak); color: var(--brand); }
.btn[data-busy="1"] { opacity: .4; pointer-events: none; }

/* ---------- 필터바 ---------- */

.filterbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 24px;
  background: var(--bg-page);
  flex-wrap: wrap;
}

.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-spacer { flex: 1 1 auto; }

.chip {
  background: var(--surface);
  border: 0;
  color: var(--text-2);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1.4;
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease;
}
.chip:hover { background: var(--grey200); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--brand); color: #fff; }
.chip .chip-n { opacity: .65; margin-left: 6px; font-variant-numeric: tabular-nums; }

.filter-field {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
}
.filter-field select,
.filter-field input {
  background: var(--surface);
  border: 0;
  color: var(--text);
  border-radius: var(--r-md);
  padding: 9px 12px;
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.4;
}
.filter-field select:focus,
.filter-field input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--brand); }
.filter-field input::placeholder { color: var(--text-muted); }
.search-field input { width: 180px; }

/* ---------- 레이아웃 ---------- */

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 16px;
  padding: 8px 24px 24px;
  min-height: 0;
}

.panel {
  background: var(--bg-page);
  border-radius: var(--r-lg);
  min-height: 0;
  overflow: hidden;
  box-shadow: var(--shadow-s);
}

.panel-list { display: flex; flex-direction: column; overflow-y: auto; }
.panel-map { position: relative; }

#map { position: absolute; inset: 0; background: var(--surface); }

.status-line {
  padding: 12px 20px;
  font-size: 13px; line-height: 1.5;
  color: var(--text-muted);
  background: var(--bg-page);
  position: sticky; top: 0; z-index: 5;
  box-shadow: 0 1px 0 0 var(--greyOpacity100);
}
/* 배너 색은 토스 램프에서만 — 새 hex를 만들지 않는다 */
.status-line[data-tone="warn"] { color: var(--grey900); background: var(--orange50); }
.status-line[data-tone="err"]  { color: var(--red900); background: color-mix(in srgb, var(--red500) 10%, #fff); }

/* 리페치 중 프레임 유지 */
.is-refetching .rec-cards,
.is-refetching .spot-list { opacity: .4; transition: opacity .2s ease; }

/* 섹션 — 파란 아이브로우 + 근사-검정 헤드라인 */
.section-head { padding: 24px 20px 12px; }
.section-head--row {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.eyebrow {
  margin: 0 0 4px;
  font-size: 14px; font-weight: 700; line-height: 1.3;
  color: var(--brand);
}
.section-head h2 {
  margin: 0; font-size: 22px; font-weight: 700; line-height: 1.3; color: var(--text);
}
.section-sub { margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.linkbtn {
  background: none; border: 0; color: var(--text-muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 0;
}
.linkbtn:hover { color: var(--brand); }
.linkbtn[aria-pressed="true"] { color: var(--brand); }

/* ---------- 추천 카드 ---------- */

.rec-cards { list-style: none; margin: 0; padding: 0 20px 8px; display: grid; gap: 8px; }

.rec-card {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 0;
  border-radius: var(--r-lg);
  padding: 16px;
  color: inherit; font: inherit;
  cursor: pointer;
  transition: background-color .2s ease, border-radius .2s var(--ease-press);
}
.rec-card:hover { background: var(--grey200); }
.rec-card:active { border-radius: var(--r-xl); }
.rec-card[data-active="1"] { background: var(--brand-weak); box-shadow: inset 0 0 0 2px var(--brand); }

.rec-rank {
  font-size: 17px; font-weight: 700; color: var(--text-muted);
  text-align: center; line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.rec-card:first-child .rec-rank { color: var(--brand); }

.rec-main { min-width: 0; }
.rec-name {
  font-size: 17px; font-weight: 700; line-height: 1.3; margin: 0 0 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rec-meta {
  font-size: 13px; line-height: 1.5; color: var(--text-muted);
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.rec-why { margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-2); }

/* ---------- 혼잡도 배지 — 색 + 글리프 + 라벨 3중 인코딩 ---------- */

.lvl-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px 5px 8px;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 600; line-height: 1.4;
  white-space: nowrap;
  background: var(--lvl-bg);
  color: var(--lvl-ink);
}
.lvl-glyph { font-size: 10px; line-height: 1; color: var(--lvl-fg); }

/* 라벨은 잉크 토큰(--grey900)을 쓴다 — 텍스트가 상태 색을 입지 않는다.
   식별은 옆의 색 글리프가 담당하고, 색약 모드에서도 라벨은 그대로 읽힌다. */
.lvl-1 { --lvl-fg: var(--lvl-1); --lvl-bg: color-mix(in srgb, var(--lvl-1) 12%, #fff); --lvl-ink: var(--grey900); }
.lvl-2 { --lvl-fg: var(--lvl-2); --lvl-bg: color-mix(in srgb, var(--lvl-2) 14%, #fff); --lvl-ink: var(--grey900); }
.lvl-3 { --lvl-fg: var(--lvl-3); --lvl-bg: color-mix(in srgb, var(--lvl-3) 12%, #fff); --lvl-ink: var(--grey900); }
.lvl-4 { --lvl-fg: var(--lvl-4); --lvl-bg: color-mix(in srgb, var(--lvl-4) 12%, #fff); --lvl-ink: var(--grey900); }

.gem-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 600; line-height: 1.4;
  background: var(--brand-weak);
  color: var(--brand);
  white-space: nowrap;
}

/* ---------- 목록 ---------- */

.spot-list { list-style: none; margin: 0; padding: 0 20px 20px; display: grid; gap: 2px; }

.spot-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--r-md);
  padding: 12px;
  color: inherit; font: inherit;
  cursor: pointer;
  transition: background-color .2s ease, border-radius .2s var(--ease-press);
}
.spot-row:hover { background: var(--surface); }
.spot-row:active { border-radius: var(--r-lg); }
.spot-row[data-active="1"] { background: var(--brand-weak); box-shadow: inset 0 0 0 2px var(--brand); }

.spot-name {
  font-size: 15px; font-weight: 600; line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spot-sub { font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.empty-note { padding: 32px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- 표 보기 ---------- */

.table-wrap { padding: 0 20px 20px; overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  text-align: left; padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th {
  color: var(--text-muted); font-weight: 600; font-size: 13px;
  position: sticky; top: 0; background: var(--bg-page);
}
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--surface); }

/* ---------- 지도 마커 ---------- */

.pin {
  border-radius: 50%;
  border: 2px solid #fff;
  box-sizing: content-box;
  box-shadow: 0 2px 8px 0 var(--greyOpacity300);
  transition: transform .2s var(--ease-press);
}
.pin-wrap { display: grid; place-items: center; }
.pin-wrap:hover .pin { transform: scale(1.3); }
.pin-wrap[data-active="1"] .pin { box-shadow: 0 0 0 4px rgba(49, 130, 246, .35); }

.leaflet-container { background: var(--surface); font-family: var(--font); }
.leaflet-control-attribution {
  font-size: 11px; background: rgba(255, 255, 255, .88) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--text-2) !important; }

.leaflet-tooltip.pin-tip {
  background: var(--grey900);
  border: 0;
  color: #fff;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; line-height: 1.5;
  padding: 8px 12px;
  box-shadow: var(--shadow-m);
}
.leaflet-tooltip.pin-tip::before { display: none; }
.pin-tip-name { font-weight: 700; }
.pin-tip-lvl { color: var(--grey400); font-size: 13px; }

.map-legend {
  position: absolute; left: 16px; bottom: 26px; z-index: 500;
  background: var(--bg-page);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 13px; line-height: 1.5;
  box-shadow: var(--shadow-m);
}
.map-legend h3 {
  margin: 0 0 8px; font-size: 13px; color: var(--brand);
  font-weight: 700;
}
.legend-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; color: var(--text-2); }
.legend-dot { border-radius: 50%; flex: none; border: 2px solid #fff; box-sizing: content-box; box-shadow: 0 2px 6px 0 var(--greyOpacity300); }

/* ---------- 상세 시트 ---------- */

.detail {
  position: fixed; right: 24px; bottom: 24px; top: 24px;
  width: min(480px, calc(100vw - 48px));
  background: var(--bg-page);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-l);
  z-index: 900;
  overflow-y: auto;
  padding: 24px;
}
.detail-close {
  position: absolute; right: 16px; top: 16px;
  background: var(--surface); border: 0;
  color: var(--text-2);
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 13px; line-height: 1;
  transition: background-color .2s ease;
}
.detail-close:hover { background: var(--grey200); color: var(--text); }

.detail h2 {
  margin: 0 0 4px; font-size: 28px; font-weight: 700; line-height: 1.3;
  padding-right: 44px;
}
.detail-cat { font-size: 14px; color: var(--brand); font-weight: 700; margin: 0 0 20px; line-height: 1.3; }

.detail-hero {
  padding: 20px; margin-bottom: 16px;
  background: var(--surface); border-radius: var(--r-lg);
}
.detail-hero-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.detail-hero-fig { font-size: 28px; font-weight: 700; line-height: 1.3; color: var(--brand); }
.detail-hero-lab { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

.stat-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 8px; margin-top: 16px; padding-top: 16px;
  box-shadow: inset 0 1px 0 0 var(--greyOpacity200);
}
.stat-cell { min-width: 0; }
.hero-note {
  margin: 12px 0 0; font-size: 13px; line-height: 1.6;
  color: var(--red900);
}
.stat-key { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.stat-val {
  font-size: 17px; font-weight: 700; line-height: 1.3; color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tip-card {
  background: var(--brand-weak);
  border: 0;
  border-radius: var(--r-lg);
  padding: 16px; margin-bottom: 20px;
  font-size: 14px; line-height: 1.6; color: var(--text-2);
}
.tip-card b { color: var(--brand); font-weight: 700; }

.chart-block { margin-bottom: 24px; }
.chart-title { font-size: 17px; font-weight: 700; margin: 0; line-height: 1.3; }
.chart-sub { font-size: 13px; color: var(--text-muted); margin: 4px 0 12px; line-height: 1.5; }

.chart-legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-key { width: 14px; height: 2px; border-radius: 1px; flex: none; }

.chart-wrap { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; touch-action: none; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--grey900);
  border: 0;
  border-radius: var(--r-md);
  padding: 10px 12px; font-size: 13px;
  box-shadow: var(--shadow-m);
  white-space: nowrap;
  transition: opacity .1s ease;
  color: #fff;
}
.chart-tip-x { color: var(--grey400); font-size: 13px; margin-bottom: 4px; line-height: 1.5; }
.chart-tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip-val { font-weight: 700; font-size: 15px; }
.chart-tip-lab { color: var(--grey400); font-size: 13px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.detail-cell {
  background: var(--surface); border: 0;
  border-radius: var(--r-lg); padding: 14px 16px;
}
.detail-cell dt { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; line-height: 1.5; }
.detail-cell dd { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.3; }

.bar-row {
  display: grid; grid-template-columns: 60px 1fr 46px;
  align-items: center; gap: 12px; margin-bottom: 6px;
  font-size: 13px; line-height: 1.5; color: var(--text-2);
}
.bar-track { height: 8px; background: var(--grey200); border-radius: var(--r-pill); overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: var(--r-pill); }
.bar-val { color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }

.detail-loading { color: var(--text-muted); font-size: 14px; padding: 24px 0; line-height: 1.6; }
.detail-err { color: var(--lvl-4); font-size: 14px; padding: 20px 0; line-height: 1.6; }

/* ---------- 푸터 ---------- */

.footer { padding: 0 24px 20px; font-size: 13px; line-height: 1.6; color: var(--text-muted); }
.footer p { margin: 0; }

/* ---------- 반응형 — 640px 단일 분기 ---------- */

@media (max-width: 639px) {
  .topbar, .filterbar { padding-left: 16px; padding-right: 16px; }
  .layout { grid-template-columns: 1fr; grid-template-rows: 320px auto; padding: 8px 16px 16px; }
  .panel-map { order: -1; min-height: 320px; }
  .panel-list { overflow: visible; }
  .topbar-stats { order: 3; margin-left: 0; width: 100%; justify-content: space-between; }
  .hero-stat { align-items: flex-start; }
  .hero-figure { font-size: 32px; }
  .detail { left: 16px; right: 16px; top: auto; bottom: 16px; height: 80vh; width: auto; }
  .footer { padding-left: 16px; padding-right: 16px; }
}

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