/* ── Reset & base ─────────────────────────────────────────── */

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

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #242836;
  --border: #2e3344;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --accent: #6c8cff;
  --accent-dim: rgba(108, 140, 255, 0.12);
  --error: #ff6b6b;
  --success: #4ecdc4;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ── Login ────────────────────────────────────────────────── */

#login-screen {
  align-items: center;
  justify-content: center;
}

.login-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 40px 24px;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  background: var(--accent);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 600;
  color: #fff;
}

.login-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 32px;
  color: var(--text);
}

#login-email,
#login-password {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  font: inherit;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s;
}
#login-password:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { opacity: 0.9; }

.error-text {
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ── Chat layout ──────────────────────────────────────────── */

.chat-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.btn-icon {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-elevated); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}
.conv-item:hover { background: var(--bg-elevated); color: var(--text); }
.conv-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-badge {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.btn-text {
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-text:hover { color: var(--text); }

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

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.sidebar-toggle { display: none; }

.chat-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tier-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  white-space: nowrap;
}
.tier-badge:empty { display: none; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.message-user .msg-content {
  background: var(--bg-elevated);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
  margin-left: auto;
  max-width: 85%;
  width: fit-content;
}

.message-model .msg-content {
  padding: 4px 0;
}

.msg-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.message-model .msg-label { color: var(--accent); }

/* Simple markdown-ish rendering */
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-text p { margin-bottom: 0.8em; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text strong { font-weight: 600; }
.msg-text em { font-style: italic; }
.msg-text code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 3px;
}
.msg-text ul, .msg-text ol { padding-left: 1.5em; margin-bottom: 0.8em; }
.msg-text li { margin-bottom: 0.3em; }

/* Streaming cursor */
.streaming .msg-text::after {
  content: '\25CF';
  color: var(--accent);
  animation: pulse 1s infinite;
  margin-left: 2px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Input */
.input-area {
  padding: 12px 20px 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text);
  font: inherit;
  resize: none;
  max-height: 160px;
  outline: none;
  transition: border-color 0.15s;
}
#message-input:focus { border-color: var(--accent); }

.btn-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-send:not(:disabled):hover { opacity: 0.9; }

/* ── Empty state ──────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 15px;
  max-width: 320px;
}

/* ── Scrollbar ────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
}
