/* Life OS — вид как у bb: широкий экран — узкая панель значков слева, страницы блока сверху, чат справа;
   узкий (телефон) — панелей нет, меню ☰ и свайп от левого края, чат — отдельная страница. Тема — как у устройства. */
:root {
  --bg: #f6f6f4; --panel: #ffffff; --rail: #ecece8; --text: #1d1d1f; --muted: #6b6b70; --line: #dcdcd6;
  --accent: #2f6fde; --accent-text: #ffffff; --danger: #d0302a; --danger-bg: #fde8e7; --ok: #1e8a4c; --warn: #b26b00;
  --radius: 10px; --rail-w: 64px; --chat-w: 360px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1c1e; --panel: #242528; --rail: #141516; --text: #ececee; --muted: #9b9ba1; --line: #37383c;
          --accent: #5b93f0; --danger: #ff5a52; --danger-bg: #3a1f1e; --ok: #46c27a; --warn: #e0a040; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); line-height: 1.4; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 18px 0 8px; }

/* верхняя полоса — только на телефоне */
#topbar { display: none; }
#rail { position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w); background: var(--rail);
        display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 12px; border-right: 1px solid var(--line); }
#rail a { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius);
          text-decoration: none; color: var(--muted); font-size: 22px; }
#rail a[aria-current] { background: var(--panel); color: var(--accent); box-shadow: 0 0 0 1px var(--line); }
#frame { margin-left: var(--rail-w); margin-right: var(--chat-w); min-height: 100%; }
body.chat-hidden #frame { margin-right: 0; }
#tabsbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: var(--bg);
           border-bottom: 1px solid var(--line); padding: 8px 16px; }
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; }
#tabs a[aria-current] { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
#chat-toggle { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; }
#main { padding: 16px; max-width: 1000px; }
#chat-panel { position: fixed; right: 0; top: 0; bottom: 0; width: var(--chat-w); background: var(--panel);
              border-left: 1px solid var(--line); display: flex; flex-direction: column; }
body.chat-hidden #chat-panel { display: none; }

/* меню (телефон) */
#drawer { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .35); }
#drawer[hidden] { display: none; }
.drawer-sheet { position: absolute; left: 0; top: 0; bottom: 0; width: min(84vw, 340px); background: var(--panel);
                overflow-y: auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
.drawer-sheet h2 { font-size: 1rem; color: var(--muted); margin: 16px 0 6px; }
.drawer-sheet a { display: block; padding: 10px 8px; border-radius: 8px; text-decoration: none; color: var(--text); }
.drawer-sheet a[aria-current] { background: var(--bg); color: var(--accent); }

@media (max-width: 767px) {
  #rail, #chat-panel, #tabsbar { display: none !important; }
  #frame { margin: 0; }
  #topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 10; background: var(--bg);
            border-bottom: 1px solid var(--line); padding: calc(6px + env(safe-area-inset-top)) 8px 6px; }
  #menu-btn { font-size: 22px; background: none; border: 0; color: var(--text); width: 44px; height: 44px; }
  .topbar-title { flex: 1; font-weight: 600; text-align: center; }
  #chat-link { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 20px; }
  #main { padding: 12px; }
}

/* списки, карточки, кнопки */
.list { list-style: none; margin: 0; padding: 0; }
.row { overflow-wrap: anywhere; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.row .meta { color: var(--muted); font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px;
               padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
.badge { display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--danger); border-color: var(--danger); }
.empty { color: var(--muted); padding: 16px 0; }
.more { margin: 8px 0; }
.out-of-range { color: var(--danger); font-weight: 600; }

/* формы: неверное поле подсвечено красным, подпись по-русски */
.field { display: block; margin: 10px 0; }
.field-label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"], .field select[aria-invalid="true"] {
  border-color: #d0302a; box-shadow: 0 0 0 1px #d0302a; background: var(--danger-bg); }
.field-error { display: block; color: var(--danger); font-size: .88rem; margin-top: 4px; }
.form-error { color: var(--danger); }

/* нет связи / неизвестный исход */
#net-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40;
              background: var(--text); color: var(--bg); border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 12px;
              align-items: center; max-width: 92vw; }
#net-banner[hidden] { display: none; }
#net-banner .net-retry { background: var(--bg); color: var(--text); }

/* вход: «Войти», ссылка, запасные коды */
body.auth { display: flex; align-items: flex-start; justify-content: center; padding: calc(40px + env(safe-area-inset-top)) 16px 40px; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1.1rem; margin: 0 0 16px; }
.auth-logo img { border-radius: 12px; }
.muted, .notice { color: var(--muted); }
.notice { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
button.wide { width: 100%; padding: 12px; font-size: 1.05rem; }
.code-login { margin-top: 20px; }
.code-login summary { cursor: pointer; color: var(--accent); }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px;
         font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.05rem; }
.settings-section h3 { font-size: 1rem; margin: 18px 0 6px; }
.qr svg { width: 200px; height: 200px; background: #fff; border-radius: 8px; }
.invite-link { word-break: break-all; }
.logout { margin-top: 24px; }
@media print {
  #rail, #topbar, #tabsbar, #chat-panel, #drawer, #net-banner, .actions, .auth-logo { display: none !important; }
  #frame { margin: 0; }
  body { background: #fff; color: #000; }
}
/* Главная (фаза 5): разделы, календарь, фильтры, формы записей */
.waiting-section h2, .day h2 { font-size: 1.05rem; margin: 20px 0 8px; }
.row-title { font-weight: 500; color: var(--text); text-decoration: none; display: block; }
a.row-title:hover { color: var(--accent); }
.badge.ok { color: var(--accent); border-color: var(--accent); }
.event { border-left: 4px solid var(--line); }
.cal-0 { border-left-color: #2f6fdf; } .cal-1 { border-left-color: #d9480f; } .cal-2 { border-left-color: #2b8a3e; }
.cal-3 { border-left-color: #ae3ec9; } .cal-4 { border-left-color: #c92a2a; } .cal-5 { border-left-color: #0b7285; }
.cal-6 { border-left-color: #e67700; } .cal-7 { border-left-color: #5c7cfa; } .cal-8 { border-left-color: #a61e4d; }
.cal-9 { border-left-color: #868e96; }
.cal-nav, .filter { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 12px; }
.cal-nav a, .filter a { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.cal-nav a[aria-current], .filter a[aria-current] { background: var(--accent); border-color: var(--accent); color: #fff; }
.cal-switch { display: inline-flex; gap: 4px; }
.cal-range { color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day h2 { font-size: .92rem; margin: 0 0 6px; color: var(--muted); }
@media (max-width: 767px) { .week { grid-template-columns: 1fr; } }
.notes-filter { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: 0 10px; align-items: end; }
@media (max-width: 767px) { .notes-filter { grid-template-columns: 1fr; } }
#new-note-slot { margin: 8px 0 12px; }
#new-note fieldset { border: 0; padding: 0; }
.radio { display: inline-flex; align-items: center; gap: 6px; margin: 4px 14px 4px 0; }
.field .radio input { width: auto; padding: 0; margin: 0; border: 0; background: none; accent-color: var(--accent); }
.note-body, .source-text { white-space: pre-wrap; }
/* «Проекты и задачи» (фаза 6) */
.tasks-filter { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 0 10px; align-items: end; }
@media (max-width: 767px) { .tasks-filter { grid-template-columns: 1fr; } }
#new-task-slot, #new-reminder-slot { margin: 8px 0 12px; }
.task-fields { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 10px 0; }
.task-fields dt { color: var(--muted); font-size: .9rem; }
.task-fields dd { margin: 0; }
#task-edit form { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 8px; }
.tree-node, .tree-leaf { overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin: 6px 0; }
.tree-node > summary { cursor: pointer; }
.tree .row-title { display: inline; }
.tree .meta { color: var(--muted); font-size: .88rem; }
.tree-children { margin: 8px 0 0 6px; padding-left: 10px; border-left: 2px solid var(--line); }
.tree-open { font-size: .88rem; }
.goal-tasks { margin: 6px 0 0; padding-left: 18px; }

/* Здоровье (US5): выбор человека, график показателя, таблица значений (вне нормы — красным) */
.person-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.person-form select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); max-width: 100%; }
.indicator { margin: 12px 0 20px; }
svg.chart { width: 100%; height: auto; max-width: 720px; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
svg.chart .axis { stroke: var(--line); stroke-width: 1; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
svg.chart .pt { fill: var(--accent); }
svg.chart .pt.out { fill: var(--danger); }
svg.chart .tick { fill: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.lab-table { border-collapse: collapse; width: 100%; max-width: 720px; }
.lab-table th, .lab-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.lab-table th { color: var(--muted); font-weight: 500; font-size: .88rem; }
.lab-row.out td.value, .lab-row.out td.norm { color: var(--danger); font-weight: 600; }
/* «Новости» (US6-3) */
.issue h2 { font-size: 1.05rem; margin: 20px 0 8px; }
.news-topic h3 { font-size: .98rem; margin: 14px 0 6px; }
.news-text { margin: 4px 0; }
.news-link { display: inline-block; overflow-wrap: anywhere; }
.news-collecting { padding: 12px 0; font-weight: 600; }

/* чат с Hermes (US7): страница «Чат» и панель справа */
.chat-box { display: flex; flex-direction: column; gap: 8px; }
#chat-panel .chat-box { flex: 1; min-height: 0; padding: 12px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-head form { margin: 0; }
.chat-log { display: flex; flex-direction: column; gap: 8px; }
#chat-panel .chat-log { flex: 1; overflow-y: auto; min-height: 0; }
.chat-msg { max-width: 92%; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line); }
.chat-msg.owner { align-self: flex-end; background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chat-msg.hermes { align-self: flex-start; background: var(--bg); }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-failed, .chat-error { color: var(--danger); margin: 4px 0 0; }
.chat-wait { color: var(--muted); margin: 0; font-size: .9em; }   /* круг 6: «Подождите: отправляется решение…» */
.chat-stopped { color: var(--muted); margin: 4px 0 0; font-size: .9em; }   /* круг 19: «Ответ остановлен: начат новый разговор» */
.chat-approval { margin-top: 8px; padding: 8px; border-radius: 8px; border: 1px solid var(--warn); background: var(--panel); }
.chat-approval p { margin: 0 0 4px; }
.chat-approval-cmd { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.chat-approval-state { font-weight: 600; }
.chat-approval-state.allowed { color: var(--ok); }
.chat-approval-state.denied, .chat-approval-state.expired, .chat-approval-state.cancelled { color: var(--muted); }
.chat-form { margin: 0; }
.chat-form .field { margin: 0 0 6px; }
.chat-old-list li { padding: 6px 0; }
