/* StudyFlow PWA — Bundled Styles */

/* ============================== STUDYFLOW PWA — CSS VARIABLES ============================== */

:root {
  /* PWA Theme Colors (dark theme for PWA) */
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-hover: #1f2a4a;
  --border: #2a3a5e;
  --border-light: #3a4a6e;
  --text: #eaeef5;
  --text-secondary: #a0b0d0;
  --text-muted: #6a7a9a;
  --primary: #4f8cff;
  --primary-light: #2a4a7a;
  --primary-dark: #3a6ad4;
  --green: #22c55e;
  --green-bg: #1a3a2a;
  --red: #ef4444;
  --red-bg: #3a1a1a;
  --amber: #f59e0b;
  --amber-bg: #3a2a1a;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --header-h: 48px;
  color-scheme: dark;
  --cat-formal: #4f8cff;
  --cat-self: #a855f7;
  --cat-work: #f97316;
  --cat-lang: #06b6d4;
  --cat-health: #22c55e;
  --cat-mind: #ec4899;
  --cat-project: #f59e0b;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Monaco', monospace;
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  :root {
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
  }
}

/* ============================== LIGHT THEME (v2 studyflow-hub palette) ==============================
   Active when <html data-theme="light"> (set by the bootstrap script in
   index.html <head> before first paint + toggled by #btn-theme). */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --border: #e2e4e8;
  --border-light: #eef0f2;
  --text: #1a1d23;
  --text-secondary: #5f6570;
  --text-muted: #9ca0a8;
  --primary: #4f6ef7;
  --primary-light: #eef1fe;
  --primary-dark: #3a56d4;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}
/* ============================== STUDYFLOW PWA — LAYOUT ============================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  /* v2 parity: fixed viewport — the app NEVER scrolls the body.
     Each .col scrolls internally (overflow-y: auto). */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: var(--primary-light);
  color: var(--text);
}

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

/* ============================== APP CONTAINER ============================== */
.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.app.hidden {
  display: none;
}

/* ============================== HEADER ============================== */
/* Re-layout (owner spec): line 1 = brand ⇤ week player … actions;
   line 2 = the status cluster, which now lives in .header-right (row 2 of
   its column). The header therefore must be allowed to WRAP: nothing can
   ever overlap, and it grows past 48px only when it has to. */
.header {
  min-height: var(--header-h);
  height: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;      /* let the right column drop to its own line */
  row-gap: 4px;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Line 1 (left): brand + nav toggle + week + player; wraps if narrow. */
.header-left {
  flex-wrap: wrap;
}

/* The right group is a 2-row column: actions on top, status below.
   margin-left:auto keeps it flush right even when it wraps onto its own
   line (space-between alone would park a lone item at the start edge). */
.header-right {
  flex-direction: column;
  align-items: flex-end;
  row-gap: 4px;
  margin-left: auto;
}

/* The two rows inside .header-right (new wrappers — no ids moved into them
   that JS did not already reach by id, and #update-panel is still inserted
   next to #ver-status by shared/status-panel.js). */
.header-actions-row,
.header-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}
.header-status-row { gap: 8px; }
/* The pill's own left margin would double the row gap. */
.header-status-row .server-status-wrap { margin-left: 0; }

.header-week {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
}

.logo-icon {
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.arr {
  cursor: pointer;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 11px;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.arr:hover {
  background: var(--surface-hover);
  color: var(--text);
}

#week-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Hamburger */
.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  color: var(--text);
  border-radius: var(--radius-xs);
  transition: background 0.15s;
}

.hamburger:hover { background: var(--surface-hover); }
.hamburger:active { background: var(--border); }

/* Header utility buttons (theme / backup / restore) — v2 inline-style parity */
.hdr-btn {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  color: var(--text-secondary);
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
.hdr-btn:hover { color: var(--text); border-color: var(--primary); background: var(--surface-hover); }
/* "Borrar todo" — destructive header action, red so it never reads as safe. */
.hdr-btn.hdr-danger { color: var(--red); border-color: var(--red); }
.hdr-btn.hdr-danger:hover { color: #fff; background: var(--red); border-color: var(--red); }

/* ============================== TAB BAR ============================== */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  padding: 0 12px;
  gap: 0;
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
}

.tab-subtitle {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.7;
}

/* ============================== MAIN GRID ============================== */
.main {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Dashboard shown → main grid hidden (see syncMainWithDashboard in app.js) */
.main.hidden { display: none; }

.view-panel { display: contents; }
.view-panel.hidden { display: none; }

/* Dashboard sits OUTSIDE .main (v2 architecture). .view-panel has
   display:contents, so .dashboard-container is a direct flex item of #app:
   it stretches (flex:1) and scrolls internally. Dashboard and .main are
   mutually exclusive (the view switch hides one when the other shows), so
   the two flex:1 items never compete. */

.col { 
  overflow-y: auto; 
  min-height: 0; 
  max-height: 100%; 
}

.col-left { 
  background: var(--surface); 
  border-right: 1px solid var(--border); 
  padding: 12px 10px 50px; 
  overflow-y: auto; 
  min-height: 0; 
  position: relative;
}

/* Keyboard hint — v2 parity (fixed, hover-free) */
.col-left::before {
  content: "Ctrl+B ocultar nav";
  position: fixed;
  bottom: 8px;
  left: 14px;
  font-size: 9px;
  white-space: pre;
  color: var(--text-muted);
  opacity: .8;
  pointer-events: none;
  z-index: 1;
}

.col-center { 
  background: var(--bg); 
  padding: 20px 24px; 
  overflow-y: auto; 
  min-height: 0; 
}

.col-title { 
  font-size: 10px; 
  font-weight: 600; 
  text-transform: uppercase; 
  letter-spacing: .5px; 
  color: var(--text-muted); 
  margin-bottom: 10px; 
  padding: 0 4px; 
}

/* ============================== PRINT ============================== */
@media print {
  .header, .tab-bar, .hamburger, .install-btn, .update-notification, .offline-indicator {
    display: none !important;
  }
  .main { display: block; }
  .col-left { display: none; }
  .col-center { padding: 0; }
}
/* ============================== STUDYFLOW PWA — CORE COMPONENTS ============================== */

/* ============================== LOADING SCREEN ============================== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================== OFFLINE INDICATOR ============================== */
.offline-indicator {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--amber-bg);
  color: var(--amber);
  padding: 8px 16px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
}

.offline-indicator.hidden { display: none; }

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================== SHARED UTILITIES ============================== */
.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state .big {
  font-size: 40px;
  display: block;
  margin-bottom: 12px;
}

.flex { display: flex; }
.flex-b { display: flex; justify-content: space-between; align-items: center; }
.mt-6 { margin-top: 6px; }

/* ============================== BUTTONS ============================== */
.btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover { background: var(--surface-hover); }
.btn:active { background: var(--border); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-danger {
  background: var(--red-bg);
  border-color: var(--red);
  color: var(--red);
}

.btn-danger:hover { background: var(--red); color: #fff; }

/* ============================== INPUTS ============================== */
input, select, textarea {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ============================== OVERLAYS / MODALS ============================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.overlay.open {
  opacity: 1;
  visibility: visible;
}

.omodal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.overlay.open .omodal { transform: scale(1); }

.omodal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.omodal-head h3 { font-size: 15px; font-weight: 600; }

.omodal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* ============================== INSTALL BUTTON ============================== */
.install-btn {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
}

.install-btn:hover { background: var(--primary-dark); }

/* PWA install banner — in-app invitation to install (supersedes .install-btn). */
.pwa-install-banner {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10000;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  line-height: 1.3;
  animation: pwaBannerFadeIn 0.35s ease;
}

.pwa-install-banner__icon { font-size: 18px; flex-shrink: 0; }

.pwa-install-banner__text { flex: 1; }

.pwa-install-banner__install {
  flex-shrink: 0;
  padding: 7px 14px;
  background: #fff;
  color: var(--primary-dark);
  border: none;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.pwa-install-banner__install:hover { background: var(--primary-light); color: #fff; }

.pwa-install-banner__dismiss {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.8;
  padding: 4px;
}

.pwa-install-banner__dismiss:hover { opacity: 1; }

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

@media (max-width: 520px) {
  .pwa-install-banner { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* ============================== UPDATE NOTIFICATION ============================== */
.update-notification {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  animation: slideUp 0.3s ease;
}

.update-notification button {
  padding: 6px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* ============================== DASHBOARD ============================== */
/* max-width 700 -> 980: con 700 solo cabian 4 tarjetas de 132px y las
   6 restantes quedaban tras el scroll lateral. 980 da sitio a 5 por fila
   (5*150 + 4*10 + 48 de padding ~= 838px) con margen comodo. */
.dashboard-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  max-width: 980px;
  margin: 0 auto;
}

/* Keep the ORIGINAL centred 980px column — we only move the scroll OFF the
   block. `syncMainWithDashboard` (app.js) toggles body.dashboard-view while
   #view-dashboard is shown; since the block no longer scrolls, the page does.
   The look is unchanged; the inner scrollbar is gone. */
body.dashboard-view {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
}
body.dashboard-view .dashboard-container {
  overflow: visible;
}

.dashboard-profile {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.dashboard-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.dashboard-greeting h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.dashboard-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

.dashboard-badges {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-base {
  background: var(--primary-light);
  color: var(--primary);
}

.dashboard-nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.dashboard-nav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.dashboard-nav-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.dnc-icon { font-size: 32px; flex-shrink: 0; }
.dnc-text { min-width: 0; flex: 1; }
.dnc-label { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.dnc-desc { font-size: 12px; color: var(--text-muted); }

/* The "Guía y tutoriales" card is an <a>, not a <div>: strip the link
   affordances so it renders exactly like the other nav cards. */
a.dashboard-nav-card { text-decoration: none; color: inherit; }

/* Google badge (v2 parity) — same gradient as studyflow-hub auth.css.
   Hidden until v3 actually has Google login to report. */
.badge-google {
  background: linear-gradient(135deg, #4285f4, #34a853);
  color: #fff;
}

/* ─── Dashboard widgets row (habits + agenda side panel) ───────── */
/* v2 parity (features/auth/auth.css): 1fr main + 380px agenda panel,
   stacking under 900px. */
.dashboard-widgets-row {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}
.dashboard-widgets-row > * { min-width: 0; /* prevent overflow */ }

/* ─── Agenda side panel (dashboard) — readOnly + compact ───────── */
.dashboard-agenda-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-y: auto;
  max-height: 420px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.dashboard-agenda-panel::-webkit-scrollbar { width: 4px; }
.dashboard-agenda-panel::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 3px;
}
/* Compact density overrides — keep proportions when packed at 380px */
.dashboard-agenda-panel .mc-head { padding: 2px 0 4px; }
.dashboard-agenda-panel .mc-grid .mc-day { padding: 2px 0; }
.dashboard-agenda-panel .mc-grid .mc-day .mc-day-num { font-size: 9px; }
.dashboard-agenda-panel .mc-grid .mc-day .mc-circle { width: 4px; height: 4px; margin-top: 1px; }
.dashboard-agenda-panel .col-title { margin-top: 8px; margin-bottom: 6px; }
.dashboard-agenda-panel .day-item { padding: 5px 7px; gap: 4px; margin-bottom: 1px; }
.dashboard-agenda-panel .day-item .d-name { font-size: 11px; min-width: 22px; }
.dashboard-agenda-panel .day-item .d-num { font-size: 11px; min-width: 16px; }
.dashboard-agenda-panel .day-item .d-stats { font-size: 8px; }
.dashboard-agenda-panel .day-item .d-eff { font-size: 8px; }
.dashboard-agenda-panel .day-item .d-dots .dot { width: 4px; height: 4px; }
.dashboard-agenda-panel .week-summary { margin-top: 8px; padding: 6px; }
.dashboard-agenda-panel .week-summary .ws { font-size: 10px; padding: 1px 0; }
.dashboard-agenda-panel .week-summary .ws-eff { padding-top: 3px; margin-top: 2px; }
/* No drag-over affordance on the readOnly side panel */
.dashboard-agenda-panel .day-item.drag-over-day { box-shadow: none; }

/* ─── Habit grid (21-day mini heatmap) ──────────────────────── */
.dashboard-habit-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.dhg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.dhg-link {
  font-size: 11px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.dhg-link:hover { text-decoration: underline; }

/* Grid layout: label + N cells + progress */
.dhg-body { overflow-x: auto; }
.dhg-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 3px;
  height: 18px;
}
.dhg-label-col {
  width: 32px;
  font-size: 9px;
  color: var(--text-muted);
  text-align: right;
  padding-right: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
.dhg-progress-col {
  width: 28px;
  font-size: 8px;
  color: var(--text-muted);
  text-align: right;
  padding-left: 4px;
  flex-shrink: 0;
}
.dhg-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.dhg-cell:hover { transform: scale(1.4); cursor: pointer; }
.dhg-day-label {
  font-size: 8px;
  color: var(--text-muted);
  text-align: center;
  line-height: 12px;
  background: transparent !important;
}
.dhg-day-label:hover { transform: none; cursor: default; }
.dhg-weekend { color: var(--primary); font-weight: 600; }
.dhg-header-row { height: 16px; margin-bottom: 6px; }
.dhg-overall-row { border-top: 1px solid var(--border); padding-top: 4px; margin-top: 2px; }
/* Cell colors */
.dhg-on  { background: #27ae60; }
.dhg-mid { background: #6abf4b; }
.dhg-low { background: #a8d68a; }
.dhg-off { background: var(--border); opacity: 0.4; }

/* Responsive — stack widgets under <900px (agenda panel under habits) */
@media (max-width: 900px) {
  .dashboard-widgets-row { grid-template-columns: 1fr; }
  .dashboard-agenda-panel { max-height: 360px; }
}

/* ============================== SERVER STATUS DOT ============================== */
/* V3: moved INTO the header, right after the "studyflow" wordmark.
   Inline pill (dot + "API" label), not fixed to a viewport corner. */
.server-status-wrap {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--surface, #1a1f2e);
  border: 1px solid var(--border, #2b3245);
  border-radius: 10px;
  font-size: 9px;
  line-height: 1;
  vertical-align: middle;
  flex: 0 0 auto;
}
.server-status-wrap .server-status-label {
  color: var(--text-muted);
  letter-spacing: .5px;
}
.server-status { width:8px; height:8px; border-radius:50%; display:inline-block; background:var(--text-muted); flex:0 0 auto; }
.server-status.online { background:var(--green); animation:status-pulse 2s ease-in-out infinite; }
.server-status.offline { background:var(--red); animation:status-blink .9s steps(2,start) infinite; }
.server-status.amber { background:var(--amber); }
@keyframes status-pulse { 0%,100%{ box-shadow:0 0 0 0 rgba(34,197,94,.45); opacity:1; } 50%{ box-shadow:0 0 0 5px rgba(34,197,94,0); opacity:.75; } }
@keyframes status-blink { 50%{ opacity:.2; } }
/* Version pill (shared/status-panel.js): the state rides on the LABEL, not a
   dot, so the same .online/.offline/.amber names map to text colours. */
.server-status-wrap .server-status-label.online { color:var(--green); }
.server-status-wrap .server-status-label.offline { color:var(--text-muted); }
.server-status-wrap .server-status-label.amber { color:var(--amber); }
#ver-status { cursor: pointer; }

/* Self-update panel (shared/status-panel.js): a second pill after the version
   one, so it inherits the header-pill chrome. Hidden until there is something
   to say. Same label colour states as the version pill. */
.update-panel { gap: 6px; padding: 1px 6px; }
.update-panel .update-msg { color: var(--text-muted); }
.update-panel .update-msg.online { color: var(--green); }
.update-panel .update-msg.amber { color: var(--amber); }
.update-panel .update-msg.offline { color: var(--red); }
.update-action-btn {
  font: inherit;
  line-height: 1.1;
  padding: 2px 8px;
  border: 1px solid var(--primary, #4f8cff);
  border-radius: 8px;
  background: var(--primary, #4f8cff);
  color: #fff;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.update-action-btn:hover:not(:disabled) { filter: brightness(1.08); }
.update-action-btn:focus-visible { outline: 2px solid var(--primary, #4f8cff); outline-offset: 2px; }
.update-action-btn:disabled { opacity: .7; cursor: progress; }
.update-rollback-link {
  font: inherit;
  line-height: 1.1;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.update-rollback-link:hover { color: var(--text, #e6ebf5); }

/* V3: the API pill is now a real <button> (click = check / start). :where()
   keeps ZERO specificity, so the pill styles above still win on the idle state
   and only the UA button chrome is stripped. Hover/focus add feedback without
   changing layout. */
:where(button.server-status-wrap) {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
button.server-status-wrap:hover { background: var(--surface-hover, #1f2a4a); }
button.server-status-wrap:focus-visible { outline: 2px solid var(--primary, #4f8cff); outline-offset: 2px; }
button.server-status-wrap[aria-busy="true"] { cursor: progress; }

/* ============================== SERVER-DOWN NOTICE ==============================
   The SW no longer intercepts /api/health, so when the local server is down the
   health check genuinely fails and server-status.js adds body.sf-server-down.
   The notice is a normal-flow sibling placed before .app, so it pushes the UI
   down a few pixels instead of covering it: no content is hidden or unmounted,
   the app is only marked stale until the next successful health check. */
#sf-server-down { display: none; }
body.sf-server-down #sf-server-down {
  display: block;
  flex: 0 0 auto;
  padding: 6px 12px;
  text-align: center;
  font-size: 12px;
  line-height: 1.3;
  color: var(--red);
  background: var(--red-bg);
  border-bottom: 1px solid var(--red);
}

/* ============================== STUDYFLOW PWA — FEATURE COMPONENTS ============================== */

/* ============================== AGENDA COMPONENTS ============================== */
.day-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.day-header {
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.day-name { font-weight: 600; font-size: 13px; }
.day-date { font-size: 11px; color: var(--text-muted); }

.day-sessions { padding: 8px; min-height: 60px; }

.session-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.session-block:hover {
  border-color: var(--primary);
  transform: translateX(2px);
}

.session-block.dragging { opacity: 0.5; transform: scale(1.02); }

.session-time { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.session-title { font-size: 13px; font-weight: 500; }
.session-category { font-size: 10px; padding: 1px 6px; border-radius: 4px; margin-left: 8px; }

.session-category.formal { background: var(--cat-formal); color: #fff; }
.session-category.self { background: var(--cat-self); color: #fff; }
.session-category.work { background: var(--cat-work); color: #fff; }
.session-category.lang { background: var(--cat-lang); color: #fff; }
.session-category.health { background: var(--cat-health); color: #fff; }
.session-category.mind { background: var(--cat-mind); color: #fff; }
.session-category.project { background: var(--cat-project); color: #fff; }

/* ============================== HABITS COMPONENTS ============================== */
.habit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.habit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.habit-name { font-weight: 600; font-size: 14px; }
.habit-streak { font-size: 12px; color: var(--green); font-weight: 500; }

.habit-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.habit-day {
  aspect-ratio: 1;
  border-radius: var(--radius-xs);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.habit-day.completed {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
}

.habit-day:hover:not(.completed) {
  background: var(--surface-hover);
  border-color: var(--primary);
}

/* ============================== COURSES COMPONENTS ============================== */
.course-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.course-header {
  padding: 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.course-title { font-size: 15px; font-weight: 600; }
.course-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.course-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.course-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.course-topics { padding: 12px 16px; }

.topic-item {
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.topic-item:hover { background: var(--surface-hover); }
.topic-item.active { background: var(--primary-light); border: 1px solid var(--primary); }

.topic-title { font-weight: 500; font-size: 13px; margin-bottom: 2px; }
.topic-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 12px; }

.topic-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.topic-status.pending { background: var(--amber-bg); color: var(--amber); }
.topic-status.in-progress { background: var(--primary-light); color: var(--primary); }
.topic-status.done { background: var(--green-bg); color: var(--green); }

/* ============================== PDF VIEWER ============================== */
.pdf-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.pdf-toolbar {
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pdf-canvas-container {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.pdf-page { box-shadow: var(--shadow-md); background: #fff; }

/* ============================== QUIZ COMPONENTS ============================== */
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.quiz-question { font-size: 15px; font-weight: 500; margin-bottom: 16px; }

.quiz-options { display: flex; flex-direction: column; gap: 8px; }

.quiz-option {
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.quiz-option:hover { border-color: var(--primary); background: var(--surface-hover); }
.quiz-option.selected { border-color: var(--primary); background: var(--primary-light); }
.quiz-option.correct { border-color: var(--green); background: var(--green-bg); }
.quiz-option.incorrect { border-color: var(--red); background: var(--red-bg); }

.quiz-actions { margin-top: 16px; display: flex; gap: 12px; justify-content: flex-end; }

/* ============================== TODO COMPONENTS ============================== */
.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  margin-bottom: 6px;
  transition: border-color 0.15s;
}

.todo-item:hover { border-color: var(--primary); }

.todo-item.completed .todo-text { text-decoration: line-through; color: var(--text-muted); }

.todo-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}

.todo-item.completed .todo-checkbox {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.todo-text { flex: 1; font-size: 13px; min-width: 0; }

.todo-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.todo-item:hover .todo-actions { opacity: 1; }

.todo-action-btn {
  padding: 4px 8px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.todo-action-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ============================== AUTH FORMS ============================== */
.auth-form { max-width: 360px; margin: 0 auto; }

.auth-form h2 { text-align: center; margin-bottom: 24px; font-size: 20px; }

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

.auth-form label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }

.auth-form input { width: 100%; }

.auth-form .btn { width: 100%; margin-top: 8px; }

/* ============================== GENERIC MODAL FORM ============================== */
.modal-form .form-group { margin-bottom: 14px; }

.modal-form label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  box-sizing: border-box;
}

.modal-form textarea { resize: vertical; min-height: 72px; }

.modal-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-form .form-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 8px;
  display: none;
}

.modal-form .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ============================== AGENDA SESSION CARD ============================== */
.agenda-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.agenda-header h2 { font-size: 18px; font-weight: 600; }

.sessions-list { display: flex; flex-direction: column; gap: 10px; }

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.session-card:hover { border-color: var(--primary); }

.session-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.session-card-title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }

.session-card-actions { display: flex; gap: 4px; }

.session-card-actions button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s;
}

.session-card-actions button:hover { border-color: var(--primary); color: var(--primary); }

.session-card-actions button.delete:hover { border-color: var(--red); color: var(--red); }

.session-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.session-card-meta .cat {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.session-card-desc {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

/* ============================== CATEGORY COLORS ============================== */
.cat-formal { color: var(--cat-formal); }
.cat-self { color: var(--cat-self); }
.cat-work { color: var(--cat-work); }
.cat-lang { color: var(--cat-lang); }
.cat-health { color: var(--cat-health); }
.cat-mind { color: var(--cat-mind); }
.cat-project { color: var(--cat-project); }

.bg-formal { background: var(--cat-formal); }
.bg-self { background: var(--cat-self); }
.bg-work { background: var(--cat-work); }
.bg-lang { background: var(--cat-lang); }
.bg-health { background: var(--cat-health); }
.bg-mind { background: var(--cat-mind); }
.bg-project { background: var(--cat-project); }
/* ============================== STUDYFLOW PWA — RESPONSIVE ============================== */

/* ============================== RESPONSIVE <768px ============================== */
@media (max-width: 768px) {
  :root {
    --header-h: 52px;
  }

  /* Main grid: single column */
  .main {
    grid-template-columns: 1fr;
    position: relative;
  }

  /* Sidebar: slide-over overlay */
  .col-left {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
    border-right: none;
    padding: 16px 12px;
    padding-top: calc(var(--header-h) + 16px);
  }

  .sidebar-open .col-left {
    transform: translateX(0);
  }

  .sidebar-open .col-left::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: -1;
  }

  .col-center {
    padding: 16px;
    padding-bottom: 100px;
  }

  /* Header compact */
  .header {
    padding: 0 12px;
  }

  .header-logo .logo-text {
    display: none;
  }

  .header-center {
    gap: 8px;
  }

  .week-nav {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  #week-label {
    font-size: 12px;
  }

  /* Hamburger */
  .hamburger {
    display: flex !important;
  }

  .sidebar-open .hamburger {
    position: relative;
    z-index: 1001;
  }

  .sidebar-open .header-center {
    display: none;
  }

  /* Tab bar scrollable */
  .tab-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
  }

  .tab-bar::-webkit-scrollbar { display: none; }

  .tab-btn {
    padding: 10px 12px;
    font-size: 12px;
  }

  .tab-subtitle {
    display: none;
  }

  /* Dashboard */
  .dashboard-container {
    padding: 16px;
  }

  .dashboard-profile {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .dashboard-nav-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-nav-card {
    padding: 16px;
  }

  .dnc-icon { font-size: 28px; }

  /* Install button position */
  .install-btn {
    bottom: 16px;
    right: 16px;
    left: 16px;
    text-align: center;
  }

  .update-notification {
    left: 16px;
    right: 16px;
    transform: none;
  }

  /* Agenda day columns stack */
  .day-column { margin-bottom: 16px; }

  /* Habits grid: smaller cells */
  .habit-grid { gap: 3px; }
  .habit-day { font-size: 9px; }

  /* Course cards */
  .course-header { padding: 12px; }
  .course-topics { padding: 8px 12px; }
  .topic-item { padding: 8px 10px; }

  /* Quiz */
  .quiz-card { padding: 16px; }
  .quiz-question { font-size: 14px; }
  .quiz-option { padding: 10px 12px; }

  /* Modals */
  .omodal { margin: 16px; max-height: 90vh; }
  .omodal-body { padding: 16px; }

  /* Auth forms */
  .auth-form { margin: 16px; }
}

/* ============================== EXTRA SMALL: <480px ============================== */
@media (max-width: 480px) {
  .col-left {
    width: 100%;
    max-width: 100%;
  }

  .header-logo {
    font-size: 0;
  }

  .header-logo .logo-icon {
    margin: 0 auto;
  }

  .tab-btn {
    padding: 10px 10px;
    font-size: 11px;
  }

  .dashboard-avatar { width: 56px; height: 56px; font-size: 24px; }
  .dashboard-greeting h1 { font-size: 18px; }
  .dashboard-nav-card { padding: 12px; gap: 12px; }
  .dnc-icon { font-size: 24px; }
  .dnc-label { font-size: 14px; }
  .dnc-desc { font-size: 11px; }

  .btn { padding: 10px 14px; font-size: 13px; }
  input, select, textarea { padding: 10px 12px; font-size: 13px; }

  .omodal-head { padding: 12px 16px; }
  .omodal-body { padding: 16px; }

  .quiz-actions { flex-direction: column; }
  .quiz-actions .btn { width: 100%; }
}

/* ============================== EXTRA SMALL: <360px ============================== */
@media (max-width: 360px) {
  /* Let tabs wrap instead of overflowing off-screen */
  .tab-bar { flex-wrap: wrap; }
  .tab-btn { padding: 10px 8px; font-size: 11px; }
}

/* Dashboard widgets: force a single column on narrow phones */
@media (max-width: 600px) {
  .dashboard-widgets-row { grid-template-columns: 1fr !important; }
}

/* Safe-area for notched devices on the fixed header. Placed after the
   768px `.header { padding: 0 12px }` shorthand so it is not reset.
   max(8px, env(...)) keeps a baseline; box-sizing:border-box + fixed
   header height means desktop layout dimensions are unchanged. */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(8px, env(safe-area-inset-top));
  }
}

/* ============================== TABLET: 768px - 1024px ============================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .main { grid-template-columns: 280px 1fr; }
  .col-left { padding: 12px 10px 80px 10px; }
  .col-center { padding: 16px 20px; }
  .dashboard-nav-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================== LARGE: >1024px ============================== */
@media (min-width: 1025px) {
  .dashboard-nav-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================== LANDSCAPE MOBILE ============================== */
@media (max-width: 768px) and (orientation: landscape) {
  .col-left {
    max-width: 50vw;
    width: 320px;
  }
  
  .install-btn { bottom: 8px; }
  .update-notification { bottom: 8px; }
}

/* ============================== HIGH DPI ============================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Sharper borders on retina */
  .session-block,
  .habit-day,
  .topic-item,
  .quiz-option,
  .todo-item {
    border-width: 0.5px;
  }
}

/* ============================== REDUCED MOTION ============================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================== DARK MODE (system) ============================== */
@media (prefers-color-scheme: dark) {
  /* Already dark by default, but ensure consistency */
  :root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --text: #eaeef5;
  }
}

/* ============================== LIGHT MODE (system) - future support ============================== */
@media (prefers-color-scheme: light) {
  /* Placeholder for future light theme */
  /* :root { --bg: #f8f9fa; --surface: #fff; --text: #1a1a2e; ... } */
}
/* ============================== BACKUP / RESTORE (issue #7) ============================== */
.br-modal { max-width: 560px; width: 92vw; }
.br-body { display: flex; flex-direction: column; max-height: 78vh; padding: 0; }
.br-meta {
  font-size: 11px; color: var(--text-muted);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.br-ver {
  background: var(--surface-alt, rgba(127,127,127,.15));
  border-radius: 8px; padding: 1px 7px; margin-left: auto;
}
.br-scroll {
  overflow-y: auto; padding: 8px 14px;
}
.br-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0;
}
.br-check {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; min-width: 0;
}
.br-check input[type=checkbox] { accent-color: var(--accent, #4f8cff); cursor: pointer; }
.br-title { font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.br-dim { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.br-empty { font-size: 12px; color: var(--text-muted); padding: 12px 0; }
.br-divider {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); letter-spacing: .06em;
  margin: 12px 0 4px; padding-top: 8px; border-top: 1px solid var(--border);
}
.br-conflict {
  margin-left: auto; font-size: 11px; padding: 3px 6px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface, var(--bg)); color: var(--text);
  outline: none; cursor: pointer; flex-shrink: 0;
}
.br-footer {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 14px; border-top: 1px solid var(--border);
}
.br-count { font-size: 11.5px; color: var(--text-muted); }
.br-toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface, #16213e); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid #2ecc71;
  border-radius: 8px; padding: 10px 16px; font-size: 13px; z-index: 9999;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease; max-width: 86vw;
}
.br-toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.br-toast.error { border-left-color: #e74c3c; }

/* ─── Header now-playing player (shared/session-miniplayer.js) ─────────
   Takes over .header-week while a session is live. The week nav is hidden
   rather than pushed aside so the strip never reflows mid-session. */
.header-week.is-playing > #week-label,
.header-week.is-playing > .arr { display: none; }

.header-player {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 3px 10px 3px 8px;
  border: 1px solid var(--accent, #4f8cff);
  border-radius: 999px;
  background: var(--surface);
}

.hp-title {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 2px 4px;
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 4px;
}
.hp-title:hover { text-decoration: underline; }
.hp-title:focus-visible { outline: 2px solid var(--accent, #4f8cff); outline-offset: 1px; }

.hp-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums; /* stop the pill jittering every second */
  color: var(--text-secondary);
  white-space: nowrap;
}

.hp-btn {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 4px;
}
.hp-btn:hover { background: var(--hover, rgba(127,127,127,.15)); }
.hp-btn:focus-visible { outline: 2px solid var(--accent, #4f8cff); outline-offset: 1px; }
.hp-stop:hover { color: #e74c3c; }

/* Paused: it must be obvious something is still live, otherwise the whole
   point of this pill is lost. A slow border/opacity pulse reads as "held"
   rather than "playing" — a flash of colour would read as an error. */
@keyframes hp-paused-pulse {
  0%, 100% { opacity: 1; border-color: var(--accent, #4f8cff); }
  50%      { opacity: .55; border-color: var(--text-muted, #888); }
}
.header-player.paused {
  animation: hp-paused-pulse 1.6s ease-in-out infinite;
}
.header-player.paused .hp-time::after { content: " · en pausa"; }

@media (prefers-reduced-motion: reduce) {
  .header-player.paused { animation: none; opacity: .8; }
}

/* Narrow screens: the title is the first thing to go, never the controls —
   stopping the session is the action this pill exists for. */
@media (max-width: 720px) {
  .hp-title { max-width: 14ch; }
  .header-player { gap: 4px; padding: 3px 6px; }
}

/* ─── Aviso de sección fallida (OpenZen) ──────────────────────────────
   Aparece cuando una sección agotó sus reintentos. El resto del documento
   ya está generado, así que el aviso ofrece regenerar SOLO ese tramo en
   lugar de obligar a repetir todo el PDF. */
.ai-chunk-warning {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid #e8a33d;
  border-left: 4px solid #e8a33d;
  border-radius: 8px;
  background: rgba(232, 163, 61, 0.08);
  color: var(--text-primary, inherit);
}
.ai-chunk-warning__head {
  font-weight: 600;
  margin-bottom: 8px;
  color: #e8a33d;
}
.ai-chunk-warning__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid rgba(232, 163, 61, 0.25);
}
.ai-chunk-warning__title {
  font-size: 0.9em;
  opacity: 0.85;
}
.ai-chunk-warning__retry {
  white-space: nowrap;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #e8a33d;
  background: transparent;
  color: #e8a33d;
  font-size: 0.85em;
}
.ai-chunk-warning__retry:disabled { opacity: 0.5; cursor: progress; }

/* ─── OpenZen: secciones que agotaron sus reintentos ─────────────────
   Two escapes, side by side: regenerate the one section (costs a call),
   or carry on without it (costs nothing — the backend already moved on). */
.ai-chunk-warning {
  margin: 12px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--warn-border, #d9a441);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--warn-bg, rgba(217, 164, 65, 0.08));
}

.ai-chunk-warning__head {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary, inherit);
  margin-bottom: 8px;
}

.ai-chunk-warning__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid var(--border-color, rgba(128, 128, 128, 0.2));
}

.ai-chunk-warning__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chunk-warning__skip {
  flex: 0 0 auto;
  margin-bottom: 8px;
  font-size: 12px;
  opacity: 0.75;
}

/* ══════════════════════════════════════════════════════════════════
   BACKUP LOG — visible progress for a ~1.3 GB download.
   The server builds the whole archive before sending a single byte, so
   the UI has to prove liveness on its own while it waits.
   ══════════════════════════════════════════════════════════════════ */

.bk-log {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 9000;
  width: 330px;
  max-width: calc(100vw - 28px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 11px;
  overflow: hidden;
}
.bk-log.hidden { display: none; }

.bk-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
}
.bk-log-x {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  padding: 0 2px;
}
.bk-log-x:hover { color: var(--text); }

.bk-log-body {
  max-height: 190px;
  overflow-y: auto;
  padding: 6px 10px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.55;
  color: var(--text-secondary);
}
.bk-log-line { white-space: pre-wrap; word-break: break-word; }
.bk-head { color: var(--primary); font-weight: 600; }
.bk-ok   { color: var(--green); }
.bk-warn { color: var(--amber); }
.bk-err  { color: var(--red); font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════
   BACKUP SELECTOR — modal de selección del backup personal
   Carga GET /api/backup/mine/options, muestra el árbol de asignaturas
   con tri-state y una estimación del tamaño resultante en vivo.
   ══════════════════════════════════════════════════════════════════ */

/* v3 adaptation (2 lines): this modal toggles `.hidden`, not `.overlay.open`,
   and v3's shared `.overlay` keeps opacity:0/visibility:hidden until `.open`
   (the hub's `.overlay` has neither). Without these it renders invisible.
   Same for `transform: none` on .omodal — v3 scales it 0.95 until
   `.overlay.open`. The hub's .omodal has no transform, so this restores
   the hub rendering. Everything else is verbatim from the hub. */
#backup-selector-overlay { opacity: 1; visibility: visible; }

#backup-selector-overlay { position: fixed; inset: 0; z-index: 9500; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 18px; }
#backup-selector-overlay.hidden { display: none; }
#backup-selector-overlay .omodal { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); transform: none; }
#backup-selector-overlay .omodal-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--surface-hover); border-radius: var(--radius) var(--radius) 0 0; }
#backup-selector-overlay .omodal-head h3 { font-size: 14px; font-weight: 600; color: var(--text); }

.bk-banner { padding: 8px 12px; border-radius: var(--radius-xs); font-size: 12px; margin-bottom: 10px; background: var(--surface-hover); color: var(--text-secondary); }
.bk-banner.err { background: rgba(220,60,60,.12); color: var(--red); }
.bk-banner.hidden { display: none; }

.bk-section-title { font-size: 12px; font-weight: 600; color: var(--text); margin: 14px 0 6px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.bk-hint { font-size: 10px; font-weight: 400; color: var(--text-muted); }

/* ─── árbol ─── */
.bk-tree { font-size: 12px; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 4px 6px; background: var(--bg); }
.bk-tree .bk-node { margin: 1px 0; }
.bk-tree .bk-node-label { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.bk-tree .bk-node-label:hover { background: var(--surface-hover); }
.bk-tree .bk-node-label input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }
.bk-tree .bk-node-children { margin-left: 20px; border-left: 1px dashed var(--border); padding-left: 6px; }
.bk-tree .bk-meta { color: var(--text-muted); font-size: 10px; white-space: nowrap; }
.bk-tree .bk-toggle { border: none; background: transparent; cursor: pointer; font-size: 10px; color: var(--text-muted); padding: 0; width: 16px; flex-shrink: 0; }
.bk-tree .bk-toggle:hover { color: var(--text); }
.bk-leaf { margin-left: 26px; color: var(--text-secondary); }

/* ─── scopes/media ─── */
.bk-scopes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; font-size: 12px; }
.bk-scope-card { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 6px 8px; background: var(--surface); cursor: pointer; }
.bk-scope-card:hover { border-color: var(--primary); }
.bk-scope-card input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }
.bk-scope-card .bk-scope-name { font-weight: 500; color: var(--text); }
.bk-scope-card .bk-meta { font-size: 10px; color: var(--text-muted); }

/* ─── estimación y pie ─── */
.bk-estimate { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; background: var(--surface-hover); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 8px 12px; font-size: 12px; margin-bottom: 4px; }
.bk-estimate b { font-size: 14px; color: var(--primary); }
.bk-estimate .bk-est-item { display: flex; flex-direction: column; }
.bk-estimate .bk-est-label { font-size: 10px; color: var(--text-muted); }

.bk-sel-row { display: flex; gap: 6px; margin: 8px 0 2px; }
.bk-btn { padding: 5px 10px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); cursor: pointer; font-size: 11px; color: var(--text-secondary); }
.bk-btn:hover { border-color: var(--primary); color: var(--text); }
.bk-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.bk-btn.primary:hover { filter: brightness(1.08); color: #fff; }
.bk-btn:disabled { opacity: .5; cursor: not-allowed; }

.bksel-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); padding: 10px 14px; background: var(--surface-hover); border-radius: 0 0 var(--radius) var(--radius); }
.bk-meta { font-size: 11px; color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════════
   RESET MODAL — "Borrar todo", doble confirmación (tipo BORRAR)
   ══════════════════════════════════════════════════════════════════ */

/* Same v3 adaptation as the backup selector: toggle `.hidden`, not
   `.overlay.open`, and neutralise the scale transform. */
#reset-overlay { opacity: 1; visibility: visible; position: fixed; inset: 0; z-index: 9600; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 18px; }
#reset-overlay.hidden { display: none; }
.reset-modal { width: 100%; max-width: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); transform: none; }
.reset-modal .omodal-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--surface-hover); border-radius: var(--radius) var(--radius) 0 0; }
.reset-modal .omodal-head h3 { font-size: 14px; font-weight: 600; color: var(--red); }
.reset-modal .omodal-body { padding: 14px 16px; font-size: 12px; color: var(--text-secondary); }
.reset-warn { margin: 0 0 10px; color: var(--text); }
.reset-warn b { color: var(--red); }
.reset-note { margin: 0 0 12px; padding: 8px 10px; background: var(--surface-hover); border: 1px solid var(--border); border-radius: var(--radius-xs); }
.reset-step { margin: 0 0 6px; font-weight: 600; color: var(--text); }
.reset-input { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius-xs); background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; letter-spacing: 2px; }
.reset-input:focus { outline: none; border-color: var(--red); }
.reset-actions { display: flex; gap: 8px; }
.bk-btn.danger { background: var(--red-bg); border-color: var(--red); color: var(--red); font-weight: 600; }
.bk-btn.danger:hover:not(:disabled) { background: var(--red); border-color: var(--red); color: #fff; }
.bk-btn.danger:disabled { opacity: .45; cursor: not-allowed; }
