/* ==========================================================================
   portal-kit.css (kit1) — адаптер портала test001.at к design-kit.
   Подключается после kit/app.css и kit/brand.css. Только токены кита (var(--…)).
   Классы старой разметки, которые строит JS (dashboard.html), оформлены здесь под вид кита:
   плитки панелей, .role-badge, .tag-*, .status-*, .btn-sm без .btn, .invite-result, строки уведомлений.
   Вшитые в JS-шаблоны цвета (style="color:#64748b" и т. п.) нейтрализуются селекторами по атрибуту style.
   ========================================================================== */

/* ---------- База ---------- */
.hidden { display: none !important; }

/* Ролевая видимость (body[data-role] ставит JS) — как было */
body[data-role="user"] .admin-only { display: none !important; }
body:not([data-role="admin"]) .admin-only { display: none !important; }

/* ---------- Каркас: шапка без сайдбара ---------- */
.app.portal-app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
.portal-app .brand { min-width: 0; }
.portal-app .brand-sub { font-size: 12.5px; font-weight: 500; color: var(--dim); margin-left: -2px; }
.portal-page { max-width: 1100px; }

.who { display: inline-flex; align-items: center; gap: 7px; min-width: 0; margin-right: 4px; font-size: 13px; color: var(--muted); }
.who .icon { color: var(--dim); }
.who .name { color: var(--text); font-weight: 550; min-width: 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Кнопки шапки: на телефоне — только значок (подпись остаётся для чтения с экрана) */
@media (max-width: 640px) {
  .topbar .btn-collapse { width: 34px; padding: 0; }
  .topbar .btn-collapse .btn-label,
  .topbar .btn-collapse .btn-label-x {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .who .name { max-width: 110px; }
}

/* ---------- Плашки ролей, статусов, тегов (их строит JS) ---------- */
.role-badge, .tag.tag-active, .tag.tag-used, .tag.tag-expired, .status-active, .status-disabled {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 8px; border-radius: 999px; margin: 0;
  font-family: var(--font); font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; letter-spacing: 0;
  background: var(--c-bg, var(--neutral-bg)); color: var(--c-fg, var(--neutral-fg)); vertical-align: middle;
}
.role-badge:empty { display: none; }
.role-admin { --c: var(--warn); --c-bg: var(--warn-bg); --c-fg: var(--warn-fg); }
.role-user { --c: var(--info); --c-bg: var(--info-bg); --c-fg: var(--info-fg); }
.role-vip { --c: var(--violet); --c-bg: var(--violet-bg); --c-fg: var(--violet-fg); }
.tag-active, .status-active { --c: var(--ok); --c-bg: var(--ok-bg); --c-fg: var(--ok-fg); }
.tag-used { --c: var(--neutral); --c-bg: var(--neutral-bg); --c-fg: var(--neutral-fg); }
.tag-expired, .status-disabled { --c: var(--danger); --c-bg: var(--danger-bg); --c-fg: var(--danger-fg); }

/* ---------- Плитки панелей ---------- */
.panel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .panel-grid { grid-template-columns: minmax(0, 1fr); } }
.panel-grid > .card + .card { margin-top: 0; }

/* Цвет панели — из PANELS (блок «Бренд» её brand/<key>.css): светлая --pc-l*, тёмная --pc-d* */
.panel-grid > .card { --pc: var(--pc-l, var(--accent)); --pc-fg: var(--pc-l-fg, var(--accent-fg)); --pc-bg: var(--pc-l-bg, var(--accent-soft)); }
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .panel-grid > .card { --pc: var(--pc-d, var(--accent)); --pc-fg: var(--pc-d-fg, var(--accent-fg)); --pc-bg: var(--pc-d-bg, var(--accent-soft)); }
}
@media screen {
  :root[data-theme="dark"] .panel-grid > .card { --pc: var(--pc-d, var(--accent)); --pc-fg: var(--pc-d-fg, var(--accent-fg)); --pc-bg: var(--pc-d-bg, var(--accent-soft)); }
}

.panel-grid > .card {
  display: flex; align-items: flex-start; gap: 14px; padding: 16px; min-height: 118px;
  color: var(--text); text-decoration: none; position: relative;
  transition: border-color .12s, box-shadow .12s;
}
.panel-grid > .card:hover { text-decoration: none; border-color: var(--pc); box-shadow: var(--shadow-2); }
.panel-grid > .card:focus-visible { outline: 2px solid var(--pc); outline-offset: 2px; }
.card-icon {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--pc); color: var(--pc-fg);
}
.card-icon .icon { width: 24px; height: 24px; }
.card-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; align-self: stretch; }
.card-header { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.card-title { font-size: 15px; font-weight: 650; color: var(--text); line-height: 1.3; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.45; flex: 1 1 auto; }
.card-footer { display: flex; align-items: center; gap: 10px; margin-top: 12px; min-width: 0; }
.card-domain {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-2); background: var(--surface-3);
  padding: 1px 7px; border-radius: 5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-arrow { color: var(--dim); flex: none; margin-left: auto; transition: color .12s, transform .12s; }
.panel-grid > .card:hover .card-arrow { color: var(--pc); transform: translateX(3px); }

/* Точка доступности: точка + слово из title (проверка... / онлайн / офлайн / недоступен) */
.card-status {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto;
  font-size: 12px; font-weight: 550; line-height: 1.3; white-space: nowrap; color: var(--c-fg, var(--muted));
  --c: var(--neutral); --c-fg: var(--muted);
}
.card-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; animation: pulse 1.4s ease-in-out infinite; }
.card-status::after { content: attr(title); overflow: hidden; text-overflow: ellipsis; }
.card-status.online { --c: var(--ok); --c-fg: var(--ok-fg); }
.card-status.offline { --c: var(--danger); --c-fg: var(--danger-fg); }
.card-status.online::before, .card-status.offline::before { animation: none; }

/* Зарезервировано: «нет доступа» */
.panel-grid > .card.card-locked { opacity: .55; cursor: default; }
.panel-grid > .card.card-locked:hover { border-color: var(--border); box-shadow: var(--shadow-1); }
.card-lock-badge {
  margin-left: auto; display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--neutral-bg); color: var(--neutral-fg); white-space: nowrap;
}

/* ---------- Экран входа ---------- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 80; background: var(--bg); overflow-y: auto;
  display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.auth-theme { position: absolute; top: 9px; right: 12px; }
.auth-overlay > .menu-wrap { position: absolute; top: 9px; right: 12px; }
.auth-overlay > .menu-wrap > .auth-theme { position: static; }
.auth-box { width: min(400px, 100%); padding: 28px 28px 24px; margin: auto 0; }
.auth-logo.brand-mark { width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 14px; }
.auth-logo.brand-mark .icon { width: 26px; height: 26px; }
.auth-box h2 { text-align: center; font-size: 18px; font-weight: 650; }
.auth-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 2px 0 18px; }
.auth-tabs { display: flex; width: 100%; margin-bottom: 16px; }
.auth-tabs .auth-tab { flex: 1 1 0; justify-content: center; height: 28px; }
.auth-box .error, .auth-box .success { display: none; margin-bottom: 14px; line-height: 1.45; }
.auth-form > .field + .field { margin-top: 12px; }
.auth-form .btn-primary { width: 100%; margin-top: 18px; }
@media (max-width: 640px) { .auth-box { padding: 22px 16px 18px; } }

/* ---------- Окно «Управление» ---------- */
.settings-modal { height: min(820px, calc(100vh - 40px)); }
.settings-modal .modal-head { padding-bottom: 4px; }
.settings-modal .modal-tabs { margin: 0; padding: 0 12px; flex: none; }
.settings-modal .modal-body { padding: 16px 18px 20px; flex: 1 1 auto; }
@media (max-width: 640px) {
  .settings-backdrop { padding: 8px; }
  .settings-modal { height: calc(100vh - 16px); max-height: calc(100vh - 16px); }
  .settings-modal .modal-body { padding: 14px 12px 16px; }
  .settings-modal .modal-tabs { padding: 0 4px; }
  .settings-modal .table td { white-space: nowrap; }   /* узко: таблица листается вбок, строки не ломаются */
}
.modal-section + .modal-section { margin-top: 22px; }
.modal-section > .section-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 10px; }
.sec-note, .th-note { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--dim); font-size: 12px; }
.sec-foot { margin-top: 8px; font-size: 12px; color: var(--dim); }
.sec-foot:empty { display: none; }

/* Таблицы окна: кит .table внутри рамки, без своей вертикальной прокрутки */
.settings-modal .table-wrap { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.settings-modal .table th { position: static; }
.settings-modal .table td { color: var(--text); }
.tbl td .mono, .tbl td.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.tbl td .mono[onclick] { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.tbl td .mono[onclick]:hover { color: var(--accent); }
.tbl td:last-child { white-space: nowrap; }
.tbl td input[type="checkbox"], .ntf-form input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; cursor: pointer; vertical-align: middle; }
.tbl td input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .5; }

/* Старые кнопки строк (.btn-sm без .btn, «Проверить») — вид кнопки кита 28px */
.tbl .btn-sm:not(.btn), #ntfPanelsTable button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 28px; padding: 0 10px !important; margin: 0 4px 0 0; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 12.5px !important; font-weight: 550; white-space: nowrap; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.tbl .btn-sm:not(.btn):hover, #ntfPanelsTable button:hover { background: var(--hover); }
.tbl .btn-sm:not(.btn):last-child { margin-right: 0; }
.tbl .btn-sm.danger:not(.btn) { color: var(--danger-fg); }
.tbl .btn-sm.danger:not(.btn):hover { background: var(--danger-bg); border-color: var(--danger); }

/* Формы в окне */
.row-form { display: grid; grid-template-columns: 130px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.row-form.row-form-2 { grid-template-columns: minmax(0, 1fr) auto; }
@media (max-width: 640px) {
  .row-form, .row-form.row-form-2 { grid-template-columns: minmax(0, 1fr); }
  .row-form .btn { width: 100%; }
}
.invite-result {
  --c: var(--ok); --c-bg: var(--ok-bg); --c-fg: var(--ok-fg);
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r); background: var(--c-bg); color: var(--c-fg); font-size: 13px;
}
.invite-result .url {
  display: block; margin-top: 8px; padding: 8px 10px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: 12px; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  word-break: break-all; cursor: pointer;
}
.invite-result .url:hover { border-color: var(--accent); }

/* Уведомления */
.ntf-form { display: flex; flex-direction: column; gap: 14px; max-width: 620px; }
.ntf-switch { flex-wrap: wrap; color: var(--text); }
.ntf-note { color: var(--dim); font-size: 12px; }
.ntf-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ntf-result { font-size: 12.5px; }
.ntf-result:empty { display: none; }
.ntf-col-panel { width: 200px; }
.ntf-col-on { width: 90px; }
.ntf-col-act { width: 110px; }
#ntfPanelsTable input[type="text"] {
  height: 28px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: 12.5px; outline: none; min-width: 140px;
  transition: border-color .12s, box-shadow .12s;
}
#ntfPanelsTable input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
#ntfPanelsTable input[type="text"]::placeholder { color: var(--dim); }

.code-inline { background: var(--surface-3); color: var(--text-2); padding: 1px 6px; border-radius: 4px; overflow-wrap: anywhere; }

/* ---------- Нейтрализация цветов, вшитых в JS-шаблоны ---------- */
#settingsModal [style*="color:#64748b"] { color: var(--dim) !important; }
#settingsModal [style*="color:#94a3b8"] { color: var(--muted) !important; }
/* Итог аудита (style="color:…" из resultColor): ok / error / denied / прочее */
#auditTable td[style*="color:#34d399"] { color: var(--ok-fg) !important; font-weight: 600; }
#auditTable td[style*="color:#f87171"] { color: var(--danger-fg) !important; font-weight: 600; }
#auditTable td[style*="color:#fbbf24"] { color: var(--warn-fg) !important; font-weight: 600; }
#auditTable td[style*="color:#94a3b8"] { color: var(--muted) !important; }
#auditTable td[style*="color:#"]::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--neutral); }
#auditTable td[style*="color:#34d399"]::before { background: var(--ok); }
#auditTable td[style*="color:#f87171"]::before { background: var(--danger); }
#auditTable td[style*="color:#fbbf24"]::before { background: var(--warn); }
/* ntfMsg(): успех / ошибка */
#ntfResult [style*="#0f766e"] { color: var(--ok-fg) !important; }
#ntfResult [style*="#b91c1c"] { color: var(--danger-fg) !important; }
