/* ── M4 웹 대시보드 — chat_overlay 1:1 재현 (다크, 전체 화면 앱) ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e0e11;
  --panel: #151518;
  --border: #27272a;
  --text: #e4e4e7;
  --secondary: #a1a1aa;
  --tertiary: #6b6b74;
  --blue: #3a82f4;
  --red: #e64040;
  --green: #22c55e;
  --chip-idle: rgba(140, 140, 140, 0.55);
  --chip-busy: rgba(230, 64, 64, 0.85);
  --chip-closing: rgba(64, 64, 66, 0.55);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, "SF Pro Text", "Pretendard", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  visibility: visible;
}

/* ── 1) 제어판 28px ── */
#ctrl {
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--tertiary);
  user-select: none;
}
#status-text {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-family: "SF Mono", "Fira Mono", monospace;
}
#status-text .sse-on { color: var(--green); }
#status-text .sse-off { color: var(--red); }
#ctrl .spacer { flex: 1; }
.ctrl-btn {
  background: none; border: 1px solid var(--border); border-radius: 5px;
  color: var(--tertiary); font-size: 11px; padding: 2px 8px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.ctrl-btn:hover { color: var(--secondary); border-color: #3f3f46; }
.ctrl-btn.active { background: #162038; border-color: #1d4ed8; color: #60a5fa; }

/* ── 2) 대화 영역 (가변) ── */
#chat-wrap { flex: 1; min-height: 0; position: relative; }
#chat {
  height: 100%;
  overflow-y: auto;
  padding: 22px 18px;
  font-size: 14px;
  line-height: 1.3;
}
#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg { padding: 4px 8px; border-radius: 4px; margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.msg-ts {
  font-size: 10.5px; color: var(--tertiary); margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.msg.role-user { background: rgba(58, 130, 244, 0.10); }
.msg.role-user .msg-body { font-weight: bold; font-size: 14px; color: var(--text); }
.msg.role-user .user-prefix { color: var(--blue); }
.msg.role-assistant .msg-body { font-size: 14px; color: var(--text); }
.msg.role-thinking .msg-body { font-size: 12px; color: var(--tertiary); }
.msg.role-tool .msg-body,
.msg.role-tool summary {
  font-family: "SF Mono", "Fira Mono", monospace;
  font-size: 11.5px; color: var(--secondary);
}
.msg.role-error .msg-body {
  font-family: "SF Mono", "Fira Mono", monospace;
  font-size: 11.5px; color: #f87171;
}
/* 꿈 — 작업 기록이 아니라 사후 반추라 한눈에 구분되게 보라색 계열 */
.msg.role-dream { background: rgba(139, 92, 246, 0.12); }
.msg.role-dream .msg-body { font-size: 13px; color: var(--text); font-style: italic; }
.msg.role-merge { background: rgba(34, 197, 94, 0.13); }
.msg.role-merge .msg-body { font-size: 14px; color: var(--text); }
.msg.role-fork { background: rgba(34, 197, 94, 0.16); }
.msg.role-fork .msg-body { font-weight: bold; font-size: 13px; color: var(--text); }
.msg.role-divider .msg-body {
  font-size: 10px; color: var(--tertiary); text-align: center;
}

.msg details summary {
  cursor: pointer; list-style: none; user-select: none;
  white-space: pre-wrap; word-break: break-word;
}
.msg details summary::-webkit-details-marker { display: none; }
.msg details summary::after { content: ' ▶'; font-size: 9px; color: var(--tertiary); }
.msg details[open] summary::after { content: ' ▼'; }
.msg details .detail-body {
  display: block; margin-top: 3px; padding-left: 8px;
  border-left: 2px solid var(--border);
  white-space: pre-wrap; word-break: break-word;
}
.msg .detail-error { color: #f87171; }

.msg-body a { color: #60a5fa; text-decoration: underline; cursor: pointer; }
.inline-img {
  display: block; max-width: 100%; max-height: 360px;
  margin: 4px 0; border-radius: 6px; cursor: zoom-in;
  border: 1px solid var(--border);
}

#jump-latest {
  position: absolute; right: 16px; bottom: 12px;
  display: none;
  background: rgba(31, 31, 36, 0.92); color: var(--secondary);
  border: 1px solid #3f3f46; border-radius: 14px;
  font-size: 11.5px; padding: 4px 12px; cursor: pointer;
  z-index: 5;
}
#jump-latest.visible { display: block; }
#jump-latest:hover { color: var(--text); border-color: #52525b; }

.chat-empty {
  color: var(--tertiary); font-size: 12px; text-align: center; padding: 30px 0;
}
.chat-spinner { display: flex; justify-content: center; padding: 8px; }
.chat-spinner::after {
  content: ''; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: #52525b;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 3) 큐 바 (~22px): 좌측 브랜치 칩 / 우측 큐 칩 ── */
#queuebar {
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 4px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  user-select: none;
}
#branch-chips {
  display: flex; align-items: center; gap: 3px;
  flex-shrink: 0; max-width: 45%;
  overflow-x: auto; scrollbar-width: none;
}
#branch-chips::-webkit-scrollbar { display: none; }

.chip {
  position: relative;
  width: 20px; height: 20px; flex-shrink: 0;
  border: 2px solid transparent; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 600; color: #fff;
  font-family: "SF Mono", "Fira Mono", monospace;
  cursor: pointer;
  background: var(--chip-idle);
}
.chip.busy { background: var(--chip-busy); }
.chip.closing { background: var(--chip-closing); }
.chip.active { border-color: #ffffff; }
.chip.pulsing { animation: chip-pulse 0.6s ease-in-out infinite alternate; }
@keyframes chip-pulse { from { opacity: 1.0; } to { opacity: 0.35; } }

.chip-x {
  position: absolute; top: -4px; right: -4px;
  width: 10px; height: 10px; border-radius: 5px;
  background: rgba(31, 31, 36, 0.92);
  color: #d4d4d8; font-size: 7px; line-height: 10px; text-align: center;
  cursor: pointer;
}
.chip-x:hover { color: #fff; background: rgba(230, 64, 64, 0.9); }

#fork-wrap { position: relative; flex-shrink: 0; }
#fork-btn {
  width: 20px; height: 20px;
  border: none; border-radius: 3px;
  background: rgba(255, 255, 255, 0.10);
  color: var(--secondary); font-size: 13px; line-height: 1;
  cursor: pointer;
}
#fork-btn:hover { background: rgba(255, 255, 255, 0.18); color: var(--text); }

#queue-chips {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 4px;
  overflow-x: auto; scrollbar-width: none;
  padding-right: 6px;
}
#queue-chips::-webkit-scrollbar { display: none; }
.qchip {
  display: flex; align-items: center; gap: 4px;
  height: 18px; padding: 0 6px; border-radius: 9px;
  color: #fff; font-size: 10.5px; white-space: nowrap;
  cursor: pointer; flex-shrink: 0;
  max-width: 180px;
  transition: transform 0.18s ease;
}
.qchip .qchip-text { overflow: hidden; text-overflow: ellipsis; }
.qchip .qchip-x {
  font-size: 9px; opacity: 0.75; cursor: pointer; flex-shrink: 0;
}
.qchip .qchip-x:hover { opacity: 1; }
.qchip.drag-over { outline: 1px dashed #fff; }
#queue-usage {
  flex-shrink: 0; font-size: 10px; color: var(--tertiary);
  padding-right: 8px; font-family: "SF Mono", monospace;
}

/* ── 4) 드래그 디바이더 6px ── */
#divider {
  height: 6px; flex-shrink: 0;
  cursor: ns-resize;
  background: var(--panel);
  position: relative;
}
#divider::after {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  height: 1px; transform: translateY(-50%);
  background: var(--border); transition: background 0.15s;
}
#divider:hover::after, #divider.dragging::after { background: #52525b; }

/* ── 5) 입력 행 72px ── */
#inputrow {
  height: 72px; flex-shrink: 0;
  display: flex; align-items: stretch; gap: 6px;
  padding: 6px 8px;
  background: var(--panel);
}
#input {
  flex: 1; min-width: 0;
  background: #0f0f11; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; resize: none;
  padding: 8px 10px;
  font-family: inherit; font-size: 13px; line-height: 1.45;
}
#input:focus { border-color: #1d4ed8; }
#input::placeholder { color: #3f3f46; }
.input-btns {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  flex-shrink: 0;
}
.in-btn {
  width: 38px; border: 1px solid var(--border); border-radius: 7px;
  background: #1c1c20; color: var(--secondary);
  font-size: 14px; cursor: pointer;
}
.in-btn:hover:not(:disabled) { background: #26262b; color: var(--text); }
.in-btn:disabled { opacity: 0.3; cursor: not-allowed; }
#enqueue-btn { height: 30px; }
#play-btn { height: 42px; }
#play-btn.hidden { display: none; }
#enqueue-btn.solo { height: 100%; }

/* ── 토스트 ── */
#toasts {
  position: fixed; top: 34px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 10000;
  pointer-events: none;
}
.toast {
  background: rgba(31, 31, 36, 0.96); color: var(--text);
  border: 1px solid #3f3f46; border-radius: 8px;
  font-size: 12.5px; padding: 8px 14px;
  max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  animation: toast-in 0.15s ease;
}
.toast.error { border-color: var(--red); color: #fca5a5; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }

/* ── 모달 공통 ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6); z-index: 9000;
  align-items: center; justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: #18181b; border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; min-width: 300px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { font-size: 14px; font-weight: 600; color: #fafafa; }
.modal label { font-size: 12px; color: var(--secondary); display: block; margin-bottom: 4px; }
.modal input[type=text], .modal select {
  width: 100%; padding: 8px 10px;
  background: #0f0f11; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); font-size: 13px; outline: none;
}
.modal input[type=text]:focus, .modal select:focus { border-color: #1d4ed8; }
.radio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-row label {
  display: flex; align-items: center; gap: 4px;
  font-size: 12.5px; color: var(--text); margin: 0; cursor: pointer;
}
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btn {
  padding: 7px 16px; border-radius: 7px; border: 1px solid var(--border);
  background: #1c1c20; color: var(--secondary); font-size: 13px; cursor: pointer;
}
.modal-btn:hover { color: var(--text); }
.modal-btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.modal-btn.primary:hover { background: #1d4ed8; }

/* 설정 모달 (모델 선택) */
#settings-modal .modal { min-width: 380px; }
.model-desc { font-size: 11.5px; color: var(--secondary); margin-top: 4px; min-height: 14px; }
.model-note { font-size: 11.5px; color: #b45309; }
.dim { color: var(--secondary); font-weight: 400; }

/* 스크린샷 모달 */
#shot-modal .modal { max-width: 92vw; }
#shot-img { max-width: 88vw; max-height: 78vh; display: block; background: #000; border-radius: 6px; }
#shot-empty { color: var(--tertiary); font-size: 12px; text-align: center; padding: 40px; }

/* 라이트박스 */
#lightbox {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.85); z-index: 9500;
  align-items: center; justify-content: center; cursor: zoom-out;
}
#lightbox.visible { display: flex; }
#lightbox img { max-width: 94vw; max-height: 94vh; }

/* ── 로그인 오버레이 (기존 재사용) ── */
#login-overlay {
  display: none; position: fixed; inset: 0;
  background: #09090b; z-index: 9999;
  align-items: center; justify-content: center;
}
#login-overlay.visible { display: flex; }
.login-box {
  background: #18181b; padding: 36px 32px; border-radius: 16px;
  border: 1px solid var(--border);
  min-width: 300px; max-width: 360px; width: 90%;
  display: flex; flex-direction: column; gap: 12px;
}
.login-box h2 { color: #fafafa; font-size: 18px; font-weight: 600; text-align: center; }
.login-box input[type=password] {
  width: 100%; padding: 11px 13px;
  background: #0f0f11; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
.login-box input[type=password]:focus { border-color: #2563eb; }
.login-box .login-btn {
  width: 100%; padding: 11px; background: #2563eb; border: none;
  border-radius: 10px; color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.login-box .login-btn:hover { background: #1d4ed8; }
.login-box .login-btn:disabled { background: #1e3a6e; cursor: not-allowed; }
#login-error { color: #f87171; font-size: 13px; text-align: center; min-height: 16px; }

@media (max-width: 640px) {
  #chat { padding: 14px 10px; }
  #ctrl { font-size: 11px; }
}
