/* ── 기본 초기화 ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg:          #1e1e2e;
  --surface:     #2a2a3d;
  --surface2:    #313145;
  --accent:      #7c6fcd;
  --accent-hover:#9380e0;
  --text:        #cdd6f4;
  --text-muted:  #6c7086;
  --user-bg:     #45475a;
  --ai-bg:       #313145;
  --border:      #45475a;
  --danger:      #f38ba8;
  --header-h:    56px;
  --footer-h:    72px;
}

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

/* ── 헤더 ───────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  gap: 8px;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#user-count {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── 드롭다운 ────────────────────────────────── */
select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

select:hover { border-color: var(--accent); }

/* ── 버튼 ────────────────────────────────────── */
button {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover  { background: var(--accent); border-color: var(--accent); }
button:active { opacity: 0.8; }

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── 채팅 영역 ───────────────────────────────── */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 스크롤바 */
#chat-container::-webkit-scrollbar { width: 6px; }
#chat-container::-webkit-scrollbar-track { background: transparent; }
#chat-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── 채팅 버블 ───────────────────────────────── */
.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.ai   { align-self: flex-start; align-items: flex-start; }

.bubble-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-wrap.user .bubble {
  background: var(--user-bg);
  border-bottom-right-radius: 3px;
}

.bubble-wrap.ai .bubble {
  background: var(--ai-bg);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--border);
}

/* 스트리밍 중 깜빡이는 커서 */
.typing-cursor::after {
  content: '▌';
  color: var(--accent);
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── 입력 푸터 ───────────────────────────────── */
#input-area {
  height: var(--footer-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  flex-shrink: 0;
}

#input-box {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
}

#input-box:focus { border-color: var(--accent); }

#send-btn {
  background: var(--accent);
  border-color: var(--accent);
  padding: 10px 18px;
  font-size: 14px;
}

#send-btn:hover { background: var(--accent-hover); }

/* ── 오버레이 딤 ─────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10;
}

/* ── 패널 공통 ───────────────────────────────── */
.panel {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.panel.hidden { display: none; }

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

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 6px;
  cursor: pointer;
}

.close-btn:hover { color: var(--danger); background: transparent; }

/* ── 로그 패널 ───────────────────────────────── */
#log-panel {
  right: 16px;
  top: calc(var(--header-h) + 12px);
  width: 380px;
  max-height: 70vh;
}

#log-content {
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-entry {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.log-entry .log-meta {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 6px;
}

.log-entry .log-input {
  margin-bottom: 6px;
  font-style: italic;
  color: var(--text);
}

.log-entry .log-metrics {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--accent);
}

/* ── 규칙 추가 패널 ──────────────────────────── */
#rules-panel {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
}

#rules-input {
  margin: 12px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 140px;
  outline: none;
}

#rules-input:focus { border-color: var(--accent); }

.panel-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

#rules-reset {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

#rules-reset:hover { background: var(--danger); color: #fff; }

#rules-save {
  background: var(--accent);
  border-color: var(--accent);
}