/* Цвета берём из темы Telegram; вне Telegram — свои светлая/тёмная палитры */
:root {
  --fb-bg: #f2f2f7;
  --fb-card: #ffffff;
  --fb-text: #0c0c0e;
  --fb-hint: #8a8a8f;
  --fb-accent: #2f7cf6;
  --fb-accent-text: #ffffff;
  --fb-danger: #ff3b30;

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --sep: rgba(128, 128, 136, .2);
  --hot: #ff5b3a;
  --warm: #f59e0b;
  --soft: rgba(128, 128, 136, .12);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 18px rgba(0, 0, 0, .05);
  --radius: 16px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Roboto", "Segoe UI", system-ui, sans-serif;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #0f0f11;
    --fb-card: #1c1c1f;
    --fb-text: #f2f2f4;
    --fb-hint: #8d8d93;
    --fb-accent: #5b9bff;
    --fb-danger: #ff6b61;
    --shadow: none;
  }
}
:root.dark { --shadow: none; --soft: rgba(160, 160, 170, .14); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
textarea, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 18px var(--pad) calc(120px + var(--safe-bottom));
}

/* ---------- header ---------- */
.top { padding: 4px 4px 10px; }
.date { color: var(--hint); font-size: 15px; letter-spacing: .01em; }
.date::first-letter { text-transform: uppercase; }
.tabs { display: flex; gap: 18px; margin-top: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15;
  color: var(--hint); opacity: .55; white-space: nowrap;
  transition: opacity .2s, color .2s;
}
.tabs button.active { color: var(--text); opacity: 1; }
.tabs sup { font-size: 13px; font-weight: 600; margin-left: 3px; vertical-align: 15px; letter-spacing: 0; }

/* ---------- common blocks ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.section-h {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--hint); margin: 26px 4px 8px;
  display: flex; align-items: baseline; justify-content: space-between;
}
.section-h small { font-weight: 500; text-transform: none; letter-spacing: 0; font-size: 13px; }
.lead {
  font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -.01em;
  margin: 8px 4px 16px; text-wrap: pretty;
}
.muted { color: var(--hint); }
.empty {
  text-align: center; color: var(--hint); padding: 48px 24px; font-size: 16px; line-height: 1.45;
}
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; font-weight: 600; }

/* ---------- task row ---------- */
.task {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 16px 13px 14px; position: relative;
  transition: opacity .3s, transform .3s;
}
.task + .task::before, .batch + .task::before, .task + .batch::before {
  content: ""; position: absolute; top: 0; left: 50px; right: 0; height: 1px; background: var(--sep);
}
.task .body { flex: 1; min-width: 0; cursor: pointer; padding-top: 1px; }
.task .title { font-size: 16.5px; line-height: 1.32; word-wrap: break-word; transition: color .3s; }
.task .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 13.5px; color: var(--hint); }
.task .why { font-size: 14px; color: var(--hint); margin-top: 3px; font-style: italic; }
.task.done .title { color: var(--hint); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--hint) 60%, transparent); }
.task.leaving { opacity: 0; transform: translateX(12px); }
.task.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--accent) 16%, transparent); } 100% { background: transparent; } }

.due { font-weight: 500; }
.due.overdue { color: var(--hot); }
.due.today { color: var(--warm); }
.due.soon { color: var(--accent); }
.meta .linked { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.meta .linked span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.meta .linked svg { flex: none; }

/* чекбокс: кольцо, цвет кольца = важность */
.check { flex: none; width: 26px; height: 26px; margin-top: -1px; border-radius: 50%; position: relative; }
.check svg { width: 26px; height: 26px; display: block; overflow: visible; }
.check .ring { fill: none; stroke: var(--hint); stroke-width: 1.7; opacity: .55; transition: all .25s; }
.check .fill { fill: var(--accent); transform: scale(0); transform-origin: 13px 13px; transition: transform .28s cubic-bezier(.3, 1.6, .5, 1); }
.check .tick { fill: none; stroke: var(--accent-text); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 14; stroke-dashoffset: 14; transition: stroke-dashoffset .25s .12s; }
.task.p1 .check .ring { stroke: var(--hot); opacity: 1; stroke-width: 2; }
.task.p3 .check .ring { stroke-dasharray: 2.5 3; }
.task.done .check .fill, .task.checking .check .fill { transform: scale(1); }
.task.done .check .tick, .task.checking .check .tick { stroke-dashoffset: 0; }
.task.done .check .ring, .task.checking .check .ring { stroke: var(--accent); opacity: 1; }

/* пачка дел «одним заходом» */
.batch { position: relative; }
.batch::after {
  content: ""; position: absolute; left: 6px; top: 34px; bottom: 14px; width: 2.5px; border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}
.batch-label {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 16px 0 50px; font-size: 13px; font-weight: 600; color: var(--accent);
}
.batch .task:first-of-type::before { display: none; }

/* ---------- plan ---------- */
.progress { display: flex; align-items: center; gap: 10px; margin: -6px 4px 14px; color: var(--hint); font-size: 13.5px; }
.progress .bar { flex: 1; height: 4px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.nudge {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 12px 0 0; padding: 13px 15px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  font-size: 15px; line-height: 1.4;
}
.nudge svg { flex: none; margin-top: 1px; color: var(--accent); }
.plan-foot { display: flex; align-items: center; justify-content: space-between; margin: 12px 4px 0; font-size: 14px; color: var(--hint); }
.text-btn { color: var(--accent); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; }
.text-btn:disabled { opacity: .5; }
.closed {
  text-align: center; padding: 30px 20px 26px;
}
.closed .big { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.closed b { display: block; font-size: 19px; font-weight: 650; margin-bottom: 4px; }
.closed span { color: var(--hint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 22px; border-radius: 13px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 16px;
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; }
.btn.wide { width: 100%; }
.plan-empty { padding: 26px 20px 22px; text-align: center; }
.plan-empty p { margin: 0 0 16px; color: var(--hint); line-height: 1.45; }
.plan-empty p b { color: var(--text); display: block; font-size: 18px; margin-bottom: 4px; font-weight: 600; }

.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .35; animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- all: toolbar ---------- */
.toolbar { position: sticky; top: 0; z-index: 3; background: var(--bg); padding: 6px 0 10px; margin: 0 calc(-1 * var(--pad)); padding-left: var(--pad); padding-right: var(--pad); }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; border-radius: 12px; background: var(--soft);
}
.search svg { color: var(--hint); flex: none; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; min-width: 0; }
.search input::placeholder { color: var(--hint); }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 10px calc(-1 * var(--pad)) 0; padding: 0 var(--pad); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 13px; border-radius: 16px;
  background: var(--card); color: var(--text); font-size: 14.5px; font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--sep);
  transition: background .15s, color .15s;
}
.chip.on { background: var(--text); color: var(--bg); box-shadow: none; }
.chip-sep { flex: none; width: 1px; background: var(--sep); margin: 6px 2px; }
.sortbar { display: flex; align-items: center; gap: 4px; margin-top: 10px; font-size: 14px; color: var(--hint); }
.sortbar button { padding: 4px 8px; border-radius: 8px; color: var(--hint); font-weight: 500; }
.sortbar button.on { color: var(--text); background: var(--soft); }

/* ---------- composer ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px var(--pad) calc(10px + var(--safe-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 26px);
}
.composer > * { max-width: 600px; margin-left: auto; margin-right: auto; }
#compose {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--card); border-radius: 24px; padding: 6px 6px 6px 16px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .08), inset 0 0 0 1px var(--sep);
}
#input {
  flex: 1; border: 0; outline: 0; background: transparent; resize: none;
  font-size: 16px; line-height: 22px; padding: 7px 0; max-height: 132px; min-width: 0;
}
#input::placeholder { color: var(--hint); }
#send {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; transition: opacity .2s, transform .12s;
}
#send:disabled { opacity: .35; }
#send:active { transform: scale(.92); }

.bubble {
  position: relative; margin-bottom: 10px; padding: 14px 40px 14px 16px;
  background: var(--card); border-radius: 18px; font-size: 15.5px; line-height: 1.42;
  box-shadow: 0 6px 30px rgba(0, 0, 0, .12), inset 0 0 0 1px var(--sep);
  max-height: 46vh; overflow-y: auto; white-space: pre-wrap;
  animation: rise .28s cubic-bezier(.2, .9, .3, 1.2);
}
.bubble .x { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--hint); }
.bubble .line { display: flex; gap: 8px; white-space: normal; }
.bubble .line + .line { margin-top: 4px; }
.bubble .line .sign { color: var(--accent); font-weight: 700; width: 12px; flex: none; text-align: center; }
.bubble .line a { color: inherit; text-decoration: none; }
.bubble .line .due { margin-left: 6px; font-size: 14px; }
.bubble .q { margin-top: 12px; font-weight: 600; white-space: normal; }
.bubble .opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.bubble .opts .chip { background: var(--soft); box-shadow: none; }
.bubble .sub { color: var(--hint); font-size: 14px; margin-top: 8px; white-space: normal; }
.bubble.thinking { color: var(--hint); }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.toast {
  margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px 11px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 15px; font-weight: 500;
  animation: rise .25s ease-out;
}
.toast button { color: var(--bg); opacity: .75; font-weight: 600; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .32); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 600px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px var(--pad) calc(18px + var(--safe-bottom));
  transform: translateY(105%); transition: transform .34s cubic-bezier(.2, .9, .25, 1);
}
.sheet.open { transform: none; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 2px auto 14px; }
.sheet-title {
  width: 100%; border: 0; outline: 0; background: transparent; resize: none;
  font-size: 22px; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; padding: 0 4px; margin-bottom: 14px;
}
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 8px 16px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--sep); }
.row > label { flex: none; width: 82px; color: var(--hint); font-size: 15px; }
.row.stack { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px 14px; }
.row.stack > label { width: auto; }
.row .grow { flex: 1; min-width: 0; }
.row input[type="text"], .row input[type="time"] { border: 0; outline: 0; background: transparent; font-size: 16px; width: 100%; }
.row input[type="time"] { width: auto; color: var(--accent); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { height: 30px; padding: 0 11px; border-radius: 15px; background: var(--soft); font-size: 14px; font-weight: 500; }
.quick button.on { background: var(--accent); color: var(--accent-text); }
.quick .pick { position: relative; overflow: hidden; }
.quick .pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 2px; flex: 1; }
.seg button { flex: 1; height: 32px; border-radius: 8px; font-size: 14.5px; font-weight: 500; color: var(--hint); transition: background .15s; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg button.on[data-p="1"] { color: var(--hot); }
.note {
  width: 100%; min-height: 84px; border: 0; outline: 0; resize: none; background: var(--card);
  border-radius: var(--radius); padding: 14px 16px; font-size: 15.5px; line-height: 1.4; margin-bottom: 14px; display: block;
}
.note::placeholder { color: var(--hint); }
.links-list .row { cursor: pointer; font-size: 15px; }
.links-list .row .kind { color: var(--hint); font-size: 13.5px; width: 82px; flex: none; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.btn.ghost { background: var(--card); color: var(--danger); }
.btn.ghost.neutral { color: var(--text); }
.src { color: var(--hint); font-size: 13px; text-align: center; margin: 14px 0 0; line-height: 1.4; }

/* ---------- skeleton ---------- */
.skel { padding: 6px 0; }
.skel div { height: 18px; border-radius: 9px; margin: 14px 16px; background: var(--soft); animation: pulse 1.4s ease-in-out infinite; }
.skel div:nth-child(2) { width: 70%; }
.skel div:nth-child(3) { width: 82%; }
@keyframes pulse { 50% { opacity: .45; } }

@media (min-width: 640px) {
  #app { padding-top: 34px; }
  .tabs button { font-size: 34px; }
}
