:root {
  --bg: #0a0a10;
  --bg-alt: #12121a;
  --panel: #181822;
  --panel-2: #1f1f2b;
  --text: #ececf1;
  --text-secondary: #b8bcc6;
  --muted: #8b92a0;
  --accent: #e81848;
  --accent-soft: rgba(233, 30, 99, 0.14);
  --border: #2a2a38;
  --font-heading: "Unbounded", "Segoe UI", sans-serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --text-base: 15px;
  --radius-card: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  font-feature-settings: "kern" 1;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4,
.brand-title,
.card-value-xl,
.card-value-hero {
  font-family: var(--font-heading);
  font-weight: 500;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

/* Масштаб UI: на .layout, не на html — иначе ломаются клики по draggable (карточки CRM) */
.layout {
  zoom: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-alt);
  padding: 24px 18px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 10px 12px;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.2s ease;
}

/* Шапка сайдбара: одна кнопка → выпадающий список разделов */
.sidebar-brand-wrap {
  position: relative;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 4px 6px 4px 0;
  margin: 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.sidebar-brand-toggle:hover {
  background: var(--panel);
}
.sidebar-brand-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.sidebar-brand-chevron {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}
.sidebar-brand-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 4px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  margin-top: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.sidebar-brand-dropdown.hidden {
  display: none;
}
.sidebar-brand-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.sidebar-brand-option:hover {
  background: var(--panel-2);
  border-color: var(--border);
}
.sidebar-brand-option.active {
  border-color: rgba(233, 30, 99, 0.45);
  background: linear-gradient(135deg, rgba(233, 30, 99, 0.12), rgba(192, 38, 211, 0.08));
}
.sidebar-brand-option-title {
  font-size: 14px;
  font-weight: 600;
}
.sidebar-brand-option-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

/* Модалка конструктора воронки: шапка фиксирована, скролл только у полотна */
.crm-flow-modal-content {
  width: min(820px, calc(100vw - 32px));
  max-width: min(820px, calc(100vw - 32px));
  max-height: min(92vh, 920px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.crm-flow-modal-header {
  flex-shrink: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.crm-flow-modal-scroll {
  flex: 1;
  min-height: 360px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
}
.crm-flow-modal-scroll::-webkit-scrollbar {
  width: 6px;
}
.crm-flow-modal-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.crm-expand-wrap {
  position: relative;
  width: 100%;
}
.crm-expand-wrap .crm-expand-field {
  display: block;
  width: 100%;
  overflow: hidden !important;
  resize: none !important;
  box-sizing: border-box;
}
.crm-expand-wrap:has(.crm-expand-toggle:not(.hidden)) .crm-expand-field {
  padding-bottom: 28px;
}
.crm-expand-readonly {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px 28px;
}
.crm-expand-readonly-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
}
.crm-expand-readonly-text a {
  color: #3b9fde;
  text-decoration: none;
}
.crm-expand-readonly-text a:hover {
  text-decoration: underline;
}
.crm-expand-toggle {
  position: absolute;
  right: 8px;
  bottom: 6px;
  width: 24px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s;
}
.crm-expand-toggle:hover {
  border-color: color-mix(in srgb, var(--crm-proj-accent, #7c3aed) 45%, var(--border));
  color: var(--crm-proj-accent, #7c3aed);
}
.crm-expand-toggle.hidden { display: none; }
.crm-expand-wrap .crm-expand-toggle {
  position: absolute;
  right: 8px;
  bottom: 8px;
}

.crm-sources-discover-box {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
}
.crm-sources-discover-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 8px;
}
.crm-sources-discover-row {
  display: flex;
  gap: 8px;
}
.crm-sources-discover-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.crm-sources-discover-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.crm-sources-discover-hint {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}
.crm-sources-discover-status {
  margin-top: 6px;
  font-size: 12px;
  min-height: 16px;
}

.crm-topic-row--input .crm-topic-thread-input {
  flex: 1;
  min-width: 0;
  max-width: none;
}
.crm-topic-icon-btn,
.crm-topic-add-btn,
.crm-topic-back-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}
.crm-topic-icon-btn:hover,
.crm-topic-add-btn:hover,
.crm-topic-back-btn:hover {
  border-color: color-mix(in srgb, var(--crm-proj-accent, #7c3aed) 45%, var(--border));
  color: var(--crm-proj-accent, #7c3aed);
}
.crm-chat-linked-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px 8px;
}
.crm-chat-linked-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: color-mix(in srgb, var(--crm-proj-accent, #7c3aed) 14%, var(--panel-2));
  border: 1px solid color-mix(in srgb, var(--crm-proj-accent, #7c3aed) 35%, var(--border));
  color: var(--text);
}
.crm-chat-linked-chip-x {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.crm-chat-linked-chip-x:hover { color: #ef4444; }

.crm-accounts-modal .modal-header {
  margin-bottom: 18px;
  min-height: 44px;
  padding-bottom: 2px;
}
.crm-accounts-modal .crm-accounts-modal-content {
  padding-bottom: 16px;
}
.crm-accounts-modal #crmAccountsChipList {
  padding-top: 12px;
  margin-top: 2px;
  border-top: 1px solid var(--border);
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel);
  border-color: var(--border);
}

.mobile-topbar {
  display: none;
}

.sidebar-burger {
  display: none;
}

.sidebar-overlay {
  display: none;
}

body.nav-open {
  overflow: hidden;
}

.log-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.log-mode-tabs .tab-btn.active {
  border-color: var(--accent);
  background: rgba(233, 30, 99, 0.16);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-status-unified {
  grid-column: span 2;
}

.card-status {
  /* same as other cards */
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.status-text {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.status-text.status-ok {
  color: #00c853;
}

.status-text.status-warn {
  color: #ffb300;
}

.status-text.status-error {
  color: #ff5252;
}

.status-time {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  font-family: var(--font-mono);
}

.niche-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  min-height: 36px;
}

.niche-panel-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-shrink: 0;
}

.niche-panel-left h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.niche-search-wrap {
  position: relative;
  width: 168px;
  flex-shrink: 0;
}

.niche-search-input {
  width: 100%;
  height: 34px;
  padding: 0 34px 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  box-sizing: border-box;
}

.niche-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.niche-search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.niche-panel-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

.niche-panel-top .period-toggle {
  margin-bottom: 0;
  height: 34px;
  padding: 2px;
  box-sizing: border-box;
  align-items: center;
}

.niche-period-toggle .period-btn {
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.select-filter-compact {
  appearance: none;
  -webkit-appearance: none;
  height: 34px;
  padding: 0 28px 0 10px;
  font-size: 13px;
  min-width: 88px;
  max-width: 104px;
  box-sizing: border-box;
  background-color: var(--panel-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b92a0' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
}

.chart-pager-compact {
  gap: 0;
  margin-left: 2px;
}

.chart-pager-compact .chart-pager-label {
  min-width: auto;
  padding: 0 6px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.chart-pager-compact .btn-pager {
  min-width: 30px;
  width: 30px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.panel-niches {
  background: var(--panel);
}

.panel-niches .chart-scroll-niches {
  height: 480px;
  overflow: hidden;
}

.panel-niches #chartNiches {
  height: 460px !important;
  max-height: 460px !important;
}

/* —— Daily chart panel —— */
.panel-daily {
  background: var(--panel);
}

.daily-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  min-height: 36px;
}

.daily-panel-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-shrink: 0;
}

.daily-panel-top h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.daily-panel-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.daily-panel-top .period-toggle {
  margin-bottom: 0;
  height: 34px;
  padding: 2px;
  box-sizing: border-box;
  align-items: center;
}

.daily-series-toggle .period-btn {
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}

.daily-series-toggle .period-btn:not(.active) {
  opacity: 0.45;
}

.daily-series-toggle .period-btn .series-dot {
  width: 7px;
  height: 7px;
}

.daily-view-toggle .period-btn {
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.daily-kpi-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 18px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.daily-kpi {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.daily-kpi strong {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}

.daily-kpi-muted {
  opacity: 0.85;
}

.series-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot, var(--accent));
  flex-shrink: 0;
}

.daily-chart-wrap {
  height: 400px;
  position: relative;
}

.panel-daily #chartDaily {
  height: 380px !important;
  max-height: 380px !important;
}

.daily-report-wrap {
  overflow: visible;
  padding: 4px 0 8px;
}

.day-report-chart-box {
  position: relative;
  min-height: 300px;
  overflow: visible;
  padding: 12px;
}

.day-report-chart-box canvas {
  display: block;
  max-width: 100%;
}

.overview-section .panel.panel-daily.panel-chart,
.panel-daily {
  overflow: visible;
}

.day-report-legend .dr-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* —— Overview responsive —— */
@media (max-width: 1280px) {
  .cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  .overview-panels {
    gap: 20px;
  }
  .niche-panel-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

@media (max-width: 960px) {
  .overview-section {
    padding-right: 0;
  }
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .card-value-xl {
    font-size: 28px;
  }
  .niche-panel-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .niche-panel-left {
    width: 100%;
    flex-wrap: wrap;
  }
  .niche-search-wrap {
    flex: 1;
    min-width: 120px;
    max-width: none;
    width: auto;
  }
  .niche-panel-controls {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
  }
  .daily-panel-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .daily-panel-controls {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
  }
  .daily-kpi-row {
    gap: 10px 14px;
  }
  .panel-niches .chart-scroll-niches {
    height: 400px;
  }
  .panel-niches #chartNiches {
    height: 380px !important;
    max-height: 380px !important;
  }
  .panel-daily .daily-chart-wrap {
    height: 340px;
  }
  .panel-daily #chartDaily {
    height: 320px !important;
    max-height: 320px !important;
  }
  .overview-section .panel.panel-chart:not(.panel-niches):not(.panel-daily) canvas {
    height: auto !important;
  }
}

@media (max-width: 520px) {
  .cards {
    grid-template-columns: 1fr;
  }
  .niche-panel-left h2 {
    font-size: 15px;
  }
  .daily-kpi {
    font-size: 12px;
  }
  .select-filter-compact {
    min-width: 76px;
    max-width: 88px;
    font-size: 12px;
  }
  .chart-pager-compact .chart-pager-label {
    font-size: 11px;
    padding: 0 4px;
  }
}

.select-filter {
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--panel-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

@media (max-width: 1100px) {
  .niche-panel-top {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .niche-panel-controls {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
  }
}

.status-unified {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.status-unified-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.status-unified-label {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.status-unified-time {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
}

.period-toggle,
.daily-view-toggle {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 16px;
  padding: 4px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.period-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.period-btn.active {
  background: rgba(233, 30, 99, 0.18);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(233, 30, 99, 0.35);
}

.panel-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.chart-pager {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chart-pager-label {
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 4.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.btn-pager {
  min-width: 36px;
  padding: 6px 10px;
  font-weight: 700;
}

.table-pager {
  justify-content: flex-end;
  margin-top: 10px;
}

.daily-sum-item {
  margin-right: 12px;
}

.day-report-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.day-report-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(180px, 1fr);
  gap: 16px;
  align-items: center;
}

.day-report-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.day-report-legend li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.day-report-legend .dr-val {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .day-report-grid {
    grid-template-columns: 1fr;
  }
}

.btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: 0.2s ease;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:active {
  transform: scale(0.97);
}

.btn-accent {
  background: var(--accent);
  border-color: transparent;
}

.btn-accent:hover {
  filter: brightness(1.05);
}

.content {
  padding: 20px 24px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

body.crm-kanban-open .content {
  overflow: hidden !important;
  padding: 0 !important;
}

body.crm-kanban-open .page-header {
  display: none;
}

body.crm-kanban-open #projects.section:not(.hidden) {
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column;
  margin: 0 !important;
  width: 100% !important;
  max-width: none !important;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section {
  height: auto;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  min-width: 0;
  flex: 1;
  min-height: 0;
}

.overview-section {
  overflow: visible;
  padding-right: 12px;
}

.overview-section .panel {
  flex: 0 0 auto;
  min-height: unset;
}

.overview-panels {
  display: flex;
  flex-direction: column;
  gap: 32px;
  min-height: 0;
  padding-bottom: 48px;
}

.chart-panel-tall {
  min-height: 0;
}

.chart-scroll {
  flex: 1;
  min-height: 0;
  overflow: visible;
  padding-right: 0;
}

.overview-section .panel.panel-chart {
  display: flex;
  flex-direction: column;
}

.overview-section .panel.panel-chart:not(.panel-niches):not(.panel-daily) canvas {
  flex: 1;
  height: 640px !important;
}

.overview-section .panel.panel-chart {
  overflow: hidden;
}

.chart-scroll {
  height: 640px;
  overflow-y: auto;
  padding-right: 6px;
}

.overview-section .panel {
  overflow: visible;
}

.overview-section .panel-header h2 {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.overview-section .panel-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.45;
}

.page-header h1 {
  margin: 0;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00c853;
  flex-shrink: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.cards.cards-4 {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
}

.cards.cards-3 {
  grid-template-columns: repeat(3, minmax(140px, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: var(--radius-card);
}

.card-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.card-sub {
  font-size: 13px;
  font-weight: 450;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 6px;
}

.card-value {
  font-size: 26px;
  margin-top: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.card-value-hero {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.05;
}

.card-value-xl {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.1;
}

.card-value-lg {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
}

.status-text.status-ok {
  color: #00c853;
}

.status-text.status-warn {
  color: #ffb300;
}

.status-text.status-error {
  color: #ff5252;
}

.card-sub {
  color: var(--muted);
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1.3fr;
  grid-template-rows: 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.panel.panel-chart {
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: stretch;
}

.panel.panel-chart canvas {
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header-with-action {
  align-items: center;
}

.panel-header-with-action .btn {
  margin-right: 0;
  margin-left: 0;
}

.niches-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 10px;
}

.input-search {
  width: 200px;
  max-width: 200px;
  height: 36px;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 500;
}

.panel-sub {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
}

.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 0;
  width: 100%;
}

input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-height: 64px;
  resize: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: none;
}

button:focus,
button:focus-visible {
  outline: none;
  box-shadow: none;
}

.layout {
  -webkit-tap-highlight-color: transparent;
}

.form {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.form-title {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.table-input {
  min-width: 120px;
}

.table-input-id {
  width: 140px;
  min-width: 140px;
  max-width: 140px;
}

/* Таблица ниш — фиксированные ширины колонок */
col.col-group { width: 90px; }
col.col-id { width: 130px; }
col.col-prompt { width: 100px; }
col.col-qualifier { width: 100px; }
col.col-region { width: 95px; }
col.col-test { width: 52px; }
col.col-keywords { width: 170px; }
col.col-donors { width: 44px; }
col.col-occupied { width: 52px; }
col.col-cardmode { width: 72px; }
col.col-target { width: 72px; }
col.col-nontarget { width: 82px; }
col.col-total { width: 58px; }
col.col-actions { width: 130px; }

.col-region .cell-text {
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.col-donors .cell-text-donors {
  max-width: 100%;
}

.cell-subline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.col-occupied,
.col-test,
.col-cardmode {
  text-align: center;
}

.col-test .region-test-checkbox {
  vertical-align: middle;
}

.col-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.occupied-checkbox,
.region-test-checkbox,
.card-mode-checkbox {
  width: 20px;
  height: 20px;
  min-width: 20px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.occupied-checkbox:checked,
.region-test-checkbox:checked,
.card-mode-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.table-input {
  background: var(--panel-2);
}

.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-delete {
  background: #ff5252;
  border-color: transparent;
  color: #fff;
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.btn-delete:hover {
  filter: brightness(1.05);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.logs {
  background: #0a0a0f;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  height: 100%;
  flex: 1;
  overflow-y: auto;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #cfd3dc;
}

.logs-timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

.log-timeline {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.log-card {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.log-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  border-radius: 12px 0 0 12px;
  background: #2c2c3a;
}

.log-card.log-c0::before { background: #f1f1f6; }
.log-card.log-c1::before { background: #f48fb1; }
.log-card.log-c2::before { background: #e91e63; }
.log-card.log-c3::before { background: #b39ddb; }
.log-card.log-c4::before { background: #80deea; }

.log-card summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.log-card summary::-webkit-details-marker {
  display: none;
}

.log-card-title {
  font-weight: 600;
  font-size: 13px;
}

.log-card-meta {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.log-card-preview {
  color: var(--text);
  font-size: 12px;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 520px;
}

.log-card-preview-meta {
  opacity: 0.85;
  font-style: italic;
}

.log-card-body {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-text {
  font-size: 12px;
  color: var(--text);
  background: #14141b;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  white-space: pre-wrap;
}

.log-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 11px;
  color: #cfd3dc;
}

.log-steps-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.log-step {
  display: grid;
  grid-template-columns: 80px 90px 1fr;
  gap: 10px;
}

.log-step-time {
  color: var(--muted);
}

.log-step-stage {
  color: #b39ddb;
}

.panel-footer {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.dash-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.dash-tabs .select-wrap {
  margin-left: auto;
}

.btn.btn-close {
  padding: 6px 10px;
  border-radius: 10px;
  line-height: 1;
}

.tab-btn.active {
  border-color: var(--accent);
}

.dashboards {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.dashboard-panel[data-dashboard="summary"] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.dashboard-panel[data-dashboard="summary"] .cards {
  margin-bottom: 0;
}

.dashboard-panel[data-dashboard="summary"] .grid.two-cols {
  min-height: 0;
  height: 100%;
}

.dashboard-panel[data-dashboard="summary"] .panel.panel-chart {
  min-height: 0;
}

.dashboard-panel[data-dashboard="monthly"] .panel.panel-chart {
  min-height: 0;
}

.dashboard-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.grid.two-cols {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  grid-template-rows: 1fr;
  flex: 1;
  min-height: 0;
}

.details {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding-right: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.details-donors {
  max-width: 25%;
}

.details-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  width: min(1280px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-help {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.modal-textarea {
  flex: 1;
  min-height: 420px;
  resize: none;
}

.keyword-dual-editor {
  display: flex; flex-direction: column; /* was grid */
  display: grid; /* legacy kept below overridden */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: min(62vh, 680px);
}

.keyword-editor-pane {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.keyword-editor-pane span {
  color: var(--muted);
  font-size: 13px;
}

.keyword-textarea {
  min-height: min(60vh, 640px);
  width: 100%;
  font-size: 15px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10100;
  pointer-events: none;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  min-width: 220px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease-out;
}

.toast.toast-error {
  border-color: #ff5252;
}

.toast.toast-success {
  border-color: #00c853;
}

.toast.toast-warn {
  border-color: #ffb300;
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.cell-text {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  color: var(--text);
}

.counter-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.counter-controls .count-value {
  display: inline-block;
  min-width: 5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.counter-buttons {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.counter-buttons button {
  padding: 2px 6px;
  font-size: 10px;
  line-height: 1;
}

.log-line.log-c0 { color: #f1f1f6; }
.log-line.log-c1 { color: #f48fb1; }
.log-line.log-c2 { color: #e91e63; }
.log-line.log-c3 { color: #b39ddb; }
.log-line.log-c4 { color: #80deea; }

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0c0c12;
}

::-webkit-scrollbar-thumb {
  background: #2c2c3a;
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3b3b4b;
}

.hidden {
  display: none;
}


@media (max-width: 1200px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .cards {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

/* Настройки — страница листается, забаненные не за экраном */
#settings.section {
  flex: 0 0 auto;
  min-height: 0;
}
#settings .panel {
  padding-bottom: 48px;
}

/* Allow the settings panel + prompt group to grow without any height cap */
#settings .panel.panel-unlocked,
.prompt-group-expanded {
  overflow: visible !important;
  min-height: unset !important;
  height: auto !important;
  flex: none !important;
}
.settings-comet-balance {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.settings-comet-balance h3 {
  margin: 0 0 4px;
  font-size: 16px;
}
.comet-balance-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.comet-balance-value {
  font-size: 20px;
  font-weight: 600;
}
.comet-balance-value.low {
  color: #ff5252;
}
.comet-balance-error {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.comet-balance-error:not(.hidden) {
  color: #ff8a80;
}

.settings-form {
  margin-bottom: 32px;
}
.settings-form .form-group {
  margin-bottom: 16px;
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.settings-form .form-group:first-child,
.settings-form #settingsSave {
  grid-column: 1 / -1;
}

.settings-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}
.settings-form textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

#settingsBasePrompt {
  min-height: 320px;
}
.settings-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.settings-bans {
  border-top: 1px solid var(--border);
  padding-top: 24px;
}
.settings-bans h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.settings-bans h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}
.ban-add {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ban-add input {
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  min-width: 140px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ban-add input:hover,
.ban-add input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: none;
}
.ban-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: stretch;
}
.ban-accordion--auto,
.ban-accordion--crm {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ban-accordion--auto ul,
.ban-accordion--crm ul {
  flex: 1 1 auto;
  max-height: 340px;
}
.ban-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ban-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 8px;
  margin-bottom: 6px;
}
.ban-list li span {
  font-family: ui-monospace, monospace;
  font-size: 13px;
}
.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
  min-width: 0;
}
.ban-remove {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: all 0.15s ease;
}
.ban-remove:hover {
  color: #fff;
  background: #e91e63;
  border-color: #e91e63;
}
.ban-list li:hover {
  background: var(--panel);
  border-color: var(--border);
}

/* ===== Settings improvements (beautiful + mobile) ===== */
.settings-header {
  margin-bottom: 8px;
}
.settings-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.settings-help-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.settings-help-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.prompt-group {
  position: relative;
}
.prompt-textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  transition: height 0.2s ease, border-color 0.2s;
}
.prompt-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.prompt-textarea.expanded {
  min-height: 320px;
  height: auto !important;
  max-height: none !important;
  overflow-y: visible !important;
  resize: vertical;
}

.prompt-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px auto 0;
  padding: 6px 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.prompt-expand-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.expand-icon {
  font-size: 13px;
  line-height: 1;
}

.settings-save-wrap {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}
.settings-save-wrap .btn {
  min-width: 220px;
  max-width: 320px;
  width: auto;
  padding-left: 32px;
  padding-right: 32px;
}

/* Beautiful collapsible ban accordions */
.ban-accordion {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  overflow: hidden;
}
.ban-accordion summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.ban-accordion summary::-webkit-details-marker {
  display: none;
}
.ban-accordion summary:hover {
  background: var(--panel);
}
.ban-chevron {
  transition: transform 0.2s ease;
  color: var(--muted);
  font-size: 13px;
}
.ban-accordion[open] .ban-chevron {
  transform: rotate(180deg);
}
.ban-accordion ul {
  list-style: none;
  margin: 0;
  padding: 0 12px 12px;
  max-height: 260px;
  overflow-y: auto;
}
.ban-accordion li {
  display: flex;
  flex-direction: column;
  padding: 9px 12px;
  background: var(--panel);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.ban-author-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ban-who {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}
.ban-author-msg {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  padding-left: 2px;
}
.ban-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
}
.ban-empty {
  color: var(--muted);
  font-style: italic;
  padding: 8px 12px !important;
}

/* Mobile responsiveness for settings */
@media (max-width: 640px) {
  .prompt-textarea.expanded {
    height: 65vh;
  }
  .settings-save-wrap .btn {
    width: 100%;
    max-width: none;
  }
  .ban-add {
    flex-direction: column;
    align-items: stretch;
  }
  .ban-add input {
    width: 100%;
  }
}
#niche-stats .panel {
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

#niche-stats .panel-header {
  flex-shrink: 0;
}

#niche-stats .dash-tabs {
  position: relative;
  z-index: 5;
  flex-shrink: 0;
  flex-wrap: wrap;
  row-gap: 10px;
  column-gap: 8px;
  align-items: center;
}

#niche-stats .dash-tabs .tab-btn {
  flex-shrink: 0;
}

#niche-stats .dashboards {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#niche-stats .dashboard-panel:not(.hidden) {
  flex: 1;
  min-height: 0;
}

.niche-requests-block .niche-requests-values {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 4px 12px;
  flex: 1;
  justify-content: center;
}

.niche-req-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.niche-req-label {
  font-size: 13px;
  color: var(--muted);
}

.niche-req-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  letter-spacing: -0.02em;
}

#niche-stats .dashboard-panel[data-dashboard="monthly"] .panel-chart {
  min-height: 360px;
}

@media (max-width: 960px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.nav-open,
  body.crm-kanban-open {
    overflow: hidden;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: 100dvh;
    width: 100%;
    overflow-x: hidden;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 900;
    height: calc(56px + env(safe-area-inset-top, 0px));
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0;
    margin: 0;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
  }

  .mobile-topbar-title {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text);
    opacity: 0.92;
  }

  .sidebar-burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-alt);
    cursor: pointer;
    flex-shrink: 0;
  }

  .sidebar-burger span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    border-radius: 2px;
    background: var(--text);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .layout.sidebar-open .sidebar-burger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .layout.sidebar-open .sidebar-burger span:nth-child(2) {
    opacity: 0;
  }

  .layout.sidebar-open .sidebar-burger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(6, 6, 10, 0.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .layout.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(288px, 88vw);
    z-index: 950;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 16px 0 48px rgba(0, 0, 0, 0.45);
  }

  .layout.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-brand-wrap {
    flex: 0 0 auto;
    min-width: 0;
    margin-bottom: 6px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand-toggle {
    white-space: normal;
  }

  .nav {
    flex-direction: column;
    flex: 0 0 auto;
    min-width: 0;
    overflow: visible;
    padding-bottom: 0;
    gap: 6px;
  }

  .nav-item {
    flex: 0 0 auto;
    white-space: normal;
    width: 100%;
    font-size: 15px;
    padding: 12px 14px;
  }

  .sidebar-footer {
    display: flex;
    flex-direction: column;
    margin-top: auto;
    padding-top: 16px;
    gap: 8px;
  }

  .sidebar-footer .btn {
    width: 100%;
    justify-content: center;
  }

  .content {
    display: block;
    height: auto;
    min-height: calc(100dvh - 56px - env(safe-area-inset-top, 0px));
    overflow-x: hidden;
    overflow-y: visible;
    padding: calc(56px + env(safe-area-inset-top, 0px) + 16px) 16px 32px;
    box-sizing: border-box;
  }

  .section {
    flex: none;
    min-height: auto;
    overflow: visible;
  }

  #projects.section {
    padding: 0 !important;
  }

  #projects.section:not(.hidden):not(.crm-kanban-active) {
    overflow: visible !important;
    height: auto !important;
  }

  #crm-list > div:first-child {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }

  @media (max-width: 768px) {
    #crm-list > div:first-child {
      flex-direction: column;
      align-items: stretch !important;
    }
  }

  #crmProjectsGrid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .project-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .cards,
  .cards.cards-3,
  .cards.cards-4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .grid,
  .grid.two-cols,
  .form-grid,
  .settings-form,
  .keyword-dual-editor {
    grid-template-columns: minmax(0, 1fr);
  }

  .overview-section {
    padding-right: 0;
  }

  .overview-panels,
  .panel,
  .card {
    min-width: 0;
    max-width: 100%;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chart-panel-tall,
  .panel.panel-chart {
    min-height: 420px;
  }

  .overview-section .panel.panel-chart canvas,
  #chartDaily,
  #chartNiches,
  #chartNichePie,
  #chartNicheMonthly {
    max-width: 100%;
  }

  .log-card summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .log-card-preview {
    max-width: 100%;
    white-space: normal;
  }

  .log-step {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }

  .modal {
    align-items: flex-end;
  }

  .modal-content {
    width: 100vw;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
  }

  .modal-header {
    flex-direction: column;
  }

  .modal-textarea {
    min-height: 45dvh;
  }

  .keyword-textarea {
    min-height: 32dvh;
  }

}

@media (max-width: 480px) {
  .sidebar {
    padding: 18px 14px;
  }

  .logo {
    width: 40px;
    height: 40px;
  }

  .brand-title {
    font-size: 15px;
  }

  .brand-subtitle {
    font-size: 11px;
  }

  .content {
    padding-inline: 14px;
  }
  .cards {
    gap: 12px;
  }

  .card {
    padding: 16px;
  }

  .card-value-xl {
    font-size: 30px;
  }

  .panel {
    padding: 16px;
    border-radius: 16px;
  }

  .chart-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #chartNiches {
    min-width: 720px;
  }

}

.form-row-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}
.form-row-inline .form-group { min-width: 140px; }

/* ── Автоподписка ── */
#autojoin.section,
.autojoin-section {
  flex: 0 0 auto;
  min-height: auto;
  overflow: visible;
}

.autojoin-page {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  min-width: 0;
  padding-bottom: 48px;
}

.autojoin-page .panel {
  flex: none;
  overflow: visible;
  min-height: unset;
}

.autojoin-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.autojoin-hero h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.autojoin-hero-text {
  flex: 1;
  min-width: 0;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

.autojoin-accounts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.autojoin-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.aj-summary-card {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(24, 24, 34, 0.78);
}

.aj-summary-card.is-warn {
  border-color: rgba(255, 179, 0, 0.35);
}

.aj-summary-label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}

.aj-summary-card strong {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.1;
}

.aj-summary-note {
  margin-left: 6px;
  font-size: 12px;
  color: var(--muted);
}

.autojoin-account-card {
  background: linear-gradient(160deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.autojoin-account-card.is-running {
  border-color: rgba(0, 200, 83, 0.35);
  box-shadow: 0 0 0 1px rgba(0, 200, 83, 0.08);
}

.aj-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.aj-card-label {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.aj-card-phone {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.aj-card-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.aj-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.aj-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.aj-badge-run {
  background: rgba(0, 200, 83, 0.12);
  color: #69f0ae;
  border-color: rgba(0, 200, 83, 0.28);
}

.aj-badge-idle {
  background: rgba(139, 146, 160, 0.12);
  color: var(--text-secondary);
  border-color: rgba(139, 146, 160, 0.25);
}

.aj-badge-mon {
  background: rgba(59, 159, 222, 0.12);
  color: #64b5f6;
  border-color: rgba(59, 159, 222, 0.28);
}

.aj-badge-warn {
  background: rgba(255, 179, 0, 0.1);
  color: #ffca28;
  border-color: rgba(255, 179, 0, 0.28);
}

.aj-badge-lock {
  background: rgba(233, 30, 99, 0.12);
  color: #f48fb1;
  border-color: rgba(233, 30, 99, 0.3);
}

.aj-card-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.aj-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.aj-stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
}

.aj-stat-label {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.aj-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.aj-card-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.aj-card-breakdown span {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
}

.aj-card-breakdown b {
  color: var(--text-secondary);
  font-weight: 600;
}

.autojoin-toolbar {
  padding: 16px 18px;
}

.autojoin-toolbar-row {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.autojoin-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.autojoin-toolbar-select {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.autojoin-toolbar-label {
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

.autojoin-accounts-select {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.aj-pill-check {
  display: inline-flex;
  align-items: center;
  gap: 0;
  cursor: pointer;
  user-select: none;
}

.aj-pill-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.aj-pill-check span {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-secondary);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.aj-pill-check input:checked + span {
  border-color: rgba(233, 30, 99, 0.5);
  background: var(--accent-soft);
  color: var(--text);
}

.aj-pill-check input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.autojoin-events-panel .panel-header h3,
.autojoin-settings-panel .panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.autojoin-events-hint {
  font-size: 12px;
}

.autojoin-table-wrap {
  max-height: min(380px, 42vh);
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.autojoin-table {
  margin: 0;
  font-size: 13px;
}

.autojoin-table th,
.autojoin-table td {
  padding: 10px 12px;
  vertical-align: top;
}

.autojoin-table td:nth-child(4),
.autojoin-table td:nth-child(5) {
  max-width: 180px;
  word-break: break-word;
}

.autojoin-params-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.aj-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.aj-field span {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.aj-field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}

.aj-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.autojoin-accordion {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--panel-2);
  overflow: hidden;
}

.autojoin-accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.autojoin-accordion summary::-webkit-details-marker {
  display: none;
}

.autojoin-accordion summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}

.autojoin-accordion[open] summary::after {
  transform: rotate(180deg);
}

.autojoin-accordion-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.autojoin-accordion-body .panel-sub {
  margin: 12px 0;
  font-size: 12px;
}

.aj-prompt {
  min-height: 120px;
  max-height: 240px;
}

.aj-api-key {
  margin-top: 8px;
}

.aj-api-key label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.aj-key-input {
  width: 100%;
  max-width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

@media (max-width: 1100px) {
  .autojoin-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .autojoin-params-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .autojoin-accounts-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .autojoin-params-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .autojoin-toolbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .autojoin-toolbar-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .autojoin-hero .btn-ghost {
    width: 100%;
  }

  .aj-card-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .autojoin-table-wrap {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .autojoin-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .autojoin-params-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .autojoin-toolbar-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .aj-card-top {
    flex-direction: column;
  }

  .aj-card-badges {
    justify-content: flex-start;
  }

  .aj-card-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .aj-card-stats .aj-stat:last-child {
    grid-column: 1 / -1;
  }
}

/* Compact polish for the auto-join page */
.autojoin-page {
  max-width: 1180px;
  margin: 0 auto;
  gap: 14px;
}

.autojoin-hero {
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    radial-gradient(circle at top left, rgba(233, 30, 99, 0.11), transparent 32%),
    linear-gradient(135deg, rgba(31, 31, 43, 0.92), rgba(18, 18, 26, 0.88));
}

.autojoin-hero h2 {
  font-size: 20px;
  line-height: 1.15;
}

.autojoin-hero .panel-sub {
  max-width: 620px;
  margin: 0;
}

.autojoin-accounts-grid {
  gap: 12px;
}

.autojoin-summary-grid {
  gap: 8px;
}

.aj-summary-card {
  padding: 10px 12px;
}

.aj-summary-card strong {
  font-size: 18px;
}

.autojoin-account-card {
  padding: 14px;
  border-radius: 18px;
  background:
    radial-gradient(circle at top right, rgba(59, 159, 222, 0.08), transparent 28%),
    var(--panel);
}

.aj-card-label {
  font-size: 14px;
}

.aj-card-phone {
  font-size: 15px;
}

.aj-card-meta {
  margin-top: 4px;
}

.aj-card-stats {
  padding: 10px;
  gap: 8px;
}

.aj-stat-value {
  font-size: 18px;
}

.aj-card-actions .btn {
  min-height: 30px;
  padding: 5px 10px;
}

.autojoin-toolbar,
.autojoin-events-panel,
.autojoin-settings-panel {
  border-radius: 18px;
}

.autojoin-toolbar {
  padding: 12px 14px;
}

.autojoin-toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.autojoin-toolbar-select {
  padding-top: 0;
  border-top: 0;
  justify-content: flex-end;
}

.autojoin-toolbar-actions .btn,
.autojoin-hero .btn {
  min-height: 34px;
  padding: 7px 12px;
}

.autojoin-events-panel,
.autojoin-settings-panel {
  padding: 14px;
}

.autojoin-table-wrap {
  max-height: 240px;
  background: rgba(10, 10, 16, 0.34);
}

.autojoin-table th,
.autojoin-table td {
  padding: 8px 10px;
}

.autojoin-settings-panel .panel-header {
  margin-bottom: 10px;
}

.autojoin-params-grid {
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.aj-field {
  margin-bottom: 0;
}

.aj-field input {
  height: 34px;
  border-radius: 9px;
}

.autojoin-accordion {
  margin-bottom: 8px;
  border-radius: 11px;
}

.autojoin-accordion summary {
  min-height: 38px;
  padding: 10px 12px;
}

.autojoin-accordion-body {
  padding: 0 12px 12px;
}

.aj-prompt {
  min-height: 96px;
  max-height: 190px;
  font-size: 13px;
}

#autojoin .settings-save-wrap {
  margin-top: 10px;
}

#autojoin .settings-save-wrap .btn {
  min-height: 36px;
  min-width: 210px;
}

@media (min-width: 1280px) {
  .autojoin-page {
    max-width: 1120px;
  }
}

@media (max-width: 960px) {
  .autojoin-page {
    max-width: 100%;
    gap: 12px;
  }

  .autojoin-toolbar-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .autojoin-toolbar-select {
    justify-content: flex-start;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  .autojoin-params-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .autojoin-hero {
    padding: 12px;
  }

  .autojoin-hero h2 {
    font-size: 18px;
  }

  .autojoin-account-card,
  .autojoin-toolbar,
  .autojoin-events-panel,
  .autojoin-settings-panel {
    border-radius: 14px;
  }

  .autojoin-params-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Mobile dashboard polish */
@media (max-width: 640px) {
  #overview.overview-section {
    gap: 12px;
  }

  #overview .cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  #overview .card {
    min-height: 118px;
    padding: 14px;
    border-radius: 16px;
  }

  #overview .card-status {
    grid-column: 1 / -1;
    min-height: 108px;
  }

  #overview .card-title {
    font-size: 12px;
    line-height: 1.3;
  }

  #overview .card-value-xl {
    margin-top: 8px;
    font-size: clamp(25px, 8vw, 34px);
    line-height: 1.05;
    letter-spacing: -0.04em;
  }

  #overview .card-sub,
  #overview .status-time {
    font-size: 11px;
    line-height: 1.35;
  }

  #overview .status-text {
    font-size: 28px;
  }

  #overview .overview-panels {
    gap: 14px;
    padding-bottom: 96px;
  }

  #overview .panel {
    padding: 14px;
    border-radius: 18px;
  }

  #overview .niche-panel-top,
  #overview .daily-panel-top {
    display: block;
    margin-bottom: 12px;
  }

  #overview .niche-panel-left,
  #overview .daily-panel-left {
    margin-bottom: 10px;
  }

  #overview .niche-panel-left h2,
  #overview .daily-panel-top h2 {
    white-space: normal;
    font-size: 16px;
  }

  #overview .niche-panel-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  #overview .niche-period-toggle,
  #overview .niche-search-wrap,
  #overview #nicheChartPager {
    grid-column: 1 / -1;
    width: 100%;
  }

  #overview .niche-period-toggle,
  #overview .daily-view-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
  }

  #overview .niche-period-toggle .period-btn,
  #overview .daily-view-toggle .period-btn {
    justify-content: center;
    min-width: 0;
    width: 100%;
  }

  #overview .select-filter-compact {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  #overview .chart-pager-compact {
    display: inline-grid;
    grid-template-columns: 34px auto 34px;
    align-items: center;
    justify-content: center;
    justify-self: center;
    width: auto;
    min-width: 132px;
    max-width: 180px;
    margin: 0 auto;
    gap: 6px;
  }

  #overview .chart-pager-compact .chart-pager-label {
    text-align: center;
    min-width: 46px;
    padding: 0;
  }

  #overview .chart-pager-compact .btn-pager {
    width: 34px;
    min-width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  #overview .panel-niches .chart-scroll-niches {
    height: 300px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
  }

  #overview .panel-niches #chartNiches {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 280px !important;
    max-height: 280px !important;
    display: block;
  }

  #overview .daily-panel-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  #overview .daily-series-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    height: auto;
    padding: 0;
    background: transparent;
    border: 0;
  }

  #overview .daily-series-toggle .period-btn {
    justify-content: center;
    min-width: 0;
    width: 100%;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
  }

  #overview .daily-kpi-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #overview .daily-kpi {
    min-width: 0;
    white-space: normal;
    font-size: 12px;
  }

  #overview .panel-daily .daily-chart-wrap {
    height: 310px;
    width: 100%;
    max-width: 100%;
  }

  #overview .panel-daily #chartDaily {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 290px !important;
    max-height: 290px !important;
    display: block;
  }
}

@media (max-width: 380px) {
  #overview .card {
    min-height: 108px;
    padding: 12px;
  }

  #overview .card-value-xl {
    font-size: 25px;
  }

  #overview .daily-series-toggle .period-btn {
    font-size: 12px;
  }
}

/* ── Overview skeleton loading ── */
@keyframes overview-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.overview-section {
  position: relative;
}

.overview-skeleton,
.overview-content {
  width: 100%;
}

.overview-content {
  min-width: 0;
}

.overview-loading .overview-content {
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  inset: 0;
  height: 0;
  overflow: hidden;
}

.overview-skeleton {
  display: none;
}

.overview-loading .overview-skeleton {
  display: block;
}

.overview-skeleton .sk {
  display: block;
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, 0.07) 0%,
    rgba(148, 163, 184, 0.16) 45%,
    rgba(148, 163, 184, 0.07) 100%
  );
  background-size: 200% 100%;
  animation: overview-shimmer 1.35s ease-in-out infinite;
  border-radius: 8px;
}

.skeleton-cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 96px;
  padding: 16px 18px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  background: var(--panel);
}

.skeleton-card .sk-label {
  width: 58%;
  height: 12px;
  max-width: 140px;
}

.skeleton-card .sk-value {
  width: 46%;
  height: 34px;
  border-radius: 10px;
}

.skeleton-card .sk-value-sm {
  width: 38%;
  height: 28px;
}

.skeleton-card .sk-sub {
  width: 72%;
  height: 10px;
  max-width: 180px;
}

.skeleton-panel {
  padding: 18px 20px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  background: var(--panel);
}

.skeleton-panel + .skeleton-panel {
  margin-top: 32px;
}

.skeleton-panel .sk-title {
  width: min(220px, 42%);
  height: 18px;
  margin-bottom: 14px;
  border-radius: 9px;
}

.skeleton-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.skeleton-toolbar .sk-pill {
  width: 92px;
  height: 34px;
  border-radius: 999px;
}

.skeleton-toolbar .sk-input {
  flex: 1 1 180px;
  min-width: 140px;
  max-width: 260px;
  height: 34px;
  border-radius: 10px;
}

.skeleton-toolbar .sk-select {
  width: 108px;
  height: 34px;
  border-radius: 10px;
}

.skeleton-toolbar .sk-pager {
  width: 118px;
  height: 34px;
  border-radius: 10px;
  margin-left: auto;
}

.skeleton-chart {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.08);
  background: rgba(148, 163, 184, 0.03);
  overflow: hidden;
}

.skeleton-bars {
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  gap: 12px;
  height: 320px;
  padding: 18px 24px 22px;
}

.skeleton-bars .sk-bar {
  flex: 1 1 0;
  max-width: none;
  height: var(--h, 50%);
  min-height: 48px;
  border-radius: 10px 10px 6px 6px;
  animation-delay: calc(var(--i, 0) * 0.08s);
}

.skeleton-bars .sk-bar:nth-child(1) { --i: 0; }
.skeleton-bars .sk-bar:nth-child(2) { --i: 1; }
.skeleton-bars .sk-bar:nth-child(3) { --i: 2; }
.skeleton-bars .sk-bar:nth-child(4) { --i: 3; }
.skeleton-bars .sk-bar:nth-child(5) { --i: 4; }
.skeleton-bars .sk-bar:nth-child(6) { --i: 5; }
.skeleton-bars .sk-bar:nth-child(7) { --i: 6; }
.skeleton-bars .sk-bar:nth-child(8) { --i: 7; }
.skeleton-bars .sk-bar:nth-child(9) { --i: 8; }
.skeleton-bars .sk-bar:nth-child(10) { --i: 9; }
.skeleton-bars .sk-bar:nth-child(11) { --i: 10; }
.skeleton-bars .sk-bar:nth-child(12) { --i: 11; }

.skeleton-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 14px;
}

.skeleton-kpis .sk-kpi {
  width: 118px;
  height: 22px;
  border-radius: 999px;
}

.skeleton-lines {
  height: 320px;
  padding: 12px;
}

.skeleton-lines svg {
  display: block;
  width: 100%;
  height: 100%;
}

.skeleton-lines .sk-line {
  fill: none;
  stroke: rgba(148, 163, 184, 0.18);
  stroke-width: 3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  animation: overview-shimmer 1.35s ease-in-out infinite;
}

.skeleton-lines .sk-line-2 {
  stroke: rgba(148, 163, 184, 0.12);
  stroke-width: 2;
}

@media (max-width: 1200px) {
  .skeleton-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .skeleton-card-wide {
    grid-column: 1 / -1;
  }

  .skeleton-bars,
  .skeleton-lines {
    height: 280px;
  }
}

@media (max-width: 640px) {
  .skeleton-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  .skeleton-card {
    min-height: 118px;
    padding: 14px;
    border-radius: 16px;
  }

  .skeleton-card-wide {
    grid-column: 1 / -1;
    min-height: 108px;
  }

  .skeleton-card .sk-label {
    width: 70%;
    height: 11px;
  }

  .skeleton-card .sk-value {
    width: 52%;
    height: 30px;
  }

  .skeleton-panel {
    padding: 14px;
    border-radius: 18px;
  }

  .skeleton-panel + .skeleton-panel {
    margin-top: 14px;
  }

  .skeleton-panel .sk-title {
    width: 68%;
    height: 16px;
    margin-bottom: 10px;
  }

  .skeleton-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }

  .skeleton-toolbar .sk-pill:first-child {
    grid-column: 1 / -1;
  }

  .skeleton-toolbar .sk-pager {
    grid-column: 1 / -1;
    justify-self: center;
    width: 132px;
    margin-left: 0;
  }

  .skeleton-toolbar .sk-input,
  .skeleton-toolbar .sk-select {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .skeleton-bars {
    height: 280px;
    padding: 14px 16px 18px;
    gap: 12px;
  }

  .skeleton-bars .sk-bar {
    max-width: none;
  }

  .skeleton-kpis {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .skeleton-kpis .sk-kpi {
    width: 100%;
    height: 20px;
  }

  .skeleton-lines {
    height: 220px;
  }
}


/* niches v3: keywords stacked */
.keyword-dual-editor {
  display: flex !important;
  flex-direction: column !important;
  gap: 14px !important;
}
.keyword-dual-editor.hidden { display: none !important; }
