:root {
  --bg: #1a1d23;
  --panel: #23272f;
  --panel-hi: #2c313a;
  --border: #363b45;
  --text: #d8dce3;
  --text-dim: #8a92a0;
  --accent: #4a9eff;
  --accent-hi: #6bb0ff;
  --ok: #3ecf6b;
  --err: #ff5f56;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 16px; font-weight: 600; }

.status { font-size: 13px; margin-left: auto; }
.status.connected { color: var(--ok); }
.status.disconnected { color: var(--err); }

.layout { flex: 1; display: flex; min-height: 0; }

/* 헤더 뷰 탭 (레이아웃 ↔ 에이전트 전체화면 전환) */
.view-tabs { display: inline-flex; gap: 4px; margin-left: 18px; }
.view-tab {
  padding: 5px 16px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.view-tab:hover { background: var(--panel-hi); color: var(--text); }
.view-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 본문 뷰: active만 표시 */
.view { display: none; flex: 1; min-height: 0; min-width: 0; }
.view.active { display: flex; }

/* 좌측 패널 */
.panel {
  width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}
.panel section { margin-bottom: 22px; }
.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.count { color: var(--accent); font-weight: 600; }

/* 레이어 정렬 토글 */
.layer-sort {
  margin-left: auto;
  display: inline-flex;
  gap: 2px;
}
.layer-sort button {
  padding: 2px 7px;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.layer-sort button:hover { background: var(--panel-hi); color: var(--text); }
.layer-sort button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }

button {
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: var(--accent-hi); }
button:active { transform: translateY(1px); }

.summary {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
}
.summary b { color: var(--text); }

.list { list-style: none; font-size: 13px; }
.list li {
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.list li:hover { background: var(--panel-hi); }
.list li.active { background: var(--accent); color: #fff; }
.list .meta { color: var(--text-dim); font-size: 11px; }
.list li.active .meta { color: rgba(255,255,255,0.8); }

.layers .swatch {
  width: 12px; height: 12px; border-radius: 2px;
  display: inline-block;
  border: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
  cursor: pointer;
}
.layers li { align-items: center; }
.layer-left  { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; overflow: hidden; }
.layer-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-left: 4px; }
.layer-name  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.layer-name:hover { text-decoration: underline dotted; }
.swatch-wrap { display: flex; align-items: center; gap: 2px; position: relative; flex-shrink: 0; }
.color-picker {
  position: absolute; opacity: 0; width: 1px; height: 1px;
  pointer-events: none;
}
.frame-indicator {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid #888; cursor: pointer; flex-shrink: 0;
  transition: transform 0.1s;
}
.frame-indicator:hover { transform: scale(1.3); }
.stipple-btn {
  background: none; border: none; cursor: pointer;
  color: #aaa; font-size: 12px; padding: 0 1px;
  line-height: 1; flex-shrink: 0;
}
.stipple-btn:hover { color: var(--text); }
.stipple-popup {
  position: fixed; z-index: 2000;
  display: grid; grid-template-columns: repeat(5, 26px);
  gap: 4px; padding: 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.5);
}
.stipple-swatch {
  width: 26px; height: 26px;
  border: 1px solid #555; border-radius: 3px;
  cursor: pointer; background-size: 8px 8px !important;
}
.stipple-swatch:hover { border-color: var(--accent); }
.stipple-swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.name-edit {
  width: 90px; font-size: 12px;
  background: var(--panel-hi); color: var(--text);
  border: 1px solid var(--accent); border-radius: 3px;
  padding: 1px 4px;
}
.eye-btn {
  background: none; border: none; cursor: pointer;
  font-size: 13px; padding: 0 2px; opacity: 0.7;
  line-height: 1;
}
.eye-btn:hover { opacity: 1; }
.layers li.layer-hidden { opacity: 0.4; }

/* 우측 뷰어 */
.viewer { flex: 1; display: flex; flex-direction: column; min-width: 0; }
/* 레이아웃 탭 */
.layout-tabs {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--border);
  min-height: 0; flex-shrink: 0;
}
.layout-tabs:empty { display: none; }
.layout-tab {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; cursor: pointer; white-space: nowrap;
  border-right: 1px solid var(--border); font-size: 12px;
  color: #aaa; user-select: none;
}
.layout-tab:hover { background: var(--panel-hi); color: var(--text); }
.layout-tab.active { background: var(--panel-hi); color: var(--accent); border-bottom: 2px solid var(--accent); }
.tab-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  background: none; border: none; cursor: pointer;
  color: #666; font-size: 14px; line-height: 1; padding: 0 2px;
  border-radius: 3px;
}
.tab-close:hover { background: #555; color: var(--text); }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.vp-info { margin-left: auto; font-size: 12px; color: var(--text-dim); }

/* depth 입력 */
.depth-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.depth-input {
  width: 58px;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  text-align: center;
  -moz-appearance: textfield;
}
.depth-input::-webkit-inner-spin-button,
.depth-input::-webkit-outer-spin-button { opacity: 0.4; }
.depth-input:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--accent);
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas { max-width: 100%; max-height: 100%; image-rendering: pixelated; cursor: default; }

.loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.7);
  padding: 10px 16px;
  border-radius: 6px;
  color: var(--accent-hi);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}
.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.load-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}
.load-progress-fill {
  height: 100%;
  background: var(--accent-hi);
  border-radius: 2px;
  width: 0%;
  transition: width 0.15s ease;
}
.loading #btn-interrupt {
  background: rgba(255,80,80,0.25);
  border: 1px solid rgba(255,80,80,0.5);
  color: #ff6060;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.hidden { display: none; }

/* 버튼 행 */
.btn-row { display: flex; gap: 8px; }
.btn-row button { flex: 1; }
#btn-browse { background: var(--panel-hi); }
#btn-browse:hover { background: var(--border); }

/* 파일 브라우저 모달 */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
/* .modal 보다 구체적이어야 hidden이 이긴다 (두 클래스 셀렉터) */
.modal.hidden { display: none; }
.modal-box {
  width: 560px; max-width: 90vw; max-height: 75vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 14px; }
.icon-btn {
  background: transparent; color: var(--text-dim);
  padding: 2px 8px; font-size: 16px;
}
.icon-btn:hover { background: var(--panel-hi); color: var(--text); }

.browser-path {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  word-break: break-all;
  font-family: ui-monospace, monospace;
}
.browser-list {
  list-style: none;
  overflow-y: auto;
  padding: 8px;
}
.browser-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}
.browser-list li:hover { background: var(--panel-hi); }
.browser-list .ico { width: 18px; text-align: center; }
.browser-list .fsize { margin-left: auto; color: var(--text-dim); font-size: 11px; }
.browser-list li.dir .name { color: var(--accent-hi); }
.browser-list li.up .name { color: var(--text-dim); }

/* ── 헤더 우측 설정 버튼 ─────────────────────────────────────────────── */
.header-settings { margin-left: 12px; font-size: 16px; }

/* ── 에이전트 뷰: 대화 기록 사이드바 + 전체폭 채팅 ──────────────────── */
.chat-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.chat-session-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.chat-session-item {
  padding: 8px 10px;
  margin-bottom: 3px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-session-item:hover { background: var(--panel-hi); }
.chat-session-item.active { background: var(--panel-hi); color: var(--accent); }
.chat-session-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-session-del {
  flex-shrink: 0;
  opacity: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.chat-session-item:hover .chat-session-del { opacity: 0.7; }
.chat-session-del:hover { opacity: 1; color: var(--err); }

.chat-main {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.chat-head h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;       /* 전체폭에서 가독성 컬럼 가운데 정렬 */
}
.chat-msg {
  max-width: 92%;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--panel-hi);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-msg.assistant table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12px;
}
.chat-msg.assistant th, .chat-msg.assistant td {
  border: 1px solid var(--border);
  padding: 2px 6px;
}
.chat-msg.assistant code {
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

/* ──────────────────────────────────────────────────────────────
   레이아웃/레이어 트리뷰
────────────────────────────────────────────────────────────── */
.tree-section { margin-bottom: 0; }
.tree-section h2 { display: flex; align-items: center; justify-content: space-between; }

.layout-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
}

/* 레이아웃 루트 노드 */
.tree-layout { margin-bottom: 2px; }
.tree-layout-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  border-radius: 4px;
  cursor: default;
  user-select: none;
}
.tree-layout-row:hover { background: var(--panel-hi); }
.tree-layout-row.active-layout { background: var(--panel-hi); border-left: 2px solid var(--accent); }

.tree-toggle {
  width: 14px;
  flex-shrink: 0;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  text-align: center;
}
.tree-layout-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.tree-layout-actions {
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.1s;
}
.tree-layout-row:hover .tree-layout-actions { opacity: 1; }
.tree-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11px;
  padding: 1px 3px;
  border-radius: 3px;
}
.tree-action-btn:hover { background: var(--border); color: var(--text); }

/* 레이어 서브리스트 */
.tree-layers {
  list-style: none;
  padding-left: 18px;
  margin: 0;
}

/* 레이어 노드 */
.tree-layer-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: default;
}
.tree-layer-row:hover { background: var(--panel-hi); }

/* 가시성 체크박스 */
.vis-cb {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

/* 숨김 상태 */
.tree-layout-row.layout-hidden { opacity: 0.4; }
.tree-layer-row.layer-hidden { opacity: 0.35; }

.tree-layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}
.tree-layer-meta {
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ──────────────────────────────────────────────────────────────
   셀 계층 패널
────────────────────────────────────────────────────────────── */
.cell-hier-section {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 6px;
}
.cell-hier-section h2 { display: flex; align-items: center; justify-content: space-between; }
.cell-hier-name {
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 3px;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

.cell-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  max-height: 300px;
  overflow-y: auto;
}
.cell-tree ul {
  list-style: none;
  padding-left: 14px;
  margin: 0;
}
.cell-tree li { padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-tree .cell-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: default;
}
.cell-tree .cell-node:hover { background: var(--panel-hi); }
.cell-tree .cell-toggle {
  width: 12px;
  flex-shrink: 0;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 9px;
  text-align: center;
}
.cell-tree .cell-name { font-weight: 600; color: var(--text); }
.cell-tree .cell-count { color: var(--text-dim); font-size: 10px; }

/* 도구 실행 칩 */
.chat-tool {
  align-self: flex-start;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  max-width: 92%;
}
.chat-tool .tool-name { color: var(--accent-hi); font-weight: 600; }
.chat-tool.err .tool-name { color: var(--err); }
.chat-tool .tool-sum { color: var(--text-dim); }

/* 인라인 렌더 이미지 */
.chat-img {
  align-self: flex-start;
  max-width: 100%;
}
.chat-img img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: block;
}
.chat-img .cap { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* 입력 행 */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  width: 100%;
  max-width: 900px;
  margin: 0 auto;       /* 메시지 컬럼과 폭 정렬 */
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); }
.chat-input-row button { align-self: stretch; padding: 0 16px; }
.chat-busy { color: var(--text-dim); font-size: 12px; align-self: flex-start; }

/* ── 설정 모달 ───────────────────────────────────────────────────────── */
.settings-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.settings-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.settings-field > span { color: var(--text-dim); }
.settings-field select,
.settings-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
.settings-field select:focus,
.settings-field input:focus { outline: none; border-color: var(--accent); }
.settings-hint { color: var(--text-dim); font-size: 11px; }
.settings-hint.ok { color: var(--ok); }
.settings-actions { display: flex; justify-content: flex-end; }

/* settings-field가 flex라 .hidden(display:none)을 이기지 못하므로 명시 */
.settings-field.hidden { display: none; }

/* 채팅 헤더 현재 프로바이더·모델 배지 */
.chat-head { gap: 8px; }
.agent-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-badge:hover { background: var(--panel-hi); color: var(--text); }
.agent-badge.ready { color: var(--ok); border-color: var(--ok); }
.agent-badge.unset { color: var(--err); border-color: var(--err); }

/* ── 계측 도구 패널 ──────────────────────────────────────────────────── */
.measure-panel {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 270px;
  max-height: calc(100% - 8px);
  overflow-y: auto;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  font-size: 12px;
}
.measure-panel.hidden { display: none; }

.measure-head {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
}
.measure-title { font-weight: 600; font-size: 13px; flex: 1; }

.measure-mode-bar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.mode-btn {
  flex: 1;
  font-size: 11px;
  padding: 4px 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
}
.mode-btn:hover { background: var(--panel-hi); }
.mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.measure-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.ms-field {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 11px;
}
.ms-input-sm {
  width: 46px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 2px 4px;
  font-size: 11px;
}
.ms-sel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  padding: 1px 2px;
}

.measure-group { border-bottom: 1px solid var(--border); }
.measure-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  color: var(--text-dim);
  font-size: 11px;
}
.measure-io-btns { display: flex; gap: 3px; }
.mio-btn {
  font-size: 10px;
  padding: 2px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
}
.mio-btn:hover { color: var(--text); background: var(--panel-hi); }

.measure-list { list-style: none; padding: 0; margin: 0; }
.measure-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-bottom: 1px solid #222;
  font-size: 11px;
}
.measure-item:hover { background: #242424; }
.measure-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}
.measure-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.measure-comment {
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 10px;
}
.measure-goto, .measure-del {
  font-size: 10px;
  padding: 1px 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}
.measure-goto:hover { color: var(--accent); }
.measure-del:hover  { color: var(--err); }

.measure-footer {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  justify-content: flex-end;
}

/* 페이지네이션 컨트롤 */
.measure-page-ctrl {
  display: flex;
  align-items: center;
  gap: 3px;
}
.ms-page-label {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 28px;
  text-align: center;
}

/* 인라인 편집 가능 필드 커서 */
.measure-swatch[data-edit-id]  { cursor: pointer; }
.measure-comment[data-edit-id] { cursor: text; }

/* 계측 모드 커서 */
.measure-cursor { cursor: crosshair !important; }

/* 계측 다이얼로그 좌표 필드 */
.mdlg-coords { padding: 8px 16px 0; }
.mdlg-coord-row { display: flex; gap: 12px; margin-bottom: 8px; }
.mdlg-coord-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.mdlg-coord-input {
  width: 90px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 12px;
}

/* ── 스케일 바 ── */
.scale-bar {
  position: absolute;
  top: 8px; left: 8px;
  pointer-events: none;
  display: none;
}
.scale-line {
  height: 8px;
  border-left: 1.5px solid rgba(255,255,255,0.9);
  border-right: 1.5px solid rgba(255,255,255,0.9);
  border-bottom: 1.5px solid rgba(255,255,255,0.9);
  width: 80px;
}
.scale-label {
  display: block;
  text-align: center;
  font-size: 11px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 0 3px rgba(0,0,0,1), 0 0 3px rgba(0,0,0,1);
  margin-top: 2px;
}

/* ── 커서 좌표 ── */
.cursor-coords {
  position: fixed;
  pointer-events: none;
  font-size: 11px;
  font-family: monospace;
  background: rgba(0,0,0,0.72);
  color: #e8e8e8;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  z-index: 200;
  display: none;
}

/* ── 로그 패널 ── */
.log-toggle-btn {
  font-size: 12px;
  padding: 3px 8px;
  background: var(--panel-hi);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  margin-left: 8px;
}
.log-toggle-btn.active, .log-toggle-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.log-panel {
  background: rgba(20, 22, 28, 0.97);
  border-bottom: 1px solid var(--border);
  max-height: 150px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.log-panel-head {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.log-panel-head span { flex: 1; }
.log-list {
  overflow-y: auto;
  padding: 4px 0;
  font-size: 11px;
  font-family: monospace;
  flex: 1;
}
.log-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  list-style: none;
}
.log-item.log-ok  { color: var(--text); }
.log-item.log-err { color: var(--err); }
.log-time  { color: var(--text-dim); flex-shrink: 0; }
.log-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-meta  { color: var(--text-dim); flex-shrink: 0; font-size: 10px; }

/* ── 빠른 미리보기 (peek) ─────────────────────────────────────────────── */
.peek-box { width: min(680px, 92vw); max-height: 84vh; display: flex; flex-direction: column; }
.peek-eye {
  background: none; border: none; cursor: pointer; font-size: 14px;
  padding: 0 4px; opacity: .55; margin-left: 6px;
}
.peek-eye:hover { opacity: 1; }
.peek-summary {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px;
}
.peek-badge {
  font-weight: 600; font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--panel-hi); color: var(--text-dim); border: 1px solid var(--border);
}
.peek-badge.ok { background: rgba(62,207,107,.15); color: var(--ok); border-color: var(--ok); }
.peek-stat { color: var(--text-dim); }
.peek-stat b { color: var(--text); font-weight: 600; }
.peek-dim { color: var(--text-dim); }
.peek-bad { color: var(--err); }
.peek-body { overflow: auto; padding: 8px 12px; flex: 1; }
.peek-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.peek-table th {
  text-align: left; color: var(--text-dim); font-weight: 500;
  border-bottom: 1px solid var(--border); padding: 4px 6px; position: sticky; top: 0;
  background: var(--panel);
}
.peek-table td { padding: 3px 6px; border-bottom: 1px solid var(--border); }
.peek-cname { color: var(--text); }
.peek-bbox { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.peek-num { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.peek-top {
  font-size: 9px; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 0 4px; margin-left: 4px;
}
.peek-layers, .peek-names { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.peek-chip {
  font-size: 11px; padding: 1px 7px; border-radius: 8px;
  background: var(--panel-hi); color: var(--text); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.peek-note { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: 4px 0 10px; }
.peek-note code { background: var(--panel-hi); padding: 1px 5px; border-radius: 4px; color: var(--accent); }
.peek-foot { padding: 10px 12px; border-top: 1px solid var(--border); text-align: right; }
.peek-foot .primary {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 7px 16px; cursor: pointer; font-weight: 600;
}
.peek-foot .primary:hover { background: var(--accent-hi); }

/* ── 조작 도움말 패널 (플로팅) ─────────────────────────────── */
.help-panel {
  position: absolute; top: 6px; right: 6px; z-index: 25;
  width: 260px; background: var(--panel, #23272f);
  border: 1px solid var(--border, #363b45); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45); font-size: 12.5px;
}
.help-panel.hidden { display: none; }
.help-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-bottom: 1px solid var(--border, #363b45);
  color: var(--text-dim, #8a92a0); font-weight: 600;
}
.help-list { list-style: none; margin: 0; padding: 8px 10px; }
.help-list li {
  display: flex; align-items: center; gap: 10px; padding: 5px 0;
  color: var(--text, #e6eaf2);
}
.help-list kbd {
  flex: 0 0 auto; min-width: 58px; text-align: center;
  background: #11151f; border: 1px solid var(--border, #363b45);
  border-radius: 5px; padding: 3px 7px; font-size: 11.5px; font-family: inherit;
  color: var(--accent, #5b8cff);
}
.help-list li span { color: var(--text-dim, #9aa6bd); }

/* ── 사이드 패널 리사이즈 + 접기 ───────────────────────────── */
.panel, .chat-sidebar { position: relative; flex: 0 0 auto; }
.panel.collapsed, .chat-sidebar.collapsed {
  width: 0 !important; min-width: 0 !important; padding: 0 !important;
  border: 0 !important; overflow: hidden !important;
}
.side-resizer {
  flex: 0 0 6px; align-self: stretch; cursor: col-resize;
  background: var(--border, #363b45); transition: background .12s;
}
.side-resizer:hover { background: var(--accent, #5b8cff); }
.side-toggle {
  background: transparent; border: 1px solid var(--border, #363b45);
  color: var(--text-dim, #8a92a0); border-radius: 5px; cursor: pointer;
  font-size: 11px; line-height: 1; padding: 3px 7px;
}
.panel > .side-toggle { position: absolute; top: 8px; right: 8px; z-index: 6; }
.side-reopen {
  align-self: stretch; flex: 0 0 18px; background: var(--panel, #23272f);
  border: 0; border-right: 1px solid var(--border, #363b45);
  color: var(--accent, #5b8cff); cursor: pointer; font-size: 11px; padding: 0;
}
.side-reopen:hover { background: #1a1f2b; }
.side-reopen.hidden, .side-toggle.hidden { display: none; }

/* ── 표준 응답 카드 (에이전트 출력 통일) ───────────────────── */
.turn-card { display: flex; flex-direction: column; gap: 8px; }
.turn-tools {
  background: #11151f; border: 1px solid var(--border, #363b45);
  border-radius: 8px; font-size: 12px;
}
.turn-tools > summary {
  cursor: pointer; padding: 6px 10px; color: var(--text-dim, #9aa6bd);
  list-style: none; user-select: none;
}
.turn-tools > summary::before { content: "▸ "; color: var(--accent, #5b8cff); }
.turn-tools[open] > summary::before { content: "▾ "; }
.turn-tools-body { padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 6px; }
.tool-step { border-left: 2px solid var(--border, #363b45); padding-left: 8px; }
.ts-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ts-name { color: var(--accent, #5b8cff); font-weight: 600; }
.ts-arg  { color: var(--text-dim, #8a92a0); font-size: 11.5px; }
.ts-status { margin-left: auto; font-weight: 700; }
.ts-status.ok { color: #36d0a8; }
.ts-status.err { color: #f2557a; }
.ts-result { color: var(--text-dim, #9aa6bd); font-size: 11.5px; margin-top: 2px; word-break: break-word; }
.turn-answer { line-height: 1.6; }
.turn-answer:empty { display: none; }
.turn-meta { font-size: 10.5px; color: var(--text-dim, #8a92a0); opacity: .75; }

/* ── 에이전트 우측 도움말/예시 패널 ───────────────────────── */
.dock-help {
  width: 250px; background: var(--panel, #23272f);
  border-left: 1px solid var(--border, #363b45); overflow-y: auto;
}
.dock-help-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border, #363b45);
  color: var(--text-dim, #8a92a0); font-weight: 600; font-size: 13px;
}
.dock-help-body { padding: 12px; }
.dock-help-body h4 {
  margin: 4px 0 8px; font-size: 12px; color: var(--text-dim, #9aa6bd);
  text-transform: uppercase; letter-spacing: .04em;
}
.ex-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ex-list li {
  cursor: pointer; padding: 8px 10px; font-size: 13px;
  background: #11151f; border: 1px solid var(--border, #363b45); border-radius: 7px;
  color: var(--text, #e6eaf2); transition: border-color .12s, background .12s;
}
.ex-list li:hover { border-color: var(--accent, #5b8cff); background: #161b27; }
.ex-list li::before { content: "💬 "; }
.ex-hint { font-size: 11px; color: var(--text-dim, #8a92a0); margin: 0 0 16px; }
.help-list.compact li { padding: 3px 0; }
.help-list.compact kbd { min-width: 46px; }

/* dock-help: tips(설명형 리스트) */
.help-list.tips { display: block; }
.help-list.tips li { display: list-item; list-style: disc; margin-left: 16px; padding: 4px 0; color: var(--text-dim, #9aa6bd); font-size: 12.5px; }
.help-list.tips li b { color: var(--text, #e6eaf2); }
.dock-help .step-list { margin: 0 0 8px; padding-left: 18px; color: var(--text-dim,#9aa6bd); font-size: 12.5px; }
.dock-help .step-list li { padding: 3px 0; }
.dock-help .step-list b { color: var(--text,#e6eaf2); }

/* 동시 접속 초과 안내 배너 */
#busy-banner {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 9999;
  background: #f2557a; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
