/* Цвета берутся из темы Telegram; фолбэки — для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16161a);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --accent: var(--tg-theme-button-color, #3478f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #3478f6);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --done: #2fa85a;
  --done-soft: color-mix(in srgb, #2fa85a 14%, transparent);
  --radius: 14px;
  --gap: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17181c);
    --bg2: var(--tg-theme-secondary-bg-color, #0f1013);
    --section: var(--tg-theme-section-bg-color, #1f2025);
    --text: var(--tg-theme-text-color, #f2f2f5);
    --hint: var(--tg-theme-hint-color, #8d8f99);
    --accent: var(--tg-theme-button-color, #5b9cff);
    --link: var(--tg-theme-link-color, #5b9cff);
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #17181c);
  --bg2: var(--tg-theme-secondary-bg-color, #0f1013);
  --section: var(--tg-theme-section-bg-color, #1f2025);
  --text: var(--tg-theme-text-color, #f2f2f5);
  --hint: var(--tg-theme-hint-color, #8d8f99);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 24px; }

/* ── шапка вида ─────────────────────────────────── */
.head { display: flex; align-items: center; gap: 8px; margin: 2px 0 14px; }
.head h1 { font-size: 22px; line-height: 1.2; margin: 0; flex: 1; text-align: center; }
.head .sub { display: block; font-size: 13px; font-weight: 400; color: var(--hint); margin-top: 2px; }
.nav-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--section);
  color: var(--hint); font-size: 18px; display: grid; place-items: center; flex: none;
}
.nav-btn:active { background: var(--soft); }

h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--hint); font-weight: 600; margin: 22px 4px 8px;
  display: flex; align-items: center; justify-content: space-between;
}
h2 .link { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--link); font-size: 14px; }

.section { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.section + .section { margin-top: 10px; }
.empty { color: var(--hint); padding: 14px 16px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }

/* ── вместимость дня ───────────────────────────── */
.capacity { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--hint); font-size: 13px; margin: -6px 0 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); }
.dot.ok { background: var(--done); }

/* ── карточка кванта ───────────────────────────── */
.q { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.q .check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--hint); display: grid; place-items: center; margin-top: 1px;
  color: transparent; font-size: 14px; transition: background .15s, border-color .15s;
}
.q.done .check { background: var(--done); border-color: var(--done); color: #fff; }
.q .body { flex: 1; min-width: 0; }
.q .title { font-weight: 500; overflow-wrap: anywhere; }
.q.done .title { color: var(--hint); }
.q .result { color: var(--hint); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.q .result::before { content: "→ "; }
.q .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-s { font-size: 12px; color: var(--hint); background: var(--bg2); border-radius: 6px; padding: 2px 7px; }
.q.main { background: var(--soft); }
.q.main .title { font-size: 17px; font-weight: 600; }
.q.main .star { color: var(--accent); }
.q.done.main { background: var(--done-soft); }
.q .star { flex: none; color: var(--line); font-size: 18px; line-height: 26px; }

.add {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 13px; color: var(--link); font-weight: 500;
  border-top: 1px dashed var(--line);
}
.add:first-child { border-top: 0; }

/* ── действия-чипы ─────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border-radius: 999px; padding: 6px 12px; background: var(--bg2); font-size: 14px;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.sel { background: var(--accent); color: var(--accent-text); }
.chip.ghost { background: transparent; border-color: var(--line); }
.chip.warn { color: var(--tg-theme-destructive-text-color, #d9534f); }
.chip:active { opacity: .7; }
.stuck { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.stuck:last-child { border-bottom: 0; }
.stuck .chips { margin-top: 8px; }

/* ── неделя ────────────────────────────────────── */
.wday { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.wday:last-child { border-bottom: 0; }
.wday .lbl { color: var(--hint); font-size: 13px; line-height: 1.2; padding-top: 3px; }
.wday .lbl b { display: block; font-size: 15px; color: var(--text); }
.wday.today .lbl b { color: var(--accent); }
.wday.past { opacity: .72; }
.slots { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.slot {
  display: flex; align-items: center; gap: 8px; text-align: left; width: 100%;
  padding: 7px 10px; border-radius: 9px; background: var(--bg2); min-width: 0;
}
.slot .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.slot.main { background: var(--soft); font-weight: 600; }
.slot.done { background: var(--done-soft); }
.slot.done .t { color: var(--hint); }
.slot .mk { flex: none; width: 16px; text-align: center; color: var(--hint); }
.slot.done .mk { color: var(--done); }
.slot.main .mk { color: var(--accent); }
.slot.free { background: transparent; border: 1px dashed var(--line); color: var(--hint); justify-content: center; padding: 5px; }

/* ── вехи и цели ───────────────────────────────── */
.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.goal { padding: 14px; border-bottom: 1px solid var(--line); }
.goal:last-child { border-bottom: 0; }
.goal .gt { font-weight: 600; font-size: 16px; }
.goal .crit { color: var(--hint); font-size: 14px; margin-top: 3px; }
.goal .ms { margin: 10px 0 0 4px; padding-left: 12px; border-left: 2px solid var(--line); }
.goal .ms .row { padding: 8px 0; border: 0; }
.status { font-size: 12px; border-radius: 6px; padding: 2px 8px; background: var(--bg2); color: var(--hint); white-space: nowrap; }
.status.done { background: var(--done-soft); color: var(--done); }
.status.partial { background: var(--soft); color: var(--accent); }
.bar { height: 4px; background: var(--bg2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--done); }
details.fold summary { list-style: none; cursor: pointer; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary h2::after { content: "▾"; margin-left: 6px; }
details.fold:not([open]) summary h2::after { content: "▸"; }

/* ── журнал ────────────────────────────────────── */
.big { text-align: center; padding: 18px 10px 8px; }
.big b { font-size: 46px; line-height: 1; display: block; }
.big span { color: var(--hint); font-size: 14px; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 4px; padding: 14px; justify-content: center; }
.heat i { width: 16px; height: 16px; border-radius: 4px; background: var(--bg2); }
.heat i.l1 { background: color-mix(in srgb, var(--done) 40%, transparent); }
.heat i.l2 { background: color-mix(in srgb, var(--done) 70%, transparent); }
.heat i.l3 { background: var(--done); }
.heat i.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.dayhead { padding: 10px 14px 4px; font-weight: 600; font-size: 14px; color: var(--hint); }
.win { padding: 6px 14px 6px 36px; position: relative; overflow-wrap: anywhere; }
.win::before { content: "✓"; position: absolute; left: 14px; color: var(--done); font-weight: 700; }
.win .r { color: var(--hint); font-size: 14px; }
.note { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .k { font-size: 12px; color: var(--hint); }

/* ── вкладки ───────────────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--hint); padding: 4px 0; position: relative; }
.tabs .ti { font-size: 18px; line-height: 1; }
.tabs button.on { color: var(--accent); }
.badge { position: absolute; top: 0; left: calc(50% + 6px); background: var(--accent); color: var(--accent-text); font-size: 10px; border-radius: 8px; padding: 1px 5px; font-weight: 600; }

/* ── нижний лист ───────────────────────────────── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--bg); border-radius: 18px 18px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 12px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--hint); margin: 0 0 6px 2px; }
.hint { font-size: 13px; color: var(--hint); margin-top: 6px; }
.hint.on { color: var(--link); }
.err { color: var(--tg-theme-destructive-text-color, #d9534f); font-size: 14px; margin: 0 0 12px; }
.btn {
  display: block; width: 100%; text-align: center; padding: 13px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.btn.sec { background: var(--bg2); color: var(--text); font-weight: 500; }
.btn + .btn { margin-top: 8px; }
.btn:disabled { opacity: .5; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.toggle input { width: auto; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; }
.inline > .btn { flex: none; width: auto; padding: 10px 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center;
}
.loading { text-align: center; color: var(--hint); padding: 40px 0; }

/* ── повторы ───────────────────────────────────── */
.wday .lbl .hb { display: block; font-size: 11px; color: var(--done); margin-top: 3px; }
.win.habit::before { content: "↻"; }

[hidden] { display: none !important; }
