:root {
  --bg: #faf8ff;
  --bg2: #f0ecf5;
  --panel: #ffffff;
  --stroke: rgba(124,58,237,0.12);
  --stroke2: rgba(124,58,237,0.18);
  --text: #0f0d1a;
  --muted: rgba(15,13,26,0.55);
  --good: #22c55e;
  --bad: #ed1c00;
  --accent: #7C3AED;
  --accent-hover: #6D28D9;
  --accent-light: #A78BFA;
  --accent2: #ff6b2c;
  --gradient: linear-gradient(135deg, #ff6b2c, #7C3AED);
  --shadow-card: 0 2px 12px rgba(124,58,237,0.06);
  --shadow-hover: 0 6px 24px rgba(124,58,237,0.12);
  --glass-bg: rgba(255,255,255,0.72);
  --glass-blur: blur(20px);

  /* Type scale: единая шкала шрифтов, на которой строится вся админка.
     - xs (11px): только для chip-меток / caption uppercase, НЕ для активного контента.
     - sm (12px): caption, help-text, ячейки таблиц.
     - base (14px): body, кнопки по умолчанию, формы.
     - md (15px): вторичные заголовки внутри карточек.
     - lg (16px): h3 карточек.
     - xl (18px): заголовки секций, page-title. */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 18px;

  /* Семантические цвета (UX-пакет polish02): используются для типизированных
     тоастов, confirm-модалов, баннеров, help-popover'ов, чек-листа.
     Старые --good / --bad оставлены — на них завязаны badge.good/bad,
     многие inline-стили в страницах (rgba(34,197,94,...)) и т.п. */
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.10);
  --success-border: rgba(34, 197, 94, 0.35);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.10);
  --warn-border: rgba(245, 158, 11, 0.35);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.10);
  --danger-border: rgba(239, 68, 68, 0.40);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.10);
  --info-border: rgba(59, 130, 246, 0.35);
}

html.dark {
  --bg: #0f0d1a;
  --bg2: #1e1b2e;
  --panel: #1e1b2e;
  --stroke: rgba(255,255,255,0.08);
  --stroke2: rgba(255,255,255,0.12);
  --text: #faf8ff;
  --muted: rgba(250,248,255,0.55);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.25);
  --shadow-hover: 0 6px 24px rgba(124,58,237,0.18);
  --glass-bg: rgba(30,27,46,0.72);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 6px; opacity: 0.5; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--text-base)/1.5 'Manrope', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 14px;
  padding: 14px;
}

.sidebar {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  width: 270px;
  transition: width 0.18s ease, background 0.3s;
  box-shadow: var(--shadow-card);
}

.sidebar.collapsed { width: 62px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .side-bottom,
.sidebar.collapsed .nav-group-title span:last-child,
.sidebar.collapsed .nav-item span:last-child { display: none; }
.sidebar.collapsed .nav-group-title { justify-content: center; padding-left: 8px; padding-right: 8px; }
.sidebar.collapsed .nav-item { justify-content: center; }

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--stroke);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--gradient) border-box;
  background-clip: border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  position: relative;
}
.logo::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 8px;
  background: var(--gradient);
  opacity: 0.18;
}
.brand-title { font-weight: 800; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 10px; color: var(--muted); font-weight: 500; }

.side-nav { padding: 8px; display: flex; flex-direction: column; gap: 3px; overflow: auto; }
.nav-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.nav-group-title {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  padding: 9px 10px;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.nav-group-title:hover {
  border-color: var(--stroke2);
  background: var(--bg2);
  color: var(--text);
}
.nav-group-title:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
}
.nav-section-arrow {
  width: 10px;
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 1;
}
.nav-section-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.18s ease, opacity 0.16s ease;
}
.nav-section.expanded .nav-section-items {
  max-height: 520px;
  opacity: 1;
}
.nav-section.hidden {
  display: none !important;
}
.nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  font-size: 12.5px;
  transition: all 0.15s;
}
.nav-item:hover {
  border-color: var(--stroke2);
  background: var(--bg2);
  color: var(--text);
}
.nav-item.active {
  border-color: rgba(124,58,237,0.35);
  background: rgba(124,58,237,0.08);
  color: var(--accent);
  font-weight: 700;
}
html.dark .nav-item.active {
  background: rgba(124,58,237,0.15);
  color: var(--accent-light);
}
.ico {
  width: 24px;
  height: 24px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--bg2);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-size: 12px;
}

.side-bottom {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--stroke);
  display: grid;
  gap: 8px;
}

.main { min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.topbar {
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: var(--shadow-card);
  transition: background 0.3s;
}
.page-title { font-weight: 800; font-size: 14px; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); font-size: 11px; font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.search-input {
  width: 280px;
  max-width: 38vw;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: var(--bg2);
  color: var(--text);
  padding: 9px 12px;
  font-size: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
.page-root { min-height: 0; overflow: auto; padding-bottom: 14px; }

.toast-wrap {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 999;
  display: grid;
  gap: 8px;
}

.theme-toggle {
  background: var(--bg2);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  background: rgba(124,58,237,0.08);
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
  }
  .sidebar {
    width: auto !important;
  }
  .sidebar.collapsed {
    width: auto !important;
  }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .side-bottom,
  .sidebar.collapsed .nav-group-title span:last-child,
  .sidebar.collapsed .nav-item span:last-child {
    display: initial;
  }
  .sidebar.collapsed .nav-group-title {
    justify-content: flex-start;
    padding-left: 10px;
    padding-right: 10px;
  }
  .sidebar.collapsed .nav-item {
    justify-content: flex-start;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-input {
    width: 100%;
    max-width: none;
  }
}

/* ── Мониторинг: мигание nav-item при проблемах ─────────────────────────── */
@keyframes navCriticalFlash {
  0%, 49%  { background: rgba(237, 28, 0, 0.22); color: #ff6b6b; }
  50%, 100% { background: transparent; color: inherit; }
}

.nav-item.nav-critical {
  animation: navCriticalFlash 1.2s ease-in-out infinite;
  border-radius: 8px;
}

.nav-item.nav-critical .ico {
  filter: none;
}

.monitoring-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--bad, #ed1c00);
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(237, 28, 0, 0.6);
  animation: monDotPulse 1.2s ease-in-out infinite;
}

@keyframes monDotPulse {
  0%   { box-shadow: 0 0 0 0 rgba(237, 28, 0, 0.6); }
  70%  { box-shadow: 0 0 0 6px rgba(237, 28, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(237, 28, 0, 0); }
}

/* pulse-dot — для заказов и перезвонов (уже используется в app.js) */
.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #facc15;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
  animation: monDotPulse 1.4s ease-in-out infinite;
}

/* nav-count-badge — красный круглый счётчик у пунктов «Заказы»/«Перезвоны»
   (суммарно по всем доступным точкам). Индикатор, а не кнопка —
   без cursor:pointer. См. app.js:_setNavCountBadge. */
.nav-count-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: #ef4444;
  color: #fff;
  border-radius: 10px;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(239,68,68,.3), 0 2px 6px rgba(239,68,68,.35);
}
.sidebar.collapsed .nav-count-badge { display: none !important; }
