/* Цвета — из темы телеграма: в тёмной теме приложение тёмное, в светлой светлое.
   Вторые значения — запасные, для проверки в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16202c);
  --hint: var(--tg-theme-hint-color, #8a93a3);
  --btn: var(--tg-theme-button-color, #2f6fb2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --sep: rgba(128, 128, 128, 0.18);
  --plus: #2e9d6b;
  --minus: #d0473d;
  /* ветки и разделы: по цвету видно, откуда задача */
  --work: #2f6fb2;
  --money: #d99a00;
  --hub: #2e9d6b;
  --study: #7b5cc4;
  --other: #8a93a3;
}

/* тёмная тема для проверки в браузере (?dark) — цвета как у тёмного телеграма */
:root.dark {
  --bg: #17212b;
  --text: #f5f5f5;
  --hint: #708499;
  --btn: #5288c1;
  --card: #232e3c;
  --sep: rgba(255, 255, 255, 0.08);
  --work: #5d9be0;
  --hub: #45b886;
  --study: #9b82e0;
  --plus: #4cc38a;
  --minus: #ef6b61;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
button { font-family: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ── шапка ── */
.top { padding: 18px 16px 6px; }
.top h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.top p { color: var(--hint); font-size: 14px; margin-top: 2px; min-height: 20px; }
.back { background: none; border: 0; color: var(--btn); font-size: 15px; padding: 0 0 6px; }

main { padding: 10px 16px 16px; }

.muted { color: var(--hint); font-size: 14px; }
.pad { padding: 14px; }

/* ── «Сегодня» ── */
.status {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: 16px;
  padding: 12px 14px; margin-bottom: 20px;
}
.status .chain { font-size: 28px; font-weight: 700; line-height: 1; min-width: 48px; text-align: center; }
.status .chain small { display: block; font-size: 11px; font-weight: 500; color: var(--hint); margin-top: 4px; }
.status .week { font-size: 14px; }

.branch { margin-bottom: 20px; }
.branch h2, .block h2 {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--hint); margin: 0 4px 8px;
}
.branch h2 .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--other)); }
.count { margin-left: auto; font-weight: 500; letter-spacing: 0; text-transform: none; }

.items, .list, .card { background: var(--card); border-radius: 16px; overflow: hidden; }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 13px 14px; cursor: pointer; }
.item + .item, .row + .row { border-top: 1px solid var(--sep); }
.item input, .tick {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 22px; height: 22px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--hint); display: grid; place-content: center;
  transition: background 0.15s, border-color 0.15s; cursor: pointer;
}
.item input:checked, .tick:checked { background: var(--c, var(--btn)); border-color: var(--c, var(--btn)); }
.item input:checked::after, .tick:checked::after {
  content: ""; width: 10px; height: 5px;
  border: 2.5px solid #fff; border-top: 0; border-right: 0;
  transform: translateY(-1px) rotate(-45deg);
}
.item .t { font-size: 15px; }
.item.done .t { color: var(--hint); text-decoration: line-through; }
.item code { font-size: 13px; background: var(--sep); padding: 1px 4px; border-radius: 4px; }
.src {
  display: block; margin-top: 3px; font-size: 12px; color: var(--money);
  text-decoration: none; font-weight: 500;
}

/* ── блоки разделов ── */
.block { margin-bottom: 22px; }
.link { margin-left: auto; background: none; border: 0; color: var(--btn); font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; }

.card { padding: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 4px 0; }
.kv span { color: var(--hint); }
.kv b { font-weight: 600; text-align: right; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; }
.stat b { display: block; font-size: 22px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.stat b small { font-size: 13px; font-weight: 500; color: var(--hint); }
.stat span { display: block; font-size: 12px; color: var(--hint); margin-top: 4px; }

/* строки списков */
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; background: none; border: 0; text-align: left;
}
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-size: 15px; font-weight: 600; }
.row-main small { display: block; font-size: 13px; color: var(--hint); margin-top: 1px; }
.amt { font-size: 15px; font-weight: 600; white-space: nowrap; }
.amt.minus { color: var(--minus); }
.amt.plus { color: var(--plus); }
.row.paid .row-main b, .row.paid .amt { color: var(--hint); text-decoration: line-through; }
.row.soon { background: rgba(217, 154, 0, 0.1); }
.row.low .row-main small { color: var(--minus); }
.date {
  flex: none; width: 44px; text-align: center; font-size: 11px; color: var(--hint);
  background: var(--bg); border-radius: 10px; padding: 4px 0;
}
.date b { display: block; font-size: 17px; color: var(--text); line-height: 1.1; }
.x { background: none; border: 0; color: var(--hint); font-size: 22px; line-height: 1; padding: 0 2px; }

.pill { flex: none; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--sep); color: var(--hint); }
.pill.s1 { background: rgba(47, 111, 178, 0.14); color: var(--work); }
.pill.s2 { background: rgba(123, 92, 196, 0.15); color: var(--study); }
.pill.s3 { background: rgba(217, 154, 0, 0.16); color: var(--money); }
.pill.s4 { background: rgba(46, 157, 107, 0.16); color: var(--hub); }
.pill.s-1 { background: rgba(208, 71, 61, 0.12); color: var(--minus); }

/* большая карточка сверху раздела */
.hero { background: var(--card); border-radius: 20px; padding: 16px; margin-bottom: 22px; }
.hero > span, .hero-row span, .macro span { display: block; font-size: 13px; color: var(--hint); }
.hero > b { display: block; font-size: 32px; font-weight: 700; letter-spacing: -0.01em; margin: 2px 0 6px; }
.hero > b small { font-size: 15px; font-weight: 500; color: var(--hint); }
.hero > b.title { font-size: 22px; }
.hero .muted { margin-top: 6px; }
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--sep); }
.hero-row b { font-size: 17px; }
.btns { display: flex; gap: 8px; margin-top: 14px; }
.btns .btn { margin: 0; }

.bar { height: 6px; border-radius: 3px; background: var(--sep); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--btn); transition: width 0.3s; }

.catrow { display: grid; grid-template-columns: 1fr auto; font-size: 14px; padding: 6px 0; }
.catrow .bar { grid-column: 1 / -1; margin-top: 5px; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macro b { font-size: 16px; }
.macro b small { font-size: 12px; font-weight: 500; color: var(--hint); }

.chart { width: 100%; height: 90px; margin-top: 10px; overflow: visible; }

/* плитки хаба */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; min-height: 118px; }
.tile-t { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--hint); }
.tile-t i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.tile b { font-size: 24px; font-weight: 700; margin-top: auto; padding-top: 10px; }
.tile small { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* кнопки */
.btn {
  display: inline-block; margin-top: 14px; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-text);
  font-size: 15px; font-weight: 600; line-height: 1; padding: 13px 18px;
}
.btn.wide { display: block; width: 100%; }
.btn.ghost { background: var(--card); color: var(--btn); }
.btn.danger { color: var(--minus); }
.block + .btn.ghost { background: var(--card); }

.fab-space { height: 72px; }
.hero .btn.ghost { background: var(--bg); }
.fab {
  position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: var(--btn); color: var(--btn-text); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

/* пустые экраны */
.empty { text-align: center; padding: 44px 20px; color: var(--hint); font-size: 15px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ── нижняя шторка ── */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); opacity: 0; transition: opacity 0.2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.22s ease-out;
}
.sheet-wrap.on .sheet-bg { opacity: 1; }
.sheet-wrap.on .sheet { transform: none; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 4px auto 12px; }
.sheet h3 { font-size: 20px; font-weight: 700; margin-bottom: 12px; }
.sheet .muted { margin-bottom: 12px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.field input {
  width: 100%; border: 0; border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; font-size: 16px; padding: 12px 14px; outline: none;
}
.field input:focus { box-shadow: 0 0 0 2px var(--btn); }
.field.big input { font-size: 26px; font-weight: 700; padding: 10px 14px; }

.chips, .seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { margin-bottom: 14px; }
#q { margin: -6px 0 14px; }
.chip {
  border: 0; border-radius: 999px; background: var(--card); color: var(--text);
  font-size: 14px; font-weight: 500; padding: 8px 14px;
}
.chip.on { background: var(--btn); color: var(--btn-text); }

.steps { display: grid; gap: 8px; margin-bottom: 4px; }
.step { border: 0; border-radius: 12px; background: var(--card); padding: 12px 14px; text-align: left; font-size: 15px; font-weight: 500; }
.step.past { color: var(--hint); }
.step.on { background: var(--btn); color: var(--btn-text); }

/* ── всплывашка и нижние вкладки ── */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px;
  font-size: 14px; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.on { opacity: 0.94; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); border-top: 1px solid var(--sep);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: 0; color: var(--hint); padding: 4px 0;
  font-size: 11px; font-weight: 500;
}
.tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--btn); }
