/* Задачи планёрок — стили.
   Главный принцип — зона большого пальца: всё, во что тыкают, внизу;
   верх только для чтения. Кнопки не меньше 48 px.
   Цвета берутся из темы мессенджера (Telegram выставляет --tg-theme-*),
   иначе — светлая/тёмная тема системы. */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #F2F3F5);
  --surface: var(--tg-theme-bg-color, #FFFFFF);
  --text: var(--tg-theme-text-color, #111827);
  --hint: var(--tg-theme-hint-color, #4B5563);
  --line: rgba(127, 127, 127, 0.18);
  --accent: var(--tg-theme-button-color, #1D4ED8);
  --accent-text: var(--tg-theme-button-text-color, #FFFFFF);
  --soft: rgba(127, 127, 127, 0.12);
  --danger: #B91C1C;
  --danger-strong: #DC2626;
  --ok: #047857;
  --warn: #C2410C;
  --badge-neutral: #6B7280;
  --radius: 16px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #0F1115);
    --surface: var(--tg-theme-bg-color, #1A1D23);
    --text: var(--tg-theme-text-color, #F3F4F6);
    --hint: var(--tg-theme-hint-color, #A1A7B3);
    --accent: var(--tg-theme-button-color, #3B82F6);
    --danger: #F87171;
    --danger-strong: #EF4444;
    --ok: #34D399;
    --warn: #FB923C;
    --badge-neutral: #4B5563;
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #0F1115);
  --surface: var(--tg-theme-bg-color, #1A1D23);
  --text: var(--tg-theme-text-color, #F3F4F6);
  --hint: var(--tg-theme-hint-color, #A1A7B3);
  --accent: var(--tg-theme-button-color, #3B82F6);
  --danger: #F87171;
  --danger-strong: #EF4444;
  --ok: #34D399;
  --warn: #FB923C;
  --badge-neutral: #4B5563;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; }

/* ---- верх: только чтение ---- */
.top { padding: 18px 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.top h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.top p { margin: 3px 0 0; font-size: 13px; color: var(--hint); }
.top .crumb { font-size: 13px; color: var(--hint); margin: 0 0 6px; }

/* ---- середина ---- */
.scroll { flex: 1; overflow-y: auto; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch; }
.group-title { margin: 0 4px 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--hint); }
.group-title.overdue { color: var(--danger); }
.group-title.done { color: var(--ok); }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; min-height: 60px; border: 0; background: none; text-align: left; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--soft); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .name { font-size: 15px; font-weight: 500; }
.row .sub { font-size: 13px; color: var(--hint); }
.row .sub.overdue { color: var(--danger); font-weight: 500; }

.avatar { width: 36px; height: 36px; border-radius: 18px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; background: var(--soft); }
.avatar.dashed { background: none; border: 1.5px dashed var(--hint); }

.badge { min-width: 28px; height: 28px; padding: 0 8px; border-radius: 14px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #FFFFFF; background: var(--badge-neutral); }
.badge.red { background: var(--danger-strong); }
.badge.orange { background: var(--warn); }
.badge.zero { background: none; color: var(--hint); font-weight: 500; }

.hero { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-text); text-align: left; }
.hero .main { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.hero .name { font-size: 17px; font-weight: 600; }
.hero .sub { font-size: 13px; opacity: 0.85; }
.hero .badge { background: var(--accent-text); color: var(--accent); }
.dashed-card { border: 1.5px dashed var(--hint); }

/* задача в списке: кружок-галочка слева (44px зона), текст — открыть карточку */
.task { display: flex; align-items: center; min-height: 64px; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.check { width: 48px; height: 56px; flex: none; border: 0; background: none; display: flex; align-items: center; justify-content: center; }
.check span { width: 24px; height: 24px; border-radius: 12px; border: 2px solid var(--hint); display: flex; align-items: center; justify-content: center; }
.check.overdue span { border-color: var(--danger-strong); }
.check.done span { background: var(--ok); border-color: var(--ok); }
.check.done span::after { content: ""; width: 10px; height: 6px; border: solid #FFFFFF; border-width: 0 0 2.5px 2.5px; transform: translateY(-1px) rotate(-45deg); }
.task .open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 0; border: 0; background: none; text-align: left; }
.task .open .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.task .title { font-size: 15px; }
.task.is-done .title { color: var(--hint); text-decoration: line-through; }
.task .meta { font-size: 13px; color: var(--hint); }
.task .meta.overdue { color: var(--danger); }
.chev { flex: none; width: 16px; height: 16px; color: var(--hint); }

.empty { text-align: center; color: var(--hint); padding: 32px 16px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.note { text-align: center; font-size: 13px; color: var(--hint); margin: 0; }

/* карточка задачи */
.detail { background: var(--surface); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.detail h2 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 700; }
.detail .text { margin: 0; font-size: 15px; line-height: 1.45; white-space: pre-line; }
.pill { align-self: flex-start; padding: 4px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; background: var(--soft); }
.pill.red { background: rgba(220, 38, 38, 0.14); color: var(--danger); }
.pill.green { background: rgba(4, 120, 87, 0.14); color: var(--ok); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.facts div { display: flex; flex-direction: column; gap: 2px; }
.facts span { font-size: 12px; color: var(--hint); }
.facts b { font-size: 15px; font-weight: 500; }
.facts b.red { color: var(--danger); }
.label { font-size: 12px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: 0.4px; }
.quote { margin: 0; font-style: italic; font-size: 15px; line-height: 1.45; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.history li { display: flex; gap: 10px; }
.history li::before { content: ""; width: 8px; height: 8px; margin-top: 6px; border-radius: 4px; background: var(--hint); flex: none; }
.history li.done::before { background: var(--ok); }
.history li.dropped::before { background: var(--danger-strong); }
.history small { display: block; font-size: 12px; color: var(--hint); }

/* ---- низ: всё нажимаемое здесь ---- */
.bottom { padding: 10px 16px calc(12px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.bar { display: flex; gap: 8px; align-items: center; }
.btn { height: var(--tap); padding: 0 16px; border-radius: 14px; border: 0; background: var(--soft); font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--ok); color: #FFFFFF; }
.btn.danger { color: var(--danger); }
.btn.small { font-size: 14px; font-weight: 500; }
.btn.icon { flex: none; width: var(--tap); padding: 0; }
.btn.back { background: var(--soft); }
.btn[disabled] { opacity: 0.5; }
.chips { display: flex; gap: 8px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: var(--tap); padding: 0 16px; border-radius: 14px; border: 0; background: var(--soft); font-size: 15px; font-weight: 500; }
.chip.on { background: var(--text); color: var(--surface); font-weight: 600; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.row3 .btn { flex: initial; }

/* всплывашка «Отменить» — над нижней панелью */
/* bottom выставляет app.js по фактической высоте нижней панели */
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(92px + var(--safe-bottom)); max-width: 616px; margin: 0 auto; padding: 8px 8px 8px 16px; border-radius: 14px; background: #1F2937; color: #FFFFFF; display: flex; align-items: center; gap: 8px; z-index: 30; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
.toast span { flex: 1; font-size: 14px; }
.toast button { height: 44px; padding: 0 14px; border: 0; border-radius: 10px; background: none; color: #93C5FD; font-weight: 600; }

/* нижний лист: выбор срока, получателя, причины */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 80dvh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom)); z-index: 50; display: flex; flex-direction: column; gap: 10px; }
.sheet > .btn { flex: none; }
.sheet .bar input { flex: 1; }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 6px; }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .list { display: flex; flex-direction: column; }
.sheet .list .row { min-height: 52px; }
.sheet input[type="date"], .sheet textarea { width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.sheet textarea { min-height: 96px; resize: vertical; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  .sheet:not([hidden]) { animation: up 0.18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
}

/* текст загрузки / аварийный — виден на любом фоне */
.boot{padding:32px 20px;text-align:center;opacity:.8;line-height:1.5}

/* правка задачи: текст — крупная цель для пальца, кнопка «Изменить» — рядом с главным действием внизу */
.editable { display: flex; flex-direction: column; gap: 8px; border-radius: 12px; margin: -6px; padding: 6px; cursor: pointer; }
.editable:active { background: var(--soft); }
.edit-hint { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; opacity: .6; }
.bar .edit-btn { flex: none; }
.sheet textarea.title-input { min-height: 0; font-weight: 600; }
