/* ============================================================
   THE BOT CONSOLE — PLATFORM ADMIN (P10E)
   ------------------------------------------------------------
   Центр управления платформой, но прежде всего рабочий экран.
   Плотность данных важнее эффекта: свечение только у фокуса и
   главного действия, Electric Field здесь не используется.
   ============================================================ */
body.ca-on.cs-on #organizations-tab { padding: 0; height: 100%; overflow: auto; }
/* Прежняя таблица остаётся в разметке — на ней держится вся
   существующая логика, — но администратор работает с карточками. */
body.ca-on #organizations-tab > h1,
body.ca-on #organizations-tab > .chats-hint,
body.ca-on #organizations-tab table.operators-table,  /* PCC-UX-2B: only the org list table -- nested tables (operators, …) must stay visible */
body.ca-on #organizations-tab > h2 { display: none !important; }
/* Форма создания видна только внутри своего диалога. */
body.ca-on #organizations-tab > .create-operator-form { display: none !important; }

.ca-root { padding: 22px 26px 60px; }
.ca-root[hidden] { display: none; }

.ca-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.ca-head-text { flex: 1; min-width: 240px; }
.ca-title { margin: 0 0 4px; font-size: 22px; font-weight: 700; color: var(--ink); }
.ca-lead { margin: 0; font-size: 13.5px; color: var(--ink-muted); }
.ca-head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.ca-search { position: relative; display: flex; align-items: center; }
.ca-search-icon {
  position: absolute; left: 11px;
  color: var(--ink-faint); font-size: 15px; pointer-events: none;
}
.ca-search input {
  width: 240px;
  padding: 9px 12px 9px 30px;
  border-radius: var(--radius);
  font-size: 13.5px;
}
.ca-search-note { margin: -8px 0 14px; font-size: 12px; color: var(--ink-faint); }

.ca-new {
  padding: 9px 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.ca-new:hover { background: var(--accent-soft); }

/* ---------- Карточки организаций ---------- */
.ca-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 12px;
}
.ca-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease);
}
.ca-card[hidden] { display: none; }
.ca-card:hover { border-color: var(--border-strong); }
/* Только что созданная организация подсвечивается коротко и спокойно. */
.ca-card.is-new { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

.ca-card-open {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 14px 16px 12px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ca-card-open:hover { background: var(--surface-alt); }
.ca-card-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ca-card-top { display: flex; align-items: center; gap: 8px; }
.ca-card-name {
  flex: 1; min-width: 0;
  font-size: 14.5px; font-weight: 650; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ca-badge {
  flex: none;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.03em;
}
.ca-badge-on  { background: var(--success-wash); color: var(--success-ink); }
.ca-badge-off { background: var(--warning-wash); color: var(--warning-ink); }
.ca-card-meta { display: flex; gap: 12px; font-size: 12px; color: var(--ink-muted); }
.ca-key {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}
.ca-card-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
body.ca-on .ca-card-actions button {
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: 11.5px; font-weight: 600;
  cursor: pointer;
}
body.ca-on .ca-card-actions button:hover { color: var(--ink); border-color: var(--accent); }
body.ca-on .ca-card-actions .delete-btn:hover { color: var(--danger); border-color: var(--danger); }

.ca-empty, .ca-list-empty {
  padding: 28px 4px;
  color: var(--ink-faint);
  font-size: 13.5px;
}

/* ---------- Контекст выбранной организации ----------
   Постоянно виден: администратор всегда должен понимать, чьими
   настройками он сейчас управляет. */
.ca-context {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 26px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  position: sticky;
  top: 0;
  z-index: 5;
}
.ca-context.hidden { display: none; }
.ca-back {
  padding: 5px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12.5px; font-weight: 600;
  cursor: pointer;
}
.ca-back:hover { color: var(--ink); border-color: var(--accent); }
.ca-context-name { font-size: 14px; font-weight: 650; color: var(--ink); }
.ca-context-tag { padding: 2px 9px; border-radius: var(--radius-pill); font-size: 10.5px; font-weight: 700; }

/* Вне выбранной организации её экраны скрыты. */
body.ca-on:not(.ca-inside) .co-screen { display: none !important; }

/* ---------- Диалог создания ---------- */
.ca-modal { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; }
.ca-modal.hidden { display: none; }
.ca-modal-back { position: absolute; inset: 0; background: rgba(4, 8, 16, 0.6); }
.ca-modal-box {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: 0 24px 60px var(--shadow-color);
}
.ca-modal-title { margin: 0 0 4px; font-size: 17px; font-weight: 700; color: var(--ink); }
.ca-modal-lead { margin: 0 0 14px; font-size: 12.5px; color: var(--ink-muted); }
body.ca-on .ca-modal-body form { display: flex; flex-direction: column; gap: 9px; }
body.ca-on .ca-modal-body input { width: 100%; padding: 9px 11px; font-size: 13.5px; }
body.ca-on .ca-modal-body button[type="submit"] {
  align-self: flex-start;
  padding: 9px 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px; font-weight: 650;
  cursor: pointer;
}
body.ca-on .ca-modal-body button[type="submit"]:disabled { opacity: 0.6; cursor: default; }
.ca-modal-cancel {
  margin-top: 12px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12.5px; font-weight: 600;
  cursor: pointer;
}
.ca-modal-cancel:hover { color: var(--ink); }

/* ---------- Заявки, анкеты, изменённые ответы ---------- */
body.ca-on #leads-tab, body.ca-on #anketa-tab, body.ca-on #edited-replies-tab {
  padding: 22px 26px 60px;
}
body.ca-on #leads-tab h1, body.ca-on #anketa-tab h1, body.ca-on #edited-replies-tab h1 {
  margin: 0 0 14px; font-size: 22px; font-weight: 700;
}
body.ca-on #leads-tab table { width: 100%; }
body.ca-on .edited-replies-list { display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 1024px) { .ca-root { padding: 20px 18px 56px; } .ca-context { padding: 10px 18px; } }
@media (max-width: 560px) {
  .ca-root { padding: 16px 12px 48px; }
  .ca-grid { grid-template-columns: 1fr; }
  .ca-search input { width: 100%; }
  .ca-head-actions { width: 100%; }
  .ca-search { flex: 1; }
  .ca-context { padding: 9px 12px; gap: 8px; }
  .ca-context-name { font-size: 13px; }
  body.ca-on #leads-tab, body.ca-on #anketa-tab, body.ca-on #edited-replies-tab { padding: 16px 12px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .ca-card, .ca-card.is-new { transition: none !important; }
}

/* Разделы выбранной организации. Живут в строке контекста, а не в
   боковой навигации: они принадлежат организации, а не платформе. */
.ca-sections { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.ca-section {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.ca-section:hover { background: var(--surface); color: var(--ink); }
.ca-section.is-on {
  background: var(--accent-wash);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
}
.ca-section:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 900px) {
  .ca-context { flex-wrap: wrap; }
  .ca-sections { margin-left: 0; width: 100%; }
  .ca-section { padding: 6px 10px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .ca-section { transition: none; } }

/* PCC-UX-2A: the create form lives in its dialog; its old heading/hint
   (nested in .platform-admin-only) must not show above an organization. */
body.ca-on #organizations-tab > .platform-admin-only > h2,
body.ca-on #organizations-tab > .platform-admin-only > .chats-hint { display: none !important; }

/* PCC-UX-2B: workspace header = one line «← Все организации · name · status»,
   tab bar on its own row below, whatever the length of the organization name. */
.ca-back { white-space: nowrap; flex: 0 0 auto; }
.ca-context-name { flex: 0 1 auto; min-width: 0; }
.ca-context-tag { flex: 0 0 auto; }
body.ca-on .ca-context { flex-wrap: wrap; row-gap: 8px; }
body.ca-on .ca-context .ca-sections { flex-basis: 100%; margin-left: 0; width: 100%; }

/* THE-BOT-OWNER-MFA-1: ссылка «Безопасность» в шапке (переносится console-shell.js в .cs-topbar-actions). */
.security-link {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.security-link:hover { color: var(--ink); background: var(--accent-wash); }
/* RAIW-LIVE-MONITOR-UX1: «Монитор» в верхней панели — тот же вид, отмечен, пока открыт Live Monitor RAIW. */
.security-link[aria-current="page"] { color: var(--ink); background: var(--accent-wash); font-weight: 600; }
/* Узкий экран: группа действий шапки прокручивается сама, страница не получает горизонтальной прокрутки. */
@media (max-width: 640px) {
  .security-link { padding: 6px 6px; font-size: 0.85rem; }
  body.cs-on .cs-topbar-actions { flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
  body.cs-on .cs-topbar-actions::-webkit-scrollbar { display: none; }
  body.cs-on .cs-topbar-actions > * { flex: 0 0 auto; }
  body.cs-on .cs-topbar-actions > #raiw-monitor-link { order: -1; }   /* «Монитор» всегда виден первым */
}

/* THE-BOT-OWNER-CONSOLE-NAV-P1: a direct link / F5 into a section this account cannot open */
.cs-route-denied { margin: 16px 0; padding: 16px; border: 1px solid var(--border-strong); border-radius: 12px; }
.cs-route-denied p { margin: 0 0 12px; color: var(--ink); }
.cs-route-denied-home { padding: 6px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: transparent; color: var(--accent); cursor: pointer; font: inherit; }
