* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1b2340;
  --muted: #6d7693;
  --line: #e4e8f2;
  --accent: #4f46e5;
  --accent-dark: #3d35c4;
  --danger: #c0392b;
  --shadow: 0 12px 32px rgba(27, 35, 64, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef1ff 0%, #f8fafc 55%, #eef7f5 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 20px;
  padding: 40px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.brand h1 { font-size: 28px; letter-spacing: -0.5px; }
.brand p { color: var(--muted); font-size: 13px; margin-top: 2px; }

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 700;
  flex-shrink: 0;
}
.brand-mark.small { width: 36px; height: 36px; border-radius: 10px; font-size: 18px; }

.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; font-weight: 600; margin-top: 10px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fbfcfe;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.primary-button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.primary-button:hover { background: var(--accent-dark); }
.primary-button:disabled { opacity: 0.55; cursor: not-allowed; }
.login-form .primary-button { margin-top: 20px; }

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 9px 13px;
  cursor: pointer;
}
.ghost-button:hover { background: #f7f8fc; }

.error-box {
  background: #fdecea;
  color: var(--danger);
  border: 1px solid #f5c6c0;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13px;
  margin-top: 10px;
}

.login-footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

.dashboard { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 72px;
  background: white;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar-title h2 { font-size: 18px; }
.topbar-title span { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-badge {
  font-size: 13px;
  font-weight: 600;
  background: #eef1ff;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 8px 14px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-layout { flex: 1; display: grid; place-items: center; padding: 28px; min-height: 0; }
.chat-panel {
  width: 100%;
  max-width: 860px;
  height: min(760px, calc(100vh - 128px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.chat-header h3 { font-size: 16px; }
.chat-header p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.usage-badge {
  font-size: 11px;
  color: var(--muted);
  background: #f6f7fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  white-space: nowrap;
}

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

.welcome-message { margin: auto; text-align: center; max-width: 520px; }
.welcome-icon {
  width: 54px; height: 54px; margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white; display: grid; place-items: center;
  font-size: 26px; font-weight: 700;
}
.welcome-message h4 { font-size: 18px; margin-bottom: 8px; }
.welcome-message p { font-size: 14px; color: var(--muted); line-height: 1.6; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.suggestion {
  border: 1px solid var(--line); background: white; color: var(--accent-dark);
  border-radius: 999px; padding: 8px 13px; font: inherit; font-size: 12px; cursor: pointer;
}
.suggestion:hover { background: #eef1ff; }

.message { display: flex; gap: 10px; align-items: flex-start; max-width: 88%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.message.bot .message-avatar { background: #eef1ff; color: var(--accent-dark); }
.message.user .message-avatar { background: #dcfce7; color: #166534; }
.message-content {
  background: #f7f8fc; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 15px; font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.message.user .message-content { background: var(--accent); color: white; border-color: transparent; }
.message-meta { font-size: 11px; color: var(--muted); margin-top: 8px; }
.message-meta strong { color: var(--ink); font-weight: 600; }

.typing { display: inline-flex; gap: 5px; align-items: center; height: 20px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.chat-form { border-top: 1px solid var(--line); padding: 16px 20px; display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea { resize: none; max-height: 140px; }
.send-button { flex-shrink: 0; }
.dashboard .error-box { margin: 0 20px 16px; }

@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .topbar-actions .ghost-button { display: none; }
  .user-badge { max-width: 130px; }
  .chat-layout { padding: 12px; }
  .chat-panel { height: calc(100vh - 96px); }
  .login-card { padding: 28px; }
}
