/* Дизайн-система з макета «Multigram — дизайн»:
   темний сайдбар, світлий теплий фон, білі картки, фіолетовий акцент, Inter. */
:root {
  --bg: #F7F7F5;
  --panel: #FFFFFF;
  --text: #1C1B1A;
  --text-2: #44413B;
  --muted: #8A8781;
  --muted-2: #78756F;
  --faint: #B9B6AF;
  --border: #EDEBE6;
  --border-2: #E5E3DE;
  --row-line: #F0EEE9;
  --hover: #FAFAF9;
  --soft: #F1F0ED;

  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-soft: #EEF2FF;
  --accent-tint: #F5F4FF;
  --accent-disabled: #C7C4F5;

  --side: #15161A;
  --side-active: #23242B;
  --side-line: #2A2B33;
  --side-text: #AEB0B8;
  --side-muted: #8A8DA0;

  --ok-bg: #ECFDF3;  --ok: #15803D;  --ok-dot: #DCFCE7; --ok-line: #A7F3D0;
  --warn-bg: #FEF3C7; --warn: #92400E;
  --orange-bg: #FFF7ED; --orange: #C2410C; --orange-line: #FED7AA;
  --err-bg: #FEF2F2; --err: #DC2626;
  --neutral-bg: #F1F0ED; --neutral: #57534E;

  --radius: 12px;
  --side-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { color: var(--accent-hover); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--soft); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
h2 { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 14px; }

/* ---------- Форми та кнопки ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: #fff;
  border: 1px solid var(--border-2); border-radius: 8px; padding: 10px 12px; min-width: 0;
}
select { padding-right: 30px; }
textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 8px; padding: 10px 16px; cursor: pointer; white-space: nowrap; border: 1px solid transparent; transition: background .12s, border-color .12s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--accent-disabled); cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border-2); font-weight: 500; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 7px; font-weight: 600; }
.btn-danger { color: var(--err); }
.btn-danger:hover { border-color: var(--err); color: var(--err); }
.btn-block { width: 100%; }
.error { color: var(--err); font-size: 13px; min-height: 1em; margin: 8px 0 0; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 20px 22px; }
.note { padding: 12px 14px; border-radius: 8px; font-size: 12px; line-height: 1.5; background: var(--soft); color: var(--muted-2); }
.note.warn { background: var(--orange-bg); color: var(--warn); border: 1px solid var(--orange-line); }
.note.amber { background: #FFFBEB; color: var(--warn); border: 1px solid #FDE68A; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.dim { background: var(--neutral-bg); color: var(--muted-2); }

.avatar { width: 34px; height: 34px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; text-transform: uppercase; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.orange { background: var(--orange-bg); color: var(--orange); }
.avatar.red { background: var(--err-bg); color: var(--err); }
.avatar.grey { background: var(--soft); color: var(--muted); }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Вхід ---------- */
.login { display: flex; min-height: 100vh; background: #fff; }
.login-hero { flex: 1.2 1 480px; min-width: 0; background: var(--side); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-hero::before { content: ""; position: absolute; inset: 0; background: radial-gradient(600px 400px at 80% 10%, rgba(79,70,229,.35), transparent); }
.login-hero > * { position: relative; }
.login-hero h1 { font-size: 34px; line-height: 1.25; margin: 0 0 16px; max-width: 420px; }
.login-hero p { color: var(--side-text); font-size: 15px; line-height: 1.6; max-width: 420px; margin: 0; }
.login-hero .foot { color: #6C6F7E; font-size: 13px; }
.login-form-wrap { flex: 1 1 480px; min-width: 0; display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-form h2 { font-size: 22px; margin: 0; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: #fff; }
.logo-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); flex-shrink: 0; }

/* ---------- Каркас ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); flex-shrink: 0; background: var(--side); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 30; }
.sidebar .logo { padding: 8px 10px 20px; }
.navitem { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 8px; font-size: 14px; color: var(--side-text); cursor: pointer; user-select: none; }
.navitem:hover { color: #fff; }
.navitem.active { background: var(--side-active); color: #fff; }
.navitem .ico { width: 18px; text-align: center; opacity: .85; }
.side-foot { margin-top: auto; border-top: 1px solid var(--side-line); padding: 12px 10px 0; display: flex; flex-direction: column; gap: 10px; }
.side-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-user .avatar { background: var(--side-line); color: #C9CBD1; }
.side-user .n { color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .r { color: var(--side-muted); font-size: 12px; }
.health { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--side-muted); }
.health .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--side-muted); }
.health.ok .dot { background: #22C55E; } .health.bad .dot { background: #EF4444; }
.side-logout { background: transparent; border: 1px solid var(--side-line); color: var(--side-text); }
.side-logout:hover { color: #fff; border-color: #3a3c46; }

.topbar { display: none; }
.scrim { display: none; }

.main { flex: 1 1 auto; min-width: 0; padding: 32px 40px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar > * { width: auto; }
.toolbar input { flex: 1 1 220px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpis { margin-top: 28px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kpi .l { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.kpi .v { font-size: 26px; font-weight: 700; }

/* ---------- Таблиці ---------- */
.table-card { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 14px 16px; border-bottom: 1px solid var(--row-line); font-size: 14px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Підключення акаунта (кроки) ---------- */
.wizard { max-width: 520px; margin: 0 auto; padding: 32px; }
.wizard .who { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.steps { display: flex; align-items: center; gap: 10px; margin: 24px 0 8px; }
.steps .dot { width: 28px; height: 28px; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; background: var(--soft); color: var(--muted); }
.steps .dot.active { background: var(--accent); color: #fff; }
.steps .dot.done { background: var(--ok-dot); color: var(--ok); }
.steps .line { flex: 1; height: 1px; background: var(--border-2); min-width: 20px; }
.steps .line.done { background: var(--ok-line); }
.step-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 24px; }
.step-labels .on { color: var(--accent); font-weight: 600; }
.choice { display: block; border: 2px solid var(--border-2); border-radius: 12px; padding: 18px 18px 18px 54px; position: relative; cursor: pointer; margin-bottom: 12px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .radio { position: absolute; left: 18px; top: 19px; width: 18px; height: 18px; border-radius: 999px; border: 2px solid var(--accent-disabled); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.choice:has(input:checked) .radio { border-color: var(--accent); }
.choice:has(input:checked) .radio::after { content: ""; display: block; width: 8px; height: 8px; background: var(--accent); border-radius: 999px; margin: 3px; }
.choice-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.choice-desc { font-size: 12px; color: var(--muted-2); line-height: 1.5; }
.qr-wrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.qr { background: #fff; padding: 10px; border: 1px solid var(--border); border-radius: 12px; width: 222px; height: 222px; flex-shrink: 0; }
.qr-steps { margin: 0; padding-left: 18px; color: var(--muted-2); font-size: 13px; line-height: 1.7; }

/* ---------- Чати ---------- */
.chat-layout { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
.chat-list { overflow-y: auto; }
.chatrow { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--row-line); cursor: pointer; }
.chatrow:hover { background: var(--hover); }
.chatrow.active { background: var(--accent-tint); }
.chatrow .body { flex: 1; min-width: 0; }
.chatrow .t { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatrow .l { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatrow .side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.chatrow .time { color: var(--muted); font-size: 12px; }
.unread { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.unread.muted-pill { background: var(--soft); color: var(--muted-2); }

.conv { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.conv-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.conv-head .back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 62%; padding: 9px 13px; border-radius: 12px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.in { background: var(--soft); color: var(--text); align-self: flex-start; }
.bubble.out { background: var(--accent); color: #fff; align-self: flex-end; }
.bubble.out.byadmin { background: var(--orange); }
.bubble .who { font-size: 11px; font-weight: 700; margin-bottom: 2px; color: var(--accent); }
.bubble .meta { font-size: 10px; opacity: .7; margin-top: 4px; }
.day-sep { align-self: center; font-size: 11px; color: var(--side-text); margin: 4px 0; }
.as-other { padding: 10px 14px; background: var(--orange-bg); border-top: 1px solid #FDE9D0; font-size: 12px; color: var(--orange); }
.composer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 46px; resize: none; border-radius: 10px; }
.conv-empty { margin: auto; color: var(--muted); text-align: center; padding: 24px; }

/* ---------- Кампанії ---------- */
.campcard { padding: 18px 20px; border-bottom: 1px solid var(--row-line); }
.campcard:last-child { border-bottom: 0; }
.campcard .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.campcard .ttl { font-weight: 700; font-size: 15px; }
.progress-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.progressbar { height: 6px; border-radius: 999px; background: var(--soft); overflow: hidden; flex: 1; }
.progressfill { height: 100%; background: var(--accent); }
.campcard .bottom { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.campcard .stats { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--soft); border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.seg label { padding: 8px 16px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted-2); cursor: pointer; }
.seg input { display: none; }
.seg label:has(input:checked) { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.aud-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.aud { border: 1.5px solid var(--border-2); border-radius: 10px; padding: 14px 16px; cursor: pointer; display: block; }
.aud input { display: none; }
.aud .t { font-weight: 600; font-size: 14px; }
.aud .d { font-size: 12px; color: var(--muted); }
.aud:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.aud:has(input:checked) .d { color: var(--accent); }
.aud.disabled { opacity: .5; cursor: not-allowed; }
.new-camp { display: flex; flex-wrap: wrap; gap: 28px; }
.new-camp .form-col { flex: 1.6 1 480px; min-width: 0; }
.new-camp .side-col { flex: 1 1 300px; min-width: 0; }
.preview { background: #E9EBF0; padding: 20px; }
.preview .pb { background: #fff; border-radius: 14px 14px 14px 4px; padding: 10px 14px; font-size: 14px; line-height: 1.45; max-width: 280px; box-shadow: 0 1px 2px rgba(0,0,0,.06); white-space: pre-wrap; overflow-wrap: anywhere; }
.kv { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; }
.pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.pick-list label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--row-line); cursor: pointer; }
.pick-list label:last-child { border-bottom: 0; }

/* ---------- Ліміти ---------- */
.pills { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; font-size: 13px; color: var(--muted-2); flex-wrap: wrap; }
.pill { padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--soft); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.tabs { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted-2); cursor: pointer; }
.tab.active { background: var(--text); color: #fff; }
.num { display: inline-block; min-width: 56px; padding: 6px 8px; border: 1px solid var(--border-2); border-radius: 6px; font-size: 13px; text-align: center; }
.switch { width: 38px; height: 22px; border-radius: 999px; background: var(--border-2); position: relative; display: inline-block; vertical-align: middle; }
.switch.on { background: var(--accent); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 999px; background: #fff; transition: left .15s; }
.switch.on::after { left: 18px; }

/* ---------- Тост ---------- */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 11px 16px; border-radius: 10px; max-width: min(420px, calc(100vw - 40px)); box-shadow: 0 8px 28px rgba(0,0,0,.18); z-index: 100; font-size: 13px; }
.toast.err { background: var(--err); }

/* =================== Адаптивність =================== */
@media (max-width: 1100px) {
  /* Таблиці → картки, поки колонки не влазять */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--row-line); }
  table.responsive tbody tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex-shrink: 0; }
  table.responsive td.lead { padding-bottom: 8px; }
  table.responsive td.lead::before, table.responsive td.actions::before { display: none; }
  table.responsive td.lead { justify-content: flex-start; text-align: left; }
  table.responsive td.actions { justify-content: flex-start; padding-top: 10px; flex-wrap: wrap; }
  .main { padding: 28px 24px; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
}

/* Планшет і менше: сайдбар стає висувною шухлядою, зверху — панель з кнопкою меню */
@media (max-width: 900px) {
  .app { display: block; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; background: var(--side); color: #fff; padding: 10px 16px; height: 56px; }
  .topbar .burger { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; padding: 6px 8px; margin-left: -8px; cursor: pointer; border-radius: 8px; }
  .topbar .burger:hover { background: var(--side-active); }
  .topbar .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: 100%; transform: translateX(-100%); transition: transform .2s ease; width: min(280px, 84vw); }
  .app.nav-open .sidebar { transform: none; box-shadow: 8px 0 24px rgba(0,0,0,.25); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(21,22,26,.45); z-index: 25; }
  .main { padding: 22px 20px; }
  .chat-layout { height: calc(100vh - 56px - 130px); }
}

/* Мобільний: таблиці → картки, чати → список/переписка по черзі */
@media (max-width: 680px) {
  h1 { font-size: 21px; }
  .main { padding: 18px 16px 28px; }
  .page-head { margin-bottom: 18px; }
  .page-head > .btn { width: 100%; }
  .toolbar > * { flex: 1 1 40%; }
  .toolbar > input { flex-basis: 100%; }
  .grid2, .aud-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; gap: 10px; margin-top: 18px; }
  .kpi { display: flex; justify-content: space-between; align-items: center; }
  .kpi .l { margin: 0; }
  .kpi .v { font-size: 20px; }

  table.scroll-x { display: block; overflow-x: auto; white-space: nowrap; }

  .chat-layout { display: block; height: auto; min-height: 0; }
  .chat-layout .chat-list { max-height: none; }
  .chat-layout.show-conv .chat-list { display: none; }
  .chat-layout:not(.show-conv) .conv { display: none; }
  .main.chat-open { padding: 10px 10px 10px; }
  .main.chat-open .page-head, .main.chat-open .toolbar, .main.chat-open .acc-switch { display: none; }
  .conv { height: calc(100vh - 56px - 20px); height: calc(100dvh - 56px - 20px); min-height: 380px; }
  .conv-head .back { display: inline-flex; }
  .messages { padding: 16px 14px; }
  .bubble { max-width: 86%; }
  .composer { padding: 10px 12px; }

  .wizard { padding: 22px 18px; }
  .qr-wrap { justify-content: center; }
  .campcard { padding: 16px; }
  .new-camp { gap: 18px; }
  .login-hero { display: none; }
  .login-form-wrap { padding: 32px 20px; }
}

@media (max-width: 900px) and (min-width: 681px) {
  .login-hero { padding: 40px; }
  .login-hero h1 { font-size: 28px; }
}

/* =================== Додаткові екрани =================== */
.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metrics.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric { padding: 16px 18px; }
.metric .l { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.metric .v { font-size: 24px; font-weight: 700; }

/* Ролі */
.perm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.perm { font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 6px; background: var(--ok-bg); color: var(--ok); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.perm.off { background: var(--soft); color: var(--faint); }
.grouplabel { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 6px; }
.checkrow { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.checkrow:hover { background: var(--hover); }
.checkrow input { margin-top: 3px; }
.checkrow .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 600; }
.checkrow.disabled { opacity: .5; cursor: not-allowed; }

/* Сегменти */
.condrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.condrow > select, .condrow > span > select, .condrow > span > input { width: auto; flex: 1 1 110px; min-width: 0; }
.condrow > span[data-k=val-wrap] { display: flex; flex: 1 1 90px; min-width: 0; }
.condrow > [data-rm] { flex: 0 0 auto; }
.condrow > span[data-k=val-wrap] > * { width: 100%; }
.condrow .conn { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 6px 10px; border-radius: 6px; flex: 0 0 auto; }
.condrow .conn-sel { flex: 0 0 110px; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.seg-count { padding: 12px 14px; background: var(--accent-soft); color: var(--accent); border-radius: 8px; font-size: 14px; }
.seglist-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--row-line); }
.seglist-item:last-child { border-bottom: 0; }
.seglist-item.tmpl { cursor: pointer; }
.seglist-item.tmpl:hover { background: var(--hover); }

/* Імпорт */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 20px; border: 2px dashed var(--border-2); text-align: center; cursor: pointer; background: #fff; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-tint); }

/* Нагляд */
.mgrcard { overflow: hidden; }
.mgr-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--row-line); flex-wrap: wrap; }
.mgrcard .chatrow { padding: 11px 18px; }
.mgr-foot { padding: 12px 18px; font-size: 13px; }

/* Статистика */
.barchart { display: flex; align-items: flex-end; gap: 10px; height: 170px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; }
.bar { width: 100%; max-width: 42px; background: var(--accent); border-radius: 6px 6px 2px 2px; }
.bar-val { font-size: 12px; font-weight: 600; }
.bar-lbl { font-size: 12px; color: var(--muted); }

/* Канали */
.bot-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--row-line); flex-wrap: wrap; }
.chanrow { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--row-line); flex-wrap: wrap; }
.chanrow:last-child { border-bottom: 0; }
.ch-add { display: flex; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--row-line); background: var(--hover); }

/* Кампанія — деталі */
.livedot { width: 8px; height: 8px; border-radius: 50%; background: #22C55E; box-shadow: 0 0 0 3px rgba(34,197,94,.2); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* Ліміти: редаговані поля */
.field-num { width: 76px; padding: 7px 8px; font-size: 13px; text-align: center; border-radius: 6px; }
.switch-wrap { display: inline-flex; cursor: pointer; }
.switch-wrap input { display: none; }
.switch-wrap input:checked + .switch { background: var(--accent); }
.switch-wrap input:checked + .switch::after { left: 18px; }

@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr; }
  .metrics.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table.responsive td .field-num { width: 90px; }
}
@media (max-width: 680px) {
  .metrics, .metrics.six { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric { padding: 12px 14px; }
  .metric .v { font-size: 20px; }
  .condrow > select, .condrow > span[data-k=val-wrap] { flex: 1 1 100%; }
  .condrow .conn-sel { flex: 1 1 100%; }
  .mgr-head, .bot-head { padding: 14px; }
  .mgrcard .chatrow, .chanrow { padding: 11px 14px; }
  .mgrcard .chatrow > .small { display: none; }
  .ch-add { flex-direction: column; }
  .barchart { gap: 6px; height: 150px; }
}

/* =================== Ієрархія, чати, композер, емоджі =================== */
.badge.mini { padding: 2px 7px; font-size: 10.5px; vertical-align: middle; }

/* Сайдбар: організація */
.org-pill { margin: -8px 4px 14px; padding: 9px 12px; border-radius: 10px; background: var(--side-active); display: flex; flex-direction: column; gap: 1px; }
.org-pill .small { color: var(--side-muted); font-size: 11px; }
.org-pill b { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Команда */
.org-card { display: flex; align-items: center; gap: 14px; padding: 18px 20px; margin-bottom: 22px; }
.org-mark { width: 46px; height: 46px; border-radius: 12px; background: var(--side); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.org-name { font-size: 18px; font-weight: 700; }
.tree { display: flex; flex-direction: column; gap: 0; margin-bottom: 22px; }
.tree-level { position: relative; padding: 0 0 22px 26px; border-left: 2px solid var(--border-2); margin-left: 12px; }
.tree-level:last-child { border-left-color: transparent; padding-bottom: 0; }
.tree-level::before { content: ""; position: absolute; left: -8px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.tree-level:last-child::before { left: -8px; }
.tree-level:last-child { border-left: 2px solid transparent; }
.tree-level:last-child::after { content: ""; position: absolute; left: -2px; top: -22px; height: 26px; border-left: 2px solid var(--border-2); }
.tree-label { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.tree-label span { font-weight: 700; font-size: 15px; }
.tree-label small { color: var(--muted); font-size: 12px; }
.tree-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.person-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.person-card.me { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.person-card.inactive { opacity: .6; }
.person-card.ghost { border-style: dashed; color: var(--muted); font-size: 13px; justify-content: center; min-height: 64px; background: transparent; }
.pc-head { display: flex; align-items: center; gap: 10px; }
.pc-head .name { font-weight: 600; }
.pc-head .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.pc-sees { font-size: 12px; color: var(--muted-2); background: var(--soft); border-radius: 8px; padding: 7px 10px; }
.pc-accs { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; background: #fff; }
.tg-chip small { color: var(--muted); }
.tg-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #22C55E; flex-shrink: 0; }
.tg-chip.off .dot { background: var(--faint); }
.tg-chip.demo { padding: 2px 8px; }
.legend-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 22px; font-size: 13px; color: var(--muted-2); line-height: 1.5; }

/* Чати: перемикач акаунтів */
.acc-switch { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: thin; }
.acc-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border: 1.5px solid var(--border-2); background: #fff; border-radius: 12px; cursor: pointer; font: inherit; text-align: left; flex-shrink: 0; color: var(--text); }
.acc-chip > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.acc-chip b { font-size: 13px; white-space: nowrap; }
.acc-chip small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.acc-chip:hover { border-color: var(--accent); }
.acc-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.chatrow .via { font-size: 11px; color: var(--accent); margin-top: 1px; }
.avatar.saved { background: #E0F2FE; color: #0369A1; font-size: 16px; }

/* Переписка: «ви пишете як» */
.as-bar { display: flex; align-items: center; gap: 10px; padding: 8px 18px; background: var(--accent-tint); border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.as-bar > span:nth-child(2) { flex: 1 1 200px; min-width: 0; }
.bubble.pending { opacity: .65; }
.bubble.failed { background: var(--err-bg) !important; color: var(--err) !important; opacity: 1; }

/* Композер як у Telegram */
.composer { position: relative; padding: 10px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; background: #fff; }
.composer textarea { flex: 1; min-height: 42px; max-height: 160px; resize: none; border-radius: 21px; padding: 10px 16px; line-height: 1.4; background: var(--bg); border-color: transparent; overflow-y: auto; }
.composer textarea:focus { background: #fff; }
.icon-btn { width: 42px; height: 42px; flex-shrink: 0; border: 0; background: transparent; border-radius: 50%; font-size: 22px; cursor: pointer; display: flex; align-items: center; justify-content: center; filter: grayscale(.2); }
.icon-btn:hover { background: var(--soft); filter: none; }
.send-btn { width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform .1s, background .12s; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: var(--soft); color: var(--faint); cursor: default; }
.composer-hint { font-size: 11px; color: var(--faint); padding: 0 18px 8px; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }

/* Панель емоджі */
.emoji-pop { position: absolute; bottom: calc(100% + 6px); left: 8px; width: 340px; max-width: calc(100vw - 32px); background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.14); padding: 8px; z-index: 20; }
.emoji-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--row-line); padding-bottom: 6px; margin-bottom: 4px; }
.emoji-tabs button { border: 0; background: transparent; font-size: 18px; padding: 5px 8px; border-radius: 8px; cursor: pointer; opacity: .55; }
.emoji-tabs button.on, .emoji-tabs button:hover { opacity: 1; background: var(--soft); }
.emoji-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px 4px 6px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 220px; overflow-y: auto; }
.emoji-grid button { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 6px 0; border-radius: 8px; cursor: pointer; }
.emoji-grid button:hover { background: var(--soft); }

@media (max-width: 1100px) {
  .legend-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .tree-level { padding-left: 18px; margin-left: 8px; }
  .tree-row { grid-template-columns: 1fr; }
  .pc-head { flex-wrap: wrap; }
  .org-card { flex-wrap: wrap; }
  .acc-chip small { display: none; }
  .as-bar { padding: 7px 12px; }
  .composer-hint { display: none; }
  .composer { padding: 8px; }
  .emoji-pop { left: 0; width: calc(100vw - 36px); }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
}

/* Telegram @username і логін у панель */
.tg-handle { display: inline-block; color: #0369A1; background: #E0F2FE; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; margin: 2px 4px 0 0; }
.login-line { font-size: 11px !important; color: var(--faint) !important; }
.owner-sel { width: auto; max-width: 200px; padding: 6px 28px 6px 10px; font-size: 13px; }

/* ---------- Медіа в чатах ---------- */
.bubble.has-media { padding: 4px; white-space: normal; }
.bubble .btext { white-space: pre-wrap; }
.bubble.has-media .btext { padding: 6px 9px 0; }
.bubble.has-media .meta, .bubble.has-media .who { padding: 0 9px; }
.bubble.has-media .meta { padding-bottom: 4px; }
.bubble.bare { background: transparent !important; padding: 0; }
.bubble.bare .meta { color: var(--muted-2); opacity: 1; }
.media-box { position: relative; width: 300px; max-width: 100%; max-height: 360px; border-radius: 9px; overflow: hidden; background: rgba(0,0,0,.08); cursor: pointer; display: grid; place-items: center; }
.media-box img, .media-box video { width: 100%; height: 100%; object-fit: cover; display: block; grid-area: 1 / 1; }
.media-box.round { width: 200px; height: 200px; border-radius: 50%; }
.media-ph { font-size: 28px; opacity: .45; grid-area: 1 / 1; }
.media-box .play { grid-area: 1 / 1; width: 46px; height: 46px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 18px; z-index: 1; }
.media-box.playing .play, .media-box.playing .media-badge { display: none; }
.media-box.busy .play { animation: pulse 1s infinite; }
.media-badge { position: absolute; left: 8px; top: 8px; z-index: 1; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 8px; }
.media-box.spoiler img { filter: blur(22px); transform: scale(1.1); }
.media-box.spoiler::after { content: 'Спойлер · натисніть'; position: absolute; z-index: 2; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 10px; }
.media-err { cursor: default; }
.sticker { width: 160px; height: 160px; display: grid; place-items: center; }
.sticker img, .sticker video { width: 100%; height: 100%; object-fit: contain; }
.sticker .media-ph { font-size: 64px; opacity: 1; }
.audio-row, .file-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-width: 220px; max-width: 320px; color: inherit; text-decoration: none; }
.file-row[data-file], .audio-row { cursor: pointer; }
.file-row.busy { opacity: .6; }
.audio-row audio { width: 260px; max-width: 100%; height: 36px; }
.audio-play, .file-ico { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center; font-size: 15px; background: var(--accent); color: #fff; cursor: pointer; }
.bubble.out .audio-play, .bubble.out .file-ico { background: rgba(255,255,255,.22); }
.file-ico { font-size: 17px; }
.audio-info { min-width: 0; display: flex; flex-direction: column; }
.audio-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-info span { font-size: 11px; opacity: .7; }
.file-dl { margin-left: auto; font-size: 16px; opacity: .7; }
.media-note { padding: 8px 10px; font-size: 12px; opacity: .8; font-style: italic; }
.poll { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.poll-opt { border: 1px solid currentColor; border-radius: 8px; padding: 5px 9px; font-size: 12px; opacity: .8; }
.service-msg { align-self: center; font-size: 11.5px; color: var(--muted-2); background: var(--soft); border-radius: 12px; padding: 4px 12px; max-width: 80%; text-align: center; }
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(10,10,14,.88); display: grid; place-items: center; padding: 24px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lb-close { position: absolute; top: 14px; right: 16px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; cursor: pointer; }
@keyframes pulse { 50% { opacity: .4; } }
@media (max-width: 680px) { .media-box { width: 240px; } .media-box.round { width: 160px; height: 160px; } .sticker { width: 128px; height: 128px; } }

/* ---------- Картка користувача ---------- */
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.perm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.activity-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.activity-row:last-of-type { border-bottom: 0; }
.side-user { cursor: pointer; border-radius: 8px; }
.side-user:hover { background: rgba(255,255,255,.06); }
[data-open-user] { cursor: pointer; }
a[data-open-user] { color: inherit; }
a[data-open-user]:hover { color: var(--accent); }

/* ---------- Публікації ---------- */
.post-day { margin: 22px 0 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); }
.post-row { display: flex; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.post-row:last-child { border-bottom: 0; }
.post-time { flex: none; width: 48px; font-weight: 700; font-size: 14px; padding-top: 2px; }
.post-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.post-main[data-edit-post]:not([data-edit-post=""]) { cursor: pointer; }
.post-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.post-snippet { font-size: 13px; color: var(--text); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.post-err { font-size: 12px; color: var(--err); background: var(--err-bg); border-radius: 6px; padding: 4px 8px; }
.post-err.soft { color: var(--warn); background: var(--warn-bg); }
.post-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; max-width: 300px; }
@media (max-width: 680px) { .post-row { flex-wrap: wrap; } .post-actions { max-width: none; justify-content: flex-start; width: 100%; } }

.fmt-bar { display: flex; gap: 4px; flex-wrap: wrap; border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0; padding: 6px; background: var(--soft); }
.fmt-bar button { min-width: 32px; height: 30px; border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; font-size: 14px; color: var(--text); }
.fmt-bar button:hover { background: #fff; border-color: var(--border); }
.rich-editor { min-height: 140px; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 0 0 8px 8px; padding: 10px 12px; font-size: 14px; line-height: 1.5; outline: none; white-space: pre-wrap; overflow-wrap: anywhere; background: #fff; color: var(--text); }
.rich-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rich-editor code, .tg-text code { font-family: ui-monospace, Menlo, monospace; background: rgba(0,0,0,.06); padding: 0 4px; border-radius: 4px; font-size: .92em; }
.rich-editor .tg-spoiler { background: #d9d6f5; border-radius: 3px; }
.rich-editor a, .tg-text a { color: var(--accent); }
#pe-count.over { color: var(--err); font-weight: 700; }

.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; text-align: left; outline: none; }
.dropzone.over, .dropzone:focus { border-color: var(--accent); background: rgba(79,70,229,.05); }
.media-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; display: flex; flex-direction: column; font-size: 12px; }
.tile.dragging { opacity: .4; }
.tile.drop-target { outline: 2px solid var(--accent); }
.tile.error { border-color: var(--err); }
.tile-thumb { position: relative; aspect-ratio: 4/3; background: var(--soft); display: grid; place-items: center; overflow: hidden; }
.tile-thumb img, .tile-thumb video { width: 100%; height: 100%; object-fit: cover; }
.tile-ico { font-size: 28px; }
.tile-play { position: absolute; inset: 0; margin: auto; width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 12px; pointer-events: none; }
.tile-name { padding: 6px 8px 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { padding: 0 8px; color: var(--muted); }
.tile-errtext { padding: 2px 8px; color: var(--err); }
.tile-bar { height: 4px; margin: 6px 8px 0; background: var(--soft); border-radius: 2px; overflow: hidden; }
.tile-bar span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.tile-tools { display: flex; align-items: center; gap: 4px; padding: 6px 8px 8px; margin-top: auto; }
.tile-tools button { border: 1px solid var(--border); background: #fff; border-radius: 6px; width: 26px; height: 24px; cursor: pointer; font-size: 11px; }
.tile-tools button:disabled { opacity: .35; cursor: default; }
.tile-n { flex: 1; text-align: center; color: var(--muted); }
.tile-tools .tile-rm { color: var(--err); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; }
.btn-cell { display: flex; gap: 4px; flex: 1 1 260px; min-width: 0; }
.btn-cell input { min-width: 0; }
.btn-cell input:first-child { flex: 0 1 40%; }
.icon-x { border: 0; background: transparent; color: var(--err); cursor: pointer; font-size: 14px; padding: 0 4px; }
.when-opts { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; }
.when-opts label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.problems { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 14px; font-size: 13px; line-height: 1.6; }

.tg-preview { background: #c7d6e4 linear-gradient(135deg, #cfdfe9, #bcd0e0); border-radius: 14px; padding: 14px; position: sticky; top: 16px; }
.tg-head { display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,.85); border-radius: 10px; padding: 8px 10px; margin-bottom: 12px; font-size: 13px; }
.tg-bubble { background: #fff; border-radius: 14px 14px 14px 4px; overflow: hidden; max-width: 340px; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.tg-text { padding: 8px 12px 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.tg-text:empty { display: none; }
.tg-text .tg-spoiler { background: #9aa0a8; color: transparent; border-radius: 3px; cursor: pointer; transition: all .2s; }
.tg-text .tg-spoiler.revealed { background: rgba(0,0,0,.06); color: inherit; }
.tg-text blockquote { border-left: 3px solid var(--accent); margin: 2px 0; padding-left: 8px; }
.tg-meta { text-align: right; font-size: 11px; color: var(--muted); padding: 2px 10px 6px; }
.tg-album { display: grid; gap: 2px; grid-template-columns: repeat(2, 1fr); }
.tg-album.n1 { grid-template-columns: 1fr; }
.tg-album.n3 .tg-cell:first-child, .tg-album.n5 .tg-cell:first-child, .tg-album.n7 .tg-cell:first-child, .tg-album.n9 .tg-cell:first-child { grid-column: span 2; }
.tg-album.n6, .tg-album.n9, .tg-album.n10 { grid-template-columns: repeat(3, 1fr); }
.tg-album.n9 .tg-cell:first-child { grid-column: span 3; }
.tg-cell { position: relative; aspect-ratio: 1; background: #dfe5ea; overflow: hidden; }
.tg-album.n1 .tg-cell { aspect-ratio: auto; min-height: 120px; }
.tg-cell img, .tg-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-album.n1 .tg-cell img, .tg-album.n1 .tg-cell video { height: auto; max-height: 360px; }
.tg-file { display: flex; gap: 10px; align-items: center; padding: 10px 12px 0; font-size: 13px; }
.tg-file b { display: block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-file-ico { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.tg-buttons { max-width: 340px; margin-top: 4px; display: flex; flex-direction: column; gap: 4px; }
.tg-brow { display: flex; gap: 4px; }
.tg-btn { flex: 1; text-align: center; background: rgba(0,0,0,.28); color: #fff; border-radius: 8px; padding: 8px 6px; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Довідка ---------- */
.nav-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.help-q { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); background: #fff; color: var(--accent); font-weight: 700; font-size: 13px; cursor: pointer; vertical-align: middle; margin-left: 6px; line-height: 1; padding: 0; }
.help-q:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.help-q.static { display: inline-grid; place-items: center; cursor: default; }
.help-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
.help-nav { padding: 10px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.help-nav input { margin-bottom: 8px; }
.help-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 8px 4px; }
.help-item { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 8px; font-size: 13px; color: var(--text); cursor: pointer; text-decoration: none; }
.help-item:hover { background: var(--soft); }
.help-item.active { background: rgba(79,70,229,.1); color: var(--accent); font-weight: 600; }
.help-article { line-height: 1.6; font-size: 14px; }
.help-article h2 { margin: 0 0 12px; }
.help-article h3 { margin: 22px 0 10px; font-size: 15px; }
.help-article p { margin: 8px 0; }
.help-article ul, .help-article ol { padding-left: 20px; margin: 8px 0; }
.help-article li { margin: 4px 0; }
.help-article code, .mini-steps code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.help-article a[data-help], .mini-steps a[data-help] { color: var(--accent); cursor: pointer; }
.h-step { display: flex; gap: 12px; padding: 8px 0; }
.h-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.h-sub { color: var(--muted-2); font-size: 13px; margin-top: 2px; }
.h-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.h-table th, .h-table td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
.h-table th { background: var(--soft); font-weight: 600; }
.h-tree { background: var(--soft); border-radius: 10px; padding: 12px 14px; font-size: 13px; line-height: 1.8; }
.h-tree .l1 { padding-left: 14px; } .h-tree .l2 { padding-left: 34px; } .h-tree .l3 { padding-left: 58px; }
.h-dl dt { font-weight: 700; margin-top: 10px; }
.h-dl dd { margin: 2px 0 0; color: var(--muted-2); }
.h-progress { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.h-progress div { height: 100%; background: var(--ok); transition: width .3s; }
.h-check { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.h-check:last-child { border-bottom: 0; }
.h-box { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.h-check.done .h-box { background: var(--ok); border-color: var(--ok); color: #fff; }
.h-check.done b { color: var(--muted); text-decoration: line-through; }
.mini-steps { font-size: 13px; line-height: 1.6; }
.mini-steps ol { padding-left: 20px; margin: 6px 0; }
@media (max-width: 900px) { .help-layout { grid-template-columns: 1fr; } .help-nav { position: static; max-height: 260px; } .h-table { display: block; overflow-x: auto; } }

/* ---------- Нове: статуси, тир, помилки кампаній ---------- */
.note.err { background: var(--err-bg); color: var(--err); border: 1px solid var(--err); }
.status-sel, .tier-sel { padding: 4px 8px; font-size: 12px; border-radius: 6px; width: auto; min-width: 0; }
.tier-sel { margin-top: 4px; }

/* ---------- Доступність і відгук інтерфейсу ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: -1px; }
.sidebar :focus-visible { outline-color: #fff; outline-offset: -2px; }
a.navitem { text-decoration: none; }
a.navitem:hover { color: #fff; }
.navitem .ico { display: inline-flex; align-items: center; justify-content: center; }
.navitem .ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 200; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; font-weight: 600; }
.skip-link:focus { top: 8px; color: #fff; }
.main:focus { outline: none; }

.toast { display: flex; align-items: center; gap: 14px; }
.toast-action { background: transparent; border: 0; color: #fff; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 2px 4px; border-radius: 6px; white-space: nowrap; }
.toast-action:hover { background: rgba(255,255,255,.16); }
.toast-action:focus-visible { outline-color: #fff; }
.pending-delete { display: none !important; }

.skeleton-wrap { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.skeleton { border-radius: 10px; background: linear-gradient(90deg, var(--soft) 25%, #fff 50%, var(--soft) 75%); background-size: 200% 100%; animation: sk-shimmer 1.3s linear infinite; }
.sk-title { height: 28px; width: 220px; }
.sk-sub { height: 14px; width: 340px; max-width: 80%; margin-top: -4px; }
.sk-card { height: 120px; border: 1px solid var(--border); }
.sk-short { height: 72px; }
@keyframes sk-shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

.auth-switch { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 2px 4px; font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer; border-radius: 4px; }
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- Підписка ---------- */
.billing-banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; border: 1px solid var(--orange-line); background: var(--orange-bg); color: var(--orange); }
.billing-banner.err { border-color: #FECACA; background: var(--err-bg); color: var(--err); }
.billing-banner a { font-weight: 700; text-decoration: underline; color: inherit; white-space: nowrap; }

/* ---------- Перемикач мови ---------- */
.langsw { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--panel); align-self: flex-start; }
.langsw button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 700; letter-spacing: .02em; padding: 4px 9px; border-radius: 7px; cursor: pointer; }
.langsw button:hover { background: var(--soft); }
.langsw button[aria-pressed="true"] { background: var(--accent); color: #fff; cursor: default; }
.side-foot .langsw { background: transparent; border-color: var(--side-line); }
.side-foot .langsw button { color: var(--side-text); }
.side-foot .langsw button:hover { background: var(--side-active); color: #fff; }
.side-foot .langsw button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.login-form-wrap { position: relative; }
.langsw-login { position: absolute; top: 20px; right: 20px; }

/* ---------- Логотип ---------- */
.logo img { display: block; height: 24px; width: auto; }
.logo-icon { width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0; }
.login-hero .logo img { height: 30px; }
