/* =====================================================================
   ExamCracker AI — UX Overhaul v3
   Mobile-first containment, accessible light theme, compact sidebar,
   responsive study rooms/settings, and distraction-free CBT workspace.
   ===================================================================== */

/* ---------- Theme-safe surfaces ---------- */
body.light-mode {
  --bg-dark:#f4f7fb;
  --bg-surface:#ffffff;
  --bg-card:#ffffff;
  --bg-card-hover:#f8fafc;
  --bg-glass:rgba(255,255,255,.92);
  --border-subtle:rgba(15,23,42,.12);
  --border-glow:rgba(79,70,229,.28);
  --text-main:#0f172a;
  --text-muted:#475569;
  --text-dim:#64748b;
  color-scheme:light;
}
body.light-mode .app-sidebar,
body.light-mode .app-header,
body.light-mode .cbt-page-toolbar,
body.light-mode .cbt-top-bar,
body.light-mode .cbt-action-footer,
body.light-mode .modal-box,
body.light-mode .room-card,
body.light-mode .rooms-hero,
body.light-mode .rooms-hero-stat,
body.light-mode .cbt-main-arena,
body.light-mode .cbt-sidebar-panel,
body.light-mode .card,
body.light-mode .pricing-card {
  background:#fff !important;
  color:var(--text-main);
  border-color:var(--border-subtle);
}
body.light-mode .app-sidebar { background:rgba(255,255,255,.98) !important; }
body.light-mode .app-header { background:rgba(255,255,255,.94) !important; }
body.light-mode .brand-title,
body.light-mode .cbt-toolbar-title,
body.light-mode .rooms-title,
body.light-mode .rooms-section-head h3,
body.light-mode .card-title,
body.light-mode .modal-box h1,
body.light-mode .modal-box h2,
body.light-mode .modal-box h3,
body.light-mode .modal-box h4,
body.light-mode .question-text,
body.light-mode .option-content,
body.light-mode .settings-modal-box label,
body.light-mode .settings-modal-box .settings-plan-name,
body.light-mode .leaderboard-table td,
body.light-mode .leaderboard-table th { color:var(--text-main) !important; }
body.light-mode .nav-item { color:#475569; }
body.light-mode .nav-item.active { color:#3730a3; background:rgba(99,102,241,.10); }
body.light-mode .nav-category-title { color:#64748b; }
body.light-mode .sidebar-tool-btn { color:#475569; background:#f8fafc; border-color:rgba(15,23,42,.08); }
body.light-mode .sidebar-tool-btn:hover { color:#1e1b4b; background:#eef2ff; }
body.light-mode .rooms-subtitle,
body.light-mode .rooms-hero-stat span,
body.light-mode .card-subtitle,
body.light-mode .q-topic-label,
body.light-mode .dynamic-test-footer,
body.light-mode .settings-modal-box .settings-hint { color:#64748b !important; }
body.light-mode .cbt-question-body,
body.light-mode .cbt-top-bar,
body.light-mode .cbt-action-footer { background:#fff !important; }
body.light-mode .option-item { background:#f8fafc; border-color:#dbe3ee; }
body.light-mode .option-item:hover { background:#f1f5f9; }
body.light-mode .cbt-timer-card { background:#f8fafc !important; }
body.light-mode .palette-btn { background:#e2e8f0; color:#0f172a; }
body.light-mode .pro-banner { background:linear-gradient(135deg,#eef2ff,#f5f3ff); border-color:#c7d2fe; }
body.light-mode .pro-banner-head { color:#1e1b4b; }
body.light-mode .pro-banner p { color:#64748b; }
body.light-mode .modal-box input,
body.light-mode .modal-box select,
body.light-mode .modal-box textarea { background:#f8fafc !important; color:#0f172a !important; border-color:#cbd5e1 !important; }
body.light-mode .modal-box input::placeholder { color:#64748b; }
body.light-mode .historical-q,
body.light-mode .history-row { background:#f8fafc; color:#0f172a; }
body.light-mode .history-row strong { color:#0f172a; }

/* Override legacy inline #fff only where the theme is visibly broken. */
body.light-mode [style*="color:#fff"],
body.light-mode [style*="color: #fff"] { color:var(--text-main) !important; }

/* ---------- Sidebar: compact, scrollable, Pro always reachable ---------- */
.app-sidebar { overflow:hidden; }
.sidebar-nav { min-height:0; scrollbar-width:thin; }
.sidebar-tools { flex:0 0 auto; }
.sidebar-footer { flex:0 0 auto; }

/* ---------- Settings ---------- */
.settings-modal-box { width:min(560px,94vw) !important; padding:22px !important; }
.settings-modal-head { display:flex; align-items:center; gap:12px; margin-bottom:18px; }
.settings-modal-head > div { min-width:0; }
.settings-modal-head h3 { margin:0 !important; }
.settings-form-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.settings-field { min-width:0; }
.settings-field.full { grid-column:1/-1; }
.settings-field label { display:block; margin-bottom:6px; }
.settings-field input { width:100% !important; min-height:46px; }
.settings-plan-card { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px; margin:4px 0 16px; border:1px solid var(--border-subtle); border-radius:14px; background:rgba(99,102,241,.05); }
.settings-actions { display:grid; grid-template-columns:1fr 1fr 1.2fr; gap:8px; align-items:stretch; }
.settings-actions .btn { min-height:44px; width:100%; justify-content:center; }
.settings-delete-btn { color:var(--crimson-alert) !important; }

/* ---------- Group Study Rooms ---------- */
#view-group-rooms { max-width:1200px; margin:0 auto; }
.rooms-hero { min-width:0; }
.rooms-hero-copy { min-width:0; flex:1 1 auto; }
.rooms-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
.room-card { min-width:0; display:flex; flex-direction:column; justify-content:space-between; min-height:205px; }
.room-card .room-card-main { min-width:0; }
.room-card h4 { overflow-wrap:anywhere; }
.room-card .room-meta { min-width:0; display:flex; gap:8px; flex-wrap:wrap; }
.room-card .room-actions { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.room-card .room-actions .btn { flex:0 1 auto; }
.room-participants { display:flex; align-items:center; flex-wrap:wrap; min-width:0; }
.leaderboard-card { margin-top:18px; overflow:hidden; }
.leaderboard-table-wrap { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.leaderboard-table-wrap .leaderboard-table { min-width:680px; }
.leaderboard-mobile-list { display:none; }

/* ---------- CBT: no page scroll, only question body scrolls ---------- */
#view-cbt-test.cbt-locked-viewport { height:calc(100dvh - var(--header-height)); min-height:0; overflow:hidden; }
#view-cbt-test.cbt-locked-viewport .cbt-page-toolbar { flex:0 0 auto; }
#view-cbt-test.cbt-locked-viewport .cbt-container { min-height:0; height:calc(100% - 58px); }
#view-cbt-test.cbt-locked-viewport .cbt-main-arena { min-height:0; height:100%; overflow:hidden; }
#view-cbt-test.cbt-locked-viewport .cbt-question-body { min-height:0; overflow-y:auto; overscroll-behavior:contain; }
#view-cbt-test.cbt-locked-viewport .cbt-action-footer { flex:0 0 auto; }
.cbt-empty-state { max-width:620px; margin:12px auto; }

/* ---------- Dashboard / Standard Mock entry ---------- */
.standard-mock-entry { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:16px; border:1px solid var(--border-subtle); border-radius:16px; background:linear-gradient(135deg,rgba(99,102,241,.08),rgba(6,182,212,.05)); }
.standard-mock-entry-copy { min-width:0; }
.standard-mock-entry-copy strong { display:block; color:var(--text-main); font-size:.98rem; }
.standard-mock-entry-copy span { display:block; color:var(--text-muted); font-size:.76rem; margin-top:3px; }

/* ---------- Mobile ---------- */
@media (max-width:767px) {
  .app-header { height:58px !important; padding:0 8px !important; }
  .exam-picker-wrap { padding:5px 9px !important; border-radius:12px !important; }
  .exam-label { display:none !important; }
  .exam-select { font-size:.82rem !important; height:38px; }
  .user-profile-btn { width:38px !important; height:38px !important; }
  .user-profile-btn .avatar { width:34px !important; height:34px !important; }

  .app-sidebar { width:min(340px,88vw) !important; }
  .sidebar-header { padding:16px 16px 12px !important; }
  .brand-logo-icon { width:38px; height:38px; }
  .brand-title { font-size:1.08rem; }
  .brand-tagline { font-size:.65rem; }
  .sidebar-nav { padding:7px 9px 8px !important; gap:2px !important; }
  .nav-category-title { padding:8px 10px 4px !important; font-size:.62rem !important; }
  .nav-item { min-height:43px !important; padding:8px 10px !important; margin:1px 0 !important; font-size:.8rem !important; gap:9px !important; }
  .nav-icon { width:22px !important; min-width:22px !important; font-size:1rem !important; }
  .nav-badge { font-size:.56rem !important; padding:2px 5px !important; }
  .sidebar-tools { display:grid !important; grid-template-columns:1fr 1fr; gap:5px !important; padding:7px 9px !important; }
  .sidebar-tool-btn { min-height:38px !important; padding:7px 8px !important; border-radius:10px !important; font-size:.7rem !important; gap:6px !important; }
  .sidebar-tool-icon { width:19px !important; min-width:19px !important; font-size:.9rem !important; }
  .sidebar-footer { padding:7px 9px calc(8px + env(safe-area-inset-bottom)) !important; }
  .pro-banner { padding:9px !important; gap:5px !important; }
  .pro-banner p { display:none !important; }
  .pro-banner-head { font-size:.7rem !important; }
  .pro-banner .upgrade-trigger-btn { min-height:34px !important; font-size:.68rem !important; padding:6px !important; }

  .settings-modal-box { width:calc(100vw - 24px) !important; max-height:calc(100dvh - 24px) !important; padding:17px !important; border-radius:20px !important; }
  .settings-modal-head { margin-bottom:14px; }
  .settings-modal-head > span { font-size:1.65rem !important; }
  .settings-modal-head h3 { font-size:1.18rem !important; }
  .settings-form-grid { grid-template-columns:1fr !important; gap:10px !important; }
  .settings-field.full { grid-column:auto; }
  .settings-field input { min-height:44px !important; font-size:16px !important; }
  .settings-plan-card { align-items:flex-start; flex-direction:column; }
  .settings-plan-card .btn { width:100%; }
  .settings-actions { grid-template-columns:1fr 1fr !important; }
  .settings-actions .settings-save { grid-column:1/-1; }
  .settings-actions .settings-delete-btn { grid-column:1/-1; order:5; }

  #view-group-rooms { padding:10px 10px 24px !important; }
  .rooms-hero { padding:16px !important; margin-bottom:12px !important; border-radius:18px !important; gap:10px !important; }
  .rooms-eyebrow { font-size:.58rem; }
  .rooms-title { font-size:1.2rem !important; line-height:1.18; }
  .rooms-subtitle { font-size:.72rem !important; line-height:1.45; }
  .rooms-hero-stat { min-width:0; width:100%; padding:9px 11px !important; }
  .rooms-section-head { margin-bottom:9px !important; }
  .rooms-section-head h3 { font-size:.92rem !important; }
  .rooms-section-head p { font-size:.67rem !important; }
  .rooms-chip { font-size:.64rem; padding:5px 8px; }
  .rooms-grid { grid-template-columns:1fr !important; gap:9px !important; }
  .room-card { min-height:0; padding:13px !important; border-radius:15px !important; }
  .room-card h4 { font-size:.9rem !important; }
  .room-card p { font-size:.72rem !important; }
  .room-card .room-actions { align-items:stretch; flex-direction:column; }
  .room-card .room-actions .btn { width:100%; }
  .leaderboard-card { margin-top:12px !important; padding:13px !important; }
  .leaderboard-card .card-title { font-size:.95rem !important; }
  .leaderboard-card .card-subtitle { font-size:.68rem !important; }
  .leaderboard-table-wrap { display:none !important; }
  .leaderboard-mobile-list { display:grid !important; gap:8px; }
  .leaderboard-mobile-row { display:grid; grid-template-columns:34px 1fr auto; gap:8px; align-items:center; padding:10px; border:1px solid var(--border-subtle); border-radius:12px; background:rgba(99,102,241,.05); }
  .leaderboard-mobile-rank { font-weight:900; color:var(--primary-light); }
  .leaderboard-mobile-name { min-width:0; }
  .leaderboard-mobile-name strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-main); font-size:.76rem; }
  .leaderboard-mobile-name small { display:block; color:var(--text-muted); font-size:.62rem; margin-top:2px; }
  .leaderboard-mobile-score { text-align:right; font-weight:800; color:var(--cyber-cyan); font-size:.72rem; }

  #view-cbt-test.cbt-locked-viewport { height:calc(100dvh - 58px) !important; padding:4px 5px 5px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-page-toolbar { min-height:42px !important; margin-bottom:5px !important; padding:4px 7px !important; border-radius:11px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-toolbar-title { font-size:.78rem !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-toolbar-actions .btn { min-height:31px !important; font-size:.62rem !important; padding:5px 7px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-container { height:calc(100% - 47px) !important; gap:0 !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-main-arena { height:100% !important; border-radius:13px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-top-bar { min-height:38px !important; padding:6px 9px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-question-body { padding:11px 10px 12px !important; }
  #view-cbt-test.cbt-locked-viewport .question-text { font-size:.92rem !important; line-height:1.48 !important; }
  #view-cbt-test.cbt-locked-viewport .option-item { min-height:48px !important; padding:9px 9px !important; }
  #view-cbt-test.cbt-locked-viewport .option-content { font-size:.82rem !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer { padding:6px !important; }
  #view-cbt-test.cbt-locked-viewport .footer-left,
  #view-cbt-test.cbt-locked-viewport .footer-right { width:auto !important; display:flex !important; flex:1 1 50%; gap:5px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer { display:flex !important; flex-wrap:wrap; }
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer .btn { min-height:40px !important; font-size:.64rem !important; padding:7px 6px !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-sidebar-panel { display:none !important; }

  .standard-mock-entry { flex-direction:column; align-items:stretch; padding:13px; }
  .standard-mock-entry .btn { width:100%; }
}

@media (max-width:390px) {
  .sidebar-tool-btn { font-size:.64rem !important; }
  .settings-actions { grid-template-columns:1fr !important; }
  .settings-actions .btn { grid-column:1 !important; }
  #view-cbt-test.cbt-locked-viewport .footer-left,
  #view-cbt-test.cbt-locked-viewport .footer-right { flex:1 1 100%; }
}

/* Tablet / desktop settings */
@media (min-width:768px) {
  .settings-modal-box { width:min(620px,94vw) !important; }
}
.room-empty-card { grid-column:1/-1; min-height:180px; padding:18px !important; }
.room-empty-icon { font-size:2.1rem; margin-bottom:8px; }
.room-empty-copy h4 { color:var(--text-main); font-size:1rem; margin:3px 0 5px; }
.room-empty-copy p { color:var(--text-muted); font-size:.78rem; line-height:1.5; max-width:620px; }
@media (max-width:767px) {
  .room-empty-card { min-height:150px; }
  .room-empty-icon { font-size:1.8rem; }
  .room-empty-copy h4 { font-size:.9rem; }
  .room-empty-copy p { font-size:.7rem; }
}
body.light-mode .btn-primary,
body.light-mode .btn-danger,
body.light-mode .nav-badge,
body.light-mode .ai-pill { color:#fff !important; }
body.light-mode .pricing-price,
body.light-mode .pricing-features strong { color:var(--text-main) !important; }
@media (max-width:767px) {
  #view-pricing { padding:12px 10px 24px !important; }
  #view-pricing .pricing-grid { gap:10px !important; }
  #view-pricing .pricing-card { padding:16px !important; border-radius:16px !important; }
  #view-pricing .pricing-card h3 { font-size:1.05rem !important; }
  #view-pricing .pricing-features { font-size:.72rem !important; line-height:1.5 !important; }
  #view-pricing .pricing-price { font-size:1.65rem !important; }
  #view-pricing .btn { min-height:44px; }
}
.cbt-compact-timer { display:inline-flex; align-items:center; justify-content:center; min-width:62px; height:34px; padding:0 9px; border-radius:9px; background:rgba(245,158,11,.10); border:1px solid rgba(245,158,11,.25); color:var(--amber-gold); font:800 .72rem var(--font-heading); letter-spacing:.5px; }
.cbt-compact-timer.danger { color:var(--crimson-alert); background:rgba(244,63,94,.08); border-color:rgba(244,63,94,.25); }
body.light-mode .cbt-compact-timer { background:#fffbeb; }
@media (max-width:390px) { .cbt-compact-timer { min-width:55px; font-size:.66rem; padding:0 7px; } }
@media (max-width:767px) {
  .app-header { display:flex !important; flex-wrap:nowrap !important; align-items:center !important; }
  .app-header .header-left { flex:1 1 auto !important; width:auto !important; max-width:none !important; min-width:0 !important; }
  .app-header .header-right { flex:0 0 auto !important; width:auto !important; max-width:none !important; margin-left:6px; }
  .app-header .user-profile-btn { position:static !important; }
}
/* Pro / annual feature cards stay readable in both themes. */
body.light-mode #view-syllabus .card,
body.light-mode #view-weak-areas .card,
body.light-mode #view-flashcards .card,
body.light-mode #view-doubt-solver .card,
body.light-mode #view-study-planner .card,
body.light-mode #view-pyq-radar .card { color:var(--text-main); }
body.light-mode #view-syllabus [style*="background:rgba(255,255,255"],
body.light-mode #view-weak-areas [style*="background:rgba(255,255,255"],
body.light-mode #view-flashcards [style*="background:rgba(255,255,255"],
body.light-mode #view-doubt-solver [style*="background:rgba(255,255,255"],
body.light-mode #view-study-planner [style*="background:rgba(255,255,255"],
body.light-mode #view-pyq-radar [style*="background:rgba(255,255,255"] { background:#f8fafc !important; }
body.light-mode #view-doubt-solver .chat-history-sidebar,
body.light-mode #view-doubt-solver .chat-window,
body.light-mode #view-flashcards .card-face,
body.light-mode #view-study-planner .plan-day-card { background:#fff !important; color:var(--text-main); }
@media (max-width:767px) {
  #view-dashboard .stat-grid { grid-template-columns:1fr 1fr !important; gap:8px !important; }
  #view-dashboard .stat-grid .countdown-widget-card { grid-column:1/-1; }
  #view-dashboard .stat-card { min-height:112px !important; padding:12px !important; border-radius:15px !important; }
  #view-dashboard .stat-card .stat-icon-wrap { width:38px !important; height:38px !important; font-size:1rem !important; }
  #view-dashboard .stat-label { font-size:.61rem !important; }
  #view-dashboard .stat-value { font-size:1.05rem !important; }
  #view-dashboard .stat-meta { font-size:.61rem !important; line-height:1.35; }
  #view-dashboard .dashboard-grid { gap:10px !important; }
  #view-dashboard .welcome-banner { padding:14px !important; }
  #view-dashboard .welcome-title { font-size:1.35rem !important; }
}
@media (max-width:360px) {
  #view-dashboard .stat-grid { grid-template-columns:1fr !important; }
  #view-dashboard .stat-grid .countdown-widget-card { grid-column:auto; }
}
/* Flex-item correction: .page-view inherits flex:1, which can expand the CBT
   beyond the viewport. Lock the CBT page to exactly the space below the header. */
#view-cbt-test.cbt-locked-viewport {
  flex:0 0 calc(100vh - var(--header-height));
  height:calc(100vh - var(--header-height));
  max-height:calc(100vh - var(--header-height));
}
@media (max-width:767px) {
  #view-cbt-test.cbt-locked-viewport {
    flex:0 0 calc(100vh - 58px) !important;
    height:calc(100vh - 58px) !important;
    max-height:calc(100vh - 58px) !important;
  }
}
#view-cbt-test.cbt-locked-viewport { animation:none !important; transform:none !important; }
@media (max-width:767px) {
  #view-cbt-test.cbt-locked-viewport {
    flex:0 0 calc(100vh - var(--header-height)) !important;
    height:calc(100vh - var(--header-height)) !important;
    max-height:calc(100vh - var(--header-height)) !important;
  }
}
@media (max-width:767px) {
  #view-cbt-test.cbt-locked-viewport .cbt-page-toolbar > div:first-child {
    flex:1 1 auto !important;
    width:auto !important;
    min-width:0 !important;
    max-width:none !important;
  }
  #view-cbt-test.cbt-locked-viewport .cbt-toolbar-actions {
    width:auto !important;
    flex:0 0 auto !important;
    min-width:max-content;
  }
}
@media (max-width:767px) {
  #view-cbt-test.cbt-locked-viewport .cbt-page-toolbar h2 {
    font-size:.78rem !important;
    line-height:1.1 !important;
    white-space:nowrap !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    margin:0 !important;
  }
  #view-cbt-test.cbt-locked-viewport .cbt-page-toolbar p { display:none !important; }
  #view-cbt-test.cbt-locked-viewport .cbt-page-toolbar { min-height:40px !important; height:40px !important; }
}
#view-cbt-test.cbt-locked-viewport { display:flex !important; flex-direction:column !important; }
#view-cbt-test.cbt-locked-viewport .cbt-container { flex:1 1 auto !important; height:auto !important; min-height:0 !important; }
@media (max-width:767px) {
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer {
    display:grid !important;
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:6px !important;
    align-items:stretch;
  }
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer .footer-left,
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer .footer-right {
    display:contents !important;
  }
  #view-cbt-test.cbt-locked-viewport .cbt-action-footer .btn {
    min-width:0 !important;
    width:100% !important;
    min-height:38px !important;
    font-size:.62rem !important;
    padding:6px 5px !important;
    white-space:nowrap !important;
  }
}
#view-cbt-test.cbt-locked-viewport:not(.active) { display:none !important; }
#view-cbt-test.cbt-locked-viewport.active { display:flex !important; }
@media (max-width:767px) {
  .pro-banner .upgrade-trigger-btn {
    width:100% !important;
    min-width:0 !important;
    max-width:none !important;
    height:auto !important;
    overflow:visible !important;
    white-space:nowrap !important;
    font-size:.68rem !important;
    font-size:0 !important;
  }
  .pro-banner .upgrade-trigger-btn::before { content:'⚡ Upgrade to Pro'; font-size:.68rem !important; }
}
@media (max-width:767px) {
  .pro-banner-head .nav-badge { display:none !important; }
  .pro-banner-head { display:flex; justify-content:space-between; align-items:center; gap:6px; }
}
body.light-mode .app-sidebar .nav-item,
body.light-mode .app-sidebar .nav-item > span { color:#334155 !important; }
body.light-mode .app-sidebar .nav-item.active,
body.light-mode .app-sidebar .nav-item.active > span { color:#3730a3 !important; }
body.light-mode .app-sidebar .nav-category-title { color:#64748b !important; }
body.light-mode .app-sidebar .sidebar-tool-btn,
body.light-mode .app-sidebar .sidebar-tool-btn > span { color:#334155 !important; }
body.light-mode .app-sidebar .pro-banner-head,
body.light-mode .app-sidebar .pro-banner-head > span { color:#1e1b4b !important; }
body.light-mode .app-sidebar .pro-banner .upgrade-trigger-btn { color:#fff !important; }
