/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --primary:    #3B82F6;
  --primary-d:  #2563EB;
  --secondary:  #F59E0B;
  --success:    #10B981;
  --danger:     #EF4444;
  --bg:         #0F172A;
  --bg-card:    #1E293B;
  --bg-card2:   #273449;
  --text:       #F1F5F9;
  --text-muted: #94A3B8;
  --border:     #334155;
  --radius:     14px;
  --sidebar-w:  240px;
}

/* ══════════════════════════════════════════════════════════════
   LIGHT MODE — body.light activates light theme
   Default is dark; toggled via toggleDark()
   ══════════════════════════════════════════════════════════════ */
body.light {
  --bg:         #F8FAFC;
  --bg-card:    #FFFFFF;
  --bg-card2:   #F1F5F9;
  --text:       #0F172A;
  --text-muted: #64748B;
  --border:     #E2E8F0;
}
/* Sidebar & bottom nav keep dark appearance in light mode for contrast */
body.light .sidebar {
  background: #1E293B;
  border-color: #334155;
}
body.light .sidebar-logo { color: #F8FAFC; }
body.light .sidebar-cur  { color: #94A3B8; }
body.light .nav-item { color: #94A3B8; }
body.light .nav-item:hover { background: rgba(255,255,255,0.08); color: #F1F5F9; }
body.light .nav-item.active { background: rgba(59,130,246,0.25); color: #93C5FD; }
body.light #b-darkmode { border-color: #475569; color: #94A3B8; }

body.light .bottom-nav {
  background: #1E293B;
  border-top-color: #334155;
}
body.light .bot-nav-item { color: #94A3B8; }
body.light .bot-nav-item.active { color: #3B82F6; }

/* Cards & inputs in light mode */
body.light .info-card {
  background: #FFFFFF;
  border-color: #E2E8F0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
body.light .form-input {
  background: #F1F5F9;
  border-color: #CBD5E1;
  color: #0F172A;
}
body.light .form-input:focus { border-color: var(--primary); }
body.light .form-input::placeholder { color: #94A3B8; }
body.light .auth-card {
  background: #FFFFFF;
  border-color: #E2E8F0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}
body.light .chat-header { background: #FFFFFF; border-color: #E2E8F0; }
body.light .msg-bubble.ai-bubble { background: #F1F5F9; color: #0F172A; }
body.light .msg-bubble.user-bubble { background: var(--primary); color: #fff; }
body.light .chat-input-area { background: #FFFFFF; border-color: #E2E8F0; }
body.light .chat-input { background: #F8FAFC; border-color: #E2E8F0; color: #0F172A; }
body.light .chat-input::placeholder { color: #94A3B8; }
body.light .screen-header { background: #FFFFFF; border-color: #E2E8F0; }
body.light .tool-chip { background: #F1F5F9; border-color: #E2E8F0; color: #475569; }
body.light .tool-chip:hover { border-color: var(--primary); color: var(--primary); }
body.light .icon-btn { background: #F1F5F9; border-color: #E2E8F0; }
body.light .btn-secondary { background: #F1F5F9; color: #0F172A; border-color: #E2E8F0; }
body.light pre { background: #F1F5F9 !important; border: 1px solid #E2E8F0; }
body.light .toast { background: #1E293B; color: #F1F5F9; }

/* smooth transition */
body, .sidebar, .chat-header, .info-card, .form-input, .msg-bubble,
.chat-input, .screen-header, .bottom-nav, .tool-chip {
  transition: background 0.25s, color 0.25s, border-color 0.25s;
}

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

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app { height: 100vh; display: flex; flex-direction: column; }

/* ── Auth screens ──────────────────────────────────────────────────────────── */
.auth-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 70% 20%, rgba(59,130,246,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 30% 80%, rgba(99,102,241,0.1) 0%, transparent 60%),
              var(--bg);
  padding: 16px;
  min-height: 100vh;
  overflow-y: auto;
}
.auth-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 24px 28px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.auth-logo {
  text-align: center; margin-bottom: 12px;
  font-size: 32px;
}
.auth-title { font-size: 22px; font-weight: 900; text-align: center; margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 16px; }
.form-group { margin-bottom: 12px; }
.form-label { font-size: 13px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%; background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px;
  font-size: 15px; color: var(--text); outline: none;
  transition: border-color .2s;
}
.form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--text-muted); }
.btn {
  width: 100%; padding: 14px; border-radius: 50px;
  font-size: 16px; font-weight: 800; border: none;
  transition: opacity .2s, transform .2s;
}
.btn:hover { opacity: .9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 16px rgba(59,130,246,0.35); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); font-size: 14px;
  padding: 12px; margin-top: 10px;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.auth-switch {
  text-align: center; margin-top: 20px;
  font-size: 14px; color: var(--text-muted);
}
.auth-switch span { color: var(--primary); font-weight: 700; cursor: pointer; }
.auth-switch span:hover { text-decoration: underline; }
.divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.divider span { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.error-msg {
  background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3);
  color: #FCA5A5; border-radius: 10px; padding: 10px 14px;
  font-size: 13px; margin-bottom: 14px; text-align: center;
}

/* ── Main layout ───────────────────────────────────────────────────────────── */
.main-layout {
  flex: 1; display: flex; overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo { font-size: 22px; font-weight: 900; color: var(--primary); }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 12px;
  font-size: 14px; font-weight: 700; color: var(--text-muted);
  cursor: pointer; transition: background .15s, color .15s;
  border: none; background: transparent; width: 100%; text-align: right;
}
.nav-item:hover { background: var(--bg-card2); color: var(--text); }
.nav-item.active { background: rgba(59,130,246,0.15); color: var(--primary); }
.nav-item .nav-icon { font-size: 18px; flex-shrink: 0; }
.nav-section-title {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  padding: 10px 12px 4px; text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar-footer {
  padding: 12px 8px; border-top: 1px solid var(--border);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  cursor: pointer; transition: background .15s;
}
.user-card:hover { background: var(--bg-card2); }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 700; }
.user-plan {
  font-size: 11px; color: var(--secondary); font-weight: 700;
}

/* ── Content area ──────────────────────────────────────────────────────────── */
.content-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}

/* ── Chat screen ───────────────────────────────────────────────────────────── */
.chat-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-header-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #818CF8);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.chat-header-name { font-size: 16px; font-weight: 800; }
.chat-header-status { font-size: 12px; color: var(--success); }
.chat-header-btns { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg-card2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; transition: background .15s;
}
.icon-btn:hover { background: var(--border); }

/* Tools strip */
.tools-strip {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none;
}
.tools-strip::-webkit-scrollbar { display: none; }
.tool-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px;
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.tool-chip:hover { border-color: var(--primary); color: var(--primary); }

/* Messages */
.messages-area {
  flex: 1; overflow-y: auto; padding: 20px 20px 8px;
  display: flex; flex-direction: column; gap: 16px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.msg-row { display: flex; gap: 10px; align-items: flex-end; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.msg-avatar.ai { background: linear-gradient(135deg, var(--primary), #818CF8); }
.msg-avatar.user-av { background: var(--primary); color: #fff; font-weight: 800; font-size: 14px; }
.msg-bubble {
  max-width: 65%; padding: 12px 16px; border-radius: 18px;
  font-size: 14px; line-height: 1.7;
}
.msg-bubble.ai {
  background: var(--bg-card); border: 1px solid var(--border);
  border-bottom-right-radius: 4px; color: var(--text);
}
.msg-bubble.user {
  background: var(--primary); color: #fff;
  border-bottom-left-radius: 4px;
}
.msg-bubble pre {
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
  font-size: 12px; overflow-x: auto; margin-top: 8px;
  white-space: pre-wrap; color: #93C5FD;
}
.msg-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 6px; }

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%,80%,100% { opacity: .25; transform: scale(.8); }
  40%         { opacity: 1;   transform: scale(1); }
}

/* Welcome */
.chat-welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px; text-align: center;
}
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.welcome-title { font-size: 24px; font-weight: 900; margin-bottom: 8px; }
.welcome-sub { font-size: 15px; color: var(--text-muted); margin-bottom: 28px; line-height: 1.6; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.suggestion-chip {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 18px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.suggestion-chip:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }

/* Input area */
.input-area {
  padding: 12px 16px 16px; border-top: 1px solid var(--border);
  background: var(--bg-card); flex-shrink: 0;
}
.input-row {
  display: flex; gap: 10px; align-items: flex-end;
}
.input-box {
  flex: 1; background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 16px; padding: 12px 16px;
  font-size: 15px; color: var(--text); outline: none; resize: none;
  min-height: 48px; max-height: 140px; line-height: 1.5;
  transition: border-color .2s;
  scrollbar-width: thin;
}
.input-box:focus { border-color: var(--primary); }
.input-box::placeholder { color: var(--text-muted); }
.send-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--primary); border: none; color: #fff;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(59,130,246,0.35);
  transition: background .2s, transform .2s;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-d); transform: scale(1.05); }
.send-btn:disabled { background: var(--border); box-shadow: none; transform: none; }
.input-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.input-action-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px;
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  transition: border-color .15s, color .15s;
}
.input-action-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Generic screen header ─────────────────────────────────────────────────── */
.screen-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.screen-title { font-size: 18px; font-weight: 800; }
.screen-body { flex: 1; overflow-y: auto; padding: 20px; }

/* ── Cards grid ────────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.info-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  transition: border-color .2s, transform .2s;
  cursor: pointer;
}
.info-card:hover { border-color: var(--primary); transform: translateY(-3px); }
.info-card .ic-icon { font-size: 28px; margin-bottom: 10px; }
.info-card .ic-title { font-size: 15px; font-weight: 800; margin-bottom: 4px; }
.info-card .ic-sub { font-size: 12px; color: var(--text-muted); }

/* ── Flashcards ────────────────────────────────────────────────────────────── */
.flashcard-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; padding: 30px;
}
.flashcard {
  width: 100%; max-width: 560px; min-height: 220px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 24px; padding: 36px;
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 18px; font-weight: 700;
  cursor: pointer; user-select: none;
  position: relative; overflow: hidden;
  transition: transform .1s;
}
.flashcard:active { transform: scale(.98); }
.flashcard.flipped { background: rgba(59,130,246,0.1); border-color: var(--primary); }
.flashcard-hint { font-size: 12px; color: var(--text-muted); }
.fc-nav { display: flex; gap: 14px; }
.fc-btn {
  padding: 12px 28px; border-radius: 50px; border: 1px solid var(--border);
  background: var(--bg-card2); color: var(--text); font-size: 14px; font-weight: 700;
  transition: background .15s, border-color .15s;
}
.fc-btn:hover { background: var(--border); }
.fc-btn.good { border-color: var(--success); color: var(--success); }
.fc-btn.good:hover { background: rgba(16,185,129,0.1); }
.fc-counter { font-size: 14px; color: var(--text-muted); font-weight: 700; }

/* ── Quiz ──────────────────────────────────────────────────────────────────── */
.quiz-wrap { padding: 24px; max-width: 700px; margin: auto; }
.quiz-progress { margin-bottom: 20px; }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .4s; }
.quiz-question {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 16px;
  font-size: 16px; font-weight: 700; line-height: 1.6;
}
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  background: var(--bg-card2); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 14px 18px;
  font-size: 15px; font-weight: 600; text-align: right;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.quiz-option:hover { border-color: var(--primary); }
.quiz-option.correct { border-color: var(--success); background: rgba(16,185,129,0.1); color: var(--success); }
.quiz-option.wrong { border-color: var(--danger); background: rgba(239,68,68,0.1); color: var(--danger); }

/* ── Profile screen ────────────────────────────────────────────────────────── */
.profile-wrap { padding: 24px; max-width: 600px; margin: auto; }
.profile-avatar-wrap { text-align: center; margin-bottom: 24px; }
.profile-big-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 900; margin: auto;
}
.profile-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.profile-section-title { font-size: 13px; font-weight: 800; color: var(--text-muted); margin-bottom: 14px; }
.profile-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.profile-row:last-child { border-bottom: none; padding-bottom: 0; }
.profile-row-label { font-size: 14px; font-weight: 700; }
.profile-row-val { font-size: 14px; color: var(--text-muted); }
.logout-btn {
  width: 100%; padding: 14px; border-radius: 50px;
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger); font-size: 15px; font-weight: 800;
  transition: background .15s;
}
.logout-btn:hover { background: rgba(239,68,68,0.2); }

/* ── Stats ─────────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; text-align: center;
}
.stat-card .s-icon { font-size: 28px; margin-bottom: 8px; }
.stat-card .s-num { font-size: 28px; font-weight: 900; color: var(--primary); }
.stat-card .s-label { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-top: 4px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 20px;
  font-size: 14px; font-weight: 700; color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; z-index: 999;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading-screen {
  height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Upgrade banner ────────────────────────────────────────────────────────── */
.upgrade-banner {
  background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(99,102,241,0.1));
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 14px; padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 16px 12px; flex-shrink: 0;
}
.upgrade-banner-text { font-size: 13px; color: var(--text-muted); }
.upgrade-banner-text strong { color: var(--primary); font-size: 15px; display: block; }
.upgrade-btn-sm {
  background: var(--primary); color: #fff;
  padding: 8px 18px; border-radius: 20px;
  font-size: 13px; font-weight: 800; border: none;
  flex-shrink: 0;
}

/* ── Mobile bottom nav ─────────────────────────────────────────────────────── */
.mobile-nav {
  display: none; background: var(--bg-card); border-top: 1px solid var(--border);
  padding: 8px 0 12px;
}
.mobile-nav-items { display: flex; justify-content: space-around; }
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 12px; cursor: pointer;
  background: none; border: none; color: var(--text-muted);
  font-family: 'Cairo', sans-serif; font-size: 11px; font-weight: 700;
  transition: color .15s;
  min-width: 60px;
}
.mobile-nav-item.active { color: var(--primary); }
.mobile-nav-item .mn-icon { font-size: 20px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-nav { display: block; }
  .main-layout { flex-direction: column; }
  .tools-strip { padding: 8px 12px; }
  .msg-bubble { max-width: 80%; }
  .chat-welcome { padding: 20px; }
}

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

/* ── Markdown in chat ──────────────────────────────────────────────────────── */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { margin: 8px 0 4px; font-weight: 900; }
.msg-bubble ul,.msg-bubble ol { padding-right: 20px; margin: 6px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { color: #93C5FD; }
.msg-bubble.user strong { color: #fff; }
.msg-bubble code {
  background: rgba(0,0,0,0.3); border-radius: 4px;
  padding: 1px 5px; font-size: 12px;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE UX IMPROVEMENTS
   ══════════════════════════════════════════════════════════════ */

/* Better touch targets */
@media (max-width: 768px) {
  .btn { padding: 15px; font-size: 16px; }
  .btn-sm { padding: 10px 18px; font-size: 14px; }
  .form-input { padding: 14px 16px; font-size: 16px; } /* prevent iOS zoom */
  .send-btn { padding: 12px 16px; font-size: 14px; }
  .chat-input { font-size: 16px; } /* prevent iOS zoom */
  .subj-sel { font-size: 16px; } /* prevent iOS zoom */
  
  /* Larger tap areas */
  .btn-icon { min-width: 44px; min-height: 44px; }
  .nav-item, .bot-nav-item { min-height: 44px; }
  
  /* Chat improvements on mobile */
  .chat-input-row { padding: 10px 12px; gap: 8px; }
  .chat-msgs { padding: 12px 12px 8px; }
  .msg-bubble { max-width: 88%; padding: 10px 14px; font-size: 14px; }
  
  /* Screen body padding */
  .screen-body { padding: 12px; }
  .screen-header { padding: 12px 16px; }
  
  /* Info cards on mobile */
  .info-card { padding: 14px; }
  
  /* Grid adjustments */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
  
  /* Upgrade page */
  .upgrade-grid { grid-template-columns: 1fr !important; }
  
  /* Bottom safe area for iOS */
  .bottom-nav { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .chat-input-row { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .nav-label { font-size: 12px; }
}

/* Pull-to-refresh hint */
.ptr-hint {
  text-align: center; font-size: 12px; color: var(--text-muted);
  padding: 8px; display: none;
}

/* Better focus rings for accessibility */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Smooth page transitions */
.screen-body {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Better empty states */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 48px 24px; gap: 12px;
  color: var(--text-muted); text-align: center; font-size: 14px;
}
.empty-state > div:first-child { font-size: 48px; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card2) 25%, var(--border) 50%, var(--bg-card2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Toast improvements */
.toast {
  max-width: 90vw;
  white-space: normal !important;
  text-align: center;
  word-break: break-word;
}
