/* Стиль «Уютный»: тёплые персиковые тона, мягкие круглые формы. Все цвета — здесь, в переменных. */
:root {
  --bg: #fbf3ec;
  --panel: #ffffff;
  --panel-2: #fdf1e8;
  --border: #f1e0d4;
  --text: #3b2a24;
  --muted: #9a7f72;
  --accent: #e5683a;
  --accent-text: #ffffff;
  --mine: #ffd9c4;
  --theirs: #ffffff;
  --hover: #fdebdf;
  --active: #ffe3d3;
  --danger: #d64545;
  --chat-bg: #fbeee4;
  --radius: 18px;
  --pos: #4f8a5b;              /* доход, «вам должны» */
  --neg-soft: #e07a52;         /* расход на графиках — спокойнее, чем красный «опасно» */
  /* Крупные заголовки — скруглённым шрифтом (на iPhone — SF Pro Rounded, у остальных — обычный системный). */
  --display: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
/* Тёмная тема: выбрана вручную (data-theme="dark") или системная, если вручную не выбрана светлая. */
/* Тёмная — тоже тёплая: шоколадные тона вместо холодного серо-синего. */
:root[data-theme="dark"] {
  --bg: #1c1613;
  --panel: #261e1a;
  --panel-2: #2f2520;
  --border: #3b2f28;
  --text: #f3e7df;
  --muted: #b09a8d;
  --accent: #ff8a5c;
  --accent-text: #2a1408;
  --mine: #5c3726;
  --theirs: #2f2520;
  --hover: #33281f;
  --active: #432e22;
  --danger: #ff7b7b;
  --chat-bg: #181210;
  --pos: #7cc08a;
  --neg-soft: #ff9670;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1613;
    --panel: #261e1a;
    --panel-2: #2f2520;
    --border: #3b2f28;
    --text: #f3e7df;
    --muted: #b09a8d;
    --accent: #ff8a5c;
    --accent-text: #2a1408;
    --mine: #5c3726;
    --theirs: #2f2520;
    --hover: #33281f;
    --active: #432e22;
    --danger: #ff7b7b;
    --chat-bg: #181210;
    --pos: #7cc08a;
    --neg-soft: #ff9670;
    color-scheme: dark;
  }
}

/* ---------- свой цвет (Настройки → Оформление), у каждого на своём устройстве ----------
   Коралл — основной, расписан вручную выше. Для остальных задаём только акцент и свой пузырь
   (--acc-l/--mine-l для светлой, --acc-d/--mine-d для тёмной), а фоны смешиваются из акцента. */
:root[data-accent="lilac"]  { --acc-l: #8a63d2; --acc-d: #b49cff; --mine-l: #e7dcff; --mine-d: #41346a; }
:root[data-accent="mint"]   { --acc-l: #2a9672; --acc-d: #5fd3a8; --mine-l: #cdeee1; --mine-d: #1f4a3c; }
:root[data-accent="sea"]    { --acc-l: #2f7fc6; --acc-d: #6fb4ff; --mine-l: #d3e7fb; --mine-d: #22405e; }
:root[data-accent="cherry"] { --acc-l: #c8436a; --acc-d: #ff7aa0; --mine-l: #fbd5e1; --mine-d: #5a2536; }
:root[data-accent="honey"]  { --acc-l: #b87d0c; --acc-d: #f0b84a; --mine-l: #fbe7bf; --mine-d: #55401a; }
:root[data-accent] {
  --accent: var(--acc-l); --accent-text: #ffffff; --mine: var(--mine-l);
  --text: #2b2730; --muted: #85808c;
  --bg: color-mix(in srgb, var(--acc-l) 7%, #ffffff);
  --panel-2: color-mix(in srgb, var(--acc-l) 6%, #ffffff);
  --border: color-mix(in srgb, var(--acc-l) 15%, #ffffff);
  --hover: color-mix(in srgb, var(--acc-l) 9%, #ffffff);
  --active: color-mix(in srgb, var(--acc-l) 16%, #ffffff);
  --chat-bg: color-mix(in srgb, var(--acc-l) 10%, #ffffff);
}
:root[data-accent][data-theme="dark"] {
  --accent: var(--acc-d); --accent-text: #15121a; --mine: var(--mine-d);
  --text: #ece8f0; --muted: #a39dab;
  --bg: color-mix(in srgb, var(--acc-d) 5%, #141317);
  --panel: color-mix(in srgb, var(--acc-d) 6%, #1c1b20);
  --panel-2: color-mix(in srgb, var(--acc-d) 8%, #232228);
  --border: color-mix(in srgb, var(--acc-d) 12%, #2c2b31);
  --hover: color-mix(in srgb, var(--acc-d) 10%, #24232a);
  --active: color-mix(in srgb, var(--acc-d) 18%, #24232a);
  --theirs: color-mix(in srgb, var(--acc-d) 8%, #232228);
  --chat-bg: color-mix(in srgb, var(--acc-d) 5%, #121115);
}
@media (prefers-color-scheme: dark) {
  :root[data-accent]:not([data-theme="light"]) {
    --accent: var(--acc-d); --accent-text: #15121a; --mine: var(--mine-d);
    --text: #ece8f0; --muted: #a39dab;
    --bg: color-mix(in srgb, var(--acc-d) 5%, #141317);
    --panel: color-mix(in srgb, var(--acc-d) 6%, #1c1b20);
    --panel-2: color-mix(in srgb, var(--acc-d) 8%, #232228);
    --border: color-mix(in srgb, var(--acc-d) 12%, #2c2b31);
    --hover: color-mix(in srgb, var(--acc-d) 10%, #24232a);
    --active: color-mix(in srgb, var(--acc-d) 18%, #24232a);
    --theirs: color-mix(in srgb, var(--acc-d) 8%, #232228);
    --chat-bg: color-mix(in srgb, var(--acc-d) 5%, #121115);
  }
}

/* ---------- фон чата ---------- */
:root[data-wallpaper="dots"] :is(.chat, .look-preview) {
  background-image: radial-gradient(color-mix(in srgb, var(--accent) 24%, transparent) 1.4px, transparent 1.7px);
  background-size: 20px 20px;
}
:root[data-wallpaper="grid"] :is(.chat, .look-preview) {
  background-image: linear-gradient(color-mix(in srgb, var(--accent) 11%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 11%, transparent) 1px, transparent 1px);
  background-size: 24px 24px;
}
:root[data-wallpaper="lines"] :is(.chat, .look-preview) {
  background-image: repeating-linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, transparent) 0 2px, transparent 2px 16px);
}
:root[data-wallpaper="glow"] :is(.chat, .look-preview) {
  background-image: radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 55%),
    radial-gradient(circle at 90% 85%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 50%);
}
/* Своё фото — с лёгкой дымкой, чтобы пузыри читались. */
:root[data-wallpaper="photo"] :is(.chat, .look-preview) {
  background-image: linear-gradient(color-mix(in srgb, var(--chat-bg) 35%, transparent), color-mix(in srgb, var(--chat-bg) 35%, transparent)),
    var(--wall-photo, none);
  background-size: cover; background-position: center;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;            /* прокручиваются только список чатов и сообщения, сама страница — никогда */
  overscroll-behavior: none;
}
body {
  font: 15px/1.4 ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
/* iPhone увеличивает страницу при фокусе на поле с шрифтом меньше 16px — из-за этого появлялась прокрутка вбок. */
@media (pointer: coarse) {
  input, textarea { font-size: 16px; }
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 14px;
  padding: 11px 18px;
  font-weight: 600;
}
button.primary:disabled { opacity: .6; cursor: default; }
button.secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 18px;
}
button.danger, .danger { color: var(--danger); }
button.icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
  flex: none;
}
/* Подсветка при наведении — только там, где есть мышь: на iPhone :hover съедает первое касание. */
@media (hover: hover) {
  button.icon:hover { background: var(--hover); color: var(--text); }
  .chat-list li:hover, .pick-list li:hover { background: var(--hover); }
  .pw-toggle:hover { color: var(--text); }
}
button.icon svg { width: 22px; height: 22px; fill: currentColor; }
.badge {
  background: var(--accent); color: var(--accent-text);
  border-radius: 999px; font-size: 12px; font-weight: 600;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}

/* ---------- auth ---------- */
.auth {
  position: fixed; inset: 0; overflow-y: auto;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.card {
  background: var(--panel);
  border-radius: 18px;
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.08);
  margin: auto;
}
.card h1 { margin: 0; font-size: 22px; text-align: center; }
.card p { margin: 0; text-align: center; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.logo { width: 56px; height: 56px; align-self: center; }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.pw-toggle svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- layout ---------- */
.app {
  /* Высоту и сдвиг подгоняет JS под видимую область (когда открыта клавиатура на iPhone). */
  position: fixed; top: 0; left: 0; right: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  max-width: 1400px;
  margin: 0 auto;
  background: var(--panel);
  overflow: hidden;
}
.sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.side-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 12px; gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-top: max(8px, env(safe-area-inset-top));
}
.side-header .actions { display: flex; }
.side-title { margin: 0; font-size: 20px; font-weight: 700; line-height: 40px; }
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-header { justify-content: flex-start; gap: 4px; padding-left: 12px; }
.page-header .page-back:not(.hidden) + .side-title { font-size: 18px; }
.page-header .page-back { margin-left: -6px; }
.page-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 12px; padding: 16px;
  background: var(--bg);
}
.page-body > *, .modal-body > * { flex-shrink: 0; }  /* иначе карточки сжимаются и обрезают строки */
.page-body h3 { margin: 6px 4px 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.page-body .note { font-size: 14px; color: var(--muted); margin: 0 4px; line-height: 1.5; }
.page-body label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.page-body input[disabled] { opacity: .7; }

/* Списки настроек в стиле телефона: карточка со строками, у каждой — цветной значок. */
.menu-list { background: var(--panel); border-radius: 14px; overflow: hidden; }
.menu-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 14px; text-align: left; font-size: 15px; color: inherit; text-decoration: none;
}
.menu-row + .menu-row { border-top: 1px solid var(--border); }
.menu-row.danger { color: var(--danger); }
/* Значок строки: мягкий фон того же цвета, что и сам значок (цвет задаётся через --ic). */
.row-icon {
  width: 32px; height: 32px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--ic, var(--accent)); background: color-mix(in srgb, var(--ic, var(--accent)) 16%, transparent);
}
.row-icon svg { width: 18px; height: 18px; fill: currentColor; }
.row-value { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; }
.menu-row .check { color: var(--accent); font-weight: 700; }
.menu-row .sub { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }
.menu-row .switch { margin-left: auto; }

.profile-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--panel); border-radius: 14px; padding: 14px;
}
.profile-hero { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0; text-align: center; }
.profile-hero .avatar.lg { width: 84px; height: 84px; font-size: 30px; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: var(--active); color: var(--accent); margin-left: 6px; vertical-align: 1px;
}
.chip.red { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.chip.gray { background: var(--panel-2); color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; font-size: 14px; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: 4px 14px 12px; }
.bar > div { height: 100%; background: var(--accent); }
.result-box { background: var(--panel); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.row-inline { display: flex; gap: 8px; }
.row-inline > * { flex: 1; min-width: 0; }
select {
  font: inherit; color: inherit; width: 100%;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
@media (pointer: coarse) { select { font-size: 16px; } }

/* ---------- вкладка «Игры» ---------- */
.game-card {
  display: flex; flex-direction: column; text-align: left; width: 100%;
  background: var(--panel); border-radius: 20px; overflow: hidden;
}
.game-card-art { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.game-card-body { display: flex; flex-direction: column; gap: 3px; padding: 12px 16px 14px; }
.game-card-body b { font-size: 18px; }
.game-card-body .sub { font-size: 14px; color: var(--muted); }
.game-card-tag { align-self: flex-start; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--active); padding: 2px 10px; border-radius: 999px; }

/* ---------- рабочие пространства ---------- */
@media (min-width: 761px) {
  /* На компьютере пространства занимают всю ширину, контент — по центру. */
  .app.wide { grid-template-columns: minmax(0, 1fr) 0; }
  .app.wide .chat { display: none; }
  .app.wide .sidebar { border-right: 0; }
  .app.wide #tab-spaces .page-body { padding-inline: max(16px, calc((100% - 820px) / 2)); }
  .app.wide #tab-spaces .page-header { padding-inline: max(12px, calc((100% - 820px) / 2)); }
  .app.wide .tabbar { justify-content: center; }
  .app.wide .tab-btn { flex: 0 0 150px; }
}
.ws-list { display: flex; flex-direction: column; gap: 8px; }
.ws-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border-radius: 14px; padding: 12px 14px;
}
.ws-emoji { font-size: 30px; width: 44px; text-align: center; flex: none; }
.ws-title { font-weight: 600; font-size: 16px; }
.ws-card .sub, .note-card .sub { font-size: 13px; color: var(--muted); }
.ws-avatars { display: flex; flex: none; }
.ws-avatars .avatar { width: 26px; height: 26px; font-size: 10px; border: 2px solid var(--panel); margin-left: -8px; }
.ws-empty { text-align: center; padding: 24px 8px 8px; display: flex; flex-direction: column; gap: 8px; }
.ws-empty-icon { font-size: 48px; }
.ws-tabs { overflow-x: auto; scrollbar-width: none; }
.ws-tabs button { font-size: 13px; padding: 8px 6px; white-space: nowrap; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--border);
}
.chip-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip-btn .n { font-size: 12px; font-weight: 600; opacity: .8; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.field-label { font-size: 14px; color: var(--muted); margin-bottom: -6px; }
.add-row { display: flex; gap: 6px; }
.add-row input { flex: 1; min-width: 0; }
.add-row input.qty { flex: 0 0 90px; }
.add-row button.primary { flex: none; }
.add-row .add-more { flex: none; background: var(--panel); border-radius: 10px; width: 42px; height: auto; font-size: 20px; }

.task-row { cursor: pointer; align-items: flex-start; }
.task-check {
  width: 24px; height: 24px; border-radius: 50%; flex: none; margin-top: 1px;
  border: 2px solid var(--pc, var(--muted)); color: transparent;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.task-check.done { background: var(--pc, var(--accent)); color: #fff; }
@media (hover: hover) { .task-check:not(.done):hover { color: var(--pc); } }
.task-title { overflow-wrap: anywhere; }
.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--pos); font-weight: 600; }
.qty-chip { margin-left: 8px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.small-x { width: 30px; height: 30px; font-size: 14px; }

.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav b { font: 600 20px/1.2 var(--display); }
.month-nav .icon { font-size: 26px; }
.stat b { font-size: 16px; overflow-wrap: anywhere; }

/* Финансы: сводка месяца — крупный остаток, полоска «сколько дохода потрачено», доходы и расходы. */
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.fin-summary { background: var(--panel); border-radius: 16px; padding: 16px 18px; display: flex; flex-direction: column; }
.fin-label { font-size: 13px; color: var(--muted); }
.fin-big { font-size: 34px; font-weight: 700; line-height: 1.15; letter-spacing: -.03em; margin-top: 2px; overflow-wrap: anywhere; white-space: normal; }
.fin-big.neg { color: var(--danger); }
.fin-meter { height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--pos) 22%, transparent); margin: 14px 0 12px; overflow: hidden; }
.fin-meter > div { height: 100%; background: var(--neg-soft); border-radius: 2px; }
.fin-flows { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fin-summary > .fin-flows:nth-child(3) { margin-top: 12px; }
.fin-flow { display: flex; flex-direction: column; gap: 1px; padding-left: 10px; border-left: 2px solid; min-width: 0; }
.fin-flow.income { border-color: var(--pos); }
.fin-flow.expense { border-color: var(--neg-soft); }
.fin-flow b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; }

.donut-card { background: var(--panel); border-radius: 16px; padding: 6px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.fin-toggle { display: flex; gap: 18px; border-bottom: 1px solid var(--border); }
.fin-toggle button { padding: 10px 0 9px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.fin-toggle button.active { color: var(--accent); font-weight: 600; border-color: var(--accent); }
.donut-body { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; justify-content: center; }
.donut { position: relative; width: 156px; height: 156px; flex: none; }
.donut svg { display: block; width: 100%; height: 100%; }
.donut circle { fill: none; stroke-width: 9; }
.donut .donut-track { stroke: var(--panel-2); }
.donut-hole { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-hole b { font-size: 16px; font-weight: 700; }
.donut-hole span { font-size: 12px; color: var(--muted); }
.legend { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 10px; }
.legend-line { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.legend-pct { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend-bar { height: 3px; border-radius: 2px; background: var(--panel-2); margin-top: 5px; overflow: hidden; }
.legend-bar > div { height: 100%; background: var(--c); border-radius: 2px; }
.cat-icon { background: var(--panel-2) !important; font-size: 17px; color: inherit; }
.amount { white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount.expense { color: var(--text); }
.amount.income { color: var(--pos); }
.amount-input { font-size: 28px !important; font-weight: 700; text-align: center; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 12px; font-size: 12px; background: var(--panel-2); border: 2px solid transparent; }
.cat.active { border-color: var(--accent); background: var(--active); }
.cat-emoji { font-size: 22px; }

.emoji-row { display: flex; flex-wrap: wrap; gap: 4px; }
.emoji-row button { font-size: 24px; width: 42px; height: 42px; border-radius: 10px; }
.emoji-row button.active { background: var(--active); outline: 2px solid var(--accent); }

.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.note-card { background: var(--panel); border-radius: 14px; padding: 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 110px; }
.note-card-title { font-weight: 600; }
.note-card-preview { font-size: 13px; color: var(--muted); flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.note-head { text-align: center; }
.note-big-emoji { font-size: 44px; }
.note-title { margin: 4px 0; font-size: 22px; overflow-wrap: anywhere; }
.note-head .sub { font-size: 13px; color: var(--muted); }
.note-body { background: var(--panel); border-radius: 14px; padding: 16px; line-height: 1.55; overflow-wrap: anywhere; }
.note-body p { margin: 0; }
.page-body .note-body h3.note-h {
  margin: 10px 0 4px; font-size: 19px; font-weight: 700;
  text-transform: none; letter-spacing: 0; color: inherit;  /* не наследовать стиль подзаголовков настроек */
}
.note-body h4 { margin: 8px 0 2px; font-size: 16px; }
.note-body .note-gap { height: 10px; }
.note-body a { color: var(--accent); }
.note-bullet { display: flex; gap: 8px; }
.note-bullet .bullet { color: var(--accent); }
.note-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 2px 0; }
.note-check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.note-check.checked span { text-decoration: line-through; color: var(--muted); }
.note-head-edit { display: flex; gap: 8px; }
.emoji-input { flex: 0 0 60px; text-align: center; font-size: 22px; padding: 6px; }
.note-title-input { flex: 1; min-width: 0; font-size: 18px !important; font-weight: 600; }
.note-toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.note-toolbar .sub { margin-left: auto; font-size: 12px; color: var(--muted); }
.note-editor { min-height: 240px; resize: none; line-height: 1.55; font-family: inherit; }

/* Галерея чата */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; border-radius: 12px; overflow: hidden; }
.tile { position: relative; aspect-ratio: 1; background: var(--panel-2); overflow: hidden; cursor: pointer; padding: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.tile .play svg { width: 20px; height: 20px; fill: currentColor; margin-left: 2px; }
.tile.no-poster { background: #1b1f27; }
.empty-note { text-align: center; color: var(--muted); padding: 24px 0; }

.tabbar {
  flex: none; display: flex;
  border-top: 1px solid var(--border); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 6px; font-size: 11px; color: var(--muted);
}
.tab-btn.active { color: var(--accent); font-weight: 600; }
/* Выбранная вкладка — значок на мягкой «таблетке». */
.tab-icon { position: relative; display: flex; justify-content: center; align-items: center; width: 56px; height: 30px; border-radius: 999px; transition: background .2s; }
.tab-btn.active .tab-icon { background: var(--active); }
.tab-icon svg { width: 24px; height: 24px; fill: currentColor; }
.tab-icon .badge { position: absolute; top: -4px; left: 32px; min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; border: 2px solid var(--panel); box-sizing: content-box; }

.segmented { display: flex; gap: 3px; padding: 3px; border-radius: 10px; background: var(--border); }
.segmented button { flex: 1; padding: 8px 4px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.segmented button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.conn-banner { background: #f5b301; color: #111; text-align: center; font-size: 13px; padding: 4px; }

.banner {
  margin: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--active); font-size: 14px;
  display: flex; gap: 10px; align-items: center;
}
.banner button.primary { padding: 6px 12px; }
.banner .close { color: var(--muted); font-size: 20px; width: 28px; height: 28px; flex: none; }
.share-icon { display: inline-block; width: 16px; height: 16px; vertical-align: -2px; fill: currentColor; }

.chat-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.chat-list:empty { flex: 0; padding: 0; }
.chat-list li {
  display: flex; gap: 12px; align-items: center;
  padding: 8px 10px; border-radius: 12px; cursor: pointer;
}
.chat-list li.active { background: var(--active); }
.chat-list .body { flex: 1; min-width: 0; }
.chat-list .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-list .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .time { font-size: 12px; color: var(--muted); flex: none; }
.chat-list .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .preview.typing { color: var(--accent); }
.chat-list .preview.draft { color: var(--danger); }
.list-empty { padding: 24px; text-align: center; color: var(--muted); line-height: 1.6; }

/* Поиск над списком чатов. Пока ищем — вместо списка показываются результаты. */
.search-bar { position: relative; margin: 8px 10px 4px; flex: none; }
.search-bar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: var(--muted); pointer-events: none; }
.search-bar input { padding: 9px 12px 9px 38px; border-radius: 999px; background: var(--panel-2); border-color: transparent; }
.search-bar input:focus { border-color: var(--accent); background: var(--panel); }
#tab-chats.searching #chat-list, #tab-chats.searching #chat-list-empty { display: none; }
.search-results { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; }
.search-results .chat-list { flex: none; overflow: visible; padding: 0 4px; }
.search-results.loading { opacity: .6; }
.search-h { font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 14px 4px; }
.search-results mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.avatar {
  position: relative;
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; flex: none; user-select: none;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
/* Аватарка-фото: лёгкая обводка, чтобы светлые фото не сливались с фоном. */
.avatar.photo { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.avatar-pick { position: relative; border-radius: 50%; }
.avatar-cam {
  position: absolute; right: 0; bottom: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); border: 3px solid var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.avatar-cam svg { width: 15px; height: 15px; fill: currentColor; }
.avatar-actions { margin-top: 6px; width: 100%; max-width: 320px; }
.avatar.online::after {
  content: ""; position: absolute; right: 0; bottom: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--panel);
}

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); position: relative; }
.chat-empty { margin: auto; color: var(--muted); background: var(--panel); padding: 6px 14px; border-radius: 999px; }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; position: relative; }
.chat-header {
  flex: none;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 12px 6px 6px; background: var(--panel); border-bottom: 1px solid var(--border);
  padding-top: max(6px, env(safe-area-inset-top));
}
.chat-header .back { display: none; }
.chat-info { display: flex; align-items: center; gap: 12px; min-width: 0; text-align: left; padding: 2px 6px; border-radius: 10px; }
.chat-titles { display: flex; flex-direction: column; min-width: 0; }
.chat-titles .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-titles #chat-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-titles #chat-status.typing { color: var(--accent); }

.messages {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 12px 16px;
}
.messages-inner { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.day { align-self: center; background: color-mix(in srgb, var(--accent) 16%, var(--panel)); color: var(--text); font-size: 13px; padding: 2px 10px; border-radius: 999px; margin: 10px 0 6px; }
.system { align-self: center; color: var(--muted); font-size: 13px; text-align: center; margin: 6px 0; max-width: 80%; }
.unread-divider {
  align-self: stretch; text-align: center; margin: 10px -16px;
  background: var(--panel); color: var(--accent); font-size: 13px; font-weight: 600; padding: 4px;
}
.msg {
  max-width: min(560px, 80%);
  min-width: 0;
  background: var(--theirs);
  border-radius: var(--radius);
  padding: 6px 10px 6px;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(120, 60, 30, .08);
  overflow-wrap: anywhere; word-break: break-word;
  margin-top: 2px;
}
.msg.mine { align-self: flex-end; background: var(--mine); }
/* «Хвостик» пузыря: первый в серии — с острым уголком к собеседнику. */
.msg.gap:not(.mine) { border-top-left-radius: var(--tail); }
.msg.gap.mine { border-top-right-radius: var(--tail); }

/* ---------- личные настройки чата (Настройки → Оформление) ---------- */
/* Шрифт и размер текста сообщений. */
:root { --chat-font: inherit; --chat-size: 15px; --tail: 6px; }
:root[data-font="rounded"] { --chat-font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif; }
:root[data-font="serif"] { --chat-font: ui-serif, "New York", Georgia, "Noto Serif", "Times New Roman", serif; }
:root[data-font="mono"] { --chat-font: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", "Droid Sans Mono", monospace; }
:root[data-fsize="s"] { --chat-size: 13.5px; }
:root[data-fsize="l"] { --chat-size: 17px; }
:root[data-fsize="xl"] { --chat-size: 19.5px; }
.msg, .composer textarea, .reply-quote { font-family: var(--chat-font); }
.msg .text, .composer textarea { font-size: var(--chat-size); }
@media (pointer: coarse) { .composer textarea { font-size: max(16px, var(--chat-size)); } }

/* Форма облачков: скругление и «хвостик». */
:root[data-bubble="classic"] { --radius: 12px; --tail: 3px; }
:root[data-bubble="square"] { --radius: 6px; --tail: 6px; }
:root[data-bubble="pill"] { --radius: 22px; --tail: 22px; }

/* Свои сообщения — яркие: заливка цветом оформления, белый текст. */
:root[data-mine="bright"] .msg.mine:not(.sticker-msg):not(.big-emoji) { background: var(--accent); color: var(--accent-text); }
:root[data-mine="bright"] .msg.mine .meta,
:root[data-mine="bright"] .msg.mine .ticks.read,
:root[data-mine="bright"] .msg.mine .vw-meta,
:root[data-mine="bright"] .msg.mine .vw-rate { color: color-mix(in srgb, var(--accent-text) 80%, transparent); }
:root[data-mine="bright"] .msg.mine .text a,
:root[data-mine="bright"] .msg.mine .fwd,
:root[data-mine="bright"] .msg.mine .reply-quote .rq-name { color: inherit; }
:root[data-mine="bright"] .msg.mine .text a { text-decoration: underline; }
:root[data-mine="bright"] .msg.mine .reply-quote { border-left-color: currentColor; background: color-mix(in srgb, var(--accent-text) 15%, transparent); }
:root[data-mine="bright"] .msg.mine .reply-quote .rq-text { color: color-mix(in srgb, var(--accent-text) 80%, transparent); }
:root[data-mine="bright"] .msg.mine .vw-play { background: var(--accent-text); color: var(--accent); }
:root[data-mine="bright"] .msg.mine .vw-wave i { background: color-mix(in srgb, var(--accent-text) 35%, transparent); }
:root[data-mine="bright"] .msg.mine .vw-wave i.on { background: var(--accent-text); }
:root[data-mine="bright"] .msg.mine .file-link .file-icon { background: var(--accent-text); color: var(--accent); }
:root[data-mine="bright"] .msg.mine .reaction { background: color-mix(in srgb, var(--accent-text) 18%, transparent); }
.msg.sticker-msg, .msg.big-emoji { border-radius: var(--radius); }
.msg.gap { margin-top: 8px; }
.msg .sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .fwd { font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.msg.has-media .fwd { padding: 2px 6px 0; }
.msg.sticker-msg .fwd { padding: 2px 8px; border-radius: 8px; background: color-mix(in srgb, var(--panel) 85%, transparent); display: inline-block; }
.msg .text a { color: var(--accent); }
.msg .meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; gap: 3px; align-items: center; }
.msg .ticks.read { color: var(--accent); }
.msg.deleted .text { font-style: italic; color: var(--muted); }
.msg.has-media { padding: 4px; }
.msg.has-media .text, .msg.has-media .sender { padding: 0 6px; display: block; margin-top: 4px; }
.msg.has-media .meta { margin-right: 6px; }
@media (pointer: coarse) {
  /* чтобы долгое нажатие открывало меню сообщения, а не выделение текста */
  .msg { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

.media-box {
  position: relative; max-width: 100%;
  border-radius: 10px; overflow: hidden; cursor: pointer;
  background: rgba(0,0,0,.08);
}
.media-box img { display: block; width: 100%; height: 100%; object-fit: cover; }
.media-box.no-size { width: 260px; }
.media-box.no-size img { height: auto; max-height: 360px; object-fit: contain; }
.media-box.video { background: #1b1f27; }
.media-box.video.no-size { aspect-ratio: 16 / 9; }
.media-box.video.no-size img { height: 100%; object-fit: cover; }
.media-box .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.media-box .play svg { width: 28px; height: 28px; fill: currentColor; margin-left: 3px; }
.msg audio { display: block; max-width: 100%; }
.file-link { display: flex; gap: 10px; align-items: center; padding: 4px 6px; color: inherit; text-decoration: none; min-width: 0; }
.file-link .file-icon {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.file-link .file-icon svg { width: 20px; height: 20px; fill: currentColor; }
.file-link .file-name { font-weight: 600; overflow-wrap: anywhere; }

.scroll-down {
  position: absolute; right: 14px; bottom: 76px; z-index: 5;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--panel); color: var(--muted);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  display: flex; align-items: center; justify-content: center;
}
.scroll-down svg { width: 28px; height: 28px; fill: currentColor; }
.scroll-down .badge { position: absolute; top: -6px; right: -4px; }

/* Цитата в ответе */
.reply-quote {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border-left: 3px solid var(--accent); border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 3px 8px; margin: 2px 0 4px; font-size: 13px; line-height: 1.3;
}
.msg.has-media .reply-quote { width: auto; margin: 2px 6px 4px; }
.reply-quote .rq-name { font-weight: 600; color: var(--accent); }
.reply-quote .rq-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.msg.highlight { animation: highlight 1.4s ease; }
@keyframes highlight { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 1px 1px rgba(0,0,0,.06); } }

/* Реакции под сообщением */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; clear: both; }
.msg.has-media .reactions { margin: 4px 6px 0; }
.reaction {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: 999px; font-size: 14px; line-height: 22px;
  background: color-mix(in srgb, var(--text) 8%, transparent); border: 1px solid transparent;
}
.reaction.mine { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }
.reaction .n { font-size: 12px; font-weight: 600; color: var(--muted); }
.msg .edited { font-style: italic; }
.msg.swiping { transition: none; }
.msg.swipe-back { transition: transform .15s ease; }

/* Панель над полем ввода: ответ или редактирование */
.composer-bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 6px 4px 6px 14px; background: var(--panel); border-top: 1px solid var(--border);
}
.cb-icon { color: var(--accent); display: flex; }
.cb-icon svg { width: 22px; height: 22px; fill: currentColor; }
.cb-title { font-size: 13px; font-weight: 600; color: var(--accent); }
.cb-text { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-bar + .composer { border-top: 0; }

/* Ряд реакций в меню сообщения */
.react-row { display: flex; justify-content: space-between; gap: 4px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.react-row button { font-size: 26px; width: 44px; height: 44px; border-radius: 50%; }
.react-row button.mine { background: var(--active); }
@media (hover: hover) { .react-row button:hover { background: var(--hover); } }

.upload-status { flex: none; background: var(--panel); padding: 6px 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); }
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px; background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: 9px 14px; line-height: 1.4; }
.composer .send, .composer .mic { color: var(--accent); }
/* Пустое поле — микрофон, есть текст — «отправить». */
.composer.has-text .mic, .composer:not(.has-text) .send { display: none; }

/* ---------- голосовые ---------- */
.rec-bar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px; background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; animation: recPulse 1s ease-in-out infinite; }
@keyframes recPulse { 50% { opacity: .3; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 38px; }
.rec-wave { flex: 1; min-width: 0; height: 28px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; overflow: hidden; }
.rec-wave i { flex: none; width: 3px; border-radius: 2px; background: var(--accent); }
.rec-bar .rec-send { background: var(--accent); color: var(--accent-text); }

.voice { display: flex; align-items: center; gap: 10px; width: min(260px, 62vw); padding: 2px 0; }
.vw-play {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text);
}
.vw-play svg { width: 22px; height: 22px; fill: currentColor; }
.voice:not(.playing) .vw-play svg { margin-left: 2px; }
.vw-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.vw-wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.vw-wave i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: color-mix(in srgb, var(--text) 25%, transparent); transition: background .15s; }
.vw-wave i.on { background: var(--accent); }
.vw-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vw-rate { font-size: 11px; font-weight: 700; line-height: 18px; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--muted); }
.drop-hint {
  position: absolute; inset: 12px; border: 3px dashed var(--accent); border-radius: 18px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; pointer-events: none;
}

/* ---------- modal ---------- */
.modal {
  border: 0; border-radius: 18px; padding: 0;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 64px);
  background: var(--panel); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  overflow: hidden;
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-header {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 10px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px 20px; overflow-y: auto; min-height: 0; outline: none; }
.modal h3 { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.modal p { margin: 0; }
.modal .buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.pick-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.pick-list li { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; cursor: pointer; }
.pick-list li input[type=checkbox] { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.invite-box { display: flex; gap: 8px; margin-bottom: 8px; }
.invite-box input { font-size: 13px; }

.profile { display: flex; align-items: center; gap: 14px; }
.profile-name { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.inline-edit { display: flex; gap: 8px; }
.inline-edit button { flex: none; }
.settings-card { background: var(--panel-2); border-radius: 14px; padding: 4px 14px; }
.setting-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0; width: 100%; text-align: left;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-row .chev { color: var(--muted); font-size: 20px; }
.settings-card .note { padding: 10px 0; font-size: 14px; color: var(--muted); }
.settings-card .form { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; }
.logout { width: 100%; padding: 12px; border-radius: 14px; background: var(--panel-2); color: var(--danger); font-weight: 600; }
.page-body .logout { background: var(--panel); }

.switch {
  appearance: none; -webkit-appearance: none;
  width: 48px !important; height: 28px; flex: none; padding: 0;
  border-radius: 999px; border: 0; background: var(--border);
  position: relative; cursor: pointer; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.menu { display: flex; flex-direction: column; }
.menu-item { padding: 14px 4px; text-align: left; font-size: 16px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.menu-item:last-child { border-bottom: 0; }

/* ---------- просмотр фото и видео ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  background: #000;
  display: flex; flex-direction: column;
}
.viewer-bar {
  flex: none; display: flex; justify-content: space-between; align-items: center;
  padding: 8px; padding-top: max(8px, env(safe-area-inset-top));
}
.viewer-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: #fff; text-decoration: none; font-size: 15px;
  padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,.12);
}
.viewer-btn svg { width: 22px; height: 22px; fill: currentColor; }
.viewer-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding-bottom: env(safe-area-inset-bottom);
}
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body video { width: 100%; }
.viewer-error { color: #fff; text-align: center; padding: 0 24px; }
.viewer-counter { color: rgba(255,255,255,.8); font-size: 14px; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.viewer-nav svg { width: 30px; height: 30px; fill: currentColor; }
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }
@media (pointer: coarse) { .viewer-nav { display: none; } }  /* на телефоне листаем свайпом */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw;
}

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app .chat { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex; }
  .chat-header .back { display: inline-flex; }
  .msg { max-width: 86%; }
  .messages { padding: 10px; }
  .unread-divider { margin: 10px -10px; }
  .modal {
    width: 100vw; max-width: 100vw; height: 100%; max-height: 100%;
    border-radius: 0; margin: 0;
  }
  .modal-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .modal-body { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .modal.sheet { height: fit-content; max-height: 85%; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .modal.sheet .modal-header { padding-top: 10px; }
}

/* ---------- поле ввода ---------- */
.composer textarea.auto-size { field-sizing: content; min-height: 40px; max-height: 160px; }
#btn-emoji.active { color: var(--accent); }

/* ---------- эмодзи и стикеры ---------- */
.emoji-panel {
  flex: none; height: 300px; display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--border);
  animation: panelUp .22s cubic-bezier(.2, .8, .2, 1);
}
.ep-tabs { display: flex; gap: 4px; padding: 6px 8px 0; }
.ep-tabs button { padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted); }
.ep-tabs button.active { background: var(--active); color: var(--accent); font-weight: 600; }
.ep-grid {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); align-content: start; padding: 6px 8px;
}
.ep-grid button { font-size: 28px; height: 44px; border-radius: 10px; line-height: 1; }
@media (hover: hover) { .ep-grid button:hover { background: var(--hover); } }
.ep-grid button:active { transform: scale(1.25); }
.ep-cats { display: flex; justify-content: space-around; border-top: 1px solid var(--border); padding: 2px 4px max(2px, env(safe-area-inset-bottom)); }
.ep-cats button { font-size: 20px; width: 36px; height: 36px; border-radius: 10px; opacity: .5; filter: grayscale(.6); }
.ep-cats button.active { opacity: 1; filter: none; background: var(--active); }
.ep-grid.stickers { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.sticker-btn { height: 84px !important; padding: 4px; }
.sticker-btn img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-select: none; user-select: none; }
.sticker-add {
  height: 84px !important; border: 2px dashed var(--border); color: var(--muted); font-size: 13px !important;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.sticker-add b { font-size: 26px; line-height: 1; }
.ep-hint { padding: 0 12px 10px; }

.msg.sticker-msg, .msg.big-emoji { background: transparent; box-shadow: none; padding: 0; }
.msg.sticker-msg .sticker-img { display: block; width: 150px; max-width: 100%; object-fit: contain; -webkit-user-select: none; user-select: none; }
.msg.sticker-msg .meta, .msg.big-emoji .meta {
  float: none; display: inline-flex; margin: 2px 0 0; padding: 1px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
}
.msg.mine.sticker-msg, .msg.mine.big-emoji { text-align: right; }
.msg.big-emoji .text { font-size: 46px; line-height: 1.15; display: block; }

/* ---------- пространства: шапка, вкладки, обзор, шаблоны ---------- */
/* Шапка пространства — без карточки и градиента: значок, название крупным шрифтом с засечками, участники. */
.ws-hero { display: flex; align-items: center; gap: 14px; padding: 4px 2px 0; }
.ws-hero-emoji { font-size: 40px; line-height: 1; flex: none; }
.ws-hero-title { font: 600 26px/1.15 var(--display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.ws-hero-sub { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.ws-hero .ws-avatars { padding-left: 8px; }
.ws-hero .ws-avatars .avatar { border-color: var(--bg); }

.ws-gear { align-self: flex-start; margin: -4px -6px 0 0; }

/* Разделы — строка текстовых вкладок с линией под выбранной. Прилипает к верху при прокрутке. */
.ws-nav {
  display: flex; justify-content: space-between; gap: 12px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 0 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: -16px; z-index: 3; background: var(--bg);
}
@media (min-width: 761px) { .ws-nav { justify-content: flex-start; gap: 28px; } }
.ws-section { display: flex; flex-direction: column; gap: 12px; }
.ws-section > * { flex-shrink: 0; }
.ws-section.appear { animation: fadeUp .25s ease both; }
.segmented .seg-n { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 5px; font-variant-numeric: tabular-nums; }
.ws-nav::-webkit-scrollbar { display: none; }
.ws-nav button {
  flex: none; padding: 10px 0 9px; font-size: 15px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.ws-nav button.active { color: var(--accent); font-weight: 600; border-color: var(--accent); }
@media (hover: hover) { .ws-nav button:hover { color: var(--text); } }

.ov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ov-tile {
  background: var(--panel); border-radius: 16px; padding: 14px 16px 16px; cursor: pointer; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.ov-tile.wide { grid-column: 1 / -1; }
.ov-head { display: flex; align-items: center; gap: 8px; }
.ov-title { flex: 1; font-size: 14px; color: var(--muted); }
.ov-head .chev { font-size: 20px; }
.ov-big { font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ov-sub { font-size: 13px; color: var(--muted); }
.ov-sub.pos { color: var(--pos); font-weight: 600; }
.ov-sub.neg { color: var(--danger); font-weight: 600; }
.ov-tasks { margin: 6px -6px -6px; }
.ov-tasks .task-row { padding: 8px 6px; border-radius: 10px; }
.ov-tasks .task-row + .task-row { border-top: 1px solid var(--border); }
.ov-chips, .ov-notes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ov-chips .qty-chip { margin: 0; }
.ov-notes .chip-btn { font-size: 13px; padding: 4px 10px; background: var(--panel-2); }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 10px 12px; border-radius: 14px; background: var(--panel-2); border: 2px solid transparent;
  transition: border-color .15s, transform .15s;
}
.tpl.active { border-color: var(--accent); background: var(--active); }
.tpl-emoji { font-size: 26px; }
.tpl .sub { font-size: 12px; color: var(--muted); }

.task-row.completing { animation: completeOut .45s ease forwards; }

/* ---------- анимации ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideFromRight { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes slideFromLeft { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.5); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes panelUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes dialogIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes shimmer { from { background-position: -300px 0; } to { background-position: 300px 0; } }
@keyframes completeOut { 0% { opacity: 1; } 60% { opacity: .6; } 100% { opacity: .35; transform: translateX(10px); } }
@keyframes confetti { to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; } }

.page-body.anim-forward > * { animation: slideFromRight .28s cubic-bezier(.2, .8, .2, 1) both; }
.page-body.anim-back > * { animation: slideFromLeft .28s cubic-bezier(.2, .8, .2, 1) both; }
.page-body.anim-fade > * { animation: fadeUp .3s ease both; }
.page-body.anim-forward > :nth-child(2), .page-body.anim-back > :nth-child(2), .page-body.anim-fade > :nth-child(2) { animation-delay: .03s; }
.page-body.anim-forward > :nth-child(3), .page-body.anim-back > :nth-child(3), .page-body.anim-fade > :nth-child(3) { animation-delay: .06s; }
.page-body.anim-forward > :nth-child(n+4), .page-body.anim-back > :nth-child(n+4), .page-body.anim-fade > :nth-child(n+4) { animation-delay: .09s; }
/* Плитки обзора выезжают по очереди только при открытии экрана, не при каждом обновлении. */
.page-body[class*="anim-"] .ov-grid > *, .ws-section.appear .ov-grid > * { animation: fadeUp .35s ease both; }
.page-body[class*="anim-"] .ov-grid > :nth-child(2), .ws-section.appear .ov-grid > :nth-child(2) { animation-delay: .05s; }
.page-body[class*="anim-"] .ov-grid > :nth-child(3), .ws-section.appear .ov-grid > :nth-child(3) { animation-delay: .1s; }
.page-body[class*="anim-"] .ov-grid > :nth-child(4), .ws-section.appear .ov-grid > :nth-child(4) { animation-delay: .15s; }

.msg.appear { animation: fadeUp .25s cubic-bezier(.2, .8, .2, 1); }
.msg.mine.appear { transform-origin: bottom right; }
.reaction { animation: pop .3s ease; }
.task-check.done.pop { animation: pop .35s ease; }  /* только при своём нажатии, не при перерисовке */
.modal[open] { animation: dialogIn .22s cubic-bezier(.2, .8, .2, 1); }
.modal[open]::backdrop { animation: fadeIn .2s ease; }
@media (max-width: 760px) {
  .modal[open] { animation: slideFromRight .25s cubic-bezier(.2, .8, .2, 1); }
  .modal.sheet[open] { animation: sheetUp .28s cubic-bezier(.2, .8, .2, 1); }
  .app.show-chat .chat { animation: slideFromRight .25s cubic-bezier(.2, .8, .2, 1); }
}
.viewer:not(.hidden) { animation: fadeIn .2s ease; }
.toast:not(.hidden) { animation: toastIn .25s cubic-bezier(.2, .8, .2, 1); }
.banner:not(.hidden) { animation: fadeUp .3s ease; }
.tab-btn.active .tab-icon { animation: pop .3s ease; }
.scroll-down:not(.hidden) { animation: pop .25s ease; }

/* Лёгкое «нажатие» у кнопок и карточек */
button.primary, button.secondary, .chip-btn, .ws-card, .ov-tile, .tpl, .note-card, .profile-card, .tab-btn, .ws-nav button, .game-card {
  transition: transform .12s ease, background-color .15s, border-color .15s;
}
button.primary:active:not(:disabled), button.secondary:active, .chip-btn:active, .ws-card:active, .ov-tile:active,
.tpl:active, .note-card:active, .profile-card:active, .ws-nav button:active, .game-card:active { transform: scale(.97); }
@media (hover: hover) {
  .ws-card:hover, .ov-tile:hover, .note-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
}

.confetti {
  position: fixed; width: 8px; height: 8px; border-radius: 2px; pointer-events: none; z-index: 100;
  margin: -4px 0 0 -4px; animation: confetti .85s cubic-bezier(.15, .6, .35, 1) forwards;
}

.skeleton-list { display: flex; flex-direction: column; gap: 10px; }
.skeleton {
  height: 64px; border-radius: 14px;
  background: linear-gradient(90deg, var(--panel) 0%, var(--panel-2) 50%, var(--panel) 100%) var(--panel);
  background-size: 600px 100%; animation: shimmer 1.2s linear infinite;
}

/* «Уютный»: все карточки и окна — с крупным мягким скруглением. */
.menu-list, .profile-card, .stat, .ws-card, .result-box, .note-card, .note-body, .ov-tile, .fin-summary, .donut-card,
.skeleton, .settings-card, .logout, .card { border-radius: 20px; }
@media (min-width: 761px) { .modal { border-radius: 24px; } }  /* на телефоне окно во весь экран — без скруглений */
@media (max-width: 760px) { .modal.sheet { border-radius: 24px 24px 0 0; } }
.ws-hero-title { font-weight: 700; }
.month-nav b { font-weight: 700; }

/* ---------- пространства: календарь, подзадачи, фото, бюджет, покупки ---------- */
/* Фильтры задач — одной строкой, лишнее прокручивается вбок. */
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip-btn { flex: none; }
.cal-card { background: var(--panel); border-radius: 20px; padding: 6px 10px 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; margin-top: 4px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-variant-numeric: tabular-nums;
}
.cal-day b { font-weight: 500; font-size: 15px; line-height: 1; }
.cal-day.today b { color: var(--accent); font-weight: 800; }
.cal-day.sel { background: var(--accent); color: var(--accent-text); }
.cal-day.sel.today b { color: inherit; }
.cal-day.late:not(.sel) b { color: var(--danger); }
.cal-day.all-done:not(.sel) b { color: var(--muted); }
.cal-dots { display: flex; gap: 2px; height: 5px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; }
.cal-day.sel .cal-dots i { background: currentColor !important; }
@media (hover: hover) { .cal-day:not(.sel):hover { background: var(--hover); } }

.subtasks { display: flex; flex-direction: column; }
.subtask { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.subtask input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.subtask.done .grow { text-decoration: line-through; color: var(--muted); }
.task-meta .subs-done { color: var(--pos); }
.task-photo { position: relative; display: inline-block; }
.task-photo img { display: block; max-width: 100%; max-height: 200px; border-radius: 14px; cursor: zoom-in; }
.task-photo .small-x { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .55); color: #fff; }

.fin-head { display: flex; align-items: center; justify-content: space-between; }
.link-btn { color: var(--accent); font-size: 14px; font-weight: 600; padding: 2px 0; }
.budget { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.budget-line { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.budget-line span:last-child { font-weight: 600; }
.budget-bar { height: 6px; border-radius: 3px; background: var(--panel-2); margin: 8px 0 4px; overflow: hidden; }
.budget-bar > div { height: 100%; border-radius: 3px; background: var(--pos); }
.budget.warn .budget-bar > div { background: #d9a441; }
.budget.over .budget-bar > div { background: var(--danger); }
.budget.over .budget-line span:last-child { color: var(--danger); }
.budget-sub { font-size: 12px; color: var(--muted); }
.legend-row.over .legend-bar > div { background: var(--danger); }
.legend-row.over .legend-pct { color: var(--danger); }
.budget-row .budget-input { flex: 0 0 120px; text-align: right; }

.quick-wrap { display: flex; flex-direction: column; gap: 6px; }
.quick-wrap .field-label { margin: 0; }
.chip-btn.quick { background: var(--active); border-color: transparent; color: var(--accent); font-weight: 600; font-size: 13px; padding: 5px 11px; }
.page-body h3.dept { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); margin-top: 4px; }

/* Оформление: пример чата и выбор иконки. */
.look-preview {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 12px; border-radius: 20px; border: 1px solid var(--border);
  background-color: var(--chat-bg);
}
.look-preview .msg { max-width: 80%; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 10px; }
.icon-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); padding: 6px 2px; border-radius: 16px; border: 2px solid transparent; }
.icon-pick img { width: 54px; height: 54px; border-radius: 13px; }
.icon-pick.active { border-color: var(--accent); color: var(--text); font-weight: 600; background: var(--panel); }

/* Оформление: выбор цвета и фона. */
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.swatch i {
  width: 44px; height: 44px; border-radius: 50%; background: var(--c);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 3px transparent; transition: box-shadow .15s;
  display: flex; align-items: center; justify-content: center; color: #fff; font-style: normal; font-size: 20px; font-weight: 700;
}
.swatch.active { color: var(--text); font-weight: 600; }
.swatch.active i { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c); }
.wall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.wall {
  aspect-ratio: 3 / 4; border-radius: 16px; border: 2px solid var(--border); overflow: hidden; position: relative;
  background-color: var(--chat-bg); display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; padding: 8px;
}
.wall.active { border-color: var(--accent); }
.wall .bub { height: 12px; border-radius: 6px; background: var(--theirs); width: 70%; }
.wall .bub.me { background: var(--mine); align-self: flex-end; width: 55%; }
.wall span { position: absolute; top: 6px; left: 8px; right: 8px; font-size: 12px; font-weight: 600; text-align: left; }
.wall[data-w="dots"] { background-image: radial-gradient(color-mix(in srgb, var(--accent) 24%, transparent) 1.4px, transparent 1.7px); background-size: 12px 12px; }
.wall[data-w="grid"] { background-image: linear-gradient(color-mix(in srgb, var(--accent) 11%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--accent) 11%, transparent) 1px, transparent 1px); background-size: 14px 14px; }
.wall[data-w="lines"] { background-image: repeating-linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, transparent) 0 2px, transparent 2px 10px); }
.wall[data-w="glow"] { background-image: radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 60%), radial-gradient(circle at 90% 85%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%); }
.wall[data-w="photo"] { background-image: var(--wall-photo, none); background-size: cover; background-position: center; }

/* Кто не любит движение (настройка «Уменьшить движение» в системе) — без анимаций. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
