/* Design system. Light by default, dark follows the OS or the toggle. */

:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --sunken: #eeece7;
  --line: #e4e1d9;
  --line-strong: #d2cec3;
  --ink: #16171b;
  --ink-2: #3c3f47;
  --muted: #6d7079;
  --faint: #9b9da3;
  --accent: #2b50d8;
  --accent-hover: #2445c0;
  --accent-ink: #ffffff;
  --accent-soft: #e9eefd;
  --ok: #157a52;
  --ok-soft: #e2f2e9;
  --warn: #9a5b0b;
  --warn-soft: #faefdb;
  --bad: #bf3429;
  --bad-soft: #fbe6e3;
  --banner: #b0510f;
  --banner-soft: #fbeadb;
  --textv: #3554b5;
  --textv-soft: #e7ecfa;
  --bubble: #effdde;
  --chat-bg: #d9e4c8;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(22, 23, 27, 0.04), 0 6px 20px rgba(22, 23, 27, 0.05);
  --shadow-pop: 0 18px 50px rgba(22, 23, 27, 0.18);
  --font: "Golos Text", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --side-w: 240px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f11;
    --surface: #16171a;
    --surface-2: #1b1c20;
    --sunken: #111214;
    --line: #26282d;
    --line-strong: #34373d;
    --ink: #ececee;
    --ink-2: #c5c7cd;
    --muted: #8e9199;
    --faint: #60636a;
    --accent: #7390ff;
    --accent-hover: #8aa2ff;
    --accent-ink: #0b0f26;
    --accent-soft: #1b2242;
    --ok: #4cc38a;
    --ok-soft: #13281e;
    --warn: #e2a64c;
    --warn-soft: #2b2213;
    --bad: #f07a70;
    --bad-soft: #2e1715;
    --banner: #f0a465;
    --banner-soft: #2c1e12;
    --textv: #93a9ff;
    --textv-soft: #1a2140;
    --bubble: #2b5278;
    --chat-bg: #0f1a24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-pop: 0 18px 50px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f11;
  --surface: #16171a;
  --surface-2: #1b1c20;
  --sunken: #111214;
  --line: #26282d;
  --line-strong: #34373d;
  --ink: #ececee;
  --ink-2: #c5c7cd;
  --muted: #8e9199;
  --faint: #60636a;
  --accent: #7390ff;
  --accent-hover: #8aa2ff;
  --accent-ink: #0b0f26;
  --accent-soft: #1b2242;
  --ok: #4cc38a;
  --ok-soft: #13281e;
  --warn: #e2a64c;
  --warn-soft: #2b2213;
  --bad: #f07a70;
  --bad-soft: #2e1715;
  --banner: #f0a465;
  --banner-soft: #2c1e12;
  --textv: #93a9ff;
  --textv-soft: #1a2140;
  --bubble: #2b5278;
  --chat-bg: #0f1a24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-pop: 0 18px 50px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- base */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 0;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.012em; }
h1 { font-size: 1.5rem; line-height: 1.25; }
h2 { font-size: 1.02rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
.mono { font-family: var(--mono); font-size: 0.86em; letter-spacing: -0.01em; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }
.hidden, [hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i-lg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- layout */

.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.main { padding: 28px 36px 72px; max-width: 1240px; width: 100%; min-width: 0; }

.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 14px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}
.brand {
  display: inline-flex; align-items: baseline; gap: 1px;
  font-weight: 700; font-size: 1.32rem; letter-spacing: -0.04em;
  color: var(--ink); padding: 0 10px 18px;
}
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); font-weight: 700; }
.side-nav { display: grid; gap: 2px; }
.side-label { font-size: 0.75rem; color: var(--faint); padding: 14px 10px 6px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--ink-2); font-weight: 500; font-size: 0.93rem;
}
.side-nav a:hover { background: var(--sunken); text-decoration: none; color: var(--ink); }
.side-nav a.on { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.side-nav a.on .i { color: var(--accent); }
.side-nav .count { margin-left: auto; font-size: 0.75rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 0.82rem; text-transform: uppercase;
}
.me b { display: block; font-size: 0.88rem; font-weight: 600; line-height: 1.2; }
.me span { font-size: 0.76rem; color: var(--muted); }
.side-foot .link-row {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%;
  height: 34px; padding: 0 10px; border-radius: 8px; border: 0; background: none;
  color: var(--muted); font: inherit; font-size: 0.86rem; font-weight: 500; cursor: pointer; text-align: left;
}
.side-foot .link-row:hover { background: var(--sunken); color: var(--ink); text-decoration: none; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 22px; flex-wrap: wrap;
}
.page-head .sub { color: var(--muted); margin-top: 5px; font-size: 0.93rem; }
.crumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.mbar { display: none; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 0.86rem; margin-top: 3px; }
.card.flat { box-shadow: none; }
.card.tight { padding: 14px 16px; }

.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.stack { display: grid; gap: 14px; align-content: start; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.sep { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k { font-size: 0.84rem; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi .v { font-size: 1.85rem; font-weight: 600; letter-spacing: -0.03em; margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .v small { font-size: 0.95rem; color: var(--faint); font-weight: 500; letter-spacing: 0; }
.kpi .m { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }
.kpi .bar { margin-top: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: 0 0 auto; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }
.dot.accent { background: var(--accent); }

.bar { height: 6px; border-radius: 99px; background: var(--sunken); overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.ok { background: var(--ok); }
.bar > i.bad { background: var(--bad); }
.bar > i.warn { background: var(--warn); }
.bar.thin { height: 4px; }

/* ---------------------------------------------------------------- controls */

button, .btn {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 0.92rem; font-weight: 600; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.secondary, .btn.secondary {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong);
}
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); border-color: var(--faint); }
button.ghost, .btn.ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
button.ghost:hover, .btn.ghost:hover { background: var(--sunken); color: var(--ink); }
button.danger, .btn.danger { background: var(--surface); color: var(--bad); border-color: var(--line-strong); }
button.danger:hover, .btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
button.stop, .btn.stop { background: var(--ink); color: var(--surface); }
button.stop:hover { background: var(--ink-2); }
button.sm, .btn.sm { height: 32px; padding: 0 11px; font-size: 0.85rem; border-radius: 8px; }
button.xs, .btn.xs { height: 28px; padding: 0 9px; font-size: 0.8rem; border-radius: 7px; }
button.icon, .btn.icon { width: 34px; padding: 0; }
button:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; }

label, .label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.field { margin-bottom: 14px; min-width: 0; }
.field .help { font-size: 0.8rem; color: var(--muted); margin-top: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 0.94rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 9px 12px; min-height: 40px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
select { padding-right: 32px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
input[type="checkbox"] { width: 17px; height: 17px; min-height: 0; padding: 0; accent-color: var(--accent); }
input[type="file"] { padding: 7px; min-height: 0; background: var(--surface-2); }
.fields { display: grid; gap: 0 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ink-2); cursor: pointer; margin: 0; font-weight: 500; }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex; gap: 22px; border-bottom: 1px solid var(--line);
  margin: 0 0 20px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  position: relative; padding: 10px 0 12px; white-space: nowrap;
  color: var(--muted); font-weight: 500; font-size: 0.93rem;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); }
.tabs a.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--ink); border-radius: 2px; }
.tabs .n { margin-left: 6px; font-size: 0.76rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/* segmented */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunken); border-radius: 10px; }
.seg a, .seg button {
  height: 30px; padding: 0 12px; border-radius: 8px; border: 0; background: transparent;
  color: var(--muted); font-weight: 500; font-size: 0.86rem; display: inline-flex; align-items: center;
}
.seg a:hover, .seg button:hover { color: var(--ink); text-decoration: none; background: transparent; }
.seg .on, .seg .active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------------------------------------------------------------- status */

.st {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.82rem; font-weight: 500; color: var(--ink-2); white-space: nowrap;
}
.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.st.pending::before { background: var(--line-strong); }
.st.assigned::before { background: var(--warn); }
.st.sent::before { background: var(--accent); }
.st.delivered::before { background: var(--ok); }
.st.failed { color: var(--bad); }
.st.failed::before { background: var(--bad); }
.st.skipped::before { background: var(--faint); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border-radius: 99px; font-size: 0.78rem; font-weight: 600;
  background: var(--sunken); color: var(--ink-2); white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.tag {
  display: inline-flex; align-items: center; height: 21px; padding: 0 7px; border-radius: 6px;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.01em;
}
.tag.banner { background: var(--banner-soft); color: var(--banner); }
.tag.text { background: var(--textv-soft); color: var(--textv); }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left; font-weight: 500; font-size: 0.8rem; color: var(--muted);
  padding: 0 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; }
.table .sub { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.table .reason { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 3px; max-width: 260px; }
.table .user { font-family: var(--mono); font-size: 0.86rem; font-weight: 500; }

/* ---------------------------------------------------------------- alerts / notes */

.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 10px; font-size: 0.9rem;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
}
.alert .i { margin-top: 2px; }
.alert.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.alert.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.alert.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.alert.info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert b { font-weight: 600; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 0.92rem; }
.empty .i { width: 28px; height: 28px; color: var(--faint); margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 0.84rem; line-height: 1.55; }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 0.9rem; line-height: 1.7; }
.kbd { font-family: var(--mono); font-size: 0.74rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--ink-2); background: var(--surface); }

/* ---------------------------------------------------------------- lists */

.list { display: grid; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--line); min-width: 0;
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item .meta { font-size: 0.84rem; color: var(--muted); margin-top: 2px; }
a.list-item { color: inherit; }
a.list-item:hover { text-decoration: none; }
a.list-item:hover .title { color: var(--accent); }

.camp {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 24px; align-items: center;
  padding: 18px 20px; color: inherit;
}
.camp:hover { text-decoration: none; border-color: var(--line-strong); }
.camp:hover h3 { color: var(--accent); }
.camp h3 { font-size: 1.04rem; }
.camp .meta { font-size: 0.85rem; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.camp .nums { display: flex; gap: 22px; text-align: right; }
.camp .nums b { display: block; font-size: 1.2rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.camp .nums span { font-size: 0.78rem; color: var(--muted); }
.camp .bar { grid-column: 1 / -1; }

/* ---------------------------------------------------------------- accounts */

.acc { display: flex; gap: 14px; align-items: flex-start; padding: 16px 0; border-bottom: 1px solid var(--line); }
.acc:last-child { border-bottom: 0; }
.acc .grow { flex: 1; min-width: 0; }
.acc .name { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.acc .meta { font-size: 0.84rem; color: var(--muted); margin-top: 2px; }
.acc .work { font-size: 0.8rem; color: var(--muted); margin-top: 6px; font-family: var(--mono); }
.acc .err { font-size: 0.82rem; color: var(--bad); margin-top: 6px; }
.acc .limit { width: 140px; flex: 0 0 auto; font-size: 0.82rem; color: var(--muted); }
.acc .limit b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.acc .limit .bar { margin-top: 6px; }
.acc .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
details.edit > summary { list-style: none; cursor: pointer; }
details.edit > summary::-webkit-details-marker { display: none; }
details.edit[open] > summary { color: var(--ink); }
.edit-panel { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }

/* ---------------------------------------------------------------- creatives */

.creatives { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.creative { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.creative.off { opacity: .55; }
.creative .thumb { aspect-ratio: 1 / 1; background: var(--sunken); display: block; }
.creative .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.creative .body { padding: 10px 12px 12px; display: grid; gap: 8px; }
.creative .title-input { border: 0; padding: 0; min-height: 0; height: auto; font-weight: 600; background: transparent; border-radius: 4px; }
.creative .title-input:focus { box-shadow: none; outline: 1px dashed var(--line-strong); outline-offset: 2px; }
.creative .stats { display: flex; gap: 12px; font-size: 0.8rem; color: var(--muted); }
.creative .stats b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.drop {
  border: 1.5px dashed var(--line-strong); border-radius: 12px; min-height: 100%;
  display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted);
  background: var(--surface-2); cursor: pointer; aspect-ratio: auto; transition: border-color .12s, background .12s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop input { display: none; }
.drop b { display: block; color: var(--ink); margin: 6px 0 2px; font-weight: 600; }

/* telegram-like preview */
.tg-preview { background: var(--chat-bg); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.bubble {
  max-width: 340px; background: var(--bubble); border-radius: 14px 14px 14px 4px;
  padding: 8px 11px 6px; font-size: 0.9rem; line-height: 1.42; color: var(--ink);
  box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.media { padding: 3px 3px 6px; }
.bubble.media img { width: 100%; border-radius: 11px 11px 4px 4px; display: block; aspect-ratio: 1; object-fit: cover; background: var(--sunken); }
.bubble.media .cap { padding: 6px 8px 0; }
.bubble .lnk { color: #1d6fd1; }
:root[data-theme="dark"] .bubble .lnk { color: #7cc0ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bubble .lnk { color: #7cc0ff; } }
.bubble time { display: block; text-align: right; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

/* UTM */
.utm { border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--surface-2); }
.utm + .utm { margin-top: 8px; }
.utm .link { font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; color: var(--ink-2); margin-top: 6px; }
.utm-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.utm-tags span { font-family: var(--mono); font-size: 0.72rem; padding: 2px 7px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.utm-tags b { color: var(--ink); font-weight: 500; }
.utm .warn-line { color: var(--bad); font-size: 0.82rem; margin-top: 6px; }

/* day chart */
.days { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; overflow-x: auto; }
.days .d { flex: 1 0 26px; max-width: 54px; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.days .col { width: 100%; display: flex; flex-direction: column-reverse; border-radius: 5px 5px 2px 2px; overflow: hidden; min-height: 2px; background: var(--sunken); }
.days .col i { display: block; width: 100%; }
.days .col i.b { background: var(--banner); }
.days .col i.t { background: var(--textv); }
.days .d span { font-size: 0.7rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.days .d em { font-style: normal; font-size: 0.74rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* workers */
.workers { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 14px; }
.worker { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 0.84rem; background: var(--surface-2); }
.worker .wl { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; align-items: center; }
.worker .ws { font-weight: 500; color: var(--muted); font-size: 0.8rem; display: inline-flex; align-items: center; gap: 6px; }
.worker .wd { color: var(--muted); margin-top: 4px; font-size: 0.8rem; }
.worker .we { color: var(--bad); margin-top: 4px; font-size: 0.78rem; }
.wdot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--faint); }
.wdot.sending, .wdot.waiting { background: var(--ok); }
.wdot.flood, .wdot.paused, .wdot.limit, .wdot.off_hours { background: var(--warn); }
.wdot.error, .wdot.stopped { background: var(--bad); }

/* queue (manual mode) */
.queue-card { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; background: var(--surface); transition: opacity .15s; }
.queue-card .user { font-family: var(--mono); font-weight: 600; font-size: 0.9rem; }
.queue-card .meta { color: var(--muted); font-size: 0.8rem; margin: 3px 0 10px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msg-box { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 0.86rem; color: var(--ink-2); }
.queue-banner-img { width: 100%; max-height: 180px; object-fit: contain; border-radius: 10px; background: var(--sunken); margin-bottom: 8px; display: block; }

/* events */
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--faint); font-family: var(--mono); font-size: 0.76rem; padding-top: 2px; }
.events .kind { color: var(--muted); }

/* pager */
.pager { display: flex; gap: 6px; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; font-size: 0.86rem; color: var(--muted); }

/* setup / onboarding */
.onboard { display: flex; gap: 18px; align-items: flex-start; }
.onboard .num-step {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 600; font-size: 0.9rem;
  background: var(--ink); color: var(--surface);
}
.onboard .grow { flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- dialogs */

.modal {
  width: min(430px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink); padding: 20px; box-shadow: var(--shadow-pop);
}
.modal::backdrop { background: rgba(10, 11, 14, 0.45); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.modal-head h2 { font-size: 1.12rem; }
.modal-head p { color: var(--muted); font-size: 0.86rem; margin-top: 3px; }
.modal .seg { display: flex; margin-bottom: 16px; }
.modal .seg button { flex: 1; justify-content: center; }
.qr-box { width: 236px; height: 236px; margin: 0 auto; border-radius: 16px; background: #fff; padding: 12px; display: grid; place-items: center; border: 1px solid var(--line); }
.qr-box svg { width: 100%; height: 100%; display: block; }
.qr-box svg path { fill: #111; }
.qr-placeholder { color: #8a8d93; font-size: 0.86rem; }
.qr-refresh { background: #111; color: #fff; }
.qr-timer { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 10px 0 12px; min-height: 1.2em; font-variant-numeric: tabular-nums; }
.login-error { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.86rem; background: var(--bad-soft); color: var(--bad); }
.done-mark { width: 60px; height: 60px; margin: 6px auto 0; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.done-mark .i { width: 28px; height: 28px; stroke-width: 2.4; }
.login-pane[hidden], form[hidden] { display: none; }

.sheet {
  margin: auto 0 0; width: 100%; max-width: 100%; border: 0; padding: 8px 12px calc(14px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop);
}
.sheet::backdrop { background: rgba(10, 11, 14, 0.4); }
.sheet .grab { width: 38px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 4px auto 10px; }
.sheet a, .sheet button.sheet-item {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 50px; padding: 0 12px;
  border-radius: 10px; color: var(--ink); font-weight: 500; font-size: 0.98rem;
  background: none; border: 0; justify-content: flex-start;
}
.sheet a:hover, .sheet button.sheet-item:hover { background: var(--sunken); text-decoration: none; }
.sheet .i { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 10px);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  font-size: 0.9rem; font-weight: 500; box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none; transition: .18s ease; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- auth pages */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { padding: 0 0 22px; font-size: 1.6rem; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 20px; font-size: 0.92rem; }
.auth-foot { margin-top: 18px; font-size: 0.82rem; color: var(--faint); text-align: center; }

/* credentials box */
.creds { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 12px; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--ok-soft); color: var(--ink); margin-bottom: 16px; }
.creds .k { color: var(--muted); font-size: 0.85rem; }
.creds .v { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- client portal */

.portal-top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.portal-top .in { max-width: 1100px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 14px; }
.portal-top .brand { padding: 0; font-size: 1.15rem; }
.portal-top .who { font-size: 0.86rem; color: var(--muted); }
.portal { max-width: 1100px; margin: 0 auto; padding: 28px 24px 64px; }
.portal-hero { margin-bottom: 20px; }
.portal-hero .eyebrow { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.preview-note { background: var(--accent-soft); color: var(--accent); font-size: 0.86rem; padding: 9px 24px; text-align: center; }

/* ---------------------------------------------------------------- mobile */

.tabbar { display: none; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-main { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 14px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
  .mbar {
    display: flex; align-items: center; justify-content: space-between;
    margin: -2px 0 14px; min-height: 36px;
  }
  .mbar .brand { padding: 0; font-size: 1.15rem; }
  .page-head { margin-bottom: 16px; align-items: flex-start; }
  h1 { font-size: 1.32rem; }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; border-radius: 13px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 6px 6px env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.5) blur(14px); -webkit-backdrop-filter: saturate(1.5) blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    height: 50px; padding: 0; margin: 0; border: 0; border-radius: 12px; background: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font: inherit; font-size: 0.68rem; font-weight: 500; letter-spacing: 0.01em;
    position: relative;
  }
  .tabbar a:hover, .tabbar button:hover { text-decoration: none; background: none; color: var(--ink); }
  .tabbar .i { width: 23px; height: 23px; stroke-width: 1.7; }
  .tabbar .on { color: var(--accent); }
  .tabbar .on::before { content: ""; position: absolute; top: -6px; width: 22px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .tabs { position: sticky; top: 0; z-index: 15; background: var(--bg); margin-left: -16px; margin-right: -16px; padding: 0 16px; gap: 20px; }
  .toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .acc { flex-wrap: wrap; }
  .acc .limit { width: 100%; order: 3; }
  .acc .actions { width: 100%; justify-content: flex-start; order: 4; }
  .camp { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .camp .nums { text-align: left; }
  .events li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .portal-top .in, .portal { padding-left: 16px; padding-right: 16px; }
  .portal { padding-top: 18px; }
}

@media (max-width: 640px) {
  .kpi { padding: 14px; }
  .kpi .v { font-size: 1.5rem; }
  .head-actions { width: 100%; }
  .head-actions > * { flex: 1 1 auto; }
  .head-actions > form { display: flex; }
  .head-actions > form > button { flex: 1; }
  /* tables become cards */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { padding: 0 !important; border: 0; }
  .table.stack td[data-label]::before { content: attr(data-label) " "; color: var(--faint); font-size: 0.78rem; }
  .table.stack td.full { grid-column: 1 / -1; }
  .table.stack td.end { text-align: right; }
  .table.stack td.hide-sm { display: none !important; }
  .table.stack td[data-label] { display: flex; justify-content: space-between; gap: 10px; grid-column: 1 / -1; }
  .table.stack td[data-label]::before { content: attr(data-label); }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
  .filters select, .filters button { width: 100%; }
  .bulk { display: none; }
  .table.stack tbody tr:hover td { background: none; }
}
@media (max-width: 480px) { .hide-xs { display: none; } }

/* account avatars + profile dialog */
img.avatar { object-fit: cover; background: var(--sunken); padding: 0; }
.avatar.lg { width: 40px; height: 40px; font-size: 0.95rem; }
.prof-photo { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.prof-ava {
  width: 84px; height: 84px; border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 1.8rem; text-transform: uppercase; position: relative;
}
.prof-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prof-ava.removing::after {
  content: "будет убрано"; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(10, 11, 14, 0.62); color: #fff; font-size: 0.72rem; font-weight: 600; text-transform: none;
}
.prefixed { display: flex; align-items: stretch; }
.prefixed span {
  display: grid; place-items: center; padding: 0 11px; border: 1px solid var(--line-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface-2); color: var(--muted);
}
.prefixed input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.prefixed.pw input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.prefixed.pw button { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; height: auto; border-left: 0; }
.modal.wide { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto; }
.prof-photo-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.prof-sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; margin-bottom: 14px; }
.prof-sec h3 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; max-height: 176px; overflow-y: auto; }
.emoji-grid button {
  height: 40px; padding: 0; font-size: 1.25rem; background: var(--surface-2); color: var(--ink);
  border: 1px solid transparent; border-radius: 9px; font-weight: 400;
}
.emoji-grid button:hover { background: var(--sunken); }
.emoji-grid button.on { border-color: var(--accent); background: var(--accent-soft); }
.emoji-grid button.none { font-size: 0.72rem; color: var(--muted); }
.gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; margin: -6px 0 16px; max-height: 240px; overflow-y: auto; }
.gif-grid button { height: auto; aspect-ratio: 1; padding: 0; overflow: hidden; background: var(--sunken); border: 2px solid transparent; border-radius: 10px; }
.gif-grid button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-grid button.on { border-color: var(--accent); }
.gif-grid .empty { grid-column: 1 / -1; padding: 14px; }
.prof-ava .badge-gif { position: absolute; bottom: 4px; right: 4px; background: var(--ink); color: var(--surface); font-size: 0.62rem; font-weight: 700; padding: 1px 5px; border-radius: 5px; }

/* message templates */
.seg label.check { color: var(--muted); border-radius: 8px; cursor: pointer; font-weight: 500; }
.seg label.check.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ranges { display: flex; flex-wrap: wrap; gap: 8px; }
.range { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 0.86rem; }
.range .rn { padding: 6px 10px; background: var(--sunken); font-variant-numeric: tabular-nums; font-weight: 600; }
.range .rt { padding: 6px 10px; }
.tpl { margin-top: 14px; }
.tpl.off { opacity: .6; }
.tpl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tpl-num { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--ink); color: var(--surface); font-weight: 700; font-size: 0.85rem; flex: 0 0 auto; }
.tpl-name { flex: 1 1 200px; border: 0; padding: 4px 6px; min-height: 0; font-size: 1.05rem; font-weight: 600; background: transparent; }
.tpl-name:focus { box-shadow: none; outline: 1px dashed var(--line-strong); }
.tpl-images { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.tpl-foot { display: flex; gap: 4px; align-items: center; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.small-thumbs { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.days .col i.r { background: var(--ok); }
.days .col i.s { background: var(--accent); }

/* subscriptions */
.acc-pick { display: grid; gap: 6px; max-height: 220px; overflow: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.sub-item { border-bottom: 1px solid var(--line); }
.sub-item:last-child { border-bottom: 0; }
.sub-item > summary { list-style: none; display: flex; gap: 14px; align-items: center; padding: 14px 0; cursor: pointer; flex-wrap: wrap; }
.sub-item > summary::-webkit-details-marker { display: none; }
.sub-item .grow { flex: 1 1 220px; min-width: 0; }
.sub-item .title { font-weight: 600; }
.sub-item .meta { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }
.sub-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.sub-body { padding: 0 0 16px; }
.sub-body .table { width: 100%; }
.sub-body .table td:first-child { width: 34%; }

/* chat with a bot (@SpamBot appeals) */
.chat { background: var(--chat-bg); border-radius: 12px; padding: 12px; height: min(46vh, 380px); overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat .bubble { max-width: 85%; }
.chat .bubble.out { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--accent-soft); }
.chat .bubble time { font-size: 0.68rem; }
.bot-keys { display: grid; gap: 6px; margin-top: 10px; }
.bot-keys .krow { display: flex; gap: 6px; }
.bot-keys button { flex: 1; height: auto; min-height: 36px; padding: 8px 10px; white-space: normal; line-height: 1.25; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-input textarea { min-height: 44px; resize: vertical; }
.chat-input button { width: 48px; height: 44px; padding: 0; }
.chip-btn { border: 0; cursor: pointer; height: 24px; font: inherit; font-size: 0.78rem; font-weight: 600; }
.chip-btn:hover { filter: brightness(0.97); background: var(--bad-soft); }

/* developer credit */
.credit { text-align: center; font-size: 0.8rem; color: var(--faint); padding: 28px 0 4px; }
.credit a { color: var(--muted); font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--line-strong); }
.credit a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.auth .credit { padding-top: 10px; }
