:root {
  --bg: #ffffff;
  --surface: #f2f5f8;
  --surface2: #e6ebf0;
  --text: #22262a;
  --muted: #98a0a9;
  --line: #e4e8ec;
  --accent: #2f8ff0;
  --red: #e5484d;
  --green: #2ea36b;
  --bar: #1e2226;
  --bar-btn: #353a40;
  --bar-active: #5b6168;
  --bar-text: #eceef0;
  --shadow: 0 6px 22px rgba(20, 30, 40, .10);
  --search-top: #3b4148;
  --search-bottom: #202428;
  --safe-b: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --font: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121417;
  --surface: #1c2024;
  --surface2: #2a3036;
  --text: #eceef0;
  --muted: #7d868f;
  --line: #2a2f34;
  --bar: #0b0d0f;
  --bar-btn: #24292e;
  --bar-active: #3d444b;
  --shadow: 0 6px 22px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
.i { width: 20px; height: 20px; flex: none; display: block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 10px 16px 8px;
  text-align: center;
}
.top-row { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; min-height: 32px; }
.top-row h1 { grid-column: 2; margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
#back { grid-column: 1; }
#refresh { grid-column: 3; justify-self: end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--surface); }
.spinning .i { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.seg {
  display: inline-flex; gap: 2px; margin-top: 8px; padding: 3px;
  background: var(--surface); border-radius: 11px;
}
.seg button {
  width: 40px; height: 28px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.seg button .i { width: 17px; height: 17px; }
.seg button.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ---------- контент ---------- */
#screen { padding: 6px 12px calc(120px + var(--safe-b)); }

.list { display: flex; flex-direction: column; gap: 6px; }
.task {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 14px; padding: 10px 12px;
  transition: opacity .25s;
}
.check {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 1.5px solid #c5ccd3; background: transparent; padding: 0;
  display: flex; align-items: center; justify-content: center; color: transparent;
}
:root[data-theme="dark"] .check { border-color: #4a525a; }
.check .i { width: 14px; height: 14px; stroke-width: 3; }
.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.task-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.task-sub.red { color: var(--red); }
.is-done .check { background: var(--green); border-color: var(--green); color: #fff; }
.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.pop { animation: pop .3s ease; }
@keyframes pop { 50% { transform: scale(1.25); } }

.ava {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: hsl(var(--h, 210) 50% 56%); color: #fff;
  font-size: 13px; font-weight: 600;
}
.ava-ico { background: var(--surface2); color: var(--muted); }
.ava-ico .i { width: 15px; height: 15px; }

.done-toggle {
  border: 0; background: none; color: var(--muted); font-size: 13px;
  padding: 14px 4px 8px; width: 100%; text-align: left;
}
.all-done {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--green); font-size: 14px; font-weight: 500; padding: 22px 0 10px;
}

/* ---------- пустые состояния / скелетоны ---------- */
.empty { text-align: center; padding: 44px 22px; }
.empty-ico {
  width: 58px; height: 58px; border-radius: 50%; background: var(--surface);
  margin: 0 auto 14px; display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.empty-ico .i { width: 26px; height: 26px; }
.empty h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.empty p { margin: 0 auto 18px; color: var(--muted); font-size: 14px; max-width: 300px; }
.empty .btn { width: auto; display: inline-flex; padding: 0 22px; }

.sk {
  height: 56px; border-radius: 14px; margin-bottom: 6px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- кнопки и поля ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 46px; border: 0; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 15px; font-weight: 600;
}
.btn.ghost { background: var(--surface); color: var(--text); font-weight: 500; }
.btn.danger { color: var(--red); }
.btn .i { width: 18px; height: 18px; }
.btn + .btn, .btn + .hint, .field + .btn, .chips + .btn { margin-top: 8px; }

.field, textarea.field, select.field {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1.5px solid transparent; border-radius: 12px;
  padding: 12px; font: inherit; font-size: 15px; outline: none; resize: none;
}
.field:focus { border-color: var(--accent); }
.field + .field, .row2 + .field, .field + .row2 { margin-top: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 110px; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 8px 4px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--surface); border: 1.5px solid transparent; font-size: 13px;
}
.chip .i { width: 15px; height: 15px; }
.chip .ava { width: 20px; height: 20px; font-size: 10px; margin-left: -6px; }
.chip.on { border-color: var(--text); }

/* ---------- нижняя панель ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: var(--bar); border-radius: 22px 22px 0 0;
}
.bar-pill, .bar-btn, .bar-search {
  height: 38px; border: 0; display: inline-flex; align-items: center; justify-content: center;
  color: var(--bar-text); background: var(--bar-btn);
}
.bar-pill { padding: 0 14px; border-radius: 19px; gap: 7px; font-size: 13px; font-weight: 500; }
.bar-btn { width: 38px; border-radius: 50%; }
.bar-btn.active, .bar-pill.active { background: var(--bar-active); }
.bar-search { width: 64px; border-radius: 19px; background: #fff; color: #15181b; }
.bar .i { width: 18px; height: 18px; }

.fab {
  position: fixed; right: 16px; bottom: calc(72px + var(--safe-b)); z-index: 6;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}

/* ---------- шторка ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 19; background: rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b));
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.sheet-open .backdrop { opacity: 1; pointer-events: auto; }
.sheet-open .sheet { transform: none; }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 14px; }
.sheet h3 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.sheet-actions .btn + .btn { margin-top: 0; }

.quote { background: var(--surface); border-radius: 14px; padding: 12px; margin: 10px 0; }
.quote-head { font-size: 12px; color: var(--muted); }
.quote-text { font-size: 14px; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.link {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 8px;
  border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; font-weight: 600;
}
.link .i { width: 14px; height: 14px; }

/* ---------- бриф ---------- */
.brief-meta { text-align: center; color: var(--muted); font-size: 12px; margin: 2px 0 4px; }
.link-inline { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; }
.sec-head {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted); font-size: 12px; font-weight: 500; margin: 18px 0 8px;
}
.brief-sec { scroll-margin-top: 110px; }
.brief-item {
  background: var(--surface); border-radius: 14px; padding: 12px;
  margin-bottom: 6px; font-size: 14px; cursor: pointer;
}
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag {
  font-size: 11px; color: var(--muted); padding: 3px 7px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line);
}
.sec-empty { text-align: center; color: var(--muted); font-size: 13px; }
.brief-jump {
  position: fixed; left: 0; right: 0; bottom: calc(68px + var(--safe-b)); z-index: 5;
  display: flex; gap: 6px; padding: 4px 10px 8px; pointer-events: none;
  overflow-x: auto; scrollbar-width: none;
}
.brief-jump::-webkit-scrollbar { display: none; }
.brief-jump > :first-child { margin-left: auto; }
.brief-jump > :last-child { margin-right: auto; }
.brief-jump button {
  pointer-events: auto; height: 32px; padding: 0 11px; border-radius: 16px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow); white-space: nowrap;
}

/* ---------- поиск (тёмный экран) ---------- */
body.dark-screen {
  background: linear-gradient(180deg, var(--search-top) 0%, var(--search-bottom) 100%) fixed;
  color: #f1f3f5;
}
body.dark-screen .top { background: transparent; }
body.dark-screen .icon-btn { color: #c9ced3; }
#composer { display: none; }
body.dark-screen #composer {
  display: flex; gap: 8px; align-items: center;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 12px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, transparent, var(--search-bottom) 30%);
}
.cmp-field {
  flex: 1; display: flex; align-items: center; gap: 8px; height: 46px;
  padding: 0 5px 0 14px; border-radius: 23px;
  background: rgba(255, 255, 255, .1); color: #aab2ba;
}
.cmp-field .i { width: 18px; height: 18px; }
.cmp-field input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  color: #fff; font: inherit; font-size: 15px;
}
.cmp-field input::placeholder { color: #8d959d; }
.cmp-send, .cmp-close {
  border: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.cmp-send { width: 36px; height: 36px; background: #fff; color: #15181b; }
.cmp-close { width: 46px; height: 46px; flex: none; background: rgba(255, 255, 255, .12); color: #fff; }

.search-empty { min-height: calc(100vh - 190px); display: flex; flex-direction: column; justify-content: flex-end; }
.search-hello { text-align: center; color: #b8bfc6; margin: auto 20px; }
.search-hello .i { width: 30px; height: 30px; margin: 0 auto 10px; opacity: .8; }
.search-hello p { margin: 0; font-size: 14px; }
.suggest { display: flex; flex-direction: column; align-items: flex-start; padding: 0 4px 10px; }
.suggest button {
  display: inline-flex; align-items: center; gap: 6px; text-align: left;
  border: 0; background: none; color: #e8ebee; font-size: 15px; padding: 7px 0;
}
.suggest .i { width: 14px; height: 14px; opacity: .45; }

.qa { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.q {
  align-self: flex-end; max-width: 82%; padding: 10px 14px;
  border-radius: 18px 18px 4px 18px; background: #fff; color: #15181b;
}
.a {
  align-self: flex-start; max-width: 94%; padding: 12px 14px;
  border-radius: 18px 18px 18px 4px; line-height: 1.45;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .07);
}
.a.err { color: #ffc2c2; }
.src {
  display: block; width: 100%; text-align: left; margin-top: 8px; padding: 8px 10px;
  border: 0; border-radius: 10px; background: rgba(0, 0, 0, .22); color: inherit;
}
.src:disabled { opacity: 1; }
.src-head { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .7; }
.src-head .ava { width: 18px; height: 18px; font-size: 9px; }
.src-text {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13px; opacity: .9; margin-top: 3px;
}
.typing { display: flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #c9ced3; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- встречи ---------- */
.day-head { color: var(--muted); font-size: 12px; margin: 14px 4px 8px; }
.day-head:first-child { margin-top: 4px; }
.meet { background: var(--surface); border-radius: 16px; padding: 14px; margin-bottom: 8px; cursor: pointer; }
.meet-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.meet-top b { font-size: 15px; font-weight: 600; }
.meet-top span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.meet-short { font-size: 14px; margin-top: 8px; padding-left: 10px; opacity: .85; }
.meet-stats { display: flex; gap: 28px; margin-top: 12px; }
.stat { display: grid; grid-template-columns: auto auto; column-gap: 6px; align-items: center; }
.stat .i { width: 15px; height: 15px; color: var(--muted); }
.stat b { font-size: 14px; }
.stat small { grid-column: 2; font-size: 11px; color: var(--muted); }

.detail h2 { margin: 4px 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.callout { background: var(--surface); border-radius: 14px; padding: 12px 14px; margin-top: 14px; font-weight: 500; }
.summary { white-space: pre-wrap; font-size: 14px; line-height: 1.55; margin: 14px 2px; }
.detail .sec-head { justify-content: flex-start; margin-left: 4px; }

/* ---------- настройки ---------- */
.set-sec { margin-bottom: 24px; }
.set-title { color: var(--muted); font-size: 12px; font-weight: 500; margin: 6px 4px 8px; }
.set-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 6px; min-height: 52px;
}
.set-row .field { width: auto; padding: 6px 10px; background: var(--bg); }
.set-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 14px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 44px; height: 26px; border-radius: 13px; background: var(--surface2);
  position: relative; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- выбор даты ---------- */
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dp-wd { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.dp-cell {
  height: 44px; border: 0; border-radius: 12px; background: none; font-size: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.dp-cell small { font-size: 9px; color: var(--muted); }
.dp-cell.past { color: var(--muted); }
.dp-cell.today { color: var(--accent); font-weight: 700; }
.dp-cell.sel { background: var(--text); color: var(--bg); }
.dp-cell.sel small { color: inherit; }
.dp-more { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.dp-more .field { padding: 10px; }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; top: 14px; z-index: 30; transform: translate(-50%, -24px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .2s, visibility .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast.err { background: var(--red); color: #fff; }

@media (min-width: 640px) {
  #screen, .top, .sheet, .bar, body.dark-screen #composer { max-width: 560px; margin: 0 auto; }
  .fab { right: calc(50% - 264px); }
}
