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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --error: #ef4444;
  --radius: 12px;
  --sidebar-w: 260px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ─── AUTH PAGE ─────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-icon {
  font-size: 26px;
  color: var(--accent);
  line-height: 1;
}

.brand h1 {
  font-size: 19px;
  font-weight: 600;
}

.tab-switcher {
  display: flex;
  background: var(--bg);
  border-radius: 9px;
  padding: 4px;
  margin-bottom: 28px;
  gap: 4px;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
}

.tab.active {
  background: var(--surface2);
  color: var(--text);
}

.tab:hover:not(.active) { color: var(--text); }

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

.auth-form.hidden { display: none; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: #444; }

.form-error {
  color: var(--error);
  font-size: 12.5px;
  min-height: 16px;
}

.submit-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  transition: background 0.15s, opacity 0.15s;
  width: 100%;
  margin-top: 4px;
}

.submit-btn:hover { background: var(--accent-hover); }
.submit-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─── CHAT PAGE ─────────────────────────────── */

.chat-page {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 16px 8px;
  flex-shrink: 0;
}

/* Conversation list */
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 7px;
  cursor: pointer;
  padding: 8px 10px;
  transition: background 0.12s;
  color: var(--text-muted);
  font-size: 13px;
}

.conv-item:hover { background: var(--surface2); color: var(--text); }
.conv-item.active { background: var(--surface2); color: var(--text); }

.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

.conv-del {
  background: none;
  border: none;
  color: transparent;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}

.conv-item:hover .conv-del { color: var(--text-muted); }
.conv-del:hover { color: #f87171 !important; background: rgba(239,68,68,0.1); }

.brand-small {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 0 16px;
  letter-spacing: 0.01em;
}

.new-chat-btn {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 9px 14px;
  text-align: left;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.new-chat-btn:hover { background: #2e2e2e; }

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

.user-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.user-meta {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-quota {
  font-size: 11px;
  color: var(--text-muted);
  transition: color 0.2s;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* Main area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.messages-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

.messages-wrap::-webkit-scrollbar { width: 5px; }
.messages-wrap::-webkit-scrollbar-track { background: transparent; }
.messages-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 12px;
}

.welcome-icon {
  font-size: 44px;
  color: var(--accent);
  line-height: 1;
}

.welcome h2 {
  font-size: 22px;
  font-weight: 600;
}

.welcome p {
  color: var(--text-muted);
  font-size: 14.5px;
}

/* Messages */
.messages-inner {
  padding: 24px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 4px 24px;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.ai   { justify-content: flex-start; }

.bubble {
  max-width: 72%;
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
}

.msg-row.user .bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-row.ai .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble pre {
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 13px;
  margin: 10px 0;
  overflow-x: auto;
  padding: 12px 14px;
  white-space: pre;
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

.bubble code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  font-size: 13px;
  padding: 1px 5px;
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

.bubble pre code {
  background: none;
  padding: 0;
}

.bubble strong { font-weight: 600; }

/* Typing indicator */
.typing-dot {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 2px;
}

.typing-dot span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: pulse 1.2s infinite ease-in-out;
}

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

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.75); }
  40%            { opacity: 1;   transform: scale(1); }
}

/* Input area */
.input-area {
  padding: 12px 24px 20px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

.limit-banner {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 8px;
  color: #f87171;
  font-size: 13px;
  margin-bottom: 10px;
  padding: 10px 14px;
  text-align: center;
}

.limit-banner.hidden { display: none; }

.input-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 11px 11px 16px;
  transition: border-color 0.15s;
}

.input-box:focus-within { border-color: #5b21b6; }

textarea {
  background: none;
  border: none;
  color: var(--text);
  flex: 1;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  max-height: 180px;
  outline: none;
  overflow-y: auto;
  resize: none;
}

textarea::placeholder { color: #444; }

textarea::-webkit-scrollbar { width: 4px; }
textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

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

.disclaimer {
  color: #3e3e3e;
  font-size: 11.5px;
  margin-top: 9px;
  text-align: center;
}

/* Utility */
.hidden { display: none !important; }

/* ─── PROMPT PACKETS ─────────────────────────── */

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
  max-width: 560px;
  width: 100%;
}

.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 14px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.prompt-card:hover { border-color: var(--accent); background: #1e1530; }

.pc-icon  { font-size: 20px; line-height: 1; }
.pc-title { color: var(--text); font-size: 13px; font-weight: 600; }
.pc-desc  { color: var(--text-muted); font-size: 11.5px; }

/* ─── MODEL SELECTOR ─────────────────────────── */

.model-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.model-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.model-btns { display: flex; gap: 4px; }

.model-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 11px;
  transition: all 0.15s;
}

.model-btn:hover { color: var(--text); border-color: #555; }
.model-btn.active { background: var(--surface2); border-color: var(--accent); color: var(--text); }

.model-cost {
  color: var(--text-muted);
  font-size: 10.5px;
  margin-left: 2px;
}
.model-btn.active .model-cost { color: #a78bfa; }

/* ─── ATTACH BUTTON + PDF BADGE ──────────────── */

.attach-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px 6px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.attach-btn:hover { color: var(--text); background: var(--surface2); }

.pdf-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 7px;
  color: #c4b5fd;
  font-size: 12.5px;
  margin-bottom: 6px;
  padding: 7px 12px;
}

.pdf-badge button {
  background: none;
  border: none;
  color: #c4b5fd;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.pdf-badge button:hover { opacity: 1; }

/* ─── DASHBOARD LINK ─────────────────────────── */

.dashboard-link {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 12.5px;
  text-decoration: none;
  padding: 8px 0;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  transition: color 0.15s;
}
.dashboard-link:hover { color: var(--text); }
