:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --bot-bubble: #eef0f3;
  --bot-text: #1f2937;
  --user-bubble: #3b82f6;
  --user-text: #ffffff;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: #dbeafe;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius-bubble: 18px;
  --radius-md: 14px;
  --max-width: 720px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-soft);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans KR", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--bg);
  box-shadow: var(--shadow-md);
}

/* Header */
.header {
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 12px;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.title-text {
  min-width: 0;
}

.title-text h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

.status {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot-online {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.reset-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.reset-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
  border-color: #d1d5db;
}

.reset-btn:active {
  transform: scale(0.98);
}

/* Chat area */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--bg);
}

.chat::-webkit-scrollbar {
  width: 8px;
}

.chat::-webkit-scrollbar-thumb {
  background: #e5e7eb;
  border-radius: 4px;
}

.chat::-webkit-scrollbar-thumb:hover {
  background: #d1d5db;
}

/* Date divider */
.date-divider {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 6px;
  position: relative;
}

.date-divider span {
  background: var(--bg);
  padding: 0 12px;
  position: relative;
  z-index: 1;
}

.date-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
  z-index: 0;
}

/* Message rows */
.row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: fadeInUp 0.28s ease-out both;
}

.row.user {
  flex-direction: row-reverse;
}

.row.bot .row-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  min-width: 0;
}

.row.user .bubble-wrap {
  align-items: flex-end;
}

.row.bot .bubble-wrap {
  align-items: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}

.row.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 6px;
}

.row.bot .bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-bottom-left-radius: 6px;
}

.row.bot .bubble.error {
  background: #fef2f2;
  color: #b91c1c;
}

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

/* Typing indicator */
.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.typing .dot {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typingDot 1.2s infinite ease-in-out;
}

.typing .dot:nth-child(2) { animation-delay: 0.18s; }
.typing .dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Composer */
.composer {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s, background 0.15s;
}

.composer-inner:focus-within {
  border-color: var(--primary);
  background: var(--bg);
}

.message-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  padding: 6px 0;
  max-height: 140px;
  min-height: 24px;
  overflow-y: auto;
}

.message-input::placeholder {
  color: #9ca3af;
}

.send-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  height: 36px;
  transition: background 0.15s, transform 0.05s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 8px 0 0;
}

/* Confirm dialog */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.15s ease-out;
}

.confirm-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confirm-card {
  background: var(--bg);
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  animation: popIn 0.18s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.confirm-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
}

.confirm-card p {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.55;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-secondary, .btn-danger {
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: #ef4444;
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

/* Mobile */
@media (max-width: 520px) {
  .app {
    box-shadow: none;
  }
  .header-inner {
    padding: 12px 14px;
  }
  .title-text h1 {
    font-size: 15px;
  }
  .chat {
    padding: 18px 14px 10px;
  }
  .bubble-wrap {
    max-width: 82%;
  }
  .bubble {
    font-size: 14px;
  }
  .reset-btn {
    padding: 7px 12px;
    font-size: 12.5px;
  }
}
