/* ── Google Fonts fallback ─────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:        #f0f4f9;
  --surface:   #ffffff;
  --border:    #e3e6ea;
  --accent:    #1a73e8;
  --accent2:   #8b5cf6;
  --text:      #1f2937;
  --muted:     #6b7280;
  --shadow:    0 4px 24px rgba(0,0,0,.08);
  --shadow-sm: 0 1px 6px  rgba(0,0,0,.06);
  --radius:    18px;
  --radius-sm: 12px;
  --sb-width:  260px;
  --topbar-h:  56px;
  --tokbar-h:  36px;
  --inputbar-h:116px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Outfit', sans-serif; background: var(--bg); color: var(--text); }
button { cursor: pointer; font-family: inherit; }
textarea { font-family: inherit; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
body { display: flex; overflow: hidden; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sb-width);
  min-width: var(--sb-width);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  z-index: 200;
  overflow: hidden;
}

.sb-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  width: 38px; height: 38px;
  border: none; background: transparent;
  border-radius: 10px; font-size: 18px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text); }

.new-chat-btn {
  flex: 1;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px; font-weight: 500; color: var(--text);
  transition: all .15s;
}
.new-chat-btn:hover { background: #e8f0fe; border-color: rgba(26,115,232,.3); color: var(--accent); }

.sb-section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted);
  padding: 14px 16px 6px;
}

.history-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.history-empty { font-size: 13px; color: var(--muted); padding: 8px 6px; }

.history-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text);
  cursor: pointer; transition: background .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item:hover { background: #f1f5f9; }
.history-item .hi-icon { font-size: 15px; flex-shrink: 0; }

.sb-footer { padding: 12px 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.model-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 13px; }
.model-card-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid var(--border); }
.model-card-row:last-child { border-bottom: none; }
.model-card-key { font-size: 11px; color: var(--muted); }
.model-card-val { font-size: 11px; font-weight: 600; }

/* Sidebar overlay on mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 199;
}

/* ─── Main area ─────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 100;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 17px; font-weight: 600; letter-spacing: -.2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.badge-live {
  display: flex; align-items: center; gap: 5px;
  background: #dcfce7; border: 1px solid #86efac;
  color: #16a34a; font-size: 11px; font-weight: 600;
  padding: 4px 11px; border-radius: 999px;
}
.dot-live {
  width: 6px; height: 6px; background: #16a34a; border-radius: 50%;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.7)} }

.model-tag {
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px;
  font-size: 11px; color: var(--muted);
}

/* Token bar */
.tok-bar {
  height: var(--tokbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tok-bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tok-track { flex: 1; height: 4px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.tok-fill  { height: 100%; border-radius: 999px; transition: width .4s ease; background: linear-gradient(90deg,#1a73e8,#8b5cf6); }
.tok-bar-val { font-size: 11px; font-weight: 600; white-space: nowrap; color: var(--muted); }

/* Chat area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0 16px;
  scroll-behavior: smooth;
}

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 24px 32px; text-align: center;
  animation: fadeUp .4s ease;
}
.empty-icon  { font-size: 50px; margin-bottom: 16px; }
.empty-title {
  font-size: 26px; font-weight: 700; letter-spacing: -.4px; margin-bottom: 8px;
  background: linear-gradient(135deg,#1a73e8,#8b5cf6);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.empty-sub { font-size: 15px; color: var(--muted); margin-bottom: 32px; }
.sug-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; width: 100%; }
.sug-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 15px 16px;
  font-size: 13px; color: var(--muted); text-align: left;
  box-shadow: var(--shadow-sm); transition: all .2s;
}
.sug-btn:hover { background: #eff6ff; border-color: rgba(26,115,232,.3); color: var(--text); transform: translateY(-2px); box-shadow: var(--shadow); }
.sug-i { font-size: 20px; display: block; margin-bottom: 6px; }

/* Messages */
@keyframes fadeUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

.msg-wrap { display: flex; gap: 12px; padding: 10px 24px; align-items: flex-start; animation: fadeUp .25s ease; }
.msg-wrap.user { flex-direction: row-reverse; }

.ava {
  width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.ava.bot  { background: linear-gradient(135deg,rgba(26,115,232,.15),rgba(139,92,246,.12)); border: 1px solid rgba(26,115,232,.2); }
.ava.user { background: linear-gradient(135deg,rgba(139,92,246,.15),rgba(26,115,232,.10)); border: 1px solid rgba(139,92,246,.2); }

.bubble-col { display: flex; flex-direction: column; gap: 5px; max-width: 72%; }
.msg-wrap.user .bubble-col { align-items: flex-end; }

.bubble { padding: 12px 15px; font-size: 14px; line-height: 1.65; color: var(--text); }
.bubble.bot  { background: #fff; border: 1px solid var(--border); border-radius: 4px 16px 16px 16px; box-shadow: var(--shadow-sm); }
.bubble.user { background: linear-gradient(135deg,#eff6ff,#f5f3ff); border: 1px solid rgba(139,92,246,.2); border-radius: 16px 4px 16px 16px; }

/* ── Markdown prose inside bot bubbles ── */
.bubble.bot h1,.bubble.bot h2,.bubble.bot h3,.bubble.bot h4 {
  font-weight: 700; margin: 12px 0 5px; line-height: 1.3; color: var(--text);
}
.bubble.bot h1 { font-size: 18px; }
.bubble.bot h2 { font-size: 16px; }
.bubble.bot h3 { font-size: 15px; }
.bubble.bot p  { margin: 6px 0; }
.bubble.bot ul,.bubble.bot ol { padding-left: 20px; margin: 6px 0; }
.bubble.bot li { margin: 3px 0; }
.bubble.bot strong { font-weight: 700; color: var(--text); }
.bubble.bot em { font-style: italic; }
.bubble.bot code {
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px;
  font-family: 'Courier New', monospace; font-size: 12.5px; color: #c026d3;
}
.bubble.bot pre {
  background: #1e293b; border-radius: 10px;
  padding: 12px 16px; margin: 10px 0;
  overflow-x: auto;
}
.bubble.bot pre code {
  background: none; border: none; color: #e2e8f0;
  font-size: 13px; padding: 0;
}
.bubble.bot blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  margin: 8px 0; color: var(--muted); font-style: italic;
}
.bubble.bot hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble.bot a  { color: var(--accent); text-decoration: underline; }
.bubble.bot table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.bubble.bot th,.bubble.bot td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble.bot th { background: #f8fafc; font-weight: 600; }

.msg-meta { font-size: 10.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; padding: 0 3px; }
.tok-badge { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 999px; padding: 2px 8px; font-size: 10px; color: #3b82f6; }

.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { background: #f8fafc; border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 10px; color: var(--muted); cursor: pointer; transition: all .15s; }
.chip:hover { background: #eff6ff; border-color: rgba(26,115,232,.3); color: var(--accent); }

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 6px 2px; }
.typing-dots span { width: 7px; height: 7px; background: #9ca3af; border-radius: 50%; animation: typingBounce 1.2s infinite; }
.typing-dots span:nth-child(2){ animation-delay:.2s }
.typing-dots span:nth-child(3){ animation-delay:.4s }
@keyframes typingBounce { 0%,80%,100%{transform:scale(1)} 40%{transform:scale(1.4)} }

/* ─── Input bar ─────────────────────────────────────────────────────────────── */
.input-bar {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  background: rgba(255,255,255,.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-input {
  width: 100%;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  min-height: 50px;
  max-height: 180px;
  overflow-y: auto;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.msg-input:focus {
  border-color: rgba(26,115,232,.55);
  box-shadow: 0 0 0 3px rgba(26,115,232,.10);
  background: #fff;
}
.msg-input::placeholder { color: #9ca3af; }

/* Button row — ALWAYS horizontal */
.btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
}
.btn {
  flex: 1;
  height: 42px;
  border: none;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  transition: all .2s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }

.btn-send  { background: linear-gradient(135deg,#1a73e8,#6d4de8); color: #fff; box-shadow: 0 4px 14px rgba(26,115,232,.28); }
.btn-send:hover  { box-shadow: 0 6px 20px rgba(26,115,232,.38); }
.btn-regen { background: #f1f5f9; color: var(--muted); border: 1px solid var(--border); }
.btn-regen:hover { background: #e8f0fe; color: var(--accent); border-color: rgba(26,115,232,.3); }
.btn-clear { background: #fff; color: var(--muted); border: 1px solid var(--border); }
.btn-clear:hover { background: #fef2f2; color: #ef4444; border-color: #fca5a5; }

/* ─── Footer ────────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 6px 0 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid rgba(0,0,0,0.03);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}
.app-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color .15s;
}
.app-footer a:hover {
  color: var(--accent2);
  text-decoration: underline;
}
.app-footer span {
  color: #d1d5db;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 999px; }

/* ─── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main { width: 100%; }

  .topbar { padding: 0 14px; }
  .topbar-title { font-size: 15px; }
  .badge-live { display: none; }
  .model-tag  { font-size: 10px; padding: 3px 9px; }

  .tok-bar { padding: 0 14px; }

  .empty-state { padding: 40px 16px 24px; }
  .empty-title  { font-size: 20px; }
  .sug-grid { grid-template-columns: 1fr; }

  .msg-wrap { padding: 8px 14px; }
  .bubble-col { max-width: 90%; }
  .bubble { font-size: 13.5px; }
  .ava { width: 30px; height: 30px; font-size: 14px; }
  .chips { display: none; }

  .input-bar { padding: 10px 14px 14px; }
  .btn { height: 40px; font-size: 13px; }
}
