/* 배전망 위험 지도 — 전력 관제 화면을 염두에 둔 어두운 배색.
   지도 색이 배경에서 또렷하게 떨어져 나오도록 바탕을 어둡게 잡았다. */

:root {
  --bg: #0e1419;
  --bg-panel: #151d24;
  --bg-raised: #1c262f;
  --line: #2a3742;
  --text: #e6edf3;
  --text-dim: #8fa3b3;
  --accent: #4da3ff;

  --grade-1: #2f6f5e; /* 안전 */
  --grade-2: #6f9a4f; /* 관심 */
  --grade-3: #d4a92b; /* 주의 */
  --grade-4: #dd7a33; /* 경계 */
  --grade-5: #cf3f45; /* 위험 */

  --radius: 10px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 650; }

/* ------------------------------------------------------------------ 머리말 */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap);
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.brand h1 { font-size: 20px; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--text-dim); font-size: 13px; }

.meta {
  display: flex;
  gap: 22px;
  margin: 0;
  font-size: 12px;
}
.meta div { display: flex; flex-direction: column; }
.meta dt { color: var(--text-dim); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ------------------------------------------------------------------ 배치 */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: var(--gap);
  padding: var(--gap);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 14px; }

/* ------------------------------------------------------------------ 범례 */

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 5px; color: var(--text-dim); }
.legend i {
  width: 12px; height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* ------------------------------------------------------------------ 지도 */

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.is-panning { cursor: grabbing; }

#map path {
  stroke: #0e1419;
  stroke-width: 0.35;
  stroke-linejoin: round;
  transition: fill 120ms linear;
}
#map path:hover { stroke: #ffffff; stroke-width: 1.1; }
#map path.is-selected { stroke: #ffffff; stroke-width: 1.6; }
#map path.is-dimmed { opacity: 0.22; }

.map-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.map-controls button {
  width: 30px; height: 30px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}
.map-controls button:hover { background: #26333e; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 12, 16, 0.94);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, -130%);
  z-index: 5;
}
.tooltip b { font-size: 13px; }
.tooltip small { color: var(--text-dim); }

/* ------------------------------------------------------------------ 시뮬레이션 */

.sim {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
}
.sim label { display: block; font-size: 13px; margin-bottom: 8px; }
.sim output {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sim input[type="range"] { width: 100%; accent-color: var(--accent); }
.sim-note { margin: 6px 0 0; font-size: 12px; color: var(--text-dim); }

/* ------------------------------------------------------------------ 옆 패널 */

.side { min-height: 0; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 11px 8px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.tab-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

/* ------------------------------------------------------------------ 상세 */

.detail-head { margin-bottom: 14px; }
.detail-head .where { color: var(--text-dim); font-size: 12px; }
.detail-head h3 { font-size: 19px; margin-top: 2px; }

.score-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 8px;
}
.score-row .score {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #0b1116;
}
.chip {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.reason {
  background: var(--bg-raised);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 10px 12px;
  margin: 14px 0;
  font-size: 13px;
}

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.metric {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
.metric dt { color: var(--text-dim); font-size: 11px; }
.metric dd {
  margin: 3px 0 0;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.metric .sub { font-size: 11px; color: var(--text-dim); font-weight: 400; }

.chart-block { margin-bottom: 18px; }
.chart-block h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.chart-block svg { width: 100%; display: block; }
.chart-block .axis { fill: var(--text-dim); font-size: 9px; }
.chart-block .grid { stroke: var(--line); stroke-width: 1; }

.empty { color: var(--text-dim); text-align: center; padding: 40px 12px; font-size: 13px; }

/* ------------------------------------------------------------------ 순위 */

.filters { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 12px; }
.filters input, .filters select {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
}

.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 7px;
  cursor: pointer;
}
.rank-list li:hover { background: var(--bg-raised); }
.rank-list li.is-selected { background: #24323d; }
.rank-list .no {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.rank-list .name { font-size: 13px; }
.rank-list .name small { display: block; color: var(--text-dim); font-size: 11px; }
.rank-list .val {
  display: flex;
  align-items: center;
  gap: 7px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.rank-list .dot { width: 9px; height: 9px; border-radius: 50%; }
.rank-list .delta { font-size: 11px; color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------------ 산출 방법 */

.about h3 { font-size: 13px; margin: 18px 0 6px; }
.about h3:first-child { margin-top: 0; }
.about p, .about li { font-size: 13px; color: var(--text-dim); }
.about ul { margin: 6px 0; padding-left: 18px; }
.about code {
  display: block;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  font-family: "Consolas", "D2Coding", monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.7;
}
.about table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.about th, .about td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
.about th { color: var(--text-dim); font-weight: 600; }

/* ------------------------------------------------------------------ 질문하기 */

.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 4px;
  -webkit-overflow-scrolling: touch;
}

.chat-row { margin-bottom: 12px; font-size: 13px; }
.chat-row p { margin: 0 0 6px; }
.chat-row p:last-child { margin-bottom: 0; }

.chat-row.is-me {
  display: flex;
  justify-content: flex-end;
}
.chat-row.is-me p {
  background: var(--accent);
  color: #08121c;
  font-weight: 500;
  border-radius: 12px 12px 3px 12px;
  padding: 7px 11px;
  max-width: 85%;
}

.chat-row.is-bot {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px 12px 12px 3px;
  padding: 10px 12px;
}

.chat-note { color: var(--text-dim); font-size: 12px; }

.chat-list { margin: 6px 0 0; padding-left: 20px; }
.chat-list li { margin-bottom: 3px; }

.chat-num { font-variant-numeric: tabular-nums; font-weight: 650; }

.chat-link {
  background: none;
  border: 0;
  border-bottom: 1px dashed var(--accent);
  color: var(--accent);
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.chat-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0 2px; }
.chat-table th, .chat-table td {
  text-align: left;
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.chat-table tr:first-child th { color: var(--text-dim); font-weight: 600; }

.chat-code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  font-family: "Consolas", "D2Coding", monospace;
  font-size: 11.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-x: auto;
}

.chat-chips {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chat-chips::-webkit-scrollbar { display: none; }

.chip-btn {
  flex: 0 0 auto;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { color: var(--text); border-color: var(--accent); }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  /* 16px 미만이면 iOS 사파리가 입력할 때 화면을 확대한다. */
  font-size: 16px;
  padding: 9px 11px;
}
.chat-form button {
  flex: 0 0 auto;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #08121c;
  font: inherit;
  font-weight: 650;
  padding: 0 15px;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ 좁은 화면 */

/* 태블릿: 옆으로 나란히 두기에는 좁으니 위아래로 쌓는다. */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .meta { gap: 16px; }
}

/* 휴대폰 */
@media (max-width: 720px) {
  :root { --gap: 10px; }

  body { font-size: 14px; }

  .topbar {
    padding: 12px 14px 10px;
    align-items: flex-start;
  }
  .brand h1 { font-size: 17px; }
  .brand p { font-size: 12px; }

  /* 머리말 항목이 넘치면 옆으로 넘겨 본다. 숨기면 기준 시점을 알 수 없다. */
  .meta {
    width: 100%;
    gap: 14px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .meta::-webkit-scrollbar { display: none; }
  .meta div { flex: 0 0 auto; }

  .layout { padding: var(--gap); gap: var(--gap); }

  /* 화면을 반씩 나눠 지도와 패널을 같이 본다. dvh 는 주소창이 접힐 때
     생기는 높이 변화를 반영한다. */
  .map-wrap { height: 42dvh; min-height: 260px; }
  .side { height: 46dvh; min-height: 300px; }

  .panel-head { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .panel-head h2 { font-size: 13px; }
  .legend { gap: 9px; font-size: 11px; width: 100%; }

  /* 손가락으로 누를 수 있게 키운다. */
  .map-controls button { width: 38px; height: 38px; font-size: 17px; }
  .tab { padding: 13px 4px; font-size: 13px; }
  .rank-list li { padding: 11px 9px; }
  .chip-btn { padding: 8px 13px; }
  .chat-form button { padding: 0 18px; }

  .sim { padding: 10px 12px 12px; }
  .sim input[type="range"] { height: 28px; }

  .tab-body { padding: 13px; }
  .chat-log { padding: 12px 13px 4px; }
  .chat-chips { padding: 8px 13px; }
  .chat-form { padding: 10px 13px 12px; }

  .metrics { gap: 7px; }
  .metric { padding: 8px 10px; }
  .metric dd { font-size: 16px; }

  .detail-head h3 { font-size: 18px; }
  .score-row .score { font-size: 30px; }

  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  /* 16px 미만이면 iOS 사파리가 입력할 때 화면을 확대한다. */
  .filters input, .filters select { font-size: 16px; padding: 9px; }
}

/* 아주 좁은 화면 */
@media (max-width: 380px) {
  .metrics { grid-template-columns: 1fr; }
  .brand p { display: none; }
}

/* 가로로 눕힌 휴대폰 */
@media (max-height: 520px) and (orientation: landscape) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .map-wrap { height: auto; }
  .side { height: auto; }
  .meta { display: none; }
}

/* 움직임을 줄이도록 설정한 사용자 */
@media (prefers-reduced-motion: reduce) {
  #map path { transition: none; }
}
