/* TimeLife — единая дизайн-система (канон).
 *
 * Источник правды: docs/ui/DESIGN-SYSTEM.md. Значения перенесены из утверждённого
 * макета docs/ui/mockups/app.html, чтобы дев-интерфейс (app/web) и прототип говорили
 * на одном языке: одни токены, одни имена компонентов.
 *
 * Подключается ПЕРВЫМ (до инлайновых стилей страницы): токены задаёт только этот
 * файл, а экранные правила страницы при необходимости их переопределяют.
 * Базовые компоненты (.btn/.input/.chip/.tag/...) даны для постепенного перевода
 * разметки экранов на канон. Новые токены в :root не добавлять мимо этого файла.
 */

:root {
  --bg:#f5f6f8; --surface:#ffffff; --surface-2:#eff1f4; --surface-3:#e7eaef;
  --border:#e1e4ea; --text:#12151c; --muted:#6a7280; --faint:#98a0ad;
  --accent:#3a56c9; --accent-soft:#e9edfb;
  --ok:#0f7a5f; --ok-soft:#e3f4ee;
  --warn:#a5620a; --warn-soft:#fbf0dc;
  --danger:#b12a2a; --danger-soft:#fbe7e7;
  --radius:14px; --radius-sm:9px;
  --shadow:0 1px 2px rgba(16,24,40,.05), 0 2px 6px rgba(16,24,40,.05);
  --mono:ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans:system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0e1116; --surface:#161a21; --surface-2:#1d222b; --surface-3:#252b36;
    --border:#2a303b; --text:#e8ebf0; --muted:#9aa3b2; --faint:#6b7482;
    --accent:#8ba2ff; --accent-soft:#1e2742;
    --ok:#5cd0ab; --ok-soft:#12291f;
    --warn:#e0a94b; --warn-soft:#2a2210;
    --danger:#f08a8a; --danger-soft:#2c1616;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
.is-hidden { display: none !important; }
mark { background: var(--accent-soft); color: inherit; border-radius: 4px; padding: 0 2px; }

/* ── Кнопки ─────────────────────────────────────────────────────────── */
.btn {
  border:1px solid var(--border); background:var(--surface-2); border-radius:var(--radius-sm);
  padding:9px 15px; font-weight:600; font-size:14px; cursor:pointer;
  transition:filter .15s, border-color .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn--primary { background:var(--accent); border-color:var(--accent); color:#fff; }
.btn--ghost { background:transparent; border-color:transparent; color:var(--muted); }
.btn--sm { padding:6px 11px; font-size:13px; }
.btn--block { width:100%; padding:11px; }
.btn[disabled] { opacity:.6; cursor:default; }

/* ── Поля ───────────────────────────────────────────────────────────── */
.field { display:block; }
.field__label { display:block; font-size:12.5px; font-weight:600; color:var(--muted); margin-bottom:6px; }
.input, .textarea {
  width:100%; background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:11px 13px; outline:none;
  transition:border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.textarea { resize:vertical; min-height:104px; }

/* ── Карточка ───────────────────────────────────────────────────────── */
.card {
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  box-shadow:var(--shadow); padding:16px; min-width:0; margin-bottom:14px;
}
.card__head { display:flex; align-items:center; gap:10px; margin-bottom:12px; flex-wrap:wrap; }
.card__title { font-size:14.5px; font-weight:650; letter-spacing:-.01em; }
.card__sub { color:var(--muted); font-size:12.5px; }

/* ── Чипы, теги, метки ──────────────────────────────────────────────── */
.chip {
  display:inline-flex; align-items:center; gap:6px; border:1px solid var(--border);
  background:var(--surface-2); color:var(--muted); border-radius:999px; padding:4px 11px;
  font-size:12.5px; font-weight:550; cursor:pointer;
}
.chip:hover { border-color:var(--accent); color:var(--accent); }
.chip--sm { padding:2px 9px; font-size:11.5px; }
.chip--ask { border-style:dashed; border-color:var(--warn); color:var(--warn); background:var(--warn-soft); }
.chip--accent { background:var(--accent-soft); border-color:var(--accent-soft); color:var(--accent); }
.tag {
  display:inline-flex; align-items:center; gap:5px; border-radius:6px; padding:2px 8px;
  font-size:11.5px; font-weight:600; white-space:nowrap;
  background:var(--surface-3); color:var(--muted);
}
.tag--event { background:var(--accent-soft); color:var(--accent); }
.tag--fact { background:var(--ok-soft); color:var(--ok); }
.tag--task { background:var(--warn-soft); color:var(--warn); }
.tag--note, .tag--thought, .tag--mood { background:var(--surface-3); color:var(--muted); }
.tag--stated { background:var(--ok-soft); color:var(--ok); }
.tag--inferred { background:var(--warn-soft); color:var(--warn); }
.tag--low { background:var(--danger-soft); color:var(--danger); }
.badge {
  display:inline-grid; place-items:center; min-width:18px; height:18px; padding:0 5px;
  border-radius:999px; background:var(--warn-soft); color:var(--warn); font-size:11px; font-weight:700;
  vertical-align:middle;
}
.pill { display:inline-flex; align-items:center; gap:4px; padding:2px 8px; border-radius:999px;
        font-size:11px; font-weight:700; }

/* ── Сегменты и сводка ──────────────────────────────────────────────── */
.seg { display:inline-flex; flex-wrap:wrap; gap:2px; padding:2px; background:var(--surface-2);
       border:1px solid var(--border); border-radius:999px; max-width:100%; }
.seg__item { border:0; background:transparent; border-radius:999px; padding:6px 12px;
             font-size:12.5px; font-weight:600; color:var(--muted); cursor:pointer; }
.seg__item[aria-pressed="true"] { background:var(--surface); color:var(--text); box-shadow:var(--shadow); }
.summary { display:grid; grid-template-columns:repeat(auto-fit, minmax(140px, 1fr)); gap:10px;
           margin-bottom:12px; }
.summary__i { border:1px solid var(--border); border-radius:var(--radius-sm);
              background:var(--surface-2); padding:10px 12px; }
.summary__k { color:var(--muted); font-size:11.5px; margin-bottom:3px; }
.summary__v { font-weight:650; font-size:15px; font-variant-numeric:tabular-nums; }

/* ── Пустые состояния ───────────────────────────────────────────────── */
.empty { color:var(--faint); font-size:13px; }

/* ── Каркас и навигация ─────────────────────────────────────────────── */
.sidebar { background:var(--surface); display:flex; flex-direction:column; gap:6px; z-index:20; }
.nav { display:flex; flex-direction:column; gap:3px; }
.nav__item {
  display:flex; align-items:center; gap:10px; text-align:left; width:100%;
  background:transparent; border:0; border-radius:var(--radius-sm); padding:9px 11px;
  color:var(--muted); font-weight:550; cursor:pointer;
}
.nav__item:hover { background:var(--surface-2); color:var(--text); }
.nav__item[aria-current="true"], .nav__item[aria-current="page"] {
  background:var(--accent-soft); color:var(--accent); font-weight:650;
}
.nav__icon { width:18px; text-align:center; }
.sidebar__foot { margin-top:auto; padding-top:16px; border-top:1px solid var(--border); }
.sys { font-size:11.5px; color:var(--faint); display:grid; gap:3px; }
.sys b { color:var(--muted); font-weight:600; }

/* ── Шапка экрана ───────────────────────────────────────────────────── */
.topbar {
  position:sticky; top:0; z-index:5; display:flex; align-items:center; gap:10px;
  margin-bottom:16px; padding:10px 0;
  background:color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter:blur(8px); border-bottom:1px solid var(--border);
}
.topbar h1 { margin:0; font-size:17px; letter-spacing:-.01em; }
.topbar__sub { color:var(--muted); font-size:12.5px; }

/* ── Извлечённые записи (факты) ─────────────────────────────────────── */
.fact {
  display:grid; grid-template-columns:auto 1fr auto; gap:10px; align-items:start;
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:9px 11px;
}
.fact__main { min-width:0; }
.fact__text { font-size:13.5px; }
.fact__cat { color:var(--muted); font-size:12px; margin-top:4px; }
.fact__val { font-variant-numeric:tabular-nums; font-weight:650; white-space:nowrap; }
.fact__actions { grid-column:1 / -1; }
.conf { display:inline-flex; align-items:center; gap:6px; font-size:11.5px; color:var(--faint); }
.conf__bar { width:44px; height:4px; border-radius:2px; background:var(--surface-3); overflow:hidden; }
.conf__fill { height:100%; background:var(--ok); }
.conf__fill--mid { background:var(--warn); }
.conf__fill--low { background:var(--danger); }

/* ── Лента дневника ─────────────────────────────────────────────────── */
.entry { border-top:1px solid var(--border); padding:15px 0 14px; }
.entry:first-of-type { border-top:0; padding-top:2px; }
.entry__meta { display:flex; align-items:center; gap:9px; margin-bottom:7px; }
.entry__time { font-size:12.5px; color:var(--muted); font-variant-numeric:tabular-nums; }
.entry__raw { margin:0; white-space:pre-wrap; word-break:break-word; }

/* ── Реестр сущностей ───────────────────────────────────────────────── */
.entity-list { list-style:none; margin:12px 0 0; padding:0; display:grid; gap:8px; }
.entity {
  display:grid; gap:6px; text-align:left; width:100%; cursor:pointer; font:inherit;
  color:inherit; background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:11px 13px;
}
.entity:hover { border-color:var(--accent); }
.entity__top { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.entity__name { font-weight:650; font-size:13.5px; }
.entity__meta { color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }
.entity__aliases { display:flex; gap:5px; flex-wrap:wrap; }
.rec__date { color:var(--faint); font-size:11.5px; font-variant-numeric:tabular-nums; min-width:74px; }

/* ── Поиск и ответ ──────────────────────────────────────────────────── */
.answer { background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius); padding:14px; }
.answer__route { color:var(--muted); font-size:11.5px; margin:0 0 10px; }
.answer__text { margin:0 0 6px; white-space:pre-wrap; }
.sources { list-style:none; margin:12px 0 0; padding:0; display:grid; gap:6px; }
.source {
  display:flex; gap:8px; align-items:baseline; width:100%; text-align:left; font:inherit;
  color:inherit; cursor:pointer; border:0; border-left:3px solid var(--accent);
  background:var(--surface); padding:8px 10px;
  border-radius:0 var(--radius-sm) var(--radius-sm) 0; font-size:12.5px;
}
.source:hover { background:var(--accent-soft); }
.source__text { overflow-wrap:anywhere; }
.source__meta { color:var(--faint); font-size:11.5px; font-variant-numeric:tabular-nums; white-space:nowrap; }

/* ── Планы ──────────────────────────────────────────────────────────── */
.tasks { list-style:none; margin:0; padding:0; display:grid; gap:8px; }
.task {
  display:grid; grid-template-columns:auto 1fr auto; gap:11px; align-items:start;
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:10px 12px;
}
.task--done { opacity:.62; }
.task--done .task__title { text-decoration:line-through; }
.task--overdue { border-color:var(--danger); }
.task__check { width:18px; height:18px; margin:2px 0 0; accent-color:var(--accent); cursor:pointer; }
.task__body { cursor:pointer; min-width:0; }
.task__title { font-weight:600; overflow-wrap:anywhere; }
.task__meta { display:flex; gap:7px; flex-wrap:wrap; align-items:center; margin-top:6px; }
.task__src { font-size:11.5px; color:var(--faint); margin-top:7px; }
.prio { width:8px; height:8px; border-radius:50%; display:inline-block; }
.prio--high { background:var(--danger); }
.prio--medium { background:var(--warn); }
.prio--low { background:var(--faint); }
.goal { padding:11px 0; border-top:1px solid var(--border); }
.goal:first-of-type { border-top:0; padding-top:2px; }
.goal--child { margin-left:18px; }
.goal__row { display:flex; flex-wrap:wrap; align-items:baseline; gap:10px; }
.goal__title { font-weight:600; font-size:13.5px; }
.progress { height:6px; border-radius:3px; background:var(--surface-2); overflow:hidden; margin-top:8px; }
.progress__fill { height:100%; background:var(--accent); border-radius:3px; }
.dots { display:flex; gap:4px; margin-top:8px; }
.dot--day { width:11px; height:11px; border-radius:3px; background:var(--surface-2);
            border:1px solid var(--border); }
.dot--day.dot--on { background:var(--ok); border-color:var(--ok); }

/* ── Таблица — канонный компонент (docs/ui/DESIGN-SYSTEM.md;
   спецификация — docs/ui/manufacturing.md §2). Редактируемые ячейки, архивные
   строки приглушены, первый столбец закреплён на телефоне. ── */
.table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table { width:100%; border-collapse:collapse; font-size:14px; }
.table th, .table td { padding:9px 10px; border-bottom:1px solid var(--border); text-align:left; }
.table th { white-space:nowrap; font-weight:600; color:var(--muted); cursor:pointer; user-select:none; }
.table td { vertical-align:middle; }
.table thead th { position:sticky; top:0; background:var(--surface-2); z-index:1; }
.table th[aria-sort="ascending"]::after { content:" ▲"; color:var(--accent); }
.table th[aria-sort="descending"]::after { content:" ▼"; color:var(--accent); }
.table td[contenteditable="true"] { cursor:text; min-width:80px; }
.table td[contenteditable="true"]:focus { outline:2px solid var(--accent); outline-offset:-2px;
                                          background:var(--accent-soft); }
.table td.table__cell--locked { color:var(--muted); cursor:not-allowed; }
.table__row--archived td { opacity:.5; }
.table__action { border:0; background:transparent; color:var(--muted); cursor:pointer;
                 font-size:16px; line-height:1; padding:2px 6px; }
.table__action:hover { color:var(--accent); }
.table__first { position:sticky; left:0; background:var(--surface); z-index:1; }
.table__select { border:1px solid var(--border); border-radius:var(--radius-sm);
                 background:var(--surface); color:inherit; font:inherit; padding:5px 6px; }
.table__num { text-align:right; font-variant-numeric:tabular-nums; }
