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

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-user-bubble: #18181b;
  --bg-bot-bubble: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-on-dark: #f9fafb;
  --accent: #22d3ee;
  --accent-hover: #06b6d4;
  --border: #e5e7eb;
  --error: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --max-width: 800px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ====== Screens ====== */
.screen {
  height: 100%;
}

/* ====== Login Screen ====== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0fdfa 0%, #ede9fe 50%, #fce7f3 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.login-logo {
  margin-bottom: 20px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.login-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.input-group input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

.btn-primary {
  padding: 12px 24px;
  background: var(--bg-user-bubble);
  color: var(--text-on-dark);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover {
  background: #27272a;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-msg {
  font-size: 13px;
  color: var(--error);
  padding: 8px 12px;
  background: #fef2f2;
  border-radius: var(--radius-sm);
  text-align: left;
}

/* ====== Chat Screen ====== */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.bot-avatar svg {
  width: 100%;
  height: 100%;
}

.header-info {
  display: flex;
  flex-direction: column;
}

.bot-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.bot-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.header-right {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar {
  width: 6px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.welcome-icon {
  margin-bottom: 16px;
}

.welcome-icon svg {
  width: 48px;
  height: 48px;
}

.welcome-message h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-message p {
  font-size: 14px;
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.message.bot .message-avatar {
  background: #18181b;
}

.message.bot .message-avatar svg {
  width: 24px;
  height: 24px;
}

.message.user .message-avatar {
  background: var(--accent);
  color: #18181b;
}

.message-content {
  max-width: 70%;
}

.message-bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
}

.message.bot .message-bubble {
  background: var(--bg-bot-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.bot-bubble-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reasoning-details {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  padding: 8px 10px;
}

.reasoning-details summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.reasoning-details summary::-webkit-details-marker {
  display: none;
}

.reasoning-details summary::before {
  content: '▸';
  color: var(--text-tertiary);
  display: inline-block;
  transform: translateY(-0.5px);
}

.reasoning-details[open] summary::before {
  content: '▾';
}

.reasoning-details:not([open]) .when-open {
  display: none;
}

.reasoning-details[open] .when-closed {
  display: none;
}

.reasoning-content {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.answer-content {
  color: inherit;
}

.message.user .message-bubble {
  background: var(--bg-user-bubble);
  color: var(--text-on-dark);
  border-bottom-right-radius: 4px;
}

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

.message.user .message-time {
  text-align: right;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat Footer */
.chat-footer {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-area:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.chat-input-area textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  padding: 6px 0;
}

.chat-input-area textarea::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #18181b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

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

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

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.footer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
}

/* ====== Responsive ====== */
@media (max-width: 640px) {
  .login-card {
    padding: 32px 24px;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .messages-area {
    padding: 14px;
  }

  .chat-footer {
    padding: 10px 12px 12px;
  }

  .chat-input-area {
    padding: 6px 6px 6px 12px;
  }

  .message-content {
    max-width: 82%;
  }

  .welcome-message {
    padding: 24px 12px;
  }
}

/* ====== Dark mode ====== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0f0f11;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    --bg-user-bubble: #22d3ee;
    --bg-bot-bubble: #27272a;
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --text-on-dark: #18181b;
    --accent: #22d3ee;
    --accent-hover: #06b6d4;
    --border: #27272a;
    --error: #f87171;
    --success: #4ade80;
  }

  .login-card {
    background: #18181b;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
  }

  .message.user .message-bubble {
    background: var(--bg-user-bubble);
    color: var(--text-on-dark);
  }

  .error-msg {
    background: rgba(239, 68, 68, 0.1);
  }
}
