/**
 * STEM System — общие компоненты
 * Единая стилистика: хедер, кнопки, загрузка, карточки
 */

:root {
  /* Цвета */
  --stem-header-bg: #1F1F1F;
  --stem-primary: #3b82f6;
  --stem-primary-dark: #2563eb;
  --stem-success: #10b981;
  --stem-success-dark: #059669;
  --stem-danger: #ef4444;
  --stem-warning: #f59e0b;
  --stem-bg: #f3f4f6;
  --stem-card-bg: #ffffff;
  --stem-border: #e5e7eb;
  --stem-text: #1f2937;
  --stem-text-muted: #6b7280;
  /* Размеры */
  --stem-radius: 8px;
  --stem-radius-lg: 12px;
  --stem-shadow: 0 2px 8px rgba(0,0,0,0.08);
  --stem-header-height: 89px;
  /* iOS «чёлка» / статус-бар: используем в отступах под фиксированные layout */
  --stem-safe-top: env(safe-area-inset-top, 0px);
}

/* ========== ОБЩИЙ ХЕДЕР СТРАНИЦ (логотип слева, название справа, #1F1F1F) ========== */
.stem-page-header {
  background: var(--stem-header-bg);
  padding: env(safe-area-inset-top, 0px) 20px 0;
  box-sizing: border-box;
  min-height: calc(var(--stem-header-height) + env(safe-area-inset-top, 0px));
  height: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}
/* Задания (tasks_*): первая полоса — .top-bar, не .stem-page-header */
header.top-bar.tasks-top-bar {
  padding: env(safe-area-inset-top, 0px) 20px 0;
  box-sizing: border-box;
  min-height: calc(var(--stem-header-height) + env(safe-area-inset-top, 0px));
}
/* Бургер в хедере при встраивании в admin (iframe) */
.stem-header-burger {
  display: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin-right: 12px;
  padding: 0;
  border: none;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.stem-header-burger .burger-line {
  display: block;
  width: 22px;
  height: 3px;
  background: white;
  border-radius: 2px;
}
/* Фикс: фиксированные layout не перекрывают хедер */
body:has(.stem-page-header) .files-layout,
body:has(.stem-page-header) .configurator-layout,
body:has(.stem-page-header) .analytics-layout {
  top: calc(var(--stem-header-height) + var(--stem-safe-top)) !important;
  height: calc(100vh - var(--stem-header-height) - var(--stem-safe-top)) !important;
  height: calc(100dvh - var(--stem-header-height) - var(--stem-safe-top)) !important;
  height: calc(100lvh - var(--stem-header-height) - var(--stem-safe-top)) !important;
}
/* При сворачивании меню в admin — хедер 69px */
body.parent-sidebar-collapsed .stem-page-header {
  height: auto !important;
  min-height: calc(69px + env(safe-area-inset-top, 0px)) !important;
}
body.parent-sidebar-collapsed .top-bar {
  height: auto !important;
  min-height: calc(69px + env(safe-area-inset-top, 0px)) !important;
}
body.parent-sidebar-collapsed:has(.stem-page-header) .files-layout,
body.parent-sidebar-collapsed:has(.stem-page-header) .configurator-layout,
body.parent-sidebar-collapsed:has(.stem-page-header) .analytics-layout {
  top: calc(69px + var(--stem-safe-top)) !important;
  height: calc(100vh - 69px - var(--stem-safe-top)) !important;
  height: calc(100dvh - 69px - var(--stem-safe-top)) !important;
  height: calc(100lvh - 69px - var(--stem-safe-top)) !important;
}
.stem-page-header-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
  display: block;
}
.stem-page-header-title {
  color: white;
  font-size: 16px;
  font-weight: 700;
  margin-left: auto;
}
/* Кнопки в хедере — стиль как в tasks_shop (.top-bar-tabs .tab-btn) */
.stem-page-header #stem-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 16px;
  flex-wrap: wrap;
}
.stem-page-header #stem-header-actions .btn,
.stem-page-header #stem-header-actions .tab-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 13px;
}
.stem-page-header #stem-header-actions .btn:hover,
.stem-page-header #stem-header-actions .tab-btn:hover {
  background: rgba(255,255,255,0.25);
}
.stem-page-header #stem-header-actions .btn.btn-primary {
  background: #3b82f6;
}
.stem-page-header #stem-header-actions .btn.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  width: 100%;
  box-sizing: border-box;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-group--flat {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-row--header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  border: none;
  border-radius: 8px;
  overflow: visible;
  width: 100%;
  max-width: 100%;
  padding: 4px 6px;
  box-sizing: border-box;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-header-tabs-gap {
  background: rgba(255, 255, 255, 0.28);
  min-height: 28px;
  margin: 0 2px;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border: none;
  border-radius: 0;
  overflow: visible;
  width: auto;
  max-width: 100%;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white !important;
  border: none !important;
  border-bottom: none !important;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-btn:hover {
  background: rgba(255,255,255,0.25);
}
.stem-page-header #stem-header-actions .settings-tabs-in-header .settings-tab-btn.active {
  background: #3b82f6 !important;
  color: white !important;
}
.stem-page-header #stem-header-actions .configurator-tabs-wrap,
.stem-page-header #stem-header-actions .analytics-tabs-wrap {
  padding-right: 16px;
  margin-right: 16px;
  border-right: 1px solid rgba(255,255,255,0.3);
}
/* Мобильный переключатель (стрелки + текущий раздел) — показывается только на экранах < 768px */
.stem-switcher-mobile { display: none; }
.stem-page-header #stem-header-actions .configurator-header-actions,
.stem-page-header #stem-header-actions .analytics-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.stem-page-header #stem-header-actions .warehouse-tabs,
.stem-page-header #stem-header-actions .top-nav-tabs {
  margin-bottom: 0;
  padding: 0;
  gap: 6px;
  display: flex;
  flex-wrap: wrap;
}
.stem-page-header #stem-header-actions .warehouse-tab,
.stem-page-header #stem-header-actions .top-nav-tabs .tab {
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 13px;
}
.stem-page-header #stem-header-actions .warehouse-tab:hover,
.stem-page-header #stem-header-actions .top-nav-tabs .tab:hover {
  background: rgba(255,255,255,0.25);
}
.stem-page-header #stem-header-actions .warehouse-tab.active,
.stem-page-header #stem-header-actions .top-nav-tabs .tab.active {
  background: #3b82f6;
  color: white;
}
.stem-page-header #stem-header-actions .btn.btn-outline {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
}
.stem-page-header #stem-header-actions .btn.btn-outline:hover {
  background: rgba(255,255,255,0.25);
}

/* ========== СТАНДАРТНЫЙ ХЕДЕР СТРАНИЦ ========== */
/* .top-bar — тёмная шапка с табами (задания, склад) */
.top-bar {
  background: var(--stem-header-bg);
  color: white;
  padding: 0 20px;
  min-height: 89px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.top-bar-title { font-size: 16px; font-weight: 800; color: white; margin-left: auto; }
.top-bar-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.top-bar-tabs .tab-btn {
  padding: 8px 14px;
  border-radius: var(--stem-radius);
  background: rgba(255,255,255,0.15);
  color: white;
  font-weight: 600;
  border: none;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}
.top-bar-tabs .tab-btn:hover { background: rgba(255,255,255,0.25); }
.top-bar-tabs .tab-btn.active { background: var(--stem-primary); color: white; }

/* .stem-header — тёмная шапка для страниц заказов и т.п. */
.stem-header,
.all-orders-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.stem-header h1,
.all-orders-header h1 { font-size: 16px; font-weight: 800; margin: 0; }
.stem-header .header-actions,
.all-orders-header .header-actions { display: flex; gap: 8px; }

/* .header — шапка настроек (tasks-conf и т.п.) */
.header {
  background: var(--stem-header-bg);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.header h1 { font-size: 18px; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 10px; }
.header a { color: rgba(255,255,255,0.9); text-decoration: none; font-size: 13px; }
.header a:hover { color: white; }

/* ========== КНОПКИ ========== */
.stem-btn,
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--stem-radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
a.stem-btn, a.btn { text-decoration: none; }

.stem-btn-primary,
.btn-primary {
  background: linear-gradient(135deg, var(--stem-primary) 0%, var(--stem-primary-dark) 100%);
  color: white;
}
.stem-btn-primary:hover,
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.stem-btn-success,
.btn-success {
  background: linear-gradient(135deg, var(--stem-success) 0%, var(--stem-success-dark) 100%);
  color: white;
}
.stem-btn-success:hover,
.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.stem-btn-outline,
.btn-outline {
  background: var(--stem-bg);
  color: var(--stem-text);
  border: 1px solid var(--stem-border);
}
.stem-btn-outline:hover,
.btn-outline:hover {
  border-color: var(--stem-primary);
  color: var(--stem-primary);
}

.stem-btn-danger,
.btn-danger {
  background: linear-gradient(135deg, var(--stem-danger) 0%, #dc2626 100%);
  color: white;
}
.stem-btn-danger:hover,
.btn-danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.stem-btn-sm,
.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* ========== ЗАГРУЗКА ========== */
.stem-loading,
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--stem-text-muted);
  text-align: center;
}
.stem-loading-spinner,
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--stem-border);
  border-top-color: var(--stem-primary);
  border-radius: 50%;
  animation: stem-spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes stem-spin { to { transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } } /* алиас для совместимости */

/* ========== ПУСТОЕ СОСТОЯНИЕ ========== */
.stem-empty-state,
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--stem-text-muted);
}
.stem-empty-state-icon,
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* ========== КАРТОЧКИ ========== */
.stem-card,
.card {
  background: var(--stem-card-bg);
  border-radius: var(--stem-radius-lg);
  padding: 16px 20px;
  box-shadow: var(--stem-shadow);
  border: 1px solid var(--stem-border);
  margin-bottom: 12px;
}

/* ========== ОСНОВНОЙ КОНТЕНТ ========== */
.stem-main-content {
  padding: var(--stem-content-padding, 20px);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 0;
}

.main-content {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 0;
}

/* Конфигуратор и файлы (fullscreen): контент на всю ширину окна / iframe */
.stem-layout.configurator-layout[data-layout="fullscreen"],
.stem-layout.files-layout[data-layout="fullscreen"] {
  width: 100%;
  max-width: none;
}
.stem-layout.configurator-layout[data-layout="fullscreen"] .layout,
.stem-layout.files-layout[data-layout="fullscreen"] .layout {
  width: 100%;
  max-width: none;
}
.configurator-layout .main-content,
.files-layout .main-content {
  max-width: none;
}

/* Единый padding 20px для всей области контента на ВСЕХ страницах */
.stem-content-area,
.stem-layout .content-area,
body > .container,
.settings-page,
.configurator-layout .main-content,
.analytics-layout .main-content,
.files-layout .main-content,
.warehouse-layout .content-area,
.warehouse-layout .stem-content-area,
body > main.main-content,
.delivery-container {
  padding: var(--stem-content-padding, 20px) !important;
  box-sizing: border-box;
}
/* Админка: iframe без отступов (контент на всю ширину) */
.admin-layout .content-area:has(.page.active .page-iframe) {
  padding: 0 !important;
}

/* ========== STEM Modal — общий стандарт (settings, admin, др.) ========== */
.modal-content.stem-modal {
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  background: var(--stem-card-bg, #fff);
  border-radius: var(--stem-radius-lg, 12px);
  padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--stem-border, #e5e7eb);
}
.modal-content.stem-modal--md {
  max-width: min(480px, 100%);
}
.modal-content.stem-modal--page-settings {
  max-width: min(800px, 100%);
  max-height: min(92vh, 100dvh - 24px);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.modal-content.stem-modal--page-settings .stem-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(70vh, calc(100dvh - 200px));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-content.stem-modal--role {
  max-width: min(1120px, 96vw);
  width: 100%;
  min-height: 0;
  flex-shrink: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-content.stem-modal--role .stem-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.stem-modal__header {
  flex-shrink: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--stem-border, #e5e7eb);
}
.stem-modal__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--stem-text, #1f2937);
}
.stem-modal__body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 0 4px;
}
.stem-modal__hint {
  margin: 0;
  font-size: 12px;
  color: var(--stem-text-muted, #6b7280);
  line-height: 1.45;
}
.stem-modal__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stem-modal__label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}
.role-modal-split {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.15fr);
  gap: 20px 28px;
  align-items: start;
  min-height: 0;
}
.role-modal-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.role-pages-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 10px;
  font-size: 12px;
  align-content: start;
  line-height: 1.35;
}
.role-pages-grid > label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  margin: 0;
}
.role-modal-col--blocks {
  min-width: 0;
}
#roleBlocksContainer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.role-blocks-wrap .stem-modal__label {
  margin-bottom: 4px;
}
.role-block-card {
  border: 1px solid var(--stem-border, #e5e7eb);
  border-radius: 8px;
  padding: 12px;
  background: #f9fafb;
}
.role-block-card__title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--stem-text, #1f2937);
}
.role-block-card__hint {
  font-size: 11px;
  color: var(--stem-text-muted, #6b7280);
  margin: 0 0 8px;
  line-height: 1.4;
}
.role-settings-tabs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  font-size: 12px;
}
.role-settings-tabs-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin: 0;
}
.stem-modal__footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--stem-border, #e5e7eb);
}
.stem-modal__input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  box-sizing: border-box;
  background: #fff;
  color: var(--stem-text, #1f2937);
}
.stem-modal__input:focus {
  outline: none;
  border-color: var(--stem-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.stem-modal__input--mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.stem-modal__btn-secondary {
  background: #e5e7eb !important;
  color: #374151 !important;
  border: none !important;
}
@media (max-width: 900px) {
  .role-modal-split {
    grid-template-columns: 1fr;
  }
  .role-pages-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .modal-content.stem-modal--role {
    max-width: 100%;
  }
}
