/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --bg-main: #212121;
  --bg-sidebar: #171717;
  --bg-input: #2f2f2f;
  --bg-user-bubble: #2f2f2f;
  --bg-ai-bubble: #1e1e1e;
  --bg-card: #2a2a2a;
  --bg-card-hover: #333;
  --border: #3a3a3a;
  --text-primary: #ececec;
  --text-secondary: #9b9b9b;
  --text-muted: #666;
  --accent: #10a37f;
  --accent-hover: #0e9470;
  --gold: #f5c518;
  --danger: #e53e3e;
  --radius: 12px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  overflow: hidden;
}

body { display: flex; height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: transform var(--transition), width var(--transition), min-width var(--transition);
  overflow: hidden;
  z-index: 10;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}

.btn-new-chat {
  width: 100%;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition);
  text-align: center;
}
.btn-new-chat:hover { background: var(--accent-hover); }

/* ===== Progress Panel ===== */
.progress-panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.progress-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.progress-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-detail {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-security {
  margin-top: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-main);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.btn-sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color var(--transition);
}
.btn-sidebar-toggle:hover { color: var(--text-primary); }

.respondent-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== Welcome Screen ===== */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-secondary);
}
.welcome-logo-placeholder {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 36px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-icon { margin-bottom: 16px; }
.chat-welcome h2 { font-size: 22px; color: var(--text-primary); margin-bottom: 8px; font-weight: 600; }
.chat-welcome p { font-size: 14px; margin-bottom: 24px; }

.btn-start {
  padding: 12px 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
}
.btn-start:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-start:active { transform: translateY(0); }

/* ===== Messages ===== */
.messages { display: flex; flex-direction: column; gap: 20px; width: 100%; }

.msg-row { display: flex; align-items: flex-start; gap: 10px; }
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.msg-avatar.ai-avatar { background: var(--accent); color: #fff; }
.msg-avatar.user-avatar { background: #4a4a4a; color: #fff; }

.msg-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--bg-user-bubble);
  border-bottom-right-radius: 4px;
  color: var(--text-primary);
}
.msg-row.ai .msg-bubble {
  background: transparent;
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
  padding: 4px 0;
}

/* Markdown inside bubbles */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin-top: 16px; margin-bottom: 8px; font-weight: 600; }
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { color: var(--text-primary); }
.msg-bubble code {
  background: #1a1a1a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: #e06c75;
}

/* ===== Chip Buttons ===== */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px 42px;
}

.chip-btn {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.chip-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}
.chip-btn:active {
  transform: translateY(0);
}

/* ===== Done Banner ===== */
.done-banner {
  background: rgba(16, 163, 127, 0.1);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 24px;
  text-align: center;
  margin-top: 16px;
}
.done-banner h3 { color: var(--accent); font-size: 18px; margin-bottom: 8px; }
.done-banner p { color: var(--text-secondary); font-size: 14px; }

/* ===== Confirm (좋아요) Button ===== */
.confirm-container {
  text-align: center;
  margin-top: 20px;
  padding: 20px 24px;
  background: rgba(16, 163, 127, 0.07);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.confirm-hint {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.btn-confirm {
  display: inline-block;
  padding: 12px 36px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-confirm:hover:not(:disabled) { opacity: 0.85; }
.btn-confirm:disabled { opacity: 0.5; cursor: default; }

/* ===== Loading dots ===== */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ===== Input Area ===== */
.input-area {
  padding: 12px 16px 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  position: relative;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  transition: border-color var(--transition);
}
.input-row:focus-within { border-color: var(--accent); }
.input-row.disabled { opacity: 0.4; pointer-events: none; }

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  outline: none;
  font-family: inherit;
}
.message-input::placeholder { color: var(--text-muted); }
.message-input::-webkit-scrollbar { width: 4px; }
.message-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.btn-send {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  padding: 7px 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), opacity var(--transition);
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px;
  flex-shrink: 0;
}

/* ===== Sidebar Overlay (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  backdrop-filter: blur(1px);
}
.sidebar-overlay.visible { display: block; }

/* ===== Scrollbar global ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== Responsive ===== */
@media (min-width: 1920px) {
  .chat-area { padding: 24px calc((100% - 1200px) / 2 + 32px); }
  .input-area { padding-left: calc((100% - 1200px) / 2 + 16px); padding-right: calc((100% - 1200px) / 2 + 16px); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
  }
  .main-content { width: 100%; height: 100vh; height: 100dvh; }
  .chat-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px;
    padding-bottom: 100px;
  }
  .msg-bubble { max-width: 92%; }
  .input-area {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    border-top: 1px solid var(--border);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .app-footer { display: none; }
  .btn-sidebar-toggle { font-size: 22px; padding: 6px 10px; }
}
