:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel2: #232733;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #ff4d4f;
  --accent2: #2f6bff;
  --line: #2c313c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", system-ui, -apple-system, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
  font-size: 14px;
}

.app-header { padding: 16px 20px 4px; }
.app-header h1 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.app-header h1 .ico { color: var(--accent2); }
.app-header .sub { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.2fr);
  gap: 16px;
  padding: 16px 20px 32px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.pane { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

/* 검색 */
.search { position: relative; display: flex; gap: 8px; }
.search input {
  flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text);
}
.search button {
  padding: 0 14px; border-radius: 8px; border: 0; cursor: pointer;
  background: var(--accent2); color: #fff; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.results {
  position: absolute; top: 46px; left: 0; right: 0; z-index: 50;
  list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
}
.results:empty { display: none; }
.results li { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results li:hover { background: #2c3340; }
.results small { color: var(--muted); }

.map { width: 100%; height: 460px; margin-top: 10px; border-radius: 8px; overflow: hidden; }
.hint { color: var(--muted); margin: 8px 2px 0; font-size: 12px; }

/* 로드뷰 — 컨테이너는 반드시 nonzero 크기여야 렌더된다 */
.roadview {
  width: 100%; height: 360px; background: #000;
  border-radius: 8px; overflow: hidden;
}
/* 녹화 클린모드: 컨트롤 UI 숨김(SDK 버전에 따라 조정 가능) */
.rv-clean [class*="control"],
.rv-clean [class*="Control"],
.rv-clean [class*="zoom"],
.rv-clean [class*="Zoom"] { display: none !important; }

.controls { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
legend { color: var(--muted); padding: 0 6px; }

.motion-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.motion-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.motion-label { display: flex; align-items: center; gap: 8px; cursor: pointer; flex: 1; min-width: 0; }
.motion-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.motion-label input { width: 16px; height: 16px; flex: none; }
.motion-play {
  flex: none; width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: #7fd1ff; cursor: pointer; font-size: 11px; line-height: 1;
}
.motion-play:hover { background: #2c3340; }

.spec { display: flex; gap: 16px; flex-wrap: wrap; }
.spec label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.spec select, .spec input {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); min-width: 110px;
}

.opt-toggle { display: flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; font-size: 13px; }
.opt-toggle input { width: 16px; height: 16px; flex: none; }

/* 촬영 스타일 (맨 앞) */
.shoot-style { display: flex; flex-direction: column; gap: 8px; border-color: #3a4760; background: #1d2230; }
.handheld-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--text); font-size: 14px; padding: 6px 8px; border-radius: 8px; background: var(--panel2);
}
.handheld-row .ico { color: #7fd1ff; flex: none; }
.hh-label { flex: 1; min-width: 120px; }

/* 세그먼트 컨트롤 (끄기/디테일/중간/강함) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 600;
  border-left: 1px solid var(--line);
}
.seg button:first-child { border-left: 0; }
.seg button:hover { background: #2c3340; color: var(--text); }
.seg button.active { background: var(--accent2); color: #fff; }

.ico { vertical-align: middle; flex: none; }

.actions { display: flex; gap: 10px; }
.btn-primary, .btn-secondary {
  flex: 1; padding: 12px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary .ico { color: #fff; }
.btn-secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn-secondary.btn-stop { background: #b54708; color: #fff; border-color: #b54708; }
.btn-secondary.btn-stop .ico { color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }

progress { width: 100%; height: 8px; }
.status { margin: 0; color: var(--text); min-height: 18px; }
.note { color: var(--muted); font-size: 12px; margin: 0; line-height: 1.5; }

.downloads { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.downloads:empty { display: none; }
.dl-row { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.dl-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px; color: #7fd1ff; text-decoration: none; font-weight: 600; }
.dl-video { width: 100%; max-width: 480px; border-radius: 8px; background: #000; display: block; }

/* 녹화 중: 로드뷰를 뷰포트 전체에 깔아 "이 탭" 캡처에 로드뷰만 담기게 함
   (Fullscreen API 와 달리 권한 창이 떠도 해제되지 않음).
   카카오 SDK 가 #roadview 에 인라인 position 을 넣으므로 전부 !important 로 덮는다. */
#roadview.rv-recording {
  position: fixed !important;
  top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
  width: 100vw !important; height: 100vh !important;
  z-index: 2147483647 !important; background: #000 !important; border-radius: 0 !important;
}

/* 서버(헤드리스) 렌더: 로드뷰만 전체화면으로 */
body.headless #roadview {
  position: fixed !important;
  top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
  width: 100vw !important; height: 100vh !important;
  z-index: 99999 !important; background: #000 !important; border-radius: 0 !important;
}
