/* 초음파는 어두운 화면에서 보는 것이 표준이다. 주변 UI가 밝으면 동공이
   조여서 저휘도 영역의 경계가 안 보인다. 전체를 어둡게 유지한다. */

:root {
  --bg: #0d1013;
  --panel: #151a1f;
  --panel-2: #1c232a;
  --line: #2a333c;
  --text: #dfe6ec;
  --text-dim: #8b99a6;
  --accent: #4dd0e1;
  --accent-warm: #ffb74d;
  --auto: #8b7bea;
  --danger: #ff5f6d;
  --ok: #66bb6a;
  --radius: 6px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 system-ui, "Malgun Gothic", -apple-system, sans-serif;
  overflow: hidden;
}

kbd {
  font: 11px/1 var(--mono);
  background: #0a0d10; border: 1px solid var(--line);
  border-radius: 3px; padding: 2px 4px; color: var(--text-dim);
}

button {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px; cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: #252e37; border-color: #3a4753; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: #1c4b52; border-color: #2b6f79; }
button.primary:hover:not(:disabled) { background: #226069; }
button.active { background: #1c4b52; border-color: var(--accent); color: #fff; }
button.mini { padding: 4px 7px; }

input[type=search], input[type=text], textarea, select {
  font: inherit; color: var(--text);
  background: #0a0d10; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 5px 7px; width: 100%;
}
textarea { resize: vertical; font-size: 12px; }
input[type=range] { accent-color: var(--accent); width: 56px; }

#app { display: grid; grid-template-columns: 216px 1fr 286px; height: 100%; }

/* ------------------------------------------------------------ 좌측 목록 */

#sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head { padding: 12px 12px 10px; border-bottom: 1px solid var(--line); }
.head-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.panel-head h1 { margin: 0; font-size: 13px; letter-spacing: .02em; font-weight: 600; flex: 1; }
#user-chip {
  font-size: 10.5px; padding: 3px 7px; max-width: 84px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.counter { font: 10.5px var(--mono); color: var(--text-dim); margin-bottom: 5px; }
.progress-bar { height: 3px; background: #0a0d10; border-radius: 2px; overflow: hidden; display: flex; }
#progress-fill { height: 100%; width: 0; background: var(--ok); transition: width .25s; }
#progress-auto { height: 100%; width: 0; background: var(--auto); transition: width .25s; }
.progress-bar.big { height: 6px; margin: 12px 0; }
#upload-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.upload-row { display: flex; gap: 5px; padding: 9px 10px 5px; }
.upload-row #upload-btn { flex: 1; }
#upload-note {
  padding: 0 10px 9px; font-size: 10.5px; line-height: 1.45;
  color: #6b7883; border-bottom: 1px solid var(--line);
}

.filter-row { display: flex; gap: 5px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.filter-row select { width: 84px; flex: none; font-size: 11px; padding: 5px 3px; }

#image-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
#image-list .group-head {
  padding: 8px 12px 4px; font: 10px/1.4 var(--mono);
  color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em;
}
#image-list li.item {
  padding: 5px 12px; cursor: pointer; display: flex; align-items: center; gap: 7px;
  border-left: 2px solid transparent;
}
#image-list li.item:hover { background: var(--panel-2); }
#image-list li.item.active { background: #1a2b30; border-left-color: var(--accent); }
#image-list .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #39434d; }
#image-list .dot.auto { background: var(--auto); }
#image-list .dot.in_progress { background: var(--accent-warm); }
#image-list .dot.done { background: var(--ok); }
#image-list .dot.skip { background: #6d7b88; }
#image-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
#image-list .n { font: 10px var(--mono); color: var(--text-dim); }
#image-list .lowconf {
  font: 700 9px var(--mono); color: #0d1013; background: var(--accent-warm);
  border-radius: 50%; width: 12px; height: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
}

/* -------------------------------------------------------------- 중앙 */

#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* 검토 액션 바 — 화면에서 가장 눈에 띄어야 하는 곳 */
#review-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 14px; min-height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
#review-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
#review-actions { display: flex; align-items: center; gap: 6px; flex: none; }
#review-actions button { padding: 7px 13px; font-size: 13px; }
#review-actions button.go {
  background: #1c5a34; border-color: #2f8a4f; color: #eafff0; font-weight: 600;
}
#review-actions button.go:hover:not(:disabled) { background: #23713f; }
#review-actions button.warn { border-color: #6b4a1c; }

.rv-badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.rv-badge.auto  { background: #2b2456; color: #c6bcff; }
.rv-badge.done  { background: #16321c; color: #a5d6a7; }
.rv-badge.empty { background: #33261a; color: #ffcc80; }
.rv-badge.edit  { background: #1c4b52; color: #b2ebf2; }
.rv-badge.busy  { background: #2a3138; color: #a9b8c4; }
.rv-detail { font: 11.5px var(--mono); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-detail b { color: var(--text); font-weight: 600; }
.rv-warn { color: var(--accent-warm); }

#canvas-wrap { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 도구 막대는 캔버스 위에 떠 있게 해서 세로 공간을 아낀다 */
#toolbar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; flex-wrap: nowrap;
  padding: 5px 8px; border-radius: 8px;
  background: rgba(16,21,26,.9); border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.tool-group { display: flex; align-items: center; gap: 3px; }
.tool-sep { width: 1px; height: 18px; background: var(--line); }
.tool-group.adjust label {
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-dim);
}
.tool-btn { display: flex; align-items: center; gap: 5px; font-size: 12px; padding: 5px 9px; }
.tool-btn .k { font: 10px var(--mono); color: var(--text-dim); }
.tool-btn.active .k { color: #cdeef2; }
.label-btn { display: flex; align-items: center; gap: 5px; font-size: 12px; padding: 5px 9px; }
.label-btn .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

#hud {
  position: absolute; top: 10px; left: 10px; pointer-events: none;
  font: 11px/1.6 var(--mono); color: #9fb4c2; text-shadow: 0 1px 3px #000;
}

/* 모드 배너 — 지금 클릭이 무슨 뜻인지 알려준다 */
#mode-banner {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px; border-radius: 8px; font-size: 12.5px;
  background: rgba(27,44,52,.95); border: 1px solid var(--accent);
  color: #d3f0f5; box-shadow: 0 4px 18px rgba(0,0,0,.45);
  pointer-events: none;   /* 안내일 뿐이므로 밑의 캔버스 클릭을 막지 않는다 */
}
#mode-banner.hidden { display: none; }
#mode-banner .mb-key {
  display: inline-flex; align-items: center; gap: 5px;
}
#mode-banner .swatch-dot { width: 9px; height: 9px; border-radius: 50%; }
#mode-banner .pos { background: var(--ok); }
#mode-banner .neg { background: var(--danger); }

#hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  pointer-events: none; font-size: 12px; color: #b9c8d4;
  background: rgba(10,13,16,.86); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 14px; opacity: 0; transition: opacity .2s;
}
#hint.show { opacity: 1; }

/* 계산 중 표시. 클릭을 가로채면 안 된다 — SAM 재계산은 수십 ms라
   연속으로 점을 찍는 동안 오버레이가 떴다 사라지는데, 그 사이 클릭이
   오버레이에 먹히면 입력이 조용히 사라진다. */
#loading {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 46px; gap: 10px; font-size: 12px; color: var(--text-dim);
  pointer-events: none;
}
#loading > * {
  background: rgba(10,13,16,.86); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 14px;
}
#loading .spinner { padding: 0; border-radius: 50%; }
#loading.hidden { display: none; }
.spinner {
  width: 15px; height: 15px; border: 2px solid var(--line) !important;
  border-top-color: var(--accent) !important; border-radius: 50%;
  animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

#statusbar {
  display: flex; align-items: center; gap: 14px;
  padding: 5px 12px; background: var(--panel); border-top: 1px solid var(--line);
  font: 11px var(--mono); color: var(--text-dim); min-height: 26px;
}
#save-state.dirty { color: var(--accent-warm); }
#save-state.saved { color: var(--ok); }
#precompute-status.working { color: var(--accent); }
#precompute-status.ready { color: var(--ok); }
#precompute-status.failed { color: var(--danger); }

/* ------------------------------------------------------------ 우측 패널 */

#inspector {
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; min-height: 0;
}
#inspector section { padding: 11px 12px; border-bottom: 1px solid var(--line); }
#inspector h2 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.badge {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 0 6px; font: 10px var(--mono); color: var(--text-dim);
}

.fold { border-bottom: 1px solid var(--line); }
.fold > summary {
  padding: 10px 12px; cursor: pointer; list-style: none;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-dim);
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: '▸ '; }
.fold[open] > summary::before { content: '▾ '; }
.fold > summary:hover { color: var(--text); }
.fold-body { padding: 0 12px 12px; }

.empty-note, .empty-note-list:empty::after {
  font-size: 11.5px; color: #6b7883; line-height: 1.55; display: block;
}
.empty-note-list:empty::after { content: attr(data-empty); }
#shape-list, #measure-list { list-style: none; margin: 0; padding: 0; }
#shape-list li, #measure-list li {
  display: flex; align-items: center; gap: 7px; padding: 5px 6px;
  border-radius: var(--radius); cursor: pointer; font-size: 12px;
}
#shape-list li:hover, #measure-list li:hover { background: var(--panel-2); }
#shape-list li.selected { background: #1a2b30; outline: 1px solid var(--accent); }
#shape-list .swatch, #measure-list .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
#shape-list .meta, #measure-list .meta { margin-left: auto; font: 10.5px var(--mono); color: var(--text-dim); }
.row-del { background: none; border: none; color: #6b7883; padding: 1px 4px; font-size: 13px; }
.row-del:hover { color: var(--danger); background: none; }

/* 결과 패널 */
.result-why {
  background: var(--panel-2); border-radius: var(--radius);
  padding: 8px 9px; margin-bottom: 8px;
}
.result-why .rw-head {
  font-size: 11.5px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
.result-why .rw-head .tag {
  font: 10px var(--mono); padding: 1px 5px; border-radius: 3px;
}
.tag.high { background: #1a3a2a; color: #a5d6a7; }
.tag.low  { background: #3a3115; color: #ffd54f; }
.tag.none { background: #33272a; color: #ffab91; }
.rw-metrics { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 11px; }
.rw-metrics dt { color: var(--text-dim); }
.rw-metrics dd { margin: 0; font-family: var(--mono); }
.rw-bar { height: 3px; background: #0a0d10; border-radius: 2px; margin-top: 2px; overflow: hidden; }
.rw-bar > div { height: 100%; background: var(--accent); }
.result-reason {
  font-size: 11px; line-height: 1.5; color: #7f8d99;
  border-left: 2px solid #3a4753; padding-left: 7px; margin-bottom: 8px;
}

/* 후보 카드 */
.cand-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 7px; }
.cand {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer; font-size: 12px;
}
.cand:hover { border-color: #3f4d59; }
.cand.active { border-color: var(--accent); background: #1a2b30; }
.cand .idx { font: 10px var(--mono); color: var(--text-dim); }
.cand .size { font: 11px var(--mono); }
.cand .strategy {
  font: 9.5px var(--mono); color: #7f8d99;
  border: 1px solid var(--line); border-radius: 3px; padding: 0 4px;
}
.cand .pts { margin-left: auto; font: 10px var(--mono); color: var(--text-dim); }
.cand.pick { outline: 1px solid var(--auto); }
.panel-actions { display: flex; gap: 5px; margin-top: 7px; }
.panel-actions button { flex: 1; font-size: 12px; }
.caveat {
  margin-top: 8px; font-size: 11px; line-height: 1.5; color: #7f8d99;
  border-left: 2px solid #3a4753; padding-left: 7px;
}

#vp-verdict { margin-top: 8px; font-size: 12px; }
.verdict { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius); }
.verdict.normal   { background: #16321c; color: #a5d6a7; }
.verdict.mild     { background: #3a3115; color: #ffd54f; }
.verdict.moderate { background: #40270f; color: #ffb74d; }
.verdict.severe   { background: #3d1a1e; color: #ff8a80; }

.status-line { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.status-line label { font-size: 11px; color: var(--text-dim); flex: none; }
.status-line select { font-size: 12px; padding: 4px 6px; }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 5px; }
.check input { width: auto; }
#export-btn { width: 100%; margin-top: 6px; }
#export-result { margin-top: 8px; font: 11px/1.55 var(--mono); color: var(--text-dim); white-space: pre-wrap; }

#meta-list { margin: 0; font-size: 11.5px; }
#meta-list dt { color: var(--text-dim); font-size: 10.5px; margin-top: 5px; }
#meta-list dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-all; }
#phi-note {
  margin-top: 10px; padding: 7px 8px; border-radius: var(--radius);
  font-size: 11px; line-height: 1.5;
}
#phi-note.safe { background: #16261c; color: #94c79a; }
#phi-note.warn { background: #3d1a1e; color: #ff9a95; }

/* ------------------------------------------------------- 드래그 · 업로드 */

#drop-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5,7,9,.86); display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#drop-overlay.hidden { display: none; }
.drop-sheet {
  border: 2px dashed var(--accent); border-radius: 14px; padding: 44px 66px;
  text-align: center; color: var(--text); font-size: 15px;
  background: rgba(21,26,31,.9);
}
.drop-icon { font-size: 38px; color: var(--accent); margin-bottom: 10px; }
.drop-sub { margin-top: 8px; font-size: 12px; color: var(--text-dim); }

/* 로그인 · 비밀번호 변경 · 충돌 */
#login-overlay, #conflict-overlay, #password-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(5,7,9,.92); display: flex; align-items: center; justify-content: center;
}
#login-overlay.hidden, #conflict-overlay.hidden, #password-overlay.hidden { display: none; }
/* 로그인 위에 겹칠 수 있어야 한다 — 첫 로그인 직후에 뜬다. */
#password-overlay { z-index: 71; }
#password-error {
  font-size: 12px; color: var(--danger); min-height: 16px; line-height: 1.4;
}
#password-submit { padding: 9px; font-size: 13px; }
#password-cancel {
  padding: 7px; font-size: 12px; background: none; border-color: var(--line);
}
#password-cancel.hidden { display: none; }
.sheet.login { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.sheet.login h2 { margin: 0; font-size: 15px; }
.login-sub { margin: 0; font-size: 12px; color: var(--text-dim); }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--text-dim); }
.field input { font-size: 13px; padding: 7px 9px; }
#login-error {
  font-size: 12px; color: var(--danger); min-height: 16px; line-height: 1.4;
}
#login-submit { padding: 9px; font-size: 13px; }
#login-setup {
  font-size: 11.5px; line-height: 1.6; color: var(--accent-warm);
  border-left: 2px solid var(--accent-warm); padding-left: 9px;
}
#login-setup.hidden { display: none; }
#login-setup code {
  display: block; margin-top: 5px; font: 11px var(--mono); color: var(--text);
}

#conflict-overlay .sheet { max-width: 460px; }
#conflict-overlay p { font-size: 12.5px; line-height: 1.6; margin: 0 0 10px; }
.conflict-note { color: var(--accent-warm); }
.warn-btn { background: #4a2320; border-color: #7a3a34; }
.warn-btn:hover:not(:disabled) { background: #5c2c28; }
.btn-row { display: flex; gap: 6px; }
.btn-row button { flex: 1; }

/* 목록의 점유 표시 */
#image-list .holder {
  font: 9.5px var(--mono); color: #0d1013; background: var(--accent-warm);
  border-radius: 3px; padding: 1px 4px; flex: none; max-width: 52px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#image-list li.item.locked .name { opacity: .6; }

#upload-overlay, #shortcut-overlay, #intro-overlay {
  position: fixed; inset: 0; z-index: 61;
  background: rgba(5,7,9,.82); display: flex; align-items: center; justify-content: center;
}
#upload-overlay.hidden, #shortcut-overlay.hidden, #intro-overlay.hidden { display: none; }
.sheet {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 20px 24px; max-width: 760px;
}
.sheet h2 { margin: 0 0 14px; font-size: 14px; }
#upload-overlay .sheet { min-width: 440px; max-width: 640px; }
#upload-detail {
  font: 11.5px/1.6 var(--mono); color: var(--text-dim);
  white-space: pre-wrap; max-height: 320px; overflow-y: auto;
}
#upload-close.hidden { display: none; }

.cols { display: flex; gap: 30px; }
.cols dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; align-items: baseline; }
.cols dt { font: 11px var(--mono); color: var(--accent); white-space: nowrap; }
.cols dd { margin: 0; font-size: 12px; color: var(--text-dim); }
#close-shortcuts { margin-top: 18px; }

.sheet.intro { max-width: 560px; }
.intro-steps { margin: 0 0 14px; padding-left: 20px; }
.intro-steps li { margin-bottom: 10px; font-size: 13px; line-height: 1.6; color: var(--text); }
.intro-note {
  margin: 0 0 16px; font-size: 12px; line-height: 1.6; color: var(--text-dim);
  border-left: 2px solid var(--auto); padding-left: 9px;
}
#intro-close { width: 100%; }
