/* Сетка, шапка, сайдбары */
/* Совместимость с Яндекс.Браузером: -webkit- префиксы, явные flex */
.app-header {
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  padding: var(--spacing-md) var(--spacing-xl);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-footer {
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(226, 232, 240, 0.8);
  padding: 6px var(--spacing-xl);
  font-size: 13px;
  color: var(--text-secondary);
}

.app-footer-inner {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.app-footer-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

.app-footer-link:hover {
  text-decoration: underline;
}

.header-content {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: flex-start;
  justify-content: flex-start;
  gap: var(--spacing-md);
}

/* Десктоп: всё в одну строку */
.header-row-top {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  gap: var(--spacing-md);
}

.header-row-bottom {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: var(--spacing-md);
}

.header-title-wrap {
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.header-title-row {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: var(--spacing-sm);
  min-width: 0;
  overflow: hidden;
}

.header-title-row .logo-title {
  margin-bottom: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-title-row .btn-delete-client {
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.header-add-wrap {
  position: relative;
}

/* Десктоп: Выйти справа в row-bottom */
.header-row-bottom .btn-logout {
  margin-left: auto;
}

#header-subtitle {
  font-size: 11px;
  margin-top: 2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-left: auto;
  position: relative;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.dashboard-layout {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: var(--spacing-xl);
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 1fr 400px;
  grid-template-columns: 1fr 400px;
  gap: var(--spacing-xl);
  position: relative;
  z-index: 1;
  overflow-x: hidden;
}

.main-content {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  gap: var(--spacing-lg);
  min-width: 0;
  max-width: 100%;
}

.section {
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-radius: var(--border-radius);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.3);
  min-width: 0;
  max-width: 100%;
}

.section-header {
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border-color);
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  min-width: 0;
}

.section-header-single-row {
  flex-wrap: nowrap;
}

.section-header h2,
.section-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.section-header h3 {
  font-size: 18px;
}

.section-header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.stats-section {
  padding: var(--spacing-md) var(--spacing-lg);
}

.stats-grid {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  gap: var(--spacing-md);
}

.stats-cards-row {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-align-items: center;
  align-items: center;
  gap: var(--spacing-md);
}

.stats-controls {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: var(--spacing-md);
  margin-left: auto;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

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

.control-label {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.control-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.control-hint {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.control-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 4px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

#sidebar-overlay,
.sidebar-overlay {
  display: block;
  position: fixed;
  top: 73px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 150;
}

#sidebar-overlay.hidden,
.sidebar-overlay.hidden {
  display: none !important;
}

#users-sidebar,
.users-sidebar {
  position: fixed;
  top: 73px;
  left: -280px;
  bottom: 0;
  width: 280px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: left 0.3s ease;
}

#users-sidebar.open,
.users-sidebar.open {
  left: 0;
}

.users-sidebar-header {
  padding: var(--spacing-lg);
  border-bottom: 2px solid var(--border-color);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.users-sidebar-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#users-sidebar #users-list,
#users-sidebar .users-list,
.users-sidebar .users-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

#dashboard-screen {
  padding-left: 0;
  transition: padding-left 0.3s ease;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

@media (max-width: 1200px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    justify-content: center;
  }

  .stats-controls {
    margin-left: 0;
    margin-top: var(--spacing-sm);
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .dashboard-layout {
    padding: var(--spacing-md);
    gap: var(--spacing-md);
  }

  .app-header {
    padding: var(--spacing-md);
  }

  .header-content {
    flex-direction: column;
    align-items: stretch;
    gap: var(--spacing-sm);
  }

  /* Верхняя строка: бургер | название | Выйти справа */
  .header-row-top {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    flex: none;
  }

  .header-row-top .header-title-wrap {
    flex: 1;
    min-width: 0;
  }

  .header-row-bottom .btn-logout {
    flex-shrink: 0;
  }

  .header-row-bottom .btn-logout {
    margin-left: auto;
  }

  /* Нижняя строка: Мониторинг | Архив | + в одной строке */
  .header-row-bottom {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
  }

  .header-row-bottom .header-tabs {
    flex: 1;
    margin: 0;
    min-width: 0;
  }

  .header-row-bottom .header-tabs .tab-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
  }

  .header-row-bottom .header-add-wrap {
    flex-shrink: 0;
  }

  .toast-container {
    left: 20px;
    right: 20px;
  }

  .toast {
    min-width: auto;
  }

  .modal-content {
    padding: var(--spacing-lg);
  }

  .users-sidebar {
    display: none;
  }

  /* Кнопки Отправить/Не клиент в одну строку — уменьшаем отступы */
  #pending-leads-list .message-actions .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Заголовок лидов: кнопка Удалить все в одну строку с названием */
  .section-header-single-row .btn {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
  }
}

@media (max-width: 1024px) {
  #dashboard-screen {
    padding-left: 0;
  }

  .users-sidebar {
    left: -280px;
    transition: left 0.3s ease;
  }

  .users-sidebar.mobile-open {
    left: 0;
  }
}