/* Палитра Цифриума (class.obita.ru). Тихо по умолчанию: серое — структура, фиолетовое — число новых, лайм — главное действие. */
:root {
  --field: #f6f4fd;
  --card: #ffffff;
  --ink: #272044;
  --muted: #79718c;
  --faint: #c9c4d8;
  --purple: #6850e8;
  --purple-deep: #4934bd;
  --purple-soft: #ece8fc;
  --grey-soft: #efedf4;
  --lime: #d1ee37;
  --lime-edge: #b4d021;
  --class-6: #6850e8;
  --class-7: #1d9e75;
  --danger: #b23450;
  --shadow: 0 1px 2px #35258c14, 0 12px 32px #35258c10;
  --small: 0.8rem;
  --body: 1rem;
  --large: 1.25rem;
}

* { box-sizing: border-box; }
html { font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; background: var(--field); color: var(--ink); }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; text-align: inherit; }
a { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.top, #panel, main { max-width: 720px; margin-inline: auto; padding-inline: 16px; }
.top { display: flex; align-items: center; gap: 16px; padding-top: 24px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { padding: 8px 12px; border-radius: 10px; color: var(--muted); white-space: nowrap; }
.tabs button[aria-current] { color: var(--ink); background: var(--card); box-shadow: var(--shadow); }
.tabs button.later { color: var(--faint); }
.tabs .n { margin-left: 6px; color: var(--purple); font-weight: 700; font-variant-numeric: tabular-nums; }
.tools { margin-left: auto; display: flex; gap: 4px; }
.icon { position: relative; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); flex-shrink: 0; }
.icon:hover { background: var(--card); color: var(--ink); }
.icon.spin svg { animation: spin 0.9s linear infinite; }
.icon .alert { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding-top: 24px; padding-bottom: 96px; }

/* Уровень 0: когорты с числом. */
.section { margin-bottom: 24px; }
.section h2 { margin: 0 0 8px 16px; font-size: var(--small); font-weight: 600; color: var(--muted); }
.rows { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 4px; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 14px; }
.row:hover { background: var(--field); }
.row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .n { color: var(--purple); font-weight: 700; font-variant-numeric: tabular-nums; }
.row.quiet .title { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.c6 { background: var(--class-6); }
.dot.c7 { background: var(--class-7); }
.add-pin { margin: 4px 0 0 4px; padding: 8px 12px; color: var(--muted); font-size: var(--small); border-radius: 10px; }
.add-pin:hover { background: var(--card); }

/* Уровни 1–2: заголовок с возвратом. */
.head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; min-width: 0; }
.head h1 { margin: 0; font-size: var(--large); font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head .icon { width: 36px; height: 36px; }

.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; width: 100%; padding: 12px; border-radius: 14px; }
.item:hover { background: var(--field); }
.item .who { color: var(--muted); font-size: var(--small); }
.item .when { color: var(--muted); font-size: var(--small); text-align: right; }
.item .when.due { color: var(--ink); font-weight: 600; }
.item .one { grid-column: 1 / -1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }

/* Лента закреплённого чата. */
.feed { display: grid; gap: 8px; }
.msg { display: grid; gap: 2px; padding: 10px 14px; border-radius: 16px; background: var(--card); max-width: 88%; width: fit-content; text-align: left; }
.msg.mine { justify-self: end; background: var(--purple-soft); }
.msg .meta { color: var(--muted); font-size: var(--small); display: flex; gap: 8px; }
.msg .meta b { color: var(--ink); font-weight: 600; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.composer { position: sticky; bottom: 0; margin-top: 16px; padding: 12px 0 16px; background: linear-gradient(transparent, var(--field) 24px); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 48px; max-height: 160px; border: 0; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); padding: 12px 14px; resize: vertical; line-height: 1.5; }

/* Уровень 2: одно сообщение и что с ним сделать. */
.detail { background: var(--card); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); }
.detail .meta { color: var(--muted); font-size: var(--small); }
.detail .meta b { color: var(--ink); font-weight: 600; font-size: var(--body); margin-right: 6px; }
.detail .root { margin-top: 16px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.detail .root b { color: var(--ink); font-weight: 600; }
.detail .text { margin-top: 12px; font-size: var(--large); line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail .root + .text { padding: 12px 14px; border-radius: 14px; background: var(--purple-soft); font-size: var(--body); }
.detail .more { margin-top: 8px; color: var(--muted); font-size: var(--small); }
.detail .hint { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.detail .hint .was { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.detail .hint .now { font-weight: 700; }
.detail .hint .label { color: var(--purple-deep); font-size: var(--small); font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 24px; }
.primary { display: inline-flex; align-items: center; gap: 8px; padding: 12px 20px; border-radius: 14px; background: var(--lime); color: #342675; font-weight: 800; box-shadow: 0 3px 0 var(--lime-edge); }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--lime-edge); }
.secondary { padding: 12px 18px; border-radius: 14px; background: var(--purple-soft); color: var(--purple-deep); font-weight: 700; }
.ghost { padding: 12px 14px; border-radius: 14px; color: var(--muted); }
.ghost:hover, .secondary:hover { filter: brightness(0.97); }
.actions .icon { margin-left: auto; }

.editor { margin-top: 20px; display: grid; gap: 12px; }
.editor textarea, .panel textarea, .panel input { width: 100%; border: 0; border-radius: 14px; background: var(--field); padding: 12px 14px; resize: vertical; line-height: 1.5; }
.editor textarea { min-height: 112px; }
.targets { display: grid; gap: 8px; }
.targets .line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.targets .label { width: 64px; color: var(--muted); font-size: var(--small); }
.toggle { padding: 8px 14px; border-radius: 10px; background: var(--grey-soft); color: var(--muted); font-weight: 600; min-height: 36px; }
.toggle[aria-pressed="true"] { background: var(--purple); color: #fff; }

.entry { padding: 12px; border-radius: 14px; display: grid; gap: 6px; }
.entry + .entry { border-top: 1px solid var(--grey-soft); border-radius: 0; }
.entry .meta { display: flex; gap: 8px; color: var(--muted); font-size: var(--small); flex-wrap: wrap; }
.entry .body { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.entry .actions { margin-top: 0; }
.entry .actions button { padding: 6px 10px; }
.state { font-weight: 600; color: var(--purple-deep); }

.calm { display: grid; justify-items: center; gap: 16px; padding: 64px 16px; color: var(--muted); }
.calm .mark { width: 64px; height: 64px; border-radius: 50%; background: var(--lime); display: grid; place-items: center; color: #342675; box-shadow: 0 4px 0 var(--lime-edge); }
.calm .mark svg { width: 28px; height: 28px; stroke-width: 2.5; }

.panel { margin-top: 16px; background: var(--card); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); display: grid; gap: 20px; }
.panel h2 { margin: 0 0 8px; font-size: var(--body); }
.panel .src { display: grid; gap: 8px; }
.panel .src .name { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.panel .src .state { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.panel .src .state.ok { background: var(--purple); }
.panel .src .state.error { background: var(--danger); }
.panel .note { color: var(--muted); font-size: var(--small); }
.panel .note.error { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; transition: opacity 0.2s ease-out, transform 0.2s ease-out; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .tabs { order: 2; width: 100%; flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .detail, .panel { padding: 20px 16px; border-radius: 20px; }
  .targets .label { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Каталог источника и подключение. */
.filter { width: 100%; border: 0; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 16px; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 14px; text-align: left; }
.pick:hover { background: var(--field); }
.pick .box { width: 22px; height: 22px; border-radius: 7px; box-shadow: inset 0 0 0 2px var(--faint); flex-shrink: 0; display: grid; place-items: center; color: transparent; }
.pick[aria-pressed="true"] .box { background: var(--purple); box-shadow: none; color: #fff; }
.pick .box svg { width: 14px; height: 14px; stroke-width: 3; }
.pick .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .meta { color: var(--muted); font-size: var(--small); flex-shrink: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section .note { margin: 0 0 8px 16px; color: var(--muted); font-size: var(--small); }
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 8px; padding: 0 4px; }
.foot .status { color: var(--muted); font-size: var(--small); }
.foot .status.error { color: var(--danger); }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; color: var(--muted); font-size: var(--small); }
.form input { width: 100%; border: 0; border-radius: 14px; background: var(--field); padding: 12px 14px; color: var(--ink); font-size: var(--body); }
.form .hint { color: var(--muted); font-size: var(--small); }
.file { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px; border-radius: 14px; text-decoration: none; }
a.file:hover { background: var(--field); }
.file .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .when { color: var(--muted); font-size: var(--small); }

/* Склад «всё из API». */
.raw-item + .raw-item { border-top: 1px solid var(--grey-soft); }
.raw-item.open { background: var(--field); border-radius: 14px; }
.raw-kv { display: grid; gap: 6px 12px; margin: 0; padding: 4px 12px 16px; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr); font-size: var(--small); }
.raw-kv > span:nth-child(odd) { color: var(--muted); font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
.raw-kv > span:nth-child(even) { overflow-wrap: anywhere; white-space: pre-wrap; }
.raw-json { margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--card); font: 0.75rem/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; }

/* Рассылка. */
.bc-text { width: 100%; min-height: 140px; border: 0; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); padding: 14px 16px; resize: vertical; line-height: 1.5; }
.bc-chips { padding: 0 4px; }
.bc-target { text-align: left; font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bc-target b { font-weight: 800; margin-right: 4px; }
.bc-aud { opacity: 0.7; font-size: var(--small); }
.section h2 .add-pin { font-weight: 600; }
