/* ==========================================================================
   Performator app shell — Apple-services register.
   White sidebar, light-gray canvas, white cards. One view at a time (routed),
   never a single long scroll of every section stacked together.
   Tokens come from /css/main.css — do not redefine colours here.
   ========================================================================== */

body { font-size: 14px; background: var(--bg-alt); }

/* Hidden until the auth check resolves — avoids a flash of dashboard
   content before a redirect to /login.html can happen for logged-out
   visitors. auth-gate.js removes .auth-pending on the successful path. */
body.auth-pending .app { display: none; }
.auth-loading { display: none; min-height: 100vh; align-items: center; justify-content: center; color: var(--faint); font-size: 0.875rem; }
body.auth-pending .auth-loading { display: flex; }

.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; }

/* --- sidebar --- */
.sidebar {
  background: var(--bg); border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; padding: 20px 14px 16px; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; padding: 4px 10px 20px;
  text-decoration: none;
}
.sidebar-brand img { height: 25px; width: auto; display: block; }

.connect-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px; width: 100%;
  height: 38px; border-radius: 999px; background: var(--primary); color: var(--primary-ink);
  font-size: 0.8438rem; font-weight: 600; border: none; cursor: pointer; margin-bottom: 22px;
  transition: background 160ms var(--ease-out-expo), transform 160ms var(--ease-out-expo);
}
.connect-btn:hover { background: oklch(0.46 0.19 258); }
.connect-btn:active { transform: scale(0.98); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 20px; }
.nav-group-label {
  font-size: 0.6875rem; color: var(--faint); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0 10px 8px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px;
  border-radius: 9px; color: var(--muted); font-size: 0.875rem; text-decoration: none;
  cursor: pointer; border: none; background: none; font: inherit; text-align: left; width: 100%;
  transition: background 140ms var(--ease-out-expo), color 140ms var(--ease-out-expo);
}
.nav-item svg { flex: none; opacity: 0.75; }
.nav-item:hover { background: var(--bg-alt); color: var(--ink); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.nav-item .count { margin-left: auto; font-family: var(--font-mono); font-size: 0.75rem; color: var(--faint); }
.nav-item.empty { color: var(--faint); cursor: default; font-size: 0.8125rem; }
.nav-item.empty:hover { background: none; color: var(--faint); }
.nav-item .disconnect-btn {
  margin-left: auto; width: 20px; height: 20px; border-radius: 6px; border: none; background: none;
  color: var(--faint); display: none; align-items: center; justify-content: center; cursor: pointer;
}
.nav-item:hover .disconnect-btn { display: flex; }
.nav-item .disconnect-btn:hover { color: var(--danger); background: var(--danger-dim); }

.sidebar-foot { margin-top: auto; padding-top: 14px; }

/* --- mobile nav (replaces the sidebar below the breakpoint) --- */
.mobile-nav { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-nav {
    display: flex; gap: 6px; overflow-x: auto; padding: 10px clamp(16px, 4vw, 24px);
    background: var(--bg); border-bottom: 1px solid var(--line-soft);
    position: sticky; top: 56px; z-index: calc(var(--z-sticky) - 1);
    scrollbar-width: none;
  }
  .mobile-nav::-webkit-scrollbar { display: none; }
  .mobile-nav button {
    flex: none; height: 32px; padding-inline: 14px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--bg); color: var(--muted); font: inherit; font-size: 0.8125rem; font-weight: 550; cursor: pointer;
  }
  .mobile-nav button.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
}

/* --- topbar --- */
.topbar {
  height: 56px; flex: none; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 clamp(16px, 3vw, 40px);
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: oklch(1 0 0 / 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; overflow: hidden; }
.workspace-name { font-size: 0.875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.workspace-badge {
  font-family: var(--font-mono); font-size: 0.6875rem; color: var(--muted);
  background: var(--bg-alt); padding: 4px 9px; border-radius: 6px; white-space: nowrap;
}
.workspace-badge.is-warning { color: var(--warning); background: var(--warning-dim); }
@media (max-width: 620px) { .workspace-badge { display: none; } }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.period-select {
  font: inherit; font-size: 0.8125rem; color: var(--ink); background: var(--bg-alt);
  border: 1px solid transparent; border-radius: 9px; padding: 7px 11px; cursor: pointer;
}
.period-select:hover { border-color: var(--line); }
.plan-tag {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border-radius: 999px; background: var(--primary-dim); color: var(--primary);
  font-size: 0.8125rem; font-weight: 620; white-space: nowrap; flex: none;
}
.plan-tag .plan-sep { color: var(--primary-line); }
.plan-tag #plan-days { color: var(--muted); font-weight: 500; }

/* --- views: exactly one is rendered at a time --- */
.canvas { flex: 1; padding: clamp(22px, 3vw, 38px) clamp(16px, 3vw, 40px) 72px; }
.view { display: none; max-width: 1080px; margin-inline: auto; }
.view.active { display: block; }
@media (prefers-reduced-motion: no-preference) {
  .view.active { animation: view-in 320ms var(--ease-out-expo) backwards; }
  @keyframes view-in { from { opacity: 0; transform: translateY(6px); } }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.5rem, 1.4vw + 1.1rem, 1.875rem); letter-spacing: -0.025em; }
.page-head p { color: var(--muted); font-size: 0.9375rem; margin-top: 6px; max-width: 62ch; }
.page-head .sub-note { font-size: 0.8125rem; color: var(--faint); margin-top: 4px; }
.page-head .sub-note[hidden] { display: none; }
.page-head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- card --- */
.card {
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 18px;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.03), 0 12px 28px -22px oklch(0 0 0 / 0.14);
  overflow: hidden;
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 17px 22px; flex-wrap: wrap; }
.card-head + * { border-top: 1px solid var(--line-soft); }
.card-head h2 { font-size: 0.9375rem; font-weight: 620; letter-spacing: -0.01em; }
.card-head .sub { font-size: 0.8125rem; color: var(--faint); margin-top: 3px; }
.card-head .hint { font-size: 0.8125rem; color: var(--faint); }
.card-body { padding: 20px 22px 22px; }
.card-empty { padding: 34px 22px; text-align: center; color: var(--faint); font-size: 0.875rem; }

.grid-2 { display: grid; grid-template-columns: 1.45fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* --- stat cards --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 16px; padding: 18px 20px;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.03);
}
.stat .label { font-size: 0.75rem; color: var(--faint); margin-bottom: 10px; }
.stat .value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 500; letter-spacing: -0.02em; }
.stat .delta { font-size: 0.75rem; margin-top: 6px; color: var(--faint); }
.stat .delta.up { color: var(--success); }
.stat .delta.down { color: var(--danger); }

/* --- segmented control (iOS-style) --- */
.segmented { display: inline-flex; background: var(--bg-alt); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  height: 30px; padding-inline: 14px; border-radius: 999px; border: none; background: none;
  color: var(--muted); font: inherit; font-size: 0.8125rem; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background 180ms var(--ease-out-expo), color 180ms var(--ease-out-expo);
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px oklch(0 0 0 / 0.09); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 22px; flex-wrap: wrap; }
.toolbar + * { border-top: 1px solid var(--line-soft); }
.toolbar-label { font-size: 0.8125rem; color: var(--faint); }

/* --- segment breakdown --- */
.seg-bar { display: flex; height: 9px; border-radius: 999px; overflow: hidden; gap: 2px; margin-bottom: 18px; }
.seg-bar span { height: 100%; border-radius: 2px; transition: width 460ms var(--ease-out-expo); }
.seg-list { display: flex; flex-direction: column; }
.seg-list-row { display: flex; align-items: center; gap: 11px; font-size: 0.875rem; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.seg-list-row:last-child { border-bottom: none; }
.seg-list-row .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.seg-list-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-list-row .val { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.seg-list-row .share { color: var(--faint); font-family: var(--font-mono); font-size: 0.75rem; width: 40px; text-align: right; }
.seg-list-row.seg-list-empty { color: var(--faint); justify-content: center; }

/* --- table --- */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); font-weight: 620; padding: 12px 22px; border-bottom: 1px solid var(--line-soft);
}
table.data td { padding: 14px 22px; border-bottom: 1px solid var(--line-soft); font-size: 0.875rem; vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--bg-alt); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.campaign-name { display: flex; align-items: center; gap: 11px; }
.campaign-name .p-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.campaign-name .meta { color: var(--faint); font-size: 0.75rem; margin-top: 2px; }
.group-header-row td { background: var(--bg-alt); padding: 9px 22px; border-bottom: 1px solid var(--line-soft); }
.group-header-row .group-name { font-size: 0.8125rem; font-weight: 620; }
.group-header-row .group-total { float: right; font-family: var(--font-mono); font-size: 0.8125rem; color: var(--muted); }

/* --- generic row (queue / log / hypotheses) --- */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 15px 22px; border-bottom: 1px solid var(--line-soft);
}
.row:last-child { border-bottom: none; }
.row .row-main { min-width: 0; }
.row .row-title { font-size: 0.875rem; }
.row .row-sub { font-size: 0.8125rem; color: var(--faint); margin-top: 3px; }
.row .row-actions { display: flex; gap: 8px; flex: none; align-items: center; }
.row.resolved {
  animation: row-out 260ms var(--ease-out-expo) forwards;
}
@keyframes row-out { to { opacity: 0; transform: translateX(10px); max-height: 0; padding-top: 0; padding-bottom: 0; border-bottom-width: 0; } }
@media (prefers-reduced-motion: reduce) { .row.resolved { display: none; } }

.icon-btn {
  width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.icon-btn:hover { background: var(--bg-alt); color: var(--ink); }
.icon-btn.approve:hover { color: var(--success); border-color: var(--success); background: var(--success-dim); }
.icon-btn.reject:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-dim); }

/* --- log --- */
.log-row { display: flex; gap: 16px; padding: 13px 22px; border-bottom: 1px solid var(--line-soft); font-size: 0.8438rem; align-items: baseline; }
.log-row:last-child { border-bottom: none; }
.log-time { font-family: var(--font-mono); color: var(--faint); font-size: 0.75rem; flex: none; width: 56px; }
.log-body strong { font-weight: 600; }
.log-body .mono { color: var(--faint); font-size: 0.75rem; }

/* --- audits --- */
.audit-progress { padding: 26px 22px; }
.audit-progress[hidden] { display: none; }
.audit-progress .step-text { font-size: 0.875rem; color: var(--muted); margin-bottom: 14px; }
.audit-progress .bar-track { height: 5px; border-radius: 5px; background: var(--bg-alt); overflow: hidden; }
.audit-progress .bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 5px; transition: width 440ms var(--ease-out-expo); }
.audit-progress .bar-fill.indeterminate { width: 40%; animation: bar-indet 1.7s ease-in-out infinite; }
@keyframes bar-indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .audit-progress .bar-fill.indeterminate { animation: none; margin-left: 0; width: 60%; }
}
.audit-results[hidden] { display: none; }
/* Fixed severity column so every finding title starts on the same x — the
   pills have different natural widths and left the headings ragged. */
.audit-item { display: grid; grid-template-columns: 132px 1fr; gap: 16px; padding: 17px 22px; border-bottom: 1px solid var(--line-soft); align-items: start; }
.audit-item:last-of-type { border-bottom: none; }
.audit-item .pill { margin-top: 1px; justify-self: start; }
@media (max-width: 640px) { .audit-item { grid-template-columns: 1fr; gap: 9px; } }
.audit-title { font-size: 0.9062rem; font-weight: 600; margin-bottom: 5px; letter-spacing: -0.005em; }
.audit-verdict { font-size: 0.8438rem; color: var(--muted); line-height: 1.6; max-width: 68ch; }
.audit-summary { padding: 15px 22px; font-size: 0.8438rem; color: var(--muted); background: var(--bg-alt); }
.audit-summary strong { color: var(--ink); }

/* --- agent hypotheses: two-step confirm --- */
.hyp-detail { padding: 0 22px 18px; border-bottom: 1px solid var(--line-soft); }
.hyp-detail[hidden] { display: none; }
.hyp-diff { background: var(--bg-alt); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.hyp-diff-line { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 0.8438rem; padding: 5px 0; }
.hyp-diff-line .field { color: var(--muted); }
.hyp-diff .d-old { color: var(--danger); text-decoration: line-through; opacity: 0.75; font-family: var(--font-mono); }
.hyp-diff .d-new { color: var(--success); font-weight: 600; font-family: var(--font-mono); }
.hyp-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hyp-note { font-size: 0.75rem; color: var(--faint); }

/* --- settings --- */
.setting-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 17px 22px; border-bottom: 1px solid var(--line-soft); }
.setting-row[hidden] { display: none; }
.setting-row:last-child { border-bottom: none; }
.setting-row .k { font-size: 0.875rem; font-weight: 550; }
.setting-row .d { font-size: 0.8125rem; color: var(--muted); margin-top: 3px; max-width: 54ch; }
.setting-row .v { font-size: 0.8438rem; color: var(--muted); text-align: right; flex: none; }
@media (max-width: 640px) { .setting-row { flex-direction: column; gap: 6px; } .setting-row .v { text-align: left; } }
.link-row { display: flex; gap: 20px; padding: 16px 22px; flex-wrap: wrap; }
.link-row a { font-size: 0.8438rem; color: var(--primary); text-decoration: none; }
.link-row a:hover { text-decoration: underline; }

/* --- integrations (Настройки → Интеграции) --- */
.integration-group + .integration-group { border-top: 1px solid var(--line-soft); }
.integration-group-label {
  font-size: 0.6875rem; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 620; padding: 14px 22px 4px;
}
.integration-row { align-items: center; }
.integration-row .k { display: flex; align-items: center; gap: 14px; min-width: 0; }
.integration-row .k-name { font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.integration-row .d { font-size: 0.8125rem; color: var(--muted); margin-top: 2px; max-width: 46ch; }
.service-logo {
  width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; overflow: hidden;
}
.service-logo img { display: block; width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.integration-row.is-soon .service-logo { opacity: 0.6; }

/* --- iOS-style toggle switch (Автоправила, Уведомления) --- */
.switch { position: relative; display: inline-flex; align-items: center; width: 38px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line);
  transition: background 160ms var(--ease-out-expo);
}
.switch-track::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg); box-shadow: 0 1px 3px oklch(0 0 0 / 0.25);
  transition: transform 160ms var(--ease-out-expo);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --- Автоправила --- */
.rule-row {
  display: flex; align-items: center; gap: 16px; padding: 15px 22px; border-bottom: 1px solid var(--line-soft);
}
.rule-row:last-child { border-bottom: none; }
.rule-main { flex: 1; min-width: 0; }
.rule-title { font-size: 0.875rem; }
.rule-sub { font-size: 0.8125rem; color: var(--faint); margin-top: 3px; }
.rule-schedule { flex: none; color: var(--muted); font-size: 0.8125rem; }
.rule-queue-link { flex: none; font-size: 0.8125rem; color: var(--primary); text-decoration: none; }
.rule-queue-link:hover { text-decoration: underline; }
@media (max-width: 760px) {
  .rule-row { flex-wrap: wrap; }
  .rule-main { flex-basis: 100%; order: 1; }
  .rule-schedule, .rule-queue-link { order: 2; }
}

/* --- modal (native <dialog>) --- */
.modal { border: none; border-radius: var(--radius-lg); padding: 0; width: min(420px, calc(100vw - 40px)); box-shadow: 0 30px 60px -20px oklch(0 0 0 / 0.35); }
#select-accounts-dialog { width: min(600px, calc(100vw - 40px)); }
.modal::backdrop { background: oklch(0.19 0 0 / 0.45); }
.modal-body { padding: 24px 24px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-title { font-size: 1.0625rem; font-weight: 620; letter-spacing: -0.01em; }
.modal-sub { font-size: 0.8438rem; color: var(--muted); margin-top: -8px; }
.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8125rem; color: var(--muted); font-weight: 550; }
.field-input {
  font: inherit; font-size: 0.875rem; color: var(--ink); background: var(--bg-alt);
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 12px; width: 100%;
}
.field-input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.field-checkbox { display: flex; align-items: center; gap: 9px; font-size: 0.8438rem; color: var(--ink); }
.checkbox-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px; }
.checkbox-list .field-checkbox { padding: 6px 6px; border-radius: var(--radius-sm); }
.checkbox-list .field-checkbox:hover { background: var(--bg-alt); }
.field-note { font-size: 0.75rem; color: var(--faint); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* --- toast --- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: var(--z-toast);
  padding: 12px 18px; border-radius: 12px; font-size: 0.8438rem; font-weight: 550;
  background: var(--ink); color: var(--bg); box-shadow: 0 16px 36px -12px oklch(0 0 0 / 0.35);
  max-width: calc(100vw - 32px);
}
.toast.success::before { content: "✓ "; color: oklch(0.75 0.16 150); }
.toast.error::before { content: "✕ "; color: oklch(0.72 0.17 25); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 260ms var(--ease-out-expo); }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
}

/* --- chat with the agent --- */
.chat-log { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; max-height: 460px; overflow-y: auto; }
.chat-row { display: flex; }
.chat-row--user { justify-content: flex-end; }
.chat-bubble {
  max-width: min(78%, 560px); padding: 9px 13px; border-radius: 14px;
  font-size: 0.8125rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  background: var(--bg-alt); color: var(--text);
}
.chat-row--user .chat-bubble { background: var(--primary-dim); color: var(--primary-ink, var(--text)); border-bottom-right-radius: 4px; }
.chat-row--agent .chat-bubble { border-bottom-left-radius: 4px; }
.chat-form { display: flex; gap: 8px; margin-top: 14px; }
.chat-input {
  flex: 1; min-width: 0; padding: 9px 13px; border-radius: 10px;
  border: 1px solid var(--line-soft); background: var(--bg); color: var(--text);
  font: inherit; font-size: 0.8125rem;
}
.chat-input:focus { outline: none; border-color: var(--primary); }
.chat-input::placeholder { color: var(--faint); }

/* --- account selection modal (MCC/agency picker) --- */
.modal-head { display: flex; flex-direction: column; gap: 3px; margin-bottom: 16px; }
.modal-eyebrow {
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  color: var(--primary); letter-spacing: 0.02em; text-transform: uppercase;
}
.modal-title { margin: 0; font-size: 1.1875rem; font-weight: 650; letter-spacing: -0.02em; color: var(--ink); }
.modal-sub { margin: 0; font-size: var(--text-sm); color: var(--muted); line-height: 1.5; max-width: 420px; }

.account-tabs { margin-bottom: 14px; width: fit-content; }
.account-tab-count {
  font-family: var(--font-mono); font-size: var(--text-xs);
  opacity: 0.75; margin-left: 4px; font-variant-numeric: tabular-nums;
}

.account-list {
  display: flex; flex-direction: column; gap: 2px; max-height: 340px; overflow-y: auto;
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 6px;
}
.account-row { display: flex; align-items: center; gap: 12px; padding: 7px 8px; border-radius: var(--r-sm); }
.account-row:hover { background: var(--bg-alt); }
.account-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.account-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); color: var(--ink); }
.account-status-pill {
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--faint);
  background: var(--bg-alt); padding: 2px 8px; border-radius: var(--r-pill); flex: none;
}
.account-status-pill--archived { color: var(--muted); }
.account-status-pill--paused { color: var(--warning); background: var(--warning-dim); }

/* Apple-style checkbox: rounded square, blue fill, white check */
.acc-check {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: var(--control-size); height: var(--control-size); border-radius: 6.5px;
  border: 1.5px solid var(--line); background: var(--bg); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 150ms var(--ease-out-expo), border-color 150ms var(--ease-out-expo), transform 100ms var(--ease-out-expo);
}
.acc-check:hover { border-color: var(--primary-line); }
.acc-check:active { transform: scale(0.92); }
.acc-check:checked { background: var(--primary); border-color: var(--primary); }
.acc-check:checked::after {
  content: ""; width: 11px; height: 11px; flex: none;
  background: var(--tooltip-fg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7.5L5.8 10.3L11 4' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 11px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7.5L5.8 10.3L11 4' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 11px no-repeat;
}
.acc-check:focus-visible { outline: 2px solid var(--primary-line); outline-offset: 2px; }

/* Per-account niche block — caption on top, input below, sits on the same
   line as the account name. Space is always reserved (visibility, not
   display), so toggling the checkbox never shifts the list. */
.account-niche {
  width: 230px; flex: none;
  visibility: hidden; opacity: 0; transform: translateY(3px);
  transition: opacity 160ms var(--ease-out-expo), transform 160ms var(--ease-out-expo);
}
.account-row.niche-open .account-niche { visibility: visible; opacity: 1; transform: none; }
.niche-caption { display: flex; align-items: center; gap: 4px; margin-bottom: 3px; }
.niche-caption-label { font-size: 0.6875rem; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }
.account-niche-input {
  width: 100%; font: inherit; font-size: var(--text-sm);
  padding: 5px 9px; border-radius: var(--r-sm); border: 1px solid var(--line-soft);
  background: var(--bg); color: var(--ink);
}
.account-niche-input:focus-visible { outline: none; border-color: var(--primary); }
.account-niche-input::placeholder { color: var(--faint); }
@media (prefers-reduced-motion: reduce) { .account-niche { transition: none; } }

/* Apple-style tooltip — dark popover above the trigger */
.tip {
  position: relative; display: inline-flex; flex: none;
  width: 16px; height: 16px; border-radius: 50%; cursor: help;
  color: var(--faint); background: none; border: none; padding: 0;
  align-items: center; justify-content: center;
}
.tip:hover, .tip:focus-visible { color: var(--primary); outline: none; }


/* --- uniform connect buttons (Интеграции) --- */
.btn-connect {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 16px; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink);
  font-size: 0.8125rem; font-weight: 600; letter-spacing: -0.01em;
  border: none; cursor: pointer; text-decoration: none;
  transition: background 160ms var(--ease-out-expo), transform 100ms var(--ease-out-expo);
}
.btn-connect:hover { background: var(--primary-hover); }
.btn-connect:active { transform: scale(0.97); }
.btn-connect:focus-visible { outline: 2px solid var(--primary-line); outline-offset: 2px; }
.btn-connect--ghost {
  background: var(--bg); color: var(--primary);
  border: 1px solid var(--primary-line);
}
.btn-connect--ghost:hover { background: var(--primary-dim); }

/* --- clients block (Интеграции) --- */
.clients-list { display: flex; flex-direction: column; }
.client-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line-soft);
  transition: background 140ms var(--ease-out-expo);
}
.client-row:last-child { border-bottom: none; }
.client-row:hover { background: var(--bg-alt); }
.client-icon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--bg-alt); display: flex; align-items: center; justify-content: center;
}
.client-icon img { width: 24px; height: 24px; object-fit: contain; }
.client-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.client-name { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.client-niche {
  font: inherit; font-size: 0.75rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
  padding: 4px 9px; width: min(220px, 100%); max-width: 260px;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.04);
  transition: border-color 140ms var(--ease-out-expo), box-shadow 140ms var(--ease-out-expo), background 140ms var(--ease-out-expo);
}
.client-niche:hover { border-color: var(--primary-line); }
.client-niche:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); background: var(--bg); }
.client-niche::placeholder { color: var(--faint); }
.client-platform { font-size: 0.75rem; color: var(--faint); flex: none; }
.client-remove {
  width: 28px; height: 28px; border-radius: 8px; border: none; cursor: pointer; flex: none;
  background: none; color: var(--faint);
  display: flex; align-items: center; justify-content: center;
  transition: color 140ms var(--ease-out-expo), background 140ms var(--ease-out-expo);
}
.client-remove:hover { color: var(--danger); background: var(--danger-dim); }

/* --- usage bar (Тариф в Настройках) --- */
.usage-bar { width: 180px; height: 6px; border-radius: 6px; background: var(--bg-alt); overflow: hidden; flex: none; margin-top: 8px; }
.usage-bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 6px; transition: width 440ms var(--ease-out-expo); }

/* --- topbar sync icon button --- */
.topbar-sync-btn {
  width: 30px; height: 30px; border-radius: 9px; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; color: var(--muted);
  transition: color 140ms var(--ease-out-expo), background 140ms var(--ease-out-expo);
}
.topbar-sync-btn:hover { color: var(--primary); background: var(--primary-dim); }
.topbar-sync-btn:focus-visible { outline: 2px solid var(--primary-line); outline-offset: 1px; }
.topbar-sync-btn.is-spinning svg { animation: sync-spin 800ms linear infinite; }
@keyframes sync-spin { to { transform: rotate(360deg); } }

/* --- period toolbar (Кампании) --- */
.period-card { padding: 0; position: relative; }
.period-toolbar { display: flex; justify-content: flex-end; padding: 10px 18px; }
.period-open {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-size: 0.8125rem; font-weight: 600; color: var(--ink);
  background: var(--bg-alt); border: 1px solid var(--line-soft); border-radius: 9px;
  padding: 6px 12px; cursor: pointer;
  transition: border-color 150ms var(--ease-out-expo), background 150ms var(--ease-out-expo);
}
.period-open:hover { border-color: var(--primary-line); background: var(--bg); }
.period-open svg { color: var(--primary); }
.period-caret { color: var(--faint) !important; transition: transform 180ms var(--ease-out-expo); }
.period-open[aria-expanded="true"] .period-caret { transform: rotate(180deg); }


/* --- period popover: compact menu that drops down from the toolbar --- */
.period-popover {
  display: grid; grid-template-columns: 132px 1fr; gap: 18px;
  position: absolute; top: calc(100% - 4px); right: 14px; z-index: var(--z-dropdown);
  width: 470px; padding: 14px 16px 12px;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  box-shadow: 0 18px 44px -14px oklch(0 0 0 / 0.28), 0 2px 8px oklch(0 0 0 / 0.06);
}
.period-popover[hidden] { display: none; }
.period-calendar { width: 286px; min-width: 0; }
.period-presets { display: flex; flex-direction: column; gap: 2px; }
.period-presets button {
  font: inherit; font-size: 0.8125rem; text-align: left; color: var(--muted);
  background: none; border: none; border-radius: 8px; padding: 7px 10px; cursor: pointer;
  transition: background 140ms var(--ease-out-expo), color 140ms var(--ease-out-expo);
}
.period-presets button:hover { background: var(--bg-alt); color: var(--ink); }
.period-presets button.active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }
.period-calendar { min-width: 0; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-nav button {
  width: 26px; height: 26px; border-radius: 8px; border: none; cursor: pointer;
  background: none; color: var(--faint); display: flex; align-items: center; justify-content: center;
}
.cal-nav button:hover { background: var(--bg-alt); color: var(--ink); }
.cal-title { font-size: 0.8125rem; font-weight: 600; color: var(--ink); text-transform: capitalize; }
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 34px); gap: 2px; margin-bottom: 4px;
}
.cal-weekdays span { text-align: center; font-size: 0.625rem; color: var(--faint); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 34px); gap: 2px; }
.cal-day {
  width: 34px; height: 34px; border: none; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 0.75rem; color: var(--ink); background: none;
  display: flex; align-items: center; justify-content: center;
  transition: background 120ms var(--ease-out-expo), color 120ms var(--ease-out-expo);
}
.cal-day:hover:not(.cal-day--future) { background: var(--bg-alt); }
.cal-day--today { box-shadow: inset 0 0 0 1.5px var(--primary-line); font-weight: 600; }
.cal-day--future { color: var(--faint); opacity: 0.5; }
.cal-day--in { background: var(--primary-dim); color: var(--primary); border-radius: 0; }
.cal-day--start, .cal-day--end { background: var(--primary); color: var(--primary-ink); border-radius: 8px; font-weight: 600; }
.cal-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.cal-today {
  font: inherit; font-size: 0.75rem; font-weight: 600; color: var(--primary);
  background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.cal-today:hover { background: var(--primary-dim); }
.cal-range-label { font-size: 0.75rem; color: var(--faint); }
.period-actions {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding-top: 10px; border-top: 1px solid var(--line-soft); margin-top: 2px;
}
.period-action-btns { display: flex; gap: 8px; flex: none; margin-left: auto; }

/* --- niche tag (clients block) --- */
.client-niche-wrap { display: flex; align-items: center; gap: 6px; }
.niche-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 0.75rem; font-weight: 550; color: var(--muted);
  background: var(--bg-alt); border: 1px solid var(--line-soft); border-radius: 999px;
  padding: 3px 10px; cursor: pointer; max-width: 260px; min-width: 110px;
  transition: border-color 140ms var(--ease-out-expo), color 140ms var(--ease-out-expo), background 140ms var(--ease-out-expo);
}
.niche-tag:hover { border-color: var(--primary-line); color: var(--ink); background: var(--bg); }
.niche-tag svg { color: var(--faint); flex: none; }
.niche-tag:hover svg { color: var(--primary); }
.niche-tag--empty { border-style: dashed; color: var(--faint); font-weight: 500; }
.niche-tag-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.niche-tag[data-editing] .niche-tag-text { overflow: visible; text-overflow: clip; outline: none; caret-color: var(--primary); }
.niche-tag[data-editing] { border-color: var(--primary-line); color: var(--ink); background: var(--bg); }
.client-niche {
  font: inherit; font-size: 0.75rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--primary-line); border-radius: 8px;
  padding: 4px 10px; width: 220px; max-width: 260px;
  box-shadow: 0 0 0 3px var(--primary-dim);
}
.client-niche:focus-visible { outline: none; }
.client-niche::placeholder { color: var(--faint); }

/* --- fixed-position tooltip popup --- */
.tip-popup {
  position: fixed; left: 0; top: 0; z-index: var(--z-tooltip);
  background: var(--tooltip-bg); color: var(--tooltip-fg);
  font-size: var(--text-xs); line-height: 1.45; font-weight: 450;
  padding: 8px 11px; border-radius: var(--r-sm); width: 230px;
  opacity: 0; pointer-events: none;
  transform: translateY(4px);
  transition: opacity 150ms var(--ease-out-expo), transform 150ms var(--ease-out-expo);
}
.tip-popup.visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .tip-popup { transition: none; } }
