/* 다크 테마(기본) — dashboard_v4.html 참고 디자인의 색·타이포·컴포넌트 톤을 이식 */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #161b27;
  --panel2: #1e2535;
  --panel3: #252d3d;
  --border: rgba(255, 255, 255, 0.08);
  --border2: rgba(255, 255, 255, 0.14);
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --text-faint: #5a6478;
  --accent: #38bdf8;
  --accent2: #818cf8;
  --ok: #34d399;
  --warn: #fb923c;
  --danger: #f87171;
  --neutral: #8892a4;
  --banner-bg: rgba(56, 189, 248, 0.08);
  --banner-border: rgba(56, 189, 248, 0.35);
  --banner-text: #7dd3fc;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
  --metric-latency: #38bdf8;
  --metric-object: #a78bfa;
  --metric-distance: #2dd4bf;
  --on-accent: #0b1220;
  /* 거리별 오차율 차트: 범주 팔레트 1~5번(다크 면 기준 검증) */
  --dist-1: #3987e5;
  --dist-2: #d95926;
  --dist-3: #199e70;
  --dist-4: #c98500;
  --dist-5: #d55181;
  --dist-overall: #8892a4;
}

/* 라이트 테마 — 토글 시 전환 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel2: #f4f5f7;
  --panel3: #eef0f3;
  --border: #e0e3e8;
  --border2: #cfd4dc;
  --text: #1c2430;
  --text-muted: #667085;
  --text-faint: #98a1b0;
  --accent: #2f6fed;
  --accent2: #7c3aed;
  --ok: #1a7f37;
  --warn: #b45309;
  --danger: #c0231a;
  --neutral: #667085;
  --banner-bg: #fff4e5;
  --banner-border: #f0b862;
  --banner-text: #7a4a00;
  --shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
  --metric-latency: #2f6fed;
  --metric-object: #7c3aed;
  --metric-distance: #0ea5a4;
  --on-accent: #ffffff;
  /* 거리별 오차율 차트: 범주 팔레트 1~5번(라이트 면 기준 검증) */
  --dist-1: #2a78d6;
  --dist-2: #eb6834;
  --dist-3: #1baf7a;
  --dist-4: #eda100;
  --dist-5: #e87ba4;
  --dist-overall: #667085;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body, .card, .section-box, .topbar, .sidebar, .btn, .select-box, .badge {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mock-banner {
  background: var(--banner-bg);
  border-bottom: 1px solid var(--banner-border);
  color: var(--banner-text);
  padding: 6px 16px;
  font-size: 12.5px;
  text-align: center;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

/* 로고 이미지: 배경·테두리 없이 테마 바탕에 그대로 올린다 */
.brand-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-logo img {
  display: block;
  height: 22px;
  width: auto;
}

/* 다크 테마: 로고의 검은 선이 바탕에 묻히므로 밝기만 뒤집는다(색상은 유지) */
:root:not([data-theme="light"]) .brand-logo img {
  filter: invert(1) hue-rotate(180deg);
}

.brand-n {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-s {
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border2);
}

.project-name {
  font-size: 13px;
  color: var(--text-muted);
}

.select-box, .btn, .input-box {
  border: 1px solid var(--border2);
  border-radius: 7px;
  padding: 6px 10px;
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
}

.btn {
  cursor: pointer;
  background: var(--panel2);
}

.btn:hover { background: var(--panel3); border-color: var(--border2); }

.btn.primary {
  background: var(--accent);
  color: #0f1117;
  border-color: var(--accent);
  font-weight: 600;
}

.theme-toggle {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 80px);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: var(--topbar-h, 57px);
  align-self: start;
  height: calc(100vh - var(--topbar-h, 57px));
  overflow-y: auto;
}

.sidebar nav a {
  display: block;
  padding: 10px 18px;
  margin: 0 8px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13.5px;
  border-left: 3px solid transparent;
}

.sidebar nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-weight: 600;
}

.sidebar nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }

.content {
  padding: 20px 24px;
  max-width: 1400px;
}

h1.page-title {
  font-size: 18px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.sub-line {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-bottom: 16px;
}

.summary-row {
  display: flex;
  gap: 24px;
  align-items: center;
  margin: 10px 0 18px;
  flex-wrap: wrap;
}

.summary-metric {
  font-size: 14px;
}

.summary-metric b { font-size: 18px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 14.5px;
}

/* KPI(지표) 카드 전용 요소 */
.metric-card { overflow: hidden; display: flex; flex-direction: column; }
.metric-card .card-actions { margin-top: auto; padding-top: 12px; }

.metric-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--c, var(--accent));
}

.mc-hd {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}

.mc-nm {
  font-size: 14.5px;
  font-weight: 700;
}

.mc-def {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.mc-val { margin-bottom: 2px; }

.mc-num {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--c, var(--accent));
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.neutral { background: var(--panel3); color: var(--neutral); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.card .status-reason {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 6px 0;
}

.card .card-actions { margin-top: 12px; display: flex; gap: 8px; }

/* 목표 대비 측정값 게이지(가로 바 + 눈금) */
.gauge { margin: 12px 0 4px; }

.gauge-track {
  position: relative;
  height: 7px;
  border-radius: 99px;
  background: var(--panel3);
  overflow: visible;
}

.gauge-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c, var(--accent)) 45%, transparent), var(--c, var(--accent)));
}

.gauge-tick {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 13px;
  background: var(--text);
  opacity: 0.5;
  border-radius: 2px;
}

.gauge-cap {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 6px;
}

.gauge-cap b { color: var(--text-muted); font-weight: 600; }

/* 스파크라인(추이) */
.spark {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.spark svg { width: 100%; height: 44px; display: block; }
.spark-empty { height: 44px; }

.mc-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.section-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.section-box h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th, table.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}

table.data-table td { font-variant-numeric: tabular-nums; }

table.data-table th {
  color: var(--text-faint);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: transparent;
}

table.data-table tbody tr:hover { background: var(--panel2); }

.table-scroll {
  overflow-x: auto;
}

.filters-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: none;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--panel2);
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 20px;
  font-size: 13px;
}

.field-grid .field-label {
  color: var(--text-faint);
  font-size: 11px;
}

.checklist-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}

.notice {
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--panel2);
  border: 1px dashed var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
}

.chart-placeholder {
  height: 160px;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12.5px;
  background: var(--panel2);
}

.image-frame {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 260px;
  background: repeating-linear-gradient(45deg, var(--panel2), var(--panel2) 10px, var(--panel3) 10px, var(--panel3) 20px);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.bbox {
  position: absolute;
  box-sizing: border-box;
  border-radius: 2px;
}

.bbox.gt {
  border: 2px solid var(--ok);
}

.bbox.pred {
  border: 2px dashed var(--danger);
}

.bbox.pred.unmatched {
  border-color: var(--danger);
  border-width: 3px;
}

.hidden-box {
  display: none;
}

.mobile-toggle { display: none; }

.hamburger-icon {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px;
  height: 13px;
}

.hamburger-icon span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text);
  border-radius: 2px;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 1279px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    align-self: auto;
    width: 240px;
    z-index: 1000;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.35);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-toggle {
    display: inline-block;
  }
  .sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
}

@media (max-width: 767px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .summary-row { gap: 14px; }
}

.pager { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.btn.disabled { opacity: 0.4; pointer-events: none; }

.stat-row { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12.5px; color: var(--text-muted); }
.stat-row b { color: var(--text); font-variant-numeric: tabular-nums; }

.badge.solid { background: var(--accent); color: var(--on-accent); }
.badge.outline { background: transparent; color: var(--text-muted); border-color: var(--border2); }


/* ---- 종합 현황: 거리별 오차율 섹션 ---- */
.dist-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.dist-head h2 { margin: 0; }
#distance-by-distance { scroll-margin-top: calc(var(--topbar-h, 57px) + 12px); }
.dist-pick { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.dist-pick .select-box { max-width: 100%; }
.dist-svg .sel-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 2 3; }
.dist-svg .dot.sel { stroke: var(--text); stroke-width: 1.5; }
.dist-legend .sw.mark { width: 2px; height: 12px; background: var(--text-muted); }
.dist-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 12px; }
.dist-col { min-width: 0; }
.dist-col h3 { font-size: 13px; font-weight: 700; margin: 0 0 8px; }
.dist-svg { width: 100%; height: auto; display: block; }
.dist-svg text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
.dist-svg .grid { stroke: var(--border); stroke-width: 1; }
.dist-svg .axis { stroke: var(--border2); stroke-width: 1; }
.dist-svg .val { fill: var(--text); font-weight: 600; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.dist-svg .ref-target { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 5 4; }
.dist-svg .ref-mean { stroke: var(--dist-overall); stroke-width: 1.5; }
.dist-svg .ref-label { fill: var(--text-muted); }
.dist-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dist-svg .line.overall { stroke-dasharray: 5 4; }
.dist-svg .dot { stroke: var(--panel); stroke-width: 2; }
.dist-svg .hit { fill: transparent; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0 0 6px; font-size: 12px; color: var(--text-muted); }
.dist-legend .sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.dist-legend .sw.solid { background: var(--dist-overall); height: 2px; }
.dist-legend .sw.dash { background: repeating-linear-gradient(90deg, var(--dist-overall) 0 5px, transparent 5px 8px) !important; }
.dist-legend .sw.warn { background: repeating-linear-gradient(90deg, var(--warn) 0 5px, transparent 5px 8px) !important; }
.dist-table { margin-top: 12px; }
.dist-table .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.dist-table tr.total td { font-weight: 700; border-top: 1px solid var(--border2); }
.dist-table .ok { color: var(--ok); }
.dist-table .over { color: var(--danger); }
.dist-note { color: var(--text-muted); font-size: 12px; margin-top: 8px; }

@media (max-width: 1100px) {
  .dist-grid { grid-template-columns: 1fr; }
}
