:root {
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --fg: #e6e8eb;
  --muted: #8f99a6;
  --border: #2a313b;
  --grid: rgba(255, 255, 255, 0.07);
  --axis: #8f99a6;
  --accent: #60a5fa;
  --accent-bg: #1b2a40;
  --danger: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

#app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }
body.sidebar-collapsed #app { grid-template-columns: 0 1fr; }

/* ---------------- sidebar ---------------- */
#sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
body.sidebar-collapsed #sidebar { overflow: hidden; border-right: 0; }
.side-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 20px; margin-bottom: 8px; }
#rec-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
#rec-list li {
  padding: 8px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent;
}
#rec-list li:hover { background: var(--bg); }
#rec-list li.active { background: var(--accent-bg); border-color: var(--accent); }
#rec-list li.rec-date {
  padding: 14px 8px 4px; margin: 0; border: 0; border-radius: 0;
  cursor: default; color: var(--muted); background: var(--panel);
  font-size: 11px; font-weight: 750; letter-spacing: .04em;
}
#rec-list li.rec-date:first-child { padding-top: 5px; }
#rec-list li.rec-date:hover { background: var(--panel); }
.rec-name { font-family: var(--mono); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.guidance-badge {
  padding: 1px 5px; border: 1px solid currentColor; border-radius: 4px;
  font-size: 9px; font-weight: 750; letter-spacing: .04em;
}
.guidance-pid { color: #60a5fa; }
.guidance-semi_pn, .guidance-png { color: #34d399; }
.guidance-semi_chiense, .guidance-chinese { color: #fbbf24; }
.rec-sub { font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.rec-sub .warn { color: var(--danger); }
#rec-list .empty { color: var(--muted); cursor: default; }

/* ---------------- main ---------------- */
#main { overflow-y: auto; padding: 0 18px 40px; min-width: 0; }
#topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 16px; padding: 12px 0 8px;
  border-bottom: 1px solid var(--border);
}
.title-block { flex: 1; min-width: 0; }
#rec-title { font-size: 17px; margin: 0; font-family: var(--mono); }
#rec-meta { font-size: 12px; }
#v-download { text-decoration: none; }
#state-legend { display: flex; gap: 12px; flex-wrap: wrap; padding: 8px 0 0; font-size: 12px; }
.section-title {
  font-size: 20px; line-height: 1.25; font-weight: 750;
  margin: 28px 0 2px; color: var(--fg); letter-spacing: -0.01em;
}
#state-legend span { display: inline-flex; align-items: center; gap: 5px; }
#state-legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; border: 1px solid var(--border); }
#errors { color: var(--danger); font-size: 12px; }
#errors div { margin-top: 6px; }
#empty { padding: 60px 0; text-align: center; line-height: 1.9; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 12px; padding: 10px;
}
.panel-head { position: relative; padding: 2px 0 8px; }
.panel-title { font-size: 17px; font-weight: 700; line-height: 1.25; }
.panel-head .note { margin-top: 3px; color: var(--muted); font-size: 12px; }
.panel-delete { position: absolute; right: 0; top: 0; }
.panel .missing { color: var(--muted); padding: 8px 0 10px; }

/* uPlot 테마 보정 */
.uplot { font-family: inherit; }
.u-legend { font-size: 12px; text-align: left; }
.u-legend .u-marker { width: 12px; height: 3px; border-radius: 1px; }
.u-legend th { font-weight: 500; }
.u-legend .u-value { font-family: var(--mono); min-width: 70px; display: inline-block; }
.u-legend tr.u-series:first-child .u-value { min-width: 60px; }
.u-select { background: rgba(37, 99, 235, 0.12); }

/* 패널 위 필터 칩: [체크박스][필드명][수식] */
.help { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
.hide-help .help .ds { display: none; }   /* 수식만 숨기고 체크박스·이름은 남긴다 */
.help .chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  font-size: 11.5px; line-height: 1.3; cursor: pointer; user-select: none;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 8px;
}
.help .chip:hover { border-color: var(--accent); }
.help .chip .cb { margin: 0; accent-color: var(--series, var(--accent)); cursor: pointer; }
.help .chip .nm { font-weight: 600; white-space: nowrap; }
.help .chip .ds { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.help .chip:has(.cb:not(:checked)) { opacity: .5; }
.help .chip:has(.cb:not(:checked)) .nm { text-decoration: line-through; }
.u-legend tr.u-series { cursor: help; }

#custom-add { display: flex; gap: 8px; margin-top: 16px; }
#custom-add input { flex: 1; min-width: 0; }
.yaml-panel {
  margin-top: 28px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.yaml-panel summary { padding: 11px 12px; cursor: pointer; font-size: 15px; font-weight: 700; }
.yaml-panel summary:hover { background: var(--panel-2); }
.yaml-panel pre {
  margin: 0; padding: 14px; overflow: auto; border-top: 1px solid var(--border);
  background: #10141a; color: #d7dde7; font-size: 12px; line-height: 1.55;
}
.yaml-key { color: #93c5fd; }
.yaml-comment { color: #7f8b99; }

/* ---------------- controls ---------------- */
input {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn {
  font: inherit; color: var(--fg); background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  #sidebar { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--border); }
  body.sidebar-collapsed #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  body.sidebar-collapsed #sidebar { display: none; }
  #main { padding: 0 16px 40px; }
  #topbar { flex-wrap: wrap; }
}

/* ---------------- 세그먼트 버튼 ---------------- */
.top-tools { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 12px; color: var(--muted); background: var(--panel);
  border: 0; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--accent-bg); color: var(--accent); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------- 레이아웃: 그래프만 / 영상 + 그래프 ---------------- */
#content { display: block; position: relative; z-index: 0; }
#content-loading {
  position: fixed; z-index: 10;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .66); color: #fff; font-size: 15px; font-weight: 650;
  backdrop-filter: blur(1px);
}
.loading-status { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.loading-spinner {
  width: 26px; height: 26px; border: 3px solid rgba(255, 255, 255, .3);
  border-top-color: #fff; border-radius: 50%; animation: loading-spin .75s linear infinite;
}
@keyframes loading-spin { to { transform: rotate(360deg); } }
.split #content {
  display: grid; grid-template-columns: minmax(320px, 44%) minmax(0, 1fr); gap: 14px; align-items: start;
}
#graphs { min-width: 0; }

#video-pane {
  position: sticky; top: 64px; margin-top: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 80px);
}
.vp-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#v-info { font-size: 12px; }
.vp-frame {
  position: relative; background: #000; border-radius: 6px; overflow: hidden;
  aspect-ratio: 3 / 2; display: flex; align-items: center; justify-content: center;
}
#v-img { width: 100%; height: 100%; object-fit: contain; display: block; }
#v-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 16px; }
#v-empty:empty { display: none; }
#v-ctrl { display: flex; align-items: center; gap: 8px; }
#v-seek { flex: 1; min-width: 0; accent-color: var(--accent); padding: 0; }
#v-speed { font: inherit; font-size: 12px; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px; }
#v-source { font: inherit; font-size: 12px; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px; max-width: 180px; }
.follow #v-ctrl { display: none; }

/* ---------------- 동기화 3D 비행 뷰 ---------------- */
#scene-pane { display: flex; flex-direction: column; gap: 7px; min-height: 0; }
.scene-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; }
#scene-canvas { width: 100%; aspect-ratio: 4 / 3; background: #090c10; border-radius: 6px; overflow: hidden; cursor: grab; }
#scene-canvas:active { cursor: grabbing; }
#scene-canvas canvas { width: 100%; height: 100%; display: block; }
#scene-metrics { font-size: 12px; line-height: 1.35; }
.scene-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.scene-control-group { display: flex; align-items: center; gap: 8px; }
.scene-controls .seg button { padding: 4px 9px; }
.scene-toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; }
.scene-toggle input { accent-color: var(--accent); }
#balloon-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
#balloon-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
#balloon-form input { width: 100%; min-width: 0; padding: 8px 10px; font-size: 14px; }
#balloon-save { grid-column: 1 / -1; }

@media (max-width: 1000px) {
  .split #content { grid-template-columns: 1fr; }
  #video-pane { position: static; max-height: none; }
}
@media (max-width: 520px) {
  #balloon-form { grid-template-columns: 1fr; }
}
