:root {
  --bg: #F4F5F2;
  --card: #FFFFFF;
  --line: #DADDD6;
  --line-soft: #ECEEE9;
  --ink: #18201C;
  --quiet: #545D57;
  --accent: #1D7357;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3F1EB;
  --accent-text: #145440;
  --chip: #EEF0EC;
  --warn-bg: #FCEFE4;
  --warn-ink: #8A420F;
  --bad-bg: #FBE9E7;
  --bad-ink: #9B2C1F;
  --box: #B4BAB1;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06);
  --chart: #118A62; /* проверено валидатором палитры: светлая тема */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1B211E;
    --line: #2E3631;
    --line-soft: #252C28;
    --ink: #E8ECE9;
    --quiet: #A3ADA7;
    --accent: #3FAE87;
    --accent-ink: #0D1A14;
    --accent-soft: #1D3A2F;
    --accent-text: #8FD9BC;
    --chip: #262D29;
    --warn-bg: #3A2A1C;
    --warn-ink: #F2C39A;
    --bad-bg: #3B201C;
    --bad-ink: #F4B4AA;
    --box: #5D6862;
    --shadow: none;
    --chart: #2E9C76; /* проверено валидатором палитры: тёмная тема */
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.boot { padding: 48px 16px; color: var(--quiet); text-align: center; }

/* ---------- шапка ---------- */
.top { padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.top-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.top h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; }
.date { color: var(--quiet); font-size: 15px; }
.deadline {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--warn-bg); color: var(--warn-ink); font-size: 15px; font-weight: 500;
}
.deadline.calm { background: var(--accent-soft); color: var(--accent-text); }
.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--quiet); }
.progress-row b { color: var(--ink); }
.bar { height: 8px; border-radius: 4px; background: var(--line-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .25s; }
.sync { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--quiet); min-height: 20px; }
.sync button { border: none; background: none; color: var(--accent-text); padding: 4px 0; font-size: 13px; font-weight: 600; }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } .bar > span { transition: none; } }

/* ---------- карточки ---------- */
.stack { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.card.locked { opacity: .5; }
.card.focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card h2 { margin: 0; font-size: 18px; }
.status { font-size: 13px; color: var(--quiet); white-space: nowrap; }
.status.ok { color: var(--accent-text); font-weight: 600; }
.label {
  font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--quiet);
}
.section { display: flex; flex-direction: column; gap: 4px; }
.section + .section { border-top: 1px solid var(--line-soft); padding-top: 12px; }
.hint { margin: 0; font-size: 14px; color: var(--quiet); }
.note { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--quiet); padding: 0 4px; }

/* ---------- отметка «принял» ---------- */
.pill {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 4px 0;
  border: none; background: none; text-align: left;
}
.box {
  flex: none; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--box);
  display: grid; place-items: center; background: var(--card);
}
.pill[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); }
.box svg { opacity: 0; }
.pill[aria-pressed="true"] .box svg { opacity: 1; }
.pill-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pill-title { font-size: 15px; }
.pill[aria-pressed="true"] .pill-title { color: var(--quiet); text-decoration: line-through; }
.pill-sub { font-size: 13px; color: var(--quiet); }
.pill:disabled .box { border-style: dashed; }

/* ---------- чипы и кнопки ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 15px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.food { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 6px 0 12px; border-radius: 999px; background: var(--chip); font-size: 15px; }
.food button { border: none; background: none; width: 32px; height: 32px; border-radius: 50%; color: var(--quiet); display: grid; place-items: center; }
.food.static { padding: 0 12px; }
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: none; background: var(--accent);
  color: var(--accent-ink); font-size: 16px; font-weight: 600;
}
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 160px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--quiet); }
.input {
  height: 48px; width: 100%; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 16px;
}
.input::placeholder { color: var(--quiet); }
.eaten { display: flex; gap: 8px; align-items: center; font-size: 15px; color: var(--accent-text); font-weight: 500; }

/* ---------- поиск ---------- */
.results { display: flex; flex-direction: column; gap: 8px; }
.result { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px; background: var(--chip); }
.result-term { font-size: 13px; color: var(--quiet); }
.result .chips { gap: 6px; }
.result .chip { min-height: 36px; font-size: 14px; }

/* ---------- задачи ---------- */
.task { margin: 0; font-size: 15px; line-height: 1.45; }
.disclaimer { margin: 0; padding: 0 4px; font-size: 13px; color: var(--quiet); }
.error { background: var(--bad-bg); color: var(--bad-ink); border-radius: 12px; padding: 12px; font-size: 14px; }

/* ---------- история ---------- */
.back { color: var(--accent-text); text-decoration: none; font-weight: 600; font-size: 15px; min-height: 44px; display: inline-flex; align-items: center; }
.day-row { text-decoration: none; color: inherit; gap: 10px; }
.day-row:hover { border-color: var(--accent); }
.day-row h2 { font-size: 16px; }
.day-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--quiet); }
.export { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---------- динамика ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--quiet); }
.tile-value { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.tile-sub { font-size: 12px; color: var(--quiet); }
@media (max-width: 340px) { .tiles { grid-template-columns: 1fr; } }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis { fill: var(--quiet); font-size: 12px; }
.chart .value { fill: var(--ink); font-size: 13px; font-weight: 600; }
.chart .mark { fill: var(--chart); }
.chart .mark-zero { stroke: var(--line); stroke-width: 2; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart); stroke: var(--card); stroke-width: 2; }
.chart .hit-area { fill: transparent; }
.chart .hit:hover .mark, .chart .hit:hover .dot { opacity: .8; }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(0, 9em) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 14px; }
.hbar-label { overflow-wrap: anywhere; }
.hbar-track { height: 10px; border-radius: 0 5px 5px 0; }
.hbar-fill { display: block; height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; }
.hbar-value { color: var(--quiet); white-space: nowrap; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
thead th { color: var(--quiet); font-weight: 600; font-size: 12px; }
tbody tr:last-child > * { border-bottom: none; }

/* ---------- вход ---------- */
.login { padding: 48px 16px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { margin: 0; font-size: 28px; }
.login ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.login code { background: var(--chip); padding: 2px 6px; border-radius: 6px; }

/* ---------- нижнее меню ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.tabs-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tab {
  text-decoration: none;
  min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: none; background: none; color: var(--quiet); font-size: 12px;
}
.tab[aria-current="page"] { color: var(--accent-text); font-weight: 600; }
.tab:disabled { opacity: .45; }

/* ---------- всплывающее сообщение ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px)); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
