:root {
  --bg: #0f1114;
  --card: #1b1e23;
  --field: #262a31;
  --text: #f1f2f4;
  --hint: #8a909c;
  --line: #2a2e36;
  --accent: #4a8cff;
  --on-accent: #ffffff;
  --danger: #ff5c61;
  --ok: #2fb36d;
  --soft: rgba(74, 140, 255, .14);
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --fc: var(--hint);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 400 15px/1.4 "Onest", -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--field); border: 1.5px solid transparent;
  border-radius: 13px; padding: 12px 13px; width: 100%; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; min-height: 88px; }

#view { max-width: 640px; margin: 0 auto; padding: 16px 14px calc(112px + var(--safe-b)); }

/* ---------- шапка ---------- */
.head { display: flex; align-items: center; gap: 10px; margin: 2px 2px 14px; min-height: 40px; }
.head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head .sub { color: var(--hint); font-size: 14px; font-weight: 500; }
.round-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--card); display: grid; place-items: center; flex: none; color: var(--hint); }

/* ---------- статистика ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 4px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 13px 13px 11px; }
.stat b { display: block; font-size: 28px; font-weight: 700; line-height: 1.1; letter-spacing: -.03em; }
.stat span { color: var(--hint); font-size: 12.5px; }
.stat.accent b { color: var(--accent); }
.stat.warn b { color: var(--danger); }

/* ---------- секции ---------- */
.sec { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 4px 8px; font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .05em; }
.sec.bad { color: var(--danger); }
.sec button { color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 14px; }
.rows { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.rows > * + * { border-top: 1px solid var(--line); }
.empty { background: var(--card); border-radius: var(--radius); color: var(--hint); padding: 30px 20px; text-align: center; }
.empty b { display: block; color: var(--text); font-size: 17px; font-weight: 600; margin-bottom: 4px; }

/* ---------- задача ---------- */
.task { display: flex; gap: 12px; padding: 13px 14px; align-items: flex-start; }
.check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--hint); margin-top: 1px; display: grid; place-items: center; color: transparent; transition: background .15s, border-color .15s; }
.check .ic { width: 14px; height: 14px; stroke-width: 2.8; }
.task.over .check { border-color: var(--danger); }
.task.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.done .t-title { text-decoration: line-through; color: var(--hint); }
.t-body { flex: 1; min-width: 0; }
.t-title { font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.t-meta { display: flex; flex-wrap: wrap; gap: 3px 12px; color: var(--hint); font-size: 13.5px; margin-top: 3px; }
.t-meta span { display: inline-flex; align-items: center; gap: 5px; }
.t-meta .ic { width: 14px; height: 14px; }
.t-meta .late { color: var(--danger); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fc); flex: none; display: inline-block; }

/* ---------- запись ---------- */
.item { display: flex; gap: 12px; padding: 13px 14px; width: 100%; align-items: flex-start; }
.badge { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--soft); color: var(--accent); }
.i-body { flex: 1; min-width: 0; }
.i-text { overflow-wrap: anywhere; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.i-text.soft { color: var(--hint); }
.i-file { font-weight: 600; overflow-wrap: anywhere; }
.i-url { color: var(--accent); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.i-meta { color: var(--hint); font-size: 12.5px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.i-meta span { display: inline-flex; align-items: center; gap: 5px; }
.i-meta .ic { width: 13px; height: 13px; }
.i-meta .due { color: var(--accent); }
.thumb { flex: none; width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--field); }
.thumb.round { border-radius: 50%; }

/* ---------- папки ---------- */
.folders { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.folder { background: var(--card); border-radius: var(--radius); padding: 15px; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; }
.folder .ic { width: 28px; height: 28px; color: var(--fc); }
.folder .nm { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .ct { color: var(--hint); font-size: 13px; }
.folder.inbox { background: var(--accent); color: var(--on-accent); }
.folder.inbox .ic { color: inherit; }
.folder.inbox .ct { color: inherit; opacity: .8; }
.folder.new { background: none; border: 1.5px dashed var(--line); color: var(--hint); }
.folder.new .ic { color: var(--hint); }

/* ---------- фильтры ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -14px 12px; padding: 0 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--accent); color: var(--on-accent); }
.search { position: relative; margin-bottom: 12px; }
.search .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--hint); pointer-events: none; }
.search input { padding-left: 42px; background: var(--card); }
.more { display: block; width: 100%; padding: 14px; color: var(--accent); font-weight: 500; text-align: center; }

/* ---------- нижняя панель ---------- */
#bar { position: fixed; left: 0; right: 0; bottom: calc(14px + var(--safe-b)); display: flex; justify-content: center; align-items: center; gap: 10px; z-index: 5; pointer-events: none; }
#bar > * { pointer-events: auto; }
#tabs { display: flex; gap: 2px; padding: 6px; border-radius: 99px; background: #23262d; box-shadow: var(--shadow); }
#tabs button { display: flex; align-items: center; gap: 7px; height: 46px; padding: 0 15px; border-radius: 99px; color: var(--hint); font-size: 14px; font-weight: 600; }
#tabs button .ic { width: 22px; height: 22px; }
#tabs button span { display: none; }
#tabs button.on { background: var(--text); color: var(--bg); }
#tabs button.on span { display: inline; }
#fab { width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: var(--shadow); }
#fab .ic { width: 26px; height: 26px; stroke-width: 2.2; }
#fab:active { transform: scale(.94); }

/* ---------- шторки ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 24px 24px 0 0; padding: 10px 16px calc(20px + var(--safe-b)); max-height: 90vh; overflow-y: auto; animation: up .22s cubic-bezier(.2, .8, .2, 1); }
.sheet::before { content: ""; display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 12px; }
.sheet label { display: block; font-size: 12.5px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .05em; margin: 14px 2px 6px; }
.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px; text-align: center; margin-top: 18px; }
.btn.quiet { background: none; color: var(--danger); margin-top: 6px; }
.actions button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 4px; font-size: 16px; }
.actions button + button { border-top: 1px solid var(--line); }
.actions .ic { color: var(--hint); }
.actions .bad, .actions .bad .ic { color: var(--danger); }
.actions .cur { margin-left: auto; }
.actions .cur .ic { color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 16px 2px 0; font-weight: 500; font-size: 16px; }
.switch input { width: 50px; height: 30px; appearance: none; -webkit-appearance: none; border-radius: 99px; background: var(--line); position: relative; padding: 0; border: 0; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 23px; }
.preview { background: var(--bg); border-radius: 14px; padding: 13px; margin-bottom: 6px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 34vh; overflow-y: auto; }
.preview .soft { color: var(--hint); }
.preview img, .preview video { max-width: 100%; border-radius: 12px; display: block; margin: 0 auto 8px; max-height: 50vh; }
.preview video.round { border-radius: 50%; aspect-ratio: 1; object-fit: cover; max-width: 240px; }
.preview audio { width: 100%; margin-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; padding: 2px; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; background: var(--fc); }
.swatches button.on { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--fc); }
.note { color: var(--hint); font-size: 13px; margin: 10px 2px 0; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(12px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30%); opacity: .5; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- важное и корзина ---------- */
.sec.first { margin-top: 6px; }
.hint-card { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 15px; border-radius: var(--radius); border: 1.5px dashed var(--line); color: var(--hint); font-size: 14px; }
.hint-card .ic { color: var(--accent); margin-top: 1px; }
.hint-card b { display: block; color: var(--text); font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.trash-row { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 22px; padding: 14px 6px; color: var(--hint); border-top: 1px solid var(--line); font-size: 15px; }
.trash-row .n { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- план дня и заметки ---------- */
.sec .count { font-variant-numeric: tabular-nums; text-transform: none; letter-spacing: 0; font-weight: 500; }
.quick { display: flex; align-items: center; gap: 12px; padding: 4px 14px 4px 16px; color: var(--hint); }
.quick input { background: none; border: 0; padding: 12px 0; border-radius: 0; font-size: 16px; }
.link-row { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 10px; padding: 14px; border-radius: var(--radius); background: var(--card); }
.link-row .ic:first-child { color: var(--accent); }
.link-row span { flex: 1; }
.link-row .ic:last-child { color: var(--hint); width: 18px; height: 18px; }
.i-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.i-sub { color: var(--hint); overflow-wrap: anywhere; margin-bottom: 2px; }
.p-title { display: block; font-size: 17px; }
.p-sub { display: block; color: var(--hint); margin-bottom: 8px; }
.modes { margin: 0 0 12px; padding: 0; }
.modes .chip { background: var(--field); }
.modes .chip.on { background: var(--accent); }
#e-title { font-size: 18px; font-weight: 600; }
#e-sub { margin: 8px 0; }

/* ---------- важное: одна строка + список ---------- */
.pin-bar { display: flex; align-items: center; border-radius: 14px; background: color-mix(in srgb, var(--accent) 15%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent); }
.pin-bar.ghost { width: 100%; gap: 10px; padding: 12px 14px; background: none; border: 1.5px dashed var(--line); color: var(--hint); }
.pin-bar.ghost .ic:last-child { margin-left: auto; }
.pin-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.pin-main .ic { color: var(--accent); }
.pin-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.pin-more { display: flex; align-items: center; gap: 2px; padding: 12px 12px 12px 8px; color: var(--accent); font-weight: 600; font-size: 14px; }
.pin-more .ic { width: 18px; height: 18px; transform: rotate(90deg); }
.pin-more.open .ic { transform: rotate(-90deg); }
.pin-list { display: flex; flex-direction: column; gap: 6px; }
.pin-row { display: flex; align-items: center; border-radius: 14px; background: var(--card); position: relative; }
.pin-row.first { background: color-mix(in srgb, var(--accent) 15%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent); }
.pin-row .pin-main { padding-left: 2px; }
.pin-row.dragging { z-index: 3; box-shadow: var(--shadow); }
.pin-row.drop-above::before, .pin-row.drop-below::after { content: ""; position: absolute; left: 6px; right: 6px; height: 2px; border-radius: 2px; background: var(--accent); }
.pin-row.drop-above::before { top: -4px; }
.pin-row.drop-below::after { bottom: -4px; }
.grip { padding: 12px 4px 12px 12px; color: var(--hint); touch-action: none; cursor: grab; }
.grip .ic { width: 18px; height: 18px; stroke-width: 3; }
.sec.toggle { width: 100%; background: none; border: 0; padding: 0; text-align: left; color: var(--hint); }
.sec.toggle .rt { display: inline-flex; align-items: center; gap: 4px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.sec.toggle .ic { width: 18px; height: 18px; transform: rotate(90deg); }
.sec.toggle.open .ic { transform: rotate(-90deg); }
.t-meta .desc { color: var(--hint); }

/* ---------- чат папки ---------- */
body.chat #bar { display: none; }
body.chat #view { padding-bottom: calc(var(--comp-h, 70px) + 20px); }
body.chat #toast { bottom: calc(var(--comp-h, 70px) + 16px); }
.head.sticky { position: sticky; top: 0; z-index: 4; background: var(--bg); margin: 0 -14px 6px; padding: 10px 14px; }
.head h1 { display: flex; align-items: center; gap: 10px; }
.head h1 .dot { width: 10px; height: 10px; }
.chat { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chat > .empty { align-self: stretch; }
.chat > .more { align-self: stretch; }
.day { align-self: center; margin: 14px 0 4px; color: var(--hint); font-size: 12.5px; font-weight: 500; }
.bubble { max-width: 88%; background: color-mix(in srgb, var(--accent) 16%, var(--card)); border-radius: 18px 18px 6px 18px; padding: 9px 12px 6px; overflow-wrap: anywhere; cursor: pointer; }
.bubble.plain { background: none; padding: 0; }
.b-title { font-weight: 600; }
.b-text { white-space: pre-wrap; }
.b-text.soft { color: var(--hint); }
.b-text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.b-meta { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 2px 10px; color: var(--hint); font-size: 11.5px; margin-top: 3px; }
.b-meta span { display: inline-flex; align-items: center; gap: 4px; }
.b-meta .ic { width: 12px; height: 12px; }
.b-photo { display: block; width: 240px; max-width: 100%; min-height: 110px; border-radius: 12px; margin-bottom: 6px; background: var(--field); }
.b-file { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.b-file .ic { color: var(--accent); width: 24px; height: 24px; }
.b-file small { display: block; color: var(--hint); }
.vplay { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0 4px; }
.vplay .pi, .vplay .pa { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--on-accent); flex: none; }
.vplay .pa, .vplay.playing .pi { display: none; }
.vplay.playing .pa { display: grid; }
.vplay .bar { flex: 1; height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--hint) 35%, transparent); overflow: hidden; }
.vplay .bar i { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); }
.vplay .vdur { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.circle { position: relative; width: 190px; height: 190px; border-radius: 50%; overflow: hidden; background: #000; display: grid; place-items: center; color: #fff; }
.circle img, .circle .cvideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.circle .cplay { position: relative; z-index: 1; width: 52px; height: 52px; border-radius: 50%; background: rgba(0, 0, 0, .5); display: grid; place-items: center; }
.circle.playing .cplay { display: none; }
.circle .vdur { position: absolute; z-index: 1; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 12px; background: rgba(0, 0, 0, .55); padding: 1px 8px; border-radius: 99px; }
.vplay.loading, .circle.loading { opacity: .6; }

/* ---------- поле ввода ---------- */
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--bg); border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-b)); }
.comp-in { max-width: 640px; margin: 0 auto; }
.comp-row { display: flex; align-items: flex-end; gap: 8px; }
.comp-row textarea { flex: 1; min-height: 44px; max-height: 120px; padding: 11px 14px; border-radius: 22px; line-height: 1.35; }
.cbtn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--hint); }
.cbtn.accent { background: var(--accent); color: var(--on-accent); }
.cbtn .ic { width: 22px; height: 22px; }
.comp-row .send, .comp-rec { display: none; }
.composer.has-text .send { display: grid; }
.composer.has-text .media { display: none; }
.composer.rec .comp-rec { display: block; }
.composer.rec .comp-row { display: none; }
.rec-row { display: flex; align-items: center; gap: 12px; }
.rec-row .grow { flex: 1; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
#c-time { font-variant-numeric: tabular-nums; font-weight: 500; }
.c-prev { display: block; width: 168px; height: 168px; border-radius: 50%; object-fit: cover; margin: 0 auto 10px; background: #000; transform: scaleX(-1); }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- поиск по всему ---------- */
.search-screen { position: fixed; inset: 0; z-index: 15; background: var(--bg); display: flex; flex-direction: column; }
.ss-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; max-width: 640px; width: 100%; margin: 0 auto; }
.ss-head .search { flex: 1; margin: 0; }
.ss-close { color: var(--accent); font-weight: 500; padding: 8px 4px; }
.ss-body { flex: 1; overflow-y: auto; padding: 0 14px 40px; max-width: 640px; width: 100%; margin: 0 auto; }

/* ---------- поправки ---------- */
#e-title, #t-title { margin-bottom: 8px; }
#t-title { font-size: 18px; font-weight: 600; }
.task .t-body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.allchat { display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px; margin-bottom: 10px; border-radius: var(--radius); background: var(--card); }
.allchat > span { flex: 1; min-width: 0; }
.allchat .nm { font-weight: 600; font-size: 16px; }
.allchat .ct { color: var(--hint); font-size: 13px; }
.allchat .ic:first-child { color: var(--accent); width: 24px; height: 24px; }
.allchat .ic:last-child { color: var(--hint); width: 18px; height: 18px; }
