:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ebeae5;
  --text: #1c1c1e;
  --muted: #6d6b65;
  --line: #e0ded7;
  --accent: #3b5bdb;
  --accent-soft: #e6eafb;
  --accent-ink: #ffffff;
  --danger: #c92a4b;
  --ok: #2b8a3e;
  --late: #c92a2a;
  --soon: #d9480f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 6px 20px rgba(20, 20, 20, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417;
    --surface: #1c1d21;
    --surface-2: #26272c;
    --text: #ececee;
    --muted: #9b9ba1;
    --line: #2e2f35;
    --accent: #8098ff;
    --accent-soft: #252b45;
    --accent-ink: #0d1020;
    --danger: #ff6b8a;
    --ok: #51cf66;
    --late: #ff8787;
    --soon: #ffa94d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); margin: 0; }
.error:empty { display: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }

.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.small { width: 34px; height: 34px; }
.link-btn { color: var(--accent); font-size: 14px; padding: 8px; align-self: center; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; font-weight: 600; }
.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- экраны по центру ---------- */

.center {
  max-width: 420px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) 20px calc(env(safe-area-inset-bottom) + 40px);
  display: flex; flex-direction: column; gap: 14px;
}
.center h1 { margin: 4px 0 0; font-size: 28px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.center p { margin: 0; }
.logo { width: 64px; height: 64px; border-radius: 16px; margin-top: 6vh; }
.row-top { margin: -8px 0 0 -10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.member-btn { justify-content: flex-start; }
.member-btn .avatar { width: 26px; height: 26px; font-size: 13px; }
.board-btn { justify-content: space-between; }
.prose ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.prose h3 { margin: 10px 0 0; font-size: 16px; }

.spinner {
  width: 32px; height: 32px; margin: 30vh auto 0; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner + p { text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- верхняя панель ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) max(12px, calc((100% - 728px) / 2)) 8px max(20px, calc((100% - 728px) / 2 + 4px));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.board-title { flex: 1; min-width: 0; margin: 0; font-size: 22px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { font-size: 13px; white-space: nowrap; }
.sync-ok { display: inline-flex; color: var(--muted); }
.sync-ok .ic { width: 16px; height: 16px; }
.sync-off { color: var(--danger); }
.sync-busy { color: var(--muted); }

.page { max-width: 760px; margin: 0 auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 48px); }

/* ---------- папки ---------- */

.folders { display: flex; gap: 6px; margin: 0 0 12px; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.folders::-webkit-scrollbar { display: none; }
.folder-chip {
  position: relative; flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 15px; font-weight: 600; white-space: nowrap;
}
.folder-chip .ic { width: 17px; height: 17px; }
.folder-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.folder-chip.active .count { background: rgba(255, 255, 255, .25); color: inherit; }
.folder-chip .tab-dot { top: 4px; right: 4px; }
.folder-name { max-width: 12em; overflow: hidden; text-overflow: ellipsis; }
.folder-add { border-style: dashed; background: transparent; }
.pill.folder { display: inline-flex; align-items: center; gap: 4px; }
.pill.folder .ic { width: 13px; height: 13px; }
.seg-btn .ic { width: 16px; height: 16px; }
.folder-row { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.folder-row > span { overflow-wrap: anywhere; font-weight: 600; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }

/* ---------- быстрое добавление ---------- */

.add { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 6px 6px; }
.add:focus-within { border-color: var(--accent); }
.add-top { display: flex; align-items: center; gap: 6px; }
.add-input { flex: 1; min-width: 0; width: 100%; border: 0; outline: none; background: transparent; padding: 10px 8px; font-size: 17px; }
.add-input:focus-visible { outline: none; }
.add-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 2px 2px 0; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer;
}
.chip-label { color: var(--muted); }
.due-chip { color: var(--muted); }
.due-chip.set { color: var(--text); }
.due-chip .ic { width: 17px; height: 17px; }
.due-text:empty { display: none; }
.due-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; margin: 0; cursor: pointer; }
.add-btn { min-height: 38px; padding: 0 14px; border-radius: 10px; }
@media (max-width: 420px) {
  .add-btn span { display: none; }
  .add-btn { padding: 0 10px; }
}

/* ---------- вкладки и поиск ---------- */

.toolbar { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 10px; }
.tabs { display: flex; gap: 3px; padding: 3px; overflow-x: auto; scrollbar-width: none; background: var(--surface-2); border-radius: 12px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 9px;
  color: var(--muted); font-size: 15px; font-weight: 600; white-space: nowrap;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.tab-label { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--line); color: var(--text); font-size: 12px; }
.tab-dot { position: absolute; top: 6px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.search-box { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.search-box:focus-within { border-color: var(--accent); }
.search { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 16px; }
.search:focus-visible { outline: none; }
@media (min-width: 640px) {
  .toolbar { flex-direction: row; align-items: center; }
  .tabs { flex: 1; }
  .search-box { width: 230px; }
}

/* ---------- список задач ---------- */

.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task { position: relative; display: flex; align-items: flex-start; gap: 2px; padding: 4px 12px 4px 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.task.unread { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.check { flex: none; width: 44px; height: 44px; display: grid; place-items: center; }
.check .ic { width: 24px; height: 24px; padding: 3px; border: 2px solid var(--line); border-radius: 50%; stroke: transparent; stroke-width: 3; transition: .15s; }
.check:hover .ic { border-color: var(--ok); stroke: var(--ok); }
.task.done .check .ic { background: var(--ok); border-color: var(--ok); stroke: #fff; }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; padding: 10px 0; text-align: left; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task.unread .task-title { font-weight: 700; }
.task.unread .task-main { padding-right: 14px; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--muted); font-size: 13px; }
.who { display: inline-flex; align-items: center; gap: 5px; }
.avatar {
  --c: #999;
  display: inline-grid; place-items: center; flex: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--c); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
}
.pill { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; }
.pill.doing { background: var(--accent-soft); color: var(--accent); }
.pill.late { color: var(--late); background: color-mix(in srgb, var(--late) 13%, transparent); }
.pill.soon { color: var(--soon); background: color-mix(in srgb, var(--soon) 13%, transparent); }
.cmt { display: inline-flex; align-items: center; gap: 3px; }
.cmt .ic { width: 15px; height: 15px; }
.dot { position: absolute; top: 15px; right: 12px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.empty { margin: 0; padding: 40px 0; text-align: center; color: var(--muted); }
.empty:empty { display: none; }

/* ---------- карточка задачи ---------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; justify-content: flex-end; background: rgba(0, 0, 0, .35); animation: fade .15s ease; }
.sheet { display: flex; flex-direction: column; width: 100%; height: 100%; background: var(--bg); animation: slide .2s ease; }
@media (min-width: 760px) {
  .sheet { width: 560px; border-left: 1px solid var(--line); box-shadow: -10px 0 40px rgba(0, 0, 0, .12); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
.sheet-top { display: flex; align-items: center; padding: calc(env(safe-area-inset-top) + 6px) 10px 6px; border-bottom: 1px solid var(--line); }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 20px 24px; }
.d-title { width: 100%; padding: 4px 0; border: 0; outline: none; resize: none; overflow: hidden; background: transparent; font-size: 22px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
.d-title:focus-visible { outline: none; }
.props { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px 12px; margin: 12px 0 18px; }
.prop-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--muted); font-size: 14px; font-weight: 600;
}
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg-btn.st-done.active { background: var(--ok); border-color: var(--ok); color: #fff; }
.due-row { display: flex; align-items: center; gap: 4px; }
.input.date { width: auto; min-height: 38px; padding: 6px 10px; }
.d-desc { width: 100%; min-height: 88px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); resize: none; overflow: hidden; outline: none; line-height: 1.5; }
.d-desc:focus { border-color: var(--accent); }
.section { margin: 24px 0 10px; color: var(--muted); font-size: 12px; letter-spacing: .07em; text-transform: uppercase; }
.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.act-event { display: flex; justify-content: space-between; gap: 10px; padding: 0 4px 0 32px; color: var(--muted); font-size: 13px; }
.act-comment { display: flex; align-items: flex-start; gap: 8px; }
.act-comment .avatar { width: 24px; height: 24px; margin-top: 2px; font-size: 12px; }
.bubble { flex: 1; min-width: 0; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; }
.act-comment.mine .bubble { background: var(--accent-soft); border-color: transparent; }
.bubble-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 2px; font-size: 13px; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-text a { color: var(--accent); }
.act-empty { padding: 12px; color: var(--muted); font-size: 14px; text-align: center; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px); border-top: 1px solid var(--line); background: var(--bg); }
.composer-input { flex: 1; min-height: 44px; max-height: 40vh; padding: 10px 16px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); resize: none; outline: none; line-height: 1.4; }
.composer-input:focus { border-color: var(--accent); }
.send { flex: none; width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }

/* ---------- меню ---------- */

.menu-wrap { justify-content: center; align-items: flex-end; }
.menu { display: flex; flex-direction: column; width: 100%; max-width: 480px; padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); background: var(--surface); border-radius: 18px 18px 0 0; animation: up .18s ease; }
@media (min-width: 760px) {
  .menu-wrap { align-items: center; }
  .menu { border-radius: 18px; }
}
@keyframes up { from { transform: translateY(20px); opacity: .5; } }
.menu-item { padding: 14px 16px; border-radius: 12px; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.muted { color: var(--muted); text-align: center; }

/* ---------- всплывашка ---------- */

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 50;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .sheet-wrap, .sheet, .menu, .spinner { animation: none; }
  #toast, .check .ic { transition: none; }
}
