/* ── Variables ─────────────────────────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --surface-3: #2d333b;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --accent: #58a6ff;
  --accent-bg: #1f3a5c;
  --danger: #da3633;
  --danger-bg: #3a1a1a;
  --success: #3fb950;
  --warning: #d29922;
  --user-bubble: #1f6feb;
  --user-bubble-text: #ffffff;
  --bot-bubble: #21262d;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --radius: 12px;
  --radius-sm: 6px;
  --header-h: 56px;
  --input-h: 80px;
  --footer-h: 40px;
  --transition: 0.2s ease;
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font); cursor: pointer; border: none; outline: none; }
input, textarea { font-family: var(--font); outline: none; }

/* ── 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-dim); }

/* ══════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════ */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(31,111,235,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(88,166,255,0.08) 0%, transparent 50%);
  pointer-events: none;
}

.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  position: relative;
  z-index: 1;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #1f6feb, #58a6ff);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(31,111,235,0.4);
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.15);
}

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

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #0d1117;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background var(--transition), transform var(--transition);
  margin-top: 8px;
}

.btn-primary:hover { background: #79b8ff; }
.btn-primary:active { transform: scale(0.98); }

.login-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #ff7b72;
  margin-bottom: 16px;
  display: none;
}
.login-error.visible { display: block; }

/* ══════════════════════════════════════════════
   CHAT PAGE LAYOUT
   ══════════════════════════════════════════════ */
.chat-page {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--input-h) var(--footer-h);
  overflow: hidden;
}

/* ── Header ─── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  height: var(--header-h);
  position: relative;
  z-index: 10;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.header-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #1f6feb, #58a6ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.header-title h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.header-user {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-icon.btn-danger:hover {
  background: var(--danger-bg);
  color: #ff7b72;
  border-color: var(--danger);
}

.btn-icon.btn-logout:hover {
  background: var(--surface-3);
  color: var(--text);
}

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

.messages-area:empty::before {
  content: 'Start a conversation — type a message below.';
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  margin: auto;
}

/* ── Message bubbles ─── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeUp 0.2s ease;
}

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

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar.user-av {
  background: var(--user-bubble);
  color: #fff;
}

.avatar.bot-av {
  background: linear-gradient(135deg, #1f6feb, #58a6ff);
  color: #fff;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

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

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

/* Markdown inside bubbles */
.bubble h1, .bubble h2, .bubble h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 10px 0 6px;
  color: var(--text);
}
.bubble p { margin: 6px 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; color: var(--text-muted); }
.bubble a { color: var(--accent); }
.message.user .bubble a { color: #b3d4ff; }

.bubble code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(0,0,0,0.3);
  padding: 1px 5px;
  border-radius: 4px;
  color: #f0883e;
}
.message.user .bubble code {
  background: rgba(0,0,0,0.2);
  color: #ffe0b2;
}

.bubble pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}
.message.user .bubble pre {
  background: rgba(0,0,0,0.25);
  border-color: rgba(255,255,255,0.15);
}
.bubble pre code {
  background: none;
  padding: 0;
  color: #e6edf3;
  font-size: 12px;
}

/* Thinking indicator */
.thinking {
  display: flex;
  gap: 5px;
  padding: 2px 0;
  align-items: center;
}
.thinking span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: dot-bounce 1.3s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%            { transform: scale(1.0); opacity: 1; }
}

/* Cursor blink during streaming */
.cursor-blink::after {
  content: '▊';
  font-size: 13px;
  opacity: 1;
  animation: blink 1s step-end infinite;
  color: var(--text-muted);
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Tool use pills ─── */
.tool-pill {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 70%;
  animation: fadeUp 0.2s ease;
  margin: 2px 0;
}
.tool-pill .tool-icon { font-size: 13px; }
.tool-pill .tool-name { font-weight: 600; color: var(--accent); }
.tool-pill .tool-query { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ── Summary display ─── */
.summary-block {
  align-self: center;
  text-align: center;
  padding: 12px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  max-width: 90%;
  margin: 8px 0;
}
.summary-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.summary-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

/* ── Input area ─── */
.input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 12px 20px;
  gap: 10px;
  height: var(--input-h);
}

.input-area textarea {
  flex: 1;
  height: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  resize: none;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-area textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.1);
}

.input-area textarea::placeholder { color: var(--text-dim); }
.input-area textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-send {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: #0d1117;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  align-self: flex-end;
}
.btn-send:hover:not(:disabled) { background: #79b8ff; }
.btn-send:active:not(:disabled) { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Footer metrics ─── */
.metrics-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: var(--footer-h);
  overflow: hidden;
}

.metric-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 20px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.metric-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.metric-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  transition: background 0.5s ease;
}
.metric-dot.warn { background: var(--warning); }
.metric-dot.crit { background: var(--danger); }

.metric-label {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metric-bar {
  width: 50px;
  height: 5px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.metric-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--success);
  transition: width 0.6s ease, background 0.5s ease;
  min-width: 2px;
}
.metric-bar-fill.warn { background: var(--warning); }
.metric-bar-fill.crit { background: var(--danger); }

.metric-val {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 50px;
}

.metric-connecting {
  color: var(--text-dim);
  font-size: 11px;
  font-style: italic;
}

/* ══════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  width: 360px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
  animation: slideUp 0.15s ease;
}
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

.modal p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-secondary {
  padding: 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-secondary:hover {
  background: var(--surface-3);
  border-color: var(--text-dim);
}

.btn-confirm-danger {
  padding: 8px 16px;
  background: var(--danger);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}
.btn-confirm-danger:hover { background: #f85149; }

.btn-confirm-compact {
  padding: 8px 16px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  color: #0d1117;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}
.btn-confirm-compact:hover { background: #79b8ff; }

/* ══════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════ */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  max-width: 320px;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.toast.toast-success { border-color: var(--success); }
.toast.toast-error   { border-color: var(--danger); color: #ff7b72; }
.toast.toast-info    { border-color: var(--accent); }

/* ── Loading spinner (for compact action) ─── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
