:root {
  color-scheme: light dark;
  --f-bg: #ffffff; --f-text: #000000; --f-hint: #8a8a8e; --f-link: #2481cc;
  --f-btn: #2481cc; --f-btn-text: #ffffff; --f-page: #efeff4; --f-section: #ffffff;
  --f-danger: #e53935; --f-sep: rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --f-bg: #17212b; --f-text: #f5f5f5; --f-hint: #7f91a4; --f-link: #6ab3f3;
    --f-btn: #5288c1; --f-btn-text: #ffffff; --f-page: #0e1621; --f-section: #17212b;
    --f-danger: #ec3942; --f-sep: rgba(255,255,255,.08);
  }
}
:root {
  --bg: var(--tg-theme-bg-color, var(--f-bg));
  --text: var(--tg-theme-text-color, var(--f-text));
  --hint: var(--tg-theme-hint-color, var(--f-hint));
  --link: var(--tg-theme-link-color, var(--f-link));
  --btn: var(--tg-theme-button-color, var(--f-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--f-btn-text));
  --page: var(--tg-theme-secondary-bg-color, var(--f-page));
  --section: var(--tg-theme-section-bg-color, var(--f-section));
  --danger: var(--tg-theme-destructive-text-color, var(--f-danger));
  --sep: var(--f-sep);
  --chip: color-mix(in srgb, var(--hint) 16%, transparent);
  --st: max(calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)), env(safe-area-inset-top, 0px));
  --sb: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --sl: max(var(--tg-safe-area-inset-left, 0px), env(safe-area-inset-left, 0px));
  --sr: max(var(--tg-safe-area-inset-right, 0px), env(safe-area-inset-right, 0px));
  --tabh: 56px;
  --toast-bg: #ffffff; --toast-line: rgba(0,0,0,.06);
}
/* Our own neutral graphite in dark mode instead of Telegram's bluish theme;
   buttons and links keep Telegram's accent. */
:root[data-theme="dark"] {
  --page: #1e1e1e; --section: #2a2a2a; --bg: #252525;
  --text: #ececec; --hint: #9a9a9a; --sep: rgba(255,255,255,.07);
  --toast-bg: #333333; --toast-line: rgba(255,255,255,.08); color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #1e1e1e; --section: #2a2a2a; --bg: #252525;
    --text: #ececec; --hint: #9a9a9a; --sep: rgba(255,255,255,.07);
    --toast-bg: #333333; --toast-line: rgba(255,255,255,.08); color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--page); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

#view { max-width: 720px; margin: 0 auto; min-height: 100vh;
  padding: calc(var(--st) + 12px) calc(var(--sr) + 12px) calc(var(--tabh) + var(--sb) + 24px) calc(var(--sl) + 12px); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center;
  background: var(--section); border-top: 1px solid var(--sep); padding: 0 var(--sr) var(--sb) var(--sl); }
.tab { flex: 1; max-width: 360px; min-height: var(--tabh); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11px; color: var(--hint); text-align: center; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--btn); }

h2.sec { margin: 20px 16px 6px; font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .02em;
  color: var(--hint); display: flex; gap: 8px; align-items: baseline; }
h2.sec:first-child { margin-top: 4px; }
h2.sec .n { opacity: .7; }
h2.sec.over { color: var(--danger); }
.card { background: var(--section); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: stretch; min-height: 52px; position: relative; transition: opacity .25s, transform .25s, max-height .3s; max-height: 220px; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 52px; right: 0; border-top: 1px solid var(--sep); }
.row.out { opacity: 0; transform: translateX(24px); max-height: 0; min-height: 0; overflow: hidden; }
.row.overdue .when { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.check { flex: none; width: 52px; min-height: 52px; display: grid; place-items: center; }
.check i { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--hint); display: grid; place-items: center; transition: .15s; }
.check:active i, .check.on i { background: var(--btn); border-color: var(--btn); }
.row.overdue .check i { border-color: var(--danger); }
.main { flex: 1; min-width: 0; display: block; padding: 8px 14px 8px 0; min-height: 52px; }
.line1 { display: flex; gap: 8px; align-items: baseline; }
.emo { flex: none; }
.title { flex: 1; min-width: 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sub { display: block; color: var(--hint); font-size: 14px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.when { font-size: 12.5px; padding: 1px 8px; border-radius: 10px; background: var(--chip); color: var(--hint); white-space: nowrap; }
.row.done .title { text-decoration: line-through; color: var(--hint); }
.date { flex: none; color: var(--hint); font-size: 13px; }
.mem-row .main { padding-left: 14px; }
.row.mem-row + .row.mem-row::before { left: 14px; }
.done-tick { width: 12px; height: 12px; stroke: var(--btn-text); fill: none; stroke-width: 3; opacity: 0; }
.check:active .done-tick, .check.on .done-tick { opacity: 1; }

.empty { text-align: center; color: var(--hint); padding: 72px 24px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; font-weight: 600; }
.error-screen { text-align: center; padding: 96px 24px; }
.error-screen .big { font-size: 48px; }
.error-screen h1 { font-size: 20px; margin: 12px 0 8px; }
.error-screen p { color: var(--hint); margin: 0 0 16px; }
.error-screen .btn { display: inline-block; flex: none; }
.loading { display: grid; place-items: center; padding: 60px; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--chip); border-top-color: var(--btn); animation: sp .8s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }
.btn .spin { width: 16px; height: 16px; border-width: 2px; border-color: rgba(255,255,255,.35); border-top-color: var(--btn-text); vertical-align: -3px; margin-right: 6px; }

.search { position: sticky; top: 0; z-index: 3; margin: calc(-12px - var(--st)) -12px 0; padding: calc(var(--st) + 12px) 12px 4px; background: var(--page); }
.search input { width: 100%; min-height: 44px; border: 0; border-radius: 12px; background: var(--section); padding: 0 14px; outline-offset: 0; }
.search input::placeholder { color: var(--hint); }
/* Wraps instead of scrolling sideways: a mouse wheel in Telegram Desktop can't scroll it. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 6px; }
.chips .chip { min-height: 36px; padding: 0 12px; }
.chip { flex: none; min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--section); color: var(--text); display: inline-flex; align-items: center; gap: 4px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--btn); color: var(--btn-text); }
.seg { display: flex; background: var(--chip); border-radius: 9px; padding: 2px; margin: 4px 0 10px; }
.seg button { flex: 1; min-height: 44px; border-radius: 7px; text-align: center; font-size: 14px; color: var(--text); }
.seg button.on { background: var(--section); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.sentinel { height: 40px; display: grid; place-items: center; }

.sheet { position: fixed; inset: 0; z-index: 20; background: var(--page); overflow-y: auto; overscroll-behavior: contain;
  padding: calc(var(--st) + 8px) calc(var(--sr) + 12px) calc(var(--sb) + 32px) calc(var(--sl) + 12px); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-in { max-width: 720px; margin: 0 auto; }
.sheet-top { display: flex; align-items: center; min-height: 44px; }
.sheet-top .back { min-height: 44px; padding: 0 8px 0 0; color: var(--link); display: inline-flex; align-items: center; gap: 4px; }
.sheet h1 { font-size: 20px; margin: 8px 4px 4px; overflow-wrap: anywhere; }
.sheet .kicker { margin: 0 4px 12px; color: var(--hint); font-size: 13px; }
.body-text { padding: 12px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.pad { padding: 12px 16px; }
.lbl { margin: 18px 16px 6px; font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .02em; }
.kinds { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.kinds .chip { background: var(--chip); }
.kinds .chip.on { background: var(--btn); }
.field { width: 100%; min-height: 44px; border: 1px solid var(--sep); border-radius: 10px; background: var(--bg); padding: 0 12px; }
.field:disabled { opacity: .5; }
/* Android draws the date field's parts (and its picker) with their own colours unless told. */
.field { color: var(--text); accent-color: var(--btn); }
.field::-webkit-datetime-edit, .field::-webkit-datetime-edit-fields-wrapper,
.field::-webkit-datetime-edit-text, .field::-webkit-datetime-edit-day-field,
.field::-webkit-datetime-edit-month-field, .field::-webkit-datetime-edit-year-field,
.field::-webkit-datetime-edit-hour-field, .field::-webkit-datetime-edit-minute-field { color: var(--text); }
:root[data-theme="dark"] .field::-webkit-calendar-picker-indicator { filter: invert(.85); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .field::-webkit-calendar-picker-indicator { filter: invert(.85); }
}
textarea.field { padding: 10px 12px; min-height: 120px; resize: vertical; display: block; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick .chip { background: var(--chip); }
.btnrow { display: flex; gap: 8px; padding: 10px 12px; }
.btn { flex: 1; min-height: 46px; border-radius: 12px; background: var(--btn); color: var(--btn-text); text-align: center; font-weight: 600; padding: 0 14px; }
.btn.sec { background: var(--chip); color: var(--text); font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); font-weight: 500; }
.btn:disabled { opacity: .55; }
.confirm { padding: 12px 16px 0; }
.confirm p { margin: 0; }
.small { color: var(--hint); font-size: 12.5px; margin: 16px 16px 0; line-height: 1.5; }
.err { color: var(--danger); font-size: 14px; padding: 8px 16px 0; }

/* Toast: a floating card above the tab bar (after Sonner): slides up, swipe down to dismiss,
   a thin bar shows how long «Отменить» stays available, the timer waits while touched. */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--sb) + 12px); z-index: 30;
  width: min(420px, calc(100vw - 24px)); translate: -50% 0; pointer-events: none; }
.toast-card { pointer-events: auto; position: relative; overflow: hidden; touch-action: none;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; min-height: 52px;
  background: var(--toast-bg); color: var(--text); border: 1px solid var(--toast-line); border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.22), 0 2px 6px rgba(0,0,0,.12);
  transform: translateY(var(--dy, 0px)) scale(var(--s, 1)); opacity: var(--o, 1);
  transition: transform .38s cubic-bezier(.21,1.02,.73,1), opacity .25s ease; }
.toast-card[data-state="enter"] { --dy: 18px; --s: .96; --o: 0; }
.toast-card[data-state="leave"] { --dy: 12px; --s: .97; --o: 0; transition-duration: .2s; transition-timing-function: ease-in; }
.toast-card.dragging { transition: none; }
.toast-card.pop { animation: toast-pop .28s cubic-bezier(.21,1.02,.73,1); }
@keyframes toast-pop { from { transform: scale(.97); } }
.toast-ic { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--hint); }
.toast-ic svg { width: 14px; height: 14px; }
.toast-ic.success { background: #34c759; }
.toast-ic.error { background: var(--danger); }
.toast-msg { flex: 1; min-width: 0; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.toast-act { flex: none; min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
  color: var(--link); background: color-mix(in srgb, var(--link) 14%, transparent); }
.toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--link); opacity: .55;
  transform-origin: left; animation: toast-time linear forwards; }
@keyframes toast-time { to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* date & time picker (app.js dateTimePicker) */
.pick { display: flex; align-items: center; text-align: left; font-size: 16px; }
.pick.empty { color: var(--hint); }
.picker { margin-top: 10px; display: grid; gap: 10px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head b { font-weight: 600; }
.cal-head .nav { width: 44px; height: 44px; border-radius: 22px; font-size: 24px; text-align: center; color: var(--link); }
.cal-head .nav:disabled { opacity: .3; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal .wd { font-size: 12px; color: var(--hint); padding: 4px 0; }
.cal .day { height: 40px; border-radius: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.cal .day.today { box-shadow: inset 0 0 0 1px var(--link); }
.cal .day.on { background: var(--btn); color: var(--btn-text); box-shadow: none; }
.cal .day:disabled { opacity: .3; }
.time { display: flex; align-items: center; justify-content: center; gap: 6px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); border-radius: 22px; padding: 2px; }
.stepper .step { width: 40px; height: 40px; border-radius: 20px; text-align: center; font-size: 22px; color: var(--link); touch-action: manipulation; user-select: none; }
.stepper .num { min-width: 2.2ch; text-align: center; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.time .colon { font-size: 22px; font-weight: 600; }
.kinds .chip:disabled { opacity: .4; }
