:root {
  --bg: #0a0e14;
  --surface: #131820;
  --surface-2: #1a212d;
  --surface-3: #232c3b;
  --text: #e8eaed;
  --text-2: #b8bdc7;
  --muted: #6e7989;
  --accent: #4fd1c5;
  --accent-2: #38b2ac;
  --warn: #f6ad55;
  --danger: #fc8181;
  --success: #68d391;
  --border: #2d3548;
  --border-light: #404b62;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  line-height: 1.5; font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.app { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

/* === Top header === */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 700; letter-spacing: 0.3px; }
.topbar .mode-pill {
  font-size: 12px; padding: 4px 10px; border-radius: 12px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.topbar .mode-pill.action { color: var(--success); border-color: rgba(104,211,145,0.4); }
.topbar .mode-pill.cautious_action { color: var(--warn); border-color: rgba(246,173,85,0.4); }
.topbar .mode-pill.crisis, .topbar .mode-pill.ed_mode, .topbar .mode-pill.medical_crisis {
  color: var(--danger); border-color: rgba(252,129,129,0.4);
}
.topbar .nav { margin-left: auto; display: flex; gap: 4px; }
.topbar .nav button {
  padding: 8px 14px; background: none; color: var(--text-2);
  border: none; border-radius: var(--r-sm); cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.topbar .nav button:hover { background: var(--surface-2); color: var(--text); }
.topbar .nav button.active { background: var(--surface-3); color: var(--text); }

/* === Main === */
main { padding: 24px; max-width: 980px; margin: 0 auto; width: 100%; }
@media (max-width: 720px) {
  main { padding: 16px 12px; }
  .topbar { padding: 12px 14px; gap: 12px; }
  .topbar .nav button { padding: 6px 8px; font-size: 13px; }
  .topbar .brand { font-size: 14px; }
}

/* === Cards === */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px; margin-bottom: 14px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-light); }
.card h2 {
  font-size: 14px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 14px;
}
.card h2 .right { float: right; color: var(--text-2); text-transform: none; }

/* === Health Score === */
.score-card { display: flex; align-items: center; gap: 24px; }
.score-ring {
  width: 100px; height: 100px; border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg, var(--surface-2) 0deg);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.score-ring::before {
  content: ''; position: absolute; inset: 8px;
  background: var(--surface); border-radius: 50%;
}
.score-ring .score-num {
  position: relative; font-size: 28px; font-weight: 700; color: var(--accent);
}
.score-card .info h3 { font-size: 22px; margin-bottom: 4px; }
.score-card .info .sub { color: var(--muted); font-size: 13px; }

/* === Circles === */
.circles { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; }
@media (max-width: 540px) { .circles { grid-template-columns: repeat(4, 1fr); } }
.circle-btn {
  aspect-ratio: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--surface-2); border: 2px solid var(--border);
  border-radius: 50%; cursor: pointer; user-select: none;
  font-size: 11px; color: var(--text); padding: 4px;
  transition: all 0.18s;
  font-family: inherit;
  position: relative;
  font-weight: 500;
}
.circle-btn:hover {
  border-color: var(--accent, #0c8);
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 6px 18px rgba(12,200,140,0.25);
  background: var(--surface);
}
.circle-btn:active { transform: translateY(0) scale(0.98); }
.circle-btn.closed {
  background: linear-gradient(135deg, rgba(79,209,197,0.35), rgba(56,178,172,0.15));
  border-color: var(--accent); color: var(--text);
  box-shadow: 0 0 12px rgba(12,200,140,0.2);
}
.circle-btn.closed::before {
  content: '✓'; position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: #062c29;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  transform: none;
}
.circle-btn .icon { font-size: 22px; line-height: 1; margin-bottom: 4px; }
/* Каждый круг — hint при hover */
.circle-btn::after {
  content: attr(data-hint);
  position: absolute; bottom: -28px; left: 50%; transform: translateX(-50%);
  background: var(--bg); color: var(--text);
  padding: 4px 8px; border-radius: 4px; font-size: 10px;
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
  border: 1px solid var(--border);
  z-index: 10;
}
.circle-btn:hover::after { opacity: 1; }

/* === Action lists === */
.action-list { list-style: none; }
.action-list li {
  padding: 12px 0; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 12px;
}
.action-list li:last-child { border-bottom: none; }
.action-list .check {
  flex-shrink: 0; width: 20px; height: 20px; margin-top: 2px;
  border: 2px solid var(--border-light); border-radius: 4px;
  cursor: pointer; transition: all 0.2s;
}
.action-list .check.done {
  background: var(--accent); border-color: var(--accent);
  position: relative;
}
.action-list .check.done::after {
  content: '✓'; position: absolute; left: 3px; top: -3px;
  color: #062c29; font-weight: 700; font-size: 14px;
}
.action-list li.done .text { color: var(--muted); text-decoration: line-through; }
.action-list .text { flex: 1; }

/* === KV grid === */
.kv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 540px) { .kv-grid { grid-template-columns: repeat(2, 1fr); } }
.kv {
  background: var(--surface-2); border-radius: var(--r-md); padding: 12px;
}
.kv .v { font-size: 18px; font-weight: 700; color: var(--text); }
.kv .l { font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-top: 4px; }

.evidence { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 12px; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 14px; font-family: inherit; font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-light); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #062c29; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.btn-block { width: 100%; padding: 14px; font-size: 15px; }

/* === Modal === */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  border: 1px solid var(--border); padding: 24px;
  max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* === Forms === */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; color: var(--text-2);
  margin-bottom: 6px; font-weight: 500;
}
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 15px; font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent);
}
.field textarea { min-height: 80px; resize: vertical; }
.field .row { display: flex; gap: 10px; }
.field .row > * { flex: 1; }

.scale {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px;
  margin-top: 4px;
}
.scale-btn {
  padding: 8px 0; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; font-family: inherit; font-size: 13px;
}
.scale-btn:hover { border-color: var(--border-light); }
.scale-btn.selected { background: var(--accent); color: #062c29; border-color: var(--accent); }
.scale-labels { display: flex; justify-content: space-between;
  margin-top: 4px; font-size: 11px; color: var(--muted); }

.checkbox-row { display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; }
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0;
  accent-color: var(--accent);
}
.checkbox-row label { font-size: 14px; color: var(--text-2); }
.checkbox-row.required label::after { content: ' *'; color: var(--danger); }

/* === Onboarding === */
.onboarding {
  max-width: 560px; margin: 40px auto; padding: 0 20px;
}
.onboarding .progress {
  display: flex; gap: 6px; margin-bottom: 32px;
}
.onboarding .progress-step {
  flex: 1; height: 4px; background: var(--surface-2);
  border-radius: 2px;
}
.onboarding .progress-step.active { background: var(--accent); }
.onboarding h1 { font-size: 26px; margin-bottom: 8px; }
.onboarding .lead { color: var(--muted); margin-bottom: 24px; font-size: 15px; }
.onboarding-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 28px;
}

/* === Crisis Mode screen === */
.crisis-screen {
  max-width: 640px; margin: 32px auto; padding: 0 16px;
}
.crisis-card {
  background: var(--surface); border: 2px solid var(--danger);
  border-radius: var(--r-lg); padding: 32px;
}
.crisis-card .label {
  display: inline-block; padding: 4px 12px;
  background: rgba(252,129,129,0.15); color: var(--danger);
  border-radius: 12px; font-size: 12px; font-weight: 600;
  margin-bottom: 16px;
}
.crisis-card h1 { font-size: 22px; margin-bottom: 16px; line-height: 1.3; }
.crisis-card .lead { font-size: 16px; line-height: 1.6; margin-bottom: 20px; color: var(--text-2); }
.helplines {
  background: var(--surface-2); border-radius: var(--r-md);
  padding: 16px; margin: 16px 0;
}
.helpline {
  display: block; padding: 10px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text);
}
.helpline:last-child { border-bottom: none; }
.helpline .num { color: var(--accent); font-weight: 600; font-size: 17px; }
.helpline .desc { color: var(--muted); font-size: 13px; }

/* === Empty / loading states === */
.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  font-size: 14px;
}
.empty .icon { font-size: 32px; margin-bottom: 8px; opacity: 0.5; }

/* === Tabs === */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Misc === */
.kbd {
  background: var(--surface-2); padding: 2px 6px;
  border-radius: 4px; font-family: monospace; font-size: 12px;
}
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card, .modal, .onboarding-card, .crisis-card { animation: fadeIn 0.3s ease-out; }


/* === BLOCK 15 — POLISH === */
/* Light theme toggle support */
body.theme-light {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --surface-3: #e6ebf2;
  --text: #1a212d;
  --text-2: #4a5468;
  --muted: #8a93a6;
  --accent: #1ba89c;
  --accent-2: #178c81;
  --warn: #c97f1a;
  --danger: #d33a3a;
  --success: #2f9d5e;
  --border: #d4dae3;
  --border-light: #c0c8d4;
}

/* Theme toggle */
#theme-toggle {
  background: none; border: 1px solid var(--border);
  width: 34px; height: 34px; border-radius: 50%;
  cursor: pointer; color: var(--text-2);
  font-family: inherit; font-size: 16px;
  transition: all 0.2s;
}
#theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Smooth animations */
.circle-btn { transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
.circle-btn.closed { transform: scale(1.02); }
.action-list li { transition: opacity 0.2s; }
.action-list li.done { opacity: 0.65; }
.tab-content { animation: fadeInUp 0.25s ease-out; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Loading spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Form validation states */
.field input:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}
.field .err {
  color: var(--danger); font-size: 12px; margin-top: 4px;
}

/* Hover states polished */
.btn { transition: transform 0.12s, background 0.2s, border-color 0.2s; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { box-shadow: 0 2px 8px rgba(79, 209, 197, 0.2); }
body.theme-light .btn.primary { box-shadow: 0 2px 8px rgba(27, 168, 156, 0.25); }

/* SVG icon style */
.svg-icon { width: 18px; height: 18px; vertical-align: -3px; fill: currentColor; }

/* Toast notification */
#toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 20px; border-radius: 24px;
  z-index: 200; opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  font-size: 14px; box-shadow: var(--shadow);
}
#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); }
#toast.info { border-color: var(--accent); color: var(--text); }

/* Improved progress steps */
.onboarding .progress-step { transition: background 0.3s; }
.onboarding .progress-step.active {
  box-shadow: 0 0 0 2px rgba(79, 209, 197, 0.2);
}

/* Scale buttons polish */
.scale-btn { transition: all 0.15s; }
.scale-btn:hover { transform: translateY(-1px); }
.scale-btn.selected { transform: scale(1.05); box-shadow: 0 2px 6px rgba(79,209,197,0.3); }

/* Better mobile font sizes */
@media (max-width: 640px) {
  h1 { font-size: 22px !important; }
  .card { padding: 16px; }
  .card h2 { font-size: 13px; }
  .score-card { gap: 14px; }
  .score-ring { width: 80px; height: 80px; }
  .score-ring .score-num { font-size: 22px; }
}

/* Focus visible — a11y */
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ============================================================
 * DESKTOP POLISH (Block 32) — для экранов ≥1024px
 * ============================================================ */

/* Theme refinements — мягкие тени + анимации для всех */
:root {
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.4);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 240px;
}

/* Smooth scroll + better selection */
html { scroll-behavior: smooth; }
::selection { background: rgba(79, 209, 197, 0.3); color: var(--text); }

/* Глобальные scrollbar (desktop) */
@media (min-width: 1024px) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: var(--bg); }
  ::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 5px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
}

/* === Desktop layout: sidebar + content === */
@media (min-width: 1024px) {
  body { padding-bottom: 0; }

  .app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: 'sidebar content';
    min-height: 100vh;
  }

  /* Topbar превращается в sidebar */
  .topbar {
    grid-area: sidebar;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 24px 16px;
    border-right: 1px solid var(--border);
    border-bottom: none;
    background: linear-gradient(180deg, var(--surface) 0%, rgba(19, 24, 32, 0.95) 100%);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .topbar .brand {
    font-size: 17px; padding: 8px 12px 16px; border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
  }

  .topbar .mode-pill {
    margin: 0 12px 12px; text-align: center; padding: 6px 10px;
  }

  .topbar .nav {
    flex-direction: column; gap: 2px; margin-left: 0; margin-top: 4px;
    overflow-y: auto;
  }

  .topbar .nav button {
    padding: 10px 14px; text-align: left;
    font-size: 14px; border-radius: 8px;
    transition: all var(--transition);
    display: flex; align-items: center; gap: 10px;
  }
  .topbar .nav button:hover { background: var(--surface-2); }
  .topbar .nav button.active {
    background: linear-gradient(90deg, rgba(79, 209, 197, 0.18), rgba(79, 209, 197, 0.06));
    color: var(--accent); font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
  }

  /* Theme toggle в sidebar — снизу */
  #theme-toggle {
    margin-left: 0 !important; margin-top: 12px !important;
    align-self: center; padding: 10px 14px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; font-size: 16px;
    transition: all var(--transition);
  }
  #theme-toggle:hover { background: var(--surface-3); transform: scale(1.05); }

  main {
    grid-area: content; padding: 32px 40px; max-width: 1280px;
    margin: 0 auto; width: 100%;
  }
}

/* === Sidebar icons (desktop) — добавляем emoji иконки навигации === */
@media (min-width: 1024px) {
  .topbar .nav button::before {
    font-size: 18px; display: inline-block; width: 22px; text-align: center;
  }
  .topbar .nav button[onclick*="'today'"]::before { content: '🏠'; }
  .topbar .nav button[onclick*="'plan'"]::before { content: '📋'; }
  .topbar .nav button[onclick*="'recipes'"]::before { content: '🍳'; }
  .topbar .nav button[onclick*="'learn'"]::before { content: '📚'; }
  .topbar .nav button[onclick*="'progress'"]::before { content: '📊'; }
  .topbar .nav button[onclick*="'journal'"]::before { content: '📔'; }
  .topbar .nav button[onclick*="'biohack'"]::before { content: '🧪'; }
  .topbar .nav button[onclick*="'settings'"]::before { content: '⚙'; }
}

/* === Multi-column для широких экранов === */
@media (min-width: 1280px) {
  /* Today: разбить на 2 колонки — left (score + circles), right (rest) */
  main { padding: 32px 48px; }

  /* Карточки в Прогресс/Знания — auto-flow grid когда подходящие */
  .cards-grid-2 {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
}

/* === Card polish (все экраны) === */
.card {
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}
.card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Карточки в Today — score (gradient highlight) */
.score-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border-light);
}

/* === Circles polish === */
@media (min-width: 1024px) {
  .circles { gap: 14px; }
  .circle-btn {
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
  }
  .circle-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
  }
}

/* === Typography scale === */
.card h2 { font-size: 13px; }
@media (min-width: 1024px) {
  .card h2 { font-size: 14px; margin-bottom: 16px; }
  body { font-size: 15px; line-height: 1.55; }
}

/* === Кнопки polish === */
.btn {
  transition: all var(--transition);
  font-weight: 500;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border: none; color: #062c29; font-weight: 600;
}
.btn.primary:hover {
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 100%);
  box-shadow: 0 6px 16px rgba(79, 209, 197, 0.3);
}

/* === Modal polish === */
.modal-backdrop {
  backdrop-filter: blur(6px);
  background: rgba(10, 14, 20, 0.6);
}
@media (min-width: 1024px) {
  .modal-content {
    max-width: 600px !important;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
  }
}

/* === Light theme support (фундамент уже есть в html data-theme) === */
[data-theme="light"] {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --surface-3: #e9ecef;
  --text: #1a1d23;
  --text-2: #495057;
  --muted: #868e96;
  --border: #e9ecef;
  --border-light: #ced4da;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

/* === Печатная версия (для Doctor Prep PDF) === */
@media print {
  .topbar, #bottom-nav, .modal-backdrop, .btn { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  body { background: #fff !important; color: #000 !important; }
}

/* === Smooth tab transitions === */
main > * { animation: fadeInUp 0.3s ease-out; }
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Better empty states === */
.card.empty {
  text-align: center; padding: 40px 20px;
  color: var(--muted); border-style: dashed;
}
.card.empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }

/* Sidebar profile mini — только desktop */
.sidebar-profile-mini { display: none; }
@media (min-width: 1024px) {
  .sidebar-profile-mini { display: block; }
  .sidebar-profile-mini:hover { background: var(--surface-3); border-color: var(--accent, #0c8); }
}
/* nav должен растягиваться чтобы theme-toggle прижался вниз */
@media (min-width: 1024px) {
  .topbar .nav { flex: 1; }
}


/* === v3.17.8: Daily Program 4 columns in one row (Утро | День | Вечер | Ночь) === */
.dp-blocks-grid { display: block; }
@media (min-width: 1200px) {
  .dp-blocks-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    align-items: start;
  }
  .dp-blocks-grid > div { margin-bottom: 0 !important; }
}
@media (min-width: 768px) and (max-width: 1199px) {
  .dp-blocks-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

/* Компактные кнопки переключателей в Settings */
@media (min-width: 1024px) {
  /* Profile mini-edit карандаши более прозрачные */
  .kv .val + button[title^="Изменить"] { opacity: .6; }
  .kv:hover button[title^="Изменить"] { opacity: 1; }
}


/* === v3.16.6: Compact 2-col dashboard === */
@media (min-width: 900px) {
  .today-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
  }
  .today-grid-2col > .card { margin: 0; }
  .today-grid-full {
    grid-column: 1 / -1;
  }
}
.compact-pick-card {
  padding: 12px 14px !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.compact-pick-card h2 { font-size: 14px !important; margin: 0 !important; }
.compact-pick-card .sub { font-size: 11px; color: var(--muted); }
.compact-pick-card .actions { display: flex; gap: 6px; }
.compact-pick-card .btn { padding: 6px 12px !important; font-size: 12px !important; }

/* ============================================================
 * SIDEBAR V2 (v3.17.5) — 3 states: full / rail / hidden
 * Desktop only; mobile keeps bottom-nav.
 * ============================================================ */
@media (min-width: 641px) {
  /* When sidebar is present, restructure body */
  body.sb-full .app,
  body.sb-rail .app,
  body.sb-hidden .app {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: 1fr;
    min-height: 100vh;
  }
  body.sb-full #app-sidebar { width: 220px; }
  body.sb-rail #app-sidebar { width: 60px; }
  body.sb-hidden #app-sidebar { width: 0; position: fixed; left: 0; top: 0; height: 100vh; z-index: 100; }

  /* Hide old top-bar nav when sidebar is active */
  body.sb-full .topbar .nav,
  body.sb-rail .topbar .nav,
  body.sb-hidden .topbar .nav { display: none !important; }
  body.sb-full .topbar .sidebar-profile-mini,
  body.sb-rail .topbar .sidebar-profile-mini,
  body.sb-hidden .topbar .sidebar-profile-mini { display: none !important; }
  body.sb-full .topbar,
  body.sb-rail .topbar,
  body.sb-hidden .topbar {
    grid-column: 1 / -1;
    display: none;  /* topbar replaced by sidebar */
  }

  /* Sidebar itself */
  .sb {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 12px 8px;
    position: sticky; top: 0; left: 0;
    height: 100vh; overflow-y: auto;
    transition: width 0.2s ease;
    z-index: 50;
  }
  .sb-header {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 12px; padding: 0 4px;
  }
  .sb-brand {
    font-weight: 700; font-size: 14px;
    letter-spacing: 0.3px; color: var(--text);
    flex: 1; white-space: nowrap; overflow: hidden;
  }
  .sb-toggle, .sb-hide {
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text-2); cursor: pointer;
    width: 28px; height: 28px; border-radius: 6px;
    font-size: 14px; line-height: 1; padding: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .sb-toggle:hover, .sb-hide:hover { background: var(--surface-3); color: var(--text); }
  body.sb-rail .sb-header { justify-content: center; flex-direction: column; gap: 4px; }

  .sb-mode-pill {
    font-size: 11px; padding: 4px 8px; border-radius: 10px;
    background: var(--surface-2); color: var(--text-2);
    border: 1px solid var(--border); text-align: center;
    margin: 0 4px 10px;
  }
  .sb-mode-pill.action { color: var(--success); border-color: rgba(104,211,145,0.4); }
  .sb-mode-pill.cautious_action { color: var(--warn); border-color: rgba(246,173,85,0.4); }
  .sb-mode-pill.crisis, .sb-mode-pill.ed_mode, .sb-mode-pill.medical_crisis {
    color: var(--danger); border-color: rgba(252,129,129,0.4);
  }

  .sb-tabs {
    display: flex; flex-direction: column; gap: 2px;
    margin-top: 8px; flex: 1;
  }
  .sb-tab {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; background: none; border: none;
    color: var(--text-2); cursor: pointer;
    font-family: inherit; font-size: 14px; text-align: left;
    border-radius: 6px; transition: background 0.15s;
  }
  .sb-tab:hover { background: var(--surface-2); color: var(--text); }
  .sb-tab.active { background: var(--surface-3); color: var(--accent, #10b981); font-weight: 600; }
  .sb-tab .sb-icon { font-size: 18px; line-height: 1; flex-shrink: 0; width: 22px; text-align: center; }
  .sb-tab .sb-text { white-space: nowrap; overflow: hidden; }
  body.sb-rail .sb-tab { justify-content: center; padding: 10px 6px; }

  .sb-footer { margin-top: auto; padding-top: 12px; display: flex; justify-content: center; }

  /* Hidden mode — show floating expand button */
  body.sb-hidden .sb { width: 0; padding: 0; overflow: visible; }
  body.sb-hidden .sb-fab-expand {
    position: fixed; top: 14px; left: 14px;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); cursor: pointer; font-size: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.4); z-index: 200;
  }
  body.sb-hidden .sb-fab-expand:hover { background: var(--surface-3); }
  body:not(.sb-hidden) .sb-fab-expand { display: none; }

  /* In rail mode hide hide-btn label */
  body.sb-rail .sb-toggle, body.sb-rail .sb-hide { font-size: 12px; }
}

/* Mobile: hide sidebar entirely, restore old topbar */
@media (max-width: 640px) {
  #app-sidebar, .sb-fab-expand { display: none !important; }
  body.sb-full .topbar, body.sb-rail .topbar, body.sb-hidden .topbar {
    display: flex !important; grid-column: 1 / -1;
  }
  body.sb-full .app, body.sb-rail .app, body.sb-hidden .app {
    display: grid; grid-template-columns: 1fr; grid-template-rows: auto 1fr;
  }
}

/* ============================================================
 * TODAY V2 LAYOUT
 * ============================================================ */
.tv2-top {
  border-left: 3px solid var(--accent, #10b981);
}
.tv2-quick h2, .tv2-col h2, .tv2-recommend h2 {
  font-size: 13px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.tv2-3col .card, .tv2-2col .card { margin-bottom: 0; }
.tv2-col { display: flex; flex-direction: column; }
.tv2-placeholder { opacity: 0.7; }

@media (max-width: 720px) {
  .tv2-top { gap: 10px !important; padding: 12px !important; }
  .tv2-top .tv2-avatar { width: 64px !important; height: 64px !important; }
  .tv2-top .tv2-score > div:first-child { width: 64px !important; height: 64px !important; }
  .tv2-top .tv2-score > div:first-child > div { inset: 5px !important; }
  .tv2-top .tv2-score span { font-size: 18px !important; }
}

/* ============================================================
 * TODAY V2 LAYOUT FIX (v3.17.6) — full-width sections per sketch
 * ============================================================ */
/* When sidebar present, let main use most of the viewport width */
@media (min-width: 641px) {
  body.sb-full main, body.sb-rail main, body.sb-hidden main {
    max-width: none !important;
    padding: 16px 20px !important;
  }
}

/* The TodayV2 container forces vertical stack and full width inside today-grid-2col */
.tv2-container {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px;
  width: 100%;
  grid-column: 1 / -1;
}

/* TopRow: avatar + 2 scores + 8 circles — never overflow, never wrap circles */
.tv2-top {
  display: flex !important;
  align-items: center;
  gap: 14px;
  padding: 14px 16px !important;
  flex-wrap: nowrap !important;
  overflow: hidden;
}
.tv2-top .tv2-day-circles {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.tv2-top .tv2-day-circles > div:last-child {
  display: grid !important;
  grid-template-columns: repeat(8, minmax(0, 1fr)) !important;
  gap: 6px;
  width: 100%;
}
.tv2-top .tv2-day-circles button {
  min-width: 0;
  max-width: 100%;
}

/* Quick actions: 5-column grid on desktop, scaled down on smaller */
.tv2-quick > div {
  display: grid !important;
  grid-template-columns: repeat(5, 1fr) !important;
  gap: 10px !important;
}
@media (max-width: 1100px) {
  .tv2-quick > div { grid-template-columns: repeat(4, 1fr) !important; }
}
@media (max-width: 800px) {
  .tv2-quick > div { grid-template-columns: repeat(3, 1fr) !important; }
}
@media (max-width: 540px) {
  .tv2-quick > div { grid-template-columns: repeat(2, 1fr) !important; }
}

/* Recommend buttons: row of 5 on desktop */
.tv2-recommend > div {
  display: grid !important;
  grid-template-columns: repeat(5, 1fr) !important;
  gap: 8px !important;
}
@media (max-width: 1100px) {
  .tv2-recommend > div { grid-template-columns: repeat(3, 1fr) !important; }
}
@media (max-width: 700px) {
  .tv2-recommend > div { grid-template-columns: repeat(2, 1fr) !important; }
}

/* 3-column row — always 3 columns side by side on desktop */
.tv2-3col {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 10px !important;
}
@media (max-width: 900px) {
  .tv2-3col { grid-template-columns: 1fr !important; }
}

/* Program row — single full-width container (v3.17.8) */
.tv2-2col {
  display: block !important;
  width: 100% !important;
}
.tv2-2col > .card { width: 100%; box-sizing: border-box; }

/* Mobile tweaks for top row */
@media (max-width: 720px) {
  .tv

/* v3.18.0: scrollbar for "Что забыл сделать" 2-column grid */
.tv2-forgot-list { scrollbar-width: thin; scrollbar-color: var(--accent, #10b981) transparent; }
.tv2-forgot-list::-webkit-scrollbar { width: 8px; }
.tv2-forgot-list::-webkit-scrollbar-track { background: transparent; }
.tv2-forgot-list::-webkit-scrollbar-thumb { background: var(--accent, #10b981); border-radius: 4px; opacity: .6; }
.tv2-forgot-list::-webkit-scrollbar-thumb:hover { background: #0ea371; }

/* v3.18.25: 2-col grid для Меню+Тренировка на сегодня */
.tv2-meal-workout {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 10px !important;
  width: 100% !important;
}
.tv2-meal-workout > .card { margin: 0; width: 100%; box-sizing: border-box; }
@media (max-width: 900px) {
  .tv2-meal-workout { grid-template-columns: 1fr !important; }
}

/* v3.18.27: Что сейчас + Совет дня в одну строку */
.tv2-context-tip {
  display: grid !important;
  grid-template-columns: 1fr 2fr !important;
  gap: 10px !important;
  width: 100% !important;
  align-items: stretch !important;
}
.tv2-context-tip > div { display: flex; }
.tv2-context-tip > div > * { width: 100%; box-sizing: border-box; }
@media (max-width: 900px) {
  .tv2-context-tip { grid-template-columns: 1fr !important; }
}
