/* ============================================================
   Inspecta AI — Premium Chat UI
   Font: Sora (display) + JetBrains Mono (code)
   ============================================================ */

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

:root {
  --font-sans: 'Sora', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Dark theme (default) */
  --bg: #0f0f11;
  --bg-sidebar: #161618;
  --bg-card: #1c1c1f;
  --bg-input: #1c1c1f;
  --bg-message-user: #2a1f6e;
  --bg-hover: #232328;
  --border: rgba(255,255,255,0.07);
  --text: #e8e8ed;
  --text-2: #9999a8;
  --text-3: #60607a;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-glow: rgba(124,58,237,0.25);
  --error: #f87171;
  --success: #34d399;
  --info: #60a5fa;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 12px;
  --sidebar-w: 260px;
}

[data-theme="light"] {
  --bg: #f7f7f8;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-message-user: #ede9fe;
  --bg-hover: #f0f0f5;
  --border: rgba(0,0,0,0.08);
  --text: #111118;
  --text-2: #555568;
  --text-3: #9999aa;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

html, body { height: 100%; font-family: var(--font-sans); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

/* ── Screens ── */
.screen { position: fixed; inset: 0; transition: opacity 0.2s; }
.screen.hidden { opacity: 0; pointer-events: none; }
.screen.active { opacity: 1; }

/* ========================================================
   AUTH SCREEN
   ======================================================== */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); overflow: hidden;
}
.auth-bg { position: absolute; inset: 0; pointer-events: none; }
.auth-orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.35;
  animation: orbFloat 8s ease-in-out infinite alternate;
}
.orb-1 { width: 400px; height: 400px; background: #7c3aed; top: -10%; left: -10%; }
.orb-2 { width: 300px; height: 300px; background: #4f46e5; bottom: 10%; right: -5%; animation-delay: -3s; }
.orb-3 { width: 200px; height: 200px; background: #a78bfa; top: 40%; left: 50%; animation-delay: -6s; }
@keyframes orbFloat { from { transform: translate(0,0) scale(1); } to { transform: translate(20px,30px) scale(1.05); } }

.auth-card {
  position: relative; z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem 2.25rem;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(124,58,237,0.1);
  animation: cardIn 0.4s cubic-bezier(0.16,1,0.3,1);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(0.97); } to { opacity: 1; transform: none; } }

.auth-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.auth-title { text-align: center; font-size: 1.5rem; font-weight: 600; margin-bottom: 0.25rem; }
.auth-subtitle { text-align: center; color: var(--text-2); font-size: 0.875rem; margin-bottom: 1.75rem; }
.auth-form-wrap { display: flex; flex-direction: column; gap: 1rem; }

.form-field { display: flex; flex-direction: column; gap: 0.35rem; }
.form-field label { font-size: 0.8rem; font-weight: 500; color: var(--text-2); letter-spacing: 0.02em; }
.form-field input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.65rem 0.85rem; color: var(--text); font-family: var(--font-sans); font-size: 0.9rem;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 2.75rem; }
.pw-toggle {
  position: absolute; right: 0.65rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px;
  display: flex; align-items: center;
}
.pw-toggle:hover { color: var(--text); }

.auth-error {
  background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3);
  color: var(--error); border-radius: 8px; padding: 0.6rem 0.85rem;
  font-size: 0.83rem;
}
.btn-auth {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 0.7rem 1rem; font-family: var(--font-sans); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.btn-auth:hover { opacity: 0.9; }
.btn-auth:active { transform: scale(0.98); }
.btn-auth:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-divider {
  display: flex; align-items: center; gap: 0.75rem; margin: 1.25rem 0 0.75rem;
  color: var(--text-3); font-size: 0.8rem;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.btn-auth-link {
  width: 100%; background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 1rem; color: var(--text-2); font-family: var(--font-sans); font-size: 0.85rem;
  cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.btn-auth-link:hover { border-color: var(--accent-light); color: var(--text); }
.btn-auth-link strong { color: var(--accent-light); }

/* ========================================================
   CHAT LAYOUT
   ======================================================== */
#chat-screen { display: flex; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.16,1,0.3,1);
  z-index: 100;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-top {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1rem 0.75rem 0.75rem;
}
.new-chat-btn {
  flex: 1; display: flex; align-items: center; gap: 0.5rem;
  background: var(--accent); color: white;
  border: none; border-radius: 8px; padding: 0.55rem 0.85rem;
  font-family: var(--font-sans); font-size: 0.85rem; font-weight: 500;
  cursor: pointer; transition: opacity 0.15s;
}
.new-chat-btn:hover { opacity: 0.85; }

.sidebar-toggle-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem; cursor: pointer; color: var(--text-2);
  display: flex; align-items: center; transition: border-color 0.15s, color 0.15s;
}
.sidebar-toggle-btn:hover { border-color: var(--border); color: var(--text); background: var(--bg-hover); }

.sidebar-search {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 0 0.75rem 0.5rem; padding: 0.45rem 0.65rem;
  background: var(--bg-hover); border-radius: 8px;
  color: var(--text-3);
}
.sidebar-search svg { flex-shrink: 0; }
.sidebar-search input {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: var(--font-sans); font-size: 0.82rem; outline: none;
}
.sidebar-search input::placeholder { color: var(--text-3); }

.conv-list {
  flex: 1; overflow-y: auto; padding: 0.25rem 0.5rem;
  display: flex; flex-direction: column; gap: 1px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.conv-group-label {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3); padding: 0.75rem 0.5rem 0.25rem;
}
.conv-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.6rem; border-radius: 8px; cursor: pointer;
  transition: background 0.1s; position: relative; group: true;
}
.conv-item:hover, .conv-item.active { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-hover); }
.conv-item-title {
  flex: 1; font-size: 0.83rem; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; line-height: 1.4;
}
.conv-item-delete {
  background: none; border: none; cursor: pointer; color: var(--text-3);
  padding: 2px; opacity: 0; transition: opacity 0.15s; display: flex;
}
.conv-item:hover .conv-item-delete { opacity: 1; }
.conv-item-delete:hover { color: var(--error); }

.sidebar-bottom { padding: 0.75rem; border-top: 1px solid var(--border); }

.rate-limit-section { margin-bottom: 0.75rem; }
.rate-limit-label { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-3); margin-bottom: 0.35rem; }
.rate-limit-track { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.rate-limit-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; }
.rate-limit-bar.low { background: var(--error); }
.rate-limit-bar.medium { background: #f59e0b; }

.user-section {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 0; 
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
  color: white; font-size: 0.8rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-email-text { flex: 1; font-size: 0.78rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign-out-btn {
  background: none; border: none; cursor: pointer; color: var(--text-3);
  padding: 4px; display: flex; align-items: center; transition: color 0.15s;
}
.sign-out-btn:hover { color: var(--error); }

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

/* ── Header ── */
.chat-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.model-select-wrap { position: relative; flex: 1; max-width: 220px; }
.model-select {
  appearance: none; width: 100%;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: var(--font-sans); font-size: 0.85rem; font-weight: 500;
  padding: 0.4rem 2rem 0.4rem 0.75rem; cursor: pointer; outline: none;
  transition: border-color 0.15s;
}
.model-select:focus { border-color: var(--accent); }
.select-caret { position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--text-3); }

.header-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.4rem; cursor: pointer; color: var(--text-2);
  display: flex; align-items: center; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Messages area ── */
.messages-area {
  flex: 1; overflow-y: auto; padding: 1.5rem 1rem;
  scroll-behavior: smooth; display: flex; flex-direction: column;
}
.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.welcome-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; text-align: center; padding: 2rem;
  animation: fadeUp 0.5s cubic-bezier(0.16,1,0.3,1);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.welcome-logo { margin-bottom: 1.5rem; }
.welcome-state h2 { font-size: 1.6rem; font-weight: 600; margin-bottom: 0.5rem; }
.welcome-state p { color: var(--text-2); font-size: 0.9rem; margin-bottom: 2rem; }
.suggestion-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; max-width: 560px; }
.chip {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 24px;
  padding: 0.5rem 0.9rem; font-family: var(--font-sans); font-size: 0.82rem;
  color: var(--text-2); cursor: pointer; transition: all 0.15s;
}
.chip:hover { border-color: var(--accent-light); color: var(--text); background: var(--bg-hover); }

/* Messages */
#messages-list { display: flex; flex-direction: column; gap: 0.25rem; max-width: 768px; margin: 0 auto; width: 100%; }

.msg-row { display: flex; padding: 0.5rem 0; animation: msgIn 0.25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-bubble {
  max-width: 80%; border-radius: 16px; padding: 0.75rem 1rem;
  font-size: 0.9rem; line-height: 1.65;
}
.msg-row.user .msg-bubble {
  background: var(--bg-message-user); color: var(--text);
  border-bottom-right-radius: 4px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-card); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Message actions */
.msg-actions {
  display: flex; gap: 0.35rem; margin-top: 0.5rem; opacity: 0;
  transition: opacity 0.15s;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 6px; cursor: pointer; color: var(--text-3); font-size: 0.75rem;
  display: flex; align-items: center; gap: 3px; transition: all 0.15s;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent-light); }
.msg-action-btn.copied { color: var(--success); border-color: var(--success); }

/* Markdown content styles */
.md-content { line-height: 1.7; }
.md-content p { margin-bottom: 0.6em; }
.md-content p:last-child { margin-bottom: 0; }
.md-content h1, .md-content h2, .md-content h3, .md-content h4 {
  font-weight: 600; margin: 0.75em 0 0.4em; line-height: 1.3;
}
.md-content h1 { font-size: 1.2em; }
.md-content h2 { font-size: 1.1em; }
.md-content h3 { font-size: 1em; }
.md-content ul, .md-content ol { padding-left: 1.5em; margin-bottom: 0.6em; }
.md-content li { margin-bottom: 0.2em; }
.md-content code {
  font-family: var(--font-mono); font-size: 0.82em;
  background: rgba(124,58,237,0.12); color: var(--accent-light);
  padding: 0.15em 0.4em; border-radius: 4px;
}
.md-content pre {
  background: #0d0d10; border: 1px solid var(--border);
  border-radius: 10px; margin: 0.75em 0; overflow: hidden;
  font-size: 0.83em;
}
[data-theme="light"] .md-content pre { background: #1e1e2e; }
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.85rem;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.code-lang { font-family: var(--font-mono); font-size: 0.75rem; color: #8888aa; text-transform: uppercase; letter-spacing: 0.05em; }
.copy-code-btn {
  background: none; border: 1px solid rgba(255,255,255,0.1); border-radius: 5px;
  padding: 2px 8px; color: #8888aa; font-size: 0.72rem; cursor: pointer;
  font-family: var(--font-sans); transition: all 0.15s; display: flex; align-items: center; gap: 4px;
}
.copy-code-btn:hover { color: white; border-color: rgba(255,255,255,0.25); }
.copy-code-btn.copied { color: var(--success); border-color: var(--success); }
.md-content pre code {
  background: none; color: inherit; padding: 0.85rem;
  display: block; overflow-x: auto; border-radius: 0;
  font-size: 1em; /* inherit from pre */
}
.md-content blockquote {
  border-left: 3px solid var(--accent); margin: 0.6em 0;
  padding: 0.4em 0 0.4em 1em; color: var(--text-2);
}
.md-content a { color: var(--accent-light); text-decoration: none; }
.md-content a:hover { text-decoration: underline; }
.md-content table { border-collapse: collapse; width: 100%; margin: 0.6em 0; font-size: 0.88em; }
.md-content th, .md-content td { border: 1px solid var(--border); padding: 0.4em 0.6em; text-align: left; }
.md-content th { background: var(--bg-hover); font-weight: 600; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 0.75em 0; }
.md-content strong { font-weight: 600; }
.md-content em { font-style: italic; }

/* Typing indicator */
.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 0.6rem 0.2rem; }
.typing-dot {
  width: 7px; height: 7px; background: var(--text-3);
  border-radius: 50%; animation: typingBounce 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Provider badge */
.provider-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7rem; color: var(--text-3); margin-top: 0.4rem;
}
.provider-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--success); }

/* Streaming cursor */
.streaming-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent-light); margin-left: 2px;
  animation: blink 0.8s step-start infinite; vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Input area ── */
.input-area {
  padding: 0.75rem 1rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.input-wrap {
  display: flex; align-items: flex-end; gap: 0.5rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 14px; padding: 0.5rem 0.6rem 0.5rem 0.75rem;
  max-width: 768px; margin: 0 auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

#chat-input {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: var(--font-sans); font-size: 0.9rem; line-height: 1.5;
  resize: none; outline: none; max-height: 200px; overflow-y: auto;
  scrollbar-width: thin;
}
#chat-input::placeholder { color: var(--text-3); }

.input-btns { display: flex; align-items: flex-end; gap: 0.35rem; }

.stop-btn {
  background: rgba(248,113,113,0.15) !important;
  border-color: rgba(248,113,113,0.3) !important;
  color: var(--error) !important;
}
.stop-btn:hover { background: rgba(248,113,113,0.25) !important; }

.send-btn {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: var(--accent); color: white; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
}
.send-btn:hover:not(:disabled) { opacity: 0.85; }
.send-btn:active:not(:disabled) { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.input-hint { text-align: center; font-size: 0.72rem; color: var(--text-3); margin-top: 0.4rem; max-width: 768px; margin-left: auto; margin-right: auto; }
.attach-btn { border: none !important; }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.65rem 1.2rem; font-size: 0.84rem; font-weight: 500;
  box-shadow: var(--shadow); pointer-events: auto;
  animation: toastIn 0.25s cubic-bezier(0.16,1,0.3,1);
  display: flex; align-items: center; gap: 0.5rem; white-space: nowrap;
}
.toast.error { border-color: rgba(248,113,113,0.3); }
.toast.success { border-color: rgba(52,211,153,0.3); }
.toast-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.toast.error .toast-dot { background: var(--error); }
.toast.success .toast-dot { background: var(--success); }
.toast.info .toast-dot { background: var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.95); } to { opacity: 1; transform: none; } }

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

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    transform: translateX(calc(-1 * var(--sidebar-w)));
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar:not(.collapsed) { transform: translateX(0); }
  .msg-bubble { max-width: 92%; }
}
