/* ============================================================================
   Сводка планирования (static/plansvod.css)
   Адаптивный дизайн, подстраивающийся под размер экрана.
   Компонент выбора иерархии в точности по скриншоту PBI (синие круглые бейджи 1, 2, 3)
   ============================================================================ */

#modal-plansvod, #modal-plansvod2 {
  position: fixed !important; inset: 0 !important; z-index: 1200 !important;
  display: flex !important; flex-direction: column !important;
  width: 100vw !important; height: 100vh !important;
  background: #eaeffa !important; padding: 0 !important; margin: 0 !important;
  overflow-y: auto !important; overflow-x: hidden !important;
  box-sizing: border-box;
}

#modal-plansvod.hidden, #modal-plansvod2.hidden {
  display: none !important;
}

.ps-shell {
  display: flex; flex-direction: column;
  width: 100%; min-height: 100%;
  background: #eaeffa; box-sizing: border-box;
}

/* ─── Шапка отчёта (PBI стиль, адаптивная) ─── */
.ps-top-header {
  display: flex; align-items: stretch; gap: 10px; padding: 8px 12px;
  background: linear-gradient(180deg, #b9cbfa 0%, #ccd8fa 100%);
  border-bottom: 1px solid #b2c2f0; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06); flex-wrap: wrap;
}

/* Переключатели МП */
.ps-mps-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-self: center;
  background: #ffffff; padding: 4px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ps-mpchip {
  font-size: 11px; font-weight: 500; padding: 3px 8px; border: 1px solid #cbd5e1;
  border-radius: 6px; background: #fff; color: #475569; cursor: pointer; text-align: center;
  transition: all 0.15s ease;
}
.ps-mpchip:hover { border-color: #2563eb; color: #2563eb; }
.ps-mpchip.active {
  border-color: #2563eb; background: #eff6ff; color: #1d4ed8; font-weight: 700;
}

/* Навигация и заголовок */
.ps-nav-group {
  display: flex; align-items: center; gap: 6px; align-self: center;
}
.ps-nav-btn {
  font-size: 14px; width: 28px; height: 28px; padding: 0; display: inline-flex;
  align-items: center; justify-content: center; border-radius: 50%; color: #334155;
  background: transparent; border: 1px solid transparent; cursor: pointer;
}
.ps-nav-btn:hover { background: rgba(255,255,255,0.4); border-color: #cbd5e1; }
.ps-title-wrap {
  display: flex; align-items: center; gap: 6px; margin-left: 2px;
}
.ps-title-icon { font-size: 18px; color: #3b82f6; }
.ps-main-title {
  font-size: 17px; font-weight: 700; color: #25449c; margin: 0; white-space: nowrap;
}

/* ─── Двойной блок фильтров (адаптивный под экран) ─── */
.ps-filters-container {
  display: flex; gap: 10px; flex: 1 1 700px; min-width: 0; flex-wrap: wrap;
}

.ps-filter-card {
  background: #ffffff; border-radius: 8px; padding: 6px 10px;
  display: flex; flex-direction: column; gap: 6px; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); flex: 1 1 340px; min-width: 320px;
  border: 1px solid rgba(255,255,255,0.8);
}

.ps-card-row {
  display: flex; align-items: center; gap: 6px; width: 100%;
}

/* ─── Единый стиль всех элементов фильтрации (в точности PBI) ─── */
.ps-f-item {
  display: flex; flex-direction: column; gap: 2px; flex: 1 1 0; min-width: 0;
}

.ps-f-item .lbl {
  font-size: 10px; font-weight: 600; color: #1e293b; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; height: 14px; line-height: 14px;
}

.ps-f-item select, 
.ps-f-item input[type=date],
.ps-f-item .msel-btn,
.ps-f-item .ps-sel,
.ps-f-item .ps-sel-btn {
  height: 26px !important;
  min-height: 26px !important;
  max-height: 26px !important;
  font-size: 11px !important;
  font-family: inherit !important;
  padding: 0 6px !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 4px !important;
  background-color: #ffffff !important;
  color: #1e293b !important;
  outline: none !important;
  box-sizing: border-box !important;
  width: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  cursor: pointer !important;
  line-height: 24px !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
}

.ps-f-item select {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%2364748b'%3E%3Cpath d='M0 0l5 5 5-5z'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
  padding-right: 22px !important;
}

.ps-f-item select:focus, 
.ps-f-item input[type=date]:focus,
.ps-f-item .msel-btn:hover,
.ps-f-item .ps-sel-btn:hover {
  border-color: #2563eb !important;
  box-shadow: 0 0 0 2px rgba(37,99,235,0.12) !important;
}

.ps-f-item .msel-btn.on,
.ps-f-item .ps-sel-btn.on {
  border-color: #2563eb !important;
  background-color: #eff6ff !important;
  color: #1d4ed8 !important;
  font-weight: 600 !important;
}

.ps-date-duo {
  display: flex; align-items: center; gap: 2px; width: 100%;
}
.ps-date-duo input[type=date] { flex: 1; min-width: 0; font-size: 10px !important; padding: 0 2px !important; }

/* ─── Компонент выбора иерархии (в точности со 2-го скриншота PBI) ─── */
.ps-msel { position: relative; width: 100%; }

/* Выпадающее окно со 2-го скриншота */
.ps-msel .msel-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 2200; background: #fff;
  border: 1px solid #94a3b8; border-radius: 6px; box-shadow: 0 10px 25px rgba(0,0,0,0.18);
  min-width: 210px; width: 230px; max-height: 340px; display: flex; flex-direction: column;
}

/* Поле поиска с лупой */
.ps-hier-search-wrap {
  padding: 8px 8px 4px; position: relative;
}
.ps-hier-search {
  width: 100%; height: 26px; font-size: 12px; padding: 0 8px 0 24px; border: 1px solid #94a3b8;
  border-radius: 4px; outline: none; box-sizing: border-box; color: #1e293b;
}
.ps-hier-search:focus { border-color: #2563eb; }
.ps-hier-search-icon {
  position: absolute; left: 14px; top: 13px; font-size: 11px; color: #64748b; pointer-events: none;
}

/* Строка счетчика и действий */
.ps-hier-actions {
  display: flex; align-items: center; justify-content: space-between; padding: 4px 10px 6px;
  font-size: 11px; border-bottom: 1px solid #e2e8f0; color: #475569;
}
.ps-hier-links { display: flex; gap: 8px; }
.ps-hier-link {
  color: #2563eb; cursor: pointer; text-decoration: none; font-size: 11px; font-weight: 500;
}
.ps-hier-link:hover { text-decoration: underline; }

/* Список чекбоксов со 2-го скриншота */
.ps-hier-list {
  overflow-y: auto; max-height: 240px; padding: 2px 0;
}
.ps-hier-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer;
  color: #1e293b; transition: background 0.1s; position: relative;
}
.ps-hier-row:hover { background: #f1f5f9; }
.ps-hier-row.selected { background: #eef5ff; font-weight: 500; }
.ps-hier-row input[type=checkbox] {
  accent-color: #2563eb; width: 15px; height: 15px; cursor: pointer; margin: 0;
}
.ps-hier-text { flex: 1; }

/* Синий круглый бейдж с белой цифрой порядка (со 2-го скриншота) */
.ps-hier-badge {
  width: 18px; height: 18px; line-height: 18px; border-radius: 50%;
  background: #1d6fe9; color: #ffffff; font-size: 11px; font-weight: 700;
  text-align: center; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Header Right */
.ps-header-right {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0; align-self: center;
}
.ps-refresh-info {
  font-size: 9px; color: #3b5284; text-align: right; line-height: 1.2;
}
.ps-refresh-info b { font-size: 11px; color: #1e293b; display: block; font-weight: 600; }
.ps-close-btn {
  font-size: 16px; width: 30px; height: 30px; padding: 0; color: #334155;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; cursor: pointer;
}
.ps-close-btn:hover { background: rgba(255,255,255,0.4); border-color: #cbd5e1; }

/* Status Strip */
.ps-status-strip {
  font-size: 11px; color: #475569; padding: 3px 16px; min-height: 18px; background: #dfe7f7;
  border-bottom: 1px solid #cbd5e1; font-weight: 500;
}

/* ─── Основной контент (адаптивная сетка) ─── */
.ps-content {
  flex: 1; padding: 12px 14px 40px; display: flex; flex-direction: column; gap: 14px;
  box-sizing: border-box; width: 100%;
}

.ps-grid-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%;
  box-sizing: border-box;
}

@media (max-width: 1280px) {
  .ps-grid-row { grid-template-columns: 1fr; }
}

/* Табличные карточки */
.ps-table-card {
  background: #ffffff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid #dbe2ef; overflow: hidden; display: flex; flex-direction: column;
  width: 100%; box-sizing: border-box;
}

.ps-card-title {
  font-size: 13px; font-weight: 700; color: #1e3a8a; padding: 8px 12px;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between;
}

.ps-table-scroll {
  overflow-x: auto; overflow-y: auto; max-height: 480px; position: relative; width: 100%;
}

/* ─── Таблицы (адаптивные, с раскрытием) ─── */
.ps-table {
  border-collapse: separate; border-spacing: 0; font-size: 11px; text-align: right;
  width: max-content; min-width: 100%;
}

.ps-table th, .ps-table td {
  padding: 4px 8px; border-bottom: 1px solid #eef0f3; border-right: 1px solid #f1f5f9;
  text-align: right; background: #fff;
}

.ps-table thead th {
  position: sticky; top: 0; z-index: 3; background: #dcebf7; font-weight: 700;
  border-bottom: 1px solid #cbd5e1; text-align: center; color: #1e293b; font-size: 10px;
  white-space: nowrap;
}

.ps-table .ps-th-week { background: #eff6ff !important; color: #1e40af !important; border-bottom: 1px solid #bfdbfe; }
.ps-table .ps-th-tot { background: #e0e7ff !important; color: #1e1b4b !important; font-weight: 700; }
.ps-table .ps-th-m { min-width: 75px; max-width: 110px; font-size: 10px; }

/* Первая колонка иерархии (липнет слева, строго по левому краю) */
.ps-table .ps-c1, #modal-plansvod .ps-table .ps-c1, #modal-plansvod2 .ps-table .ps-c1 {
  position: sticky !important; left: 0 !important; z-index: 2 !important;
  text-align: left !important; vertical-align: middle !important;
  min-width: 260px; max-width: 360px; white-space: normal; border-right: 1px solid #cbd5e1;
  background: #ffffff !important; word-break: break-word; line-height: 1.25;
}
.ps-table thead .ps-c1, #modal-plansvod thead .ps-c1, #modal-plansvod2 thead .ps-c1 {
  z-index: 4 !important; background: #dcebf7 !important; text-align: left !important;
}

.ps-metric-subrow td.ps-c1, #modal-plansvod2 .ps-metric-subrow td.ps-c1 {
  text-align: left !important; padding-left: 28px !important;
  color: #475569 !important; font-weight: 500 !important;
}

/* Колонки иерархии и параметров для Таблиц 1 и 3 */
#modal-plansvod2 .ps-table .ps-c1 {
  min-width: 140px !important; max-width: 200px !important; text-align: left !important;
}
#modal-plansvod2 .ps-table .ps-c2 {
  min-width: 140px !important; max-width: 220px !important; text-align: left !important;
  border-right: 1px solid #cbd5e1 !important; background: #fff !important;
}
#modal-plansvod2 .ps-table thead .ps-c2 {
  background: #dcebf7 !important; text-align: left !important;
}
#modal-plansvod2 .ps-table .ps-c3 {
  min-width: 130px !important; max-width: 170px !important; text-align: left !important;
  border-right: 1px solid #cbd5e1 !important; color: #334155 !important;
  font-weight: 500 !important; white-space: nowrap !important; background: #fff !important;
}
#modal-plansvod2 .ps-table thead .ps-c3 {
  background: #dcebf7 !important; text-align: left !important;
}

/* Кнопка раскрытия дерева (стиль PBI: аккуратный квадратик с плюсом/минусом) */
.ps-tog {
  width: 18px; height: 18px; line-height: 14px; padding: 0; margin-right: 6px;
  border: 1px solid #8ba4ca; border-radius: 3px; background: #f8fbfe; color: #2c4a75;
  cursor: pointer; font-weight: 700; vertical-align: middle; display: inline-flex;
  align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.ps-tog:hover { background: #2563eb; color: #fff; border-color: #2563eb; }
.ps-tog-sp { display: inline-block; width: 24px; flex-shrink: 0; }

/* Ячейка узла и артикула (исправление проблемы с ... на 3-м скриншоте) */
.ps-lab { display: inline-flex; gap: 8px; align-items: center; vertical-align: middle; width: calc(100% - 24px); }
.ps-img { width: 32px; height: 42px; object-fit: cover; border-radius: 3px; flex-shrink: 0; border: 1px solid #e2e8f0; }
.ps-sku-link { color: #1d4ed8; text-decoration: none; font-weight: 700; font-size: 11px; }
.ps-sku-link:hover { text-decoration: underline; }
.ps-sub { font-size: 10px; color: #334155; margin-top: 2px; white-space: normal; line-height: 1.2; word-break: break-word; }

/* Цвета ячеек */
.ps-g1 td:not(.ps-c1), td.ps-c-g1 { background: #e6f7ec !important; font-weight: 700; color: #0e623b !important; }
.ps-g2 td:not(.ps-c1), td.ps-c-g2 { background: #eef4fc !important; font-weight: 700; color: #1d4ed8 !important; }
.ps-b1 td:not(.ps-c1), td.ps-c-b1 { background: #dbe8f7 !important; font-weight: 700; color: #1e3a8a !important; }
.ps-b2 td:not(.ps-c1), td.ps-c-b2 { background: #bcd3ef !important; font-weight: 700; }
.ps-y1 td:not(.ps-c1), td.ps-c-y1 { background: #fbe7a6 !important; font-weight: 700; color: #9a5b00 !important; }

/* Итоговая строка */
.ps-grand td { background: #f0f4ff !important; font-weight: 700 !important; color: #1e1b4b; }
.ps-grand .ps-c1 { background: #e2eafd !important; }

/* ABC */
.ps-abc-cell { text-align: center !important; font-weight: 700; }
.ps-abc-A { color: #16a34a; }
.ps-abc-B { color: #2563eb; }
.ps-abc-C { color: #dc2626; }

/* ─── График «Динамика заказов» ─── */
.ps-chart-card {
  background: #ffffff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid #dbe2ef; padding: 14px 20px; display: flex; flex-direction: column;
  width: 100%; box-sizing: border-box;
}
.ps-chart-header {
  text-align: center; margin-bottom: 6px;
}
.ps-chart-title {
  font-size: 15px; font-weight: 700; color: #1e293b; margin: 0;
}
.ps-chart-container {
  height: 330px; width: 100%; position: relative;
}

/* ─── Матричный вид Таблиц 1 и 3 (Сводка планирования 2) ─── */
.ps-metric-subrow td {
  background: #fcfdfe !important;
  border-bottom: 1px solid #edf2f7 !important;
  font-size: 11px;
  padding: 3px 8px !important;
  line-height: 1.3;
}
.ps-metric-subrow:hover td {
  background: #f1f5f9 !important;
}
.ps-metric-subname {
  font-size: 11px;
  font-weight: 500;
  color: #475569;
  white-space: nowrap;
  display: inline-block;
}
.ps-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}
.ps-pill-green {
  background: #dcfce7 !important;
  color: #15803d !important;
  border: 1px solid #bbf7d0;
}
.ps-highlight-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}
.ps-highlight-pill.yellow {
  background: #fef9c3 !important;
  color: #854d0e !important;
  border: 1px solid #fef08a;
}
.ps-highlight-pill.green {
  background: #dcfce7 !important;
  color: #15803d !important;
  border: 1px solid #bbf7d0;
}
.ps-highlight-pill.red {
  background: #fee2e2 !important;
  color: #991b1b !important;
  border: 1px solid #fecaca;
}

/* ─── Тепловые градиентные полосы в ячейках (Heatmap bars) ─── */
.ps-bar-cell {
  position: relative;
  background-clip: padding-box;
  z-index: 1;
}
.ps-bar-fill {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  border-radius: 3px;
  z-index: -1;
  pointer-events: none;
}



/* ─── Плавное раскрытие компактных фильтров в шапке Plansvod ─── */
.ps-row-secondary {
  display: flex !important;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0 !important;
  padding-top: 0 !important;
  border-top: 1px dashed transparent !important;
  pointer-events: none;
  transform: translateY(-5px);
  transition: max-height 0.48s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.42s ease,
              transform 0.48s cubic-bezier(0.16, 1, 0.3, 1),
              margin-top 0.48s cubic-bezier(0.16, 1, 0.3, 1),
              padding-top 0.48s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.35s ease;
  will-change: max-height, opacity, transform;
}

.ps-show-secondary .ps-row-secondary,
.ps-row-secondary.ps-visible {
  max-height: 120px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  margin-top: 6px !important;
  padding-top: 6px !important;
  border-top: 1px dashed #cbd5e1 !important;
}

/* После завершения анимации разрешаем выпадающим спискам выходить за границы */
.ps-row-secondary.ps-overflow-visible {
  overflow: visible !important;
}

.ps-filter-card {
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.ps-more-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 28px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  background: #ffffff;
  border: 1px solid #bfdbfe;
  cursor: pointer;
  white-space: nowrap;
  align-self: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.ps-more-toggle:hover {
  background: #eff6ff;
  border-color: #3b82f6;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(37,99,235,0.14);
}
.ps-more-toggle.active {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
}
.ps-more-toggle.active:hover {
  background: #1d4ed8;
}
.ps-more-arrow {
  display: inline-block;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  font-size: 10px;
  line-height: 1;
}
.ps-more-toggle.active .ps-more-arrow {
  transform: rotate(180deg);
}
.ps-more-badge {
  display: inline-block;
  background: #ef4444;
  color: #ffffff;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
}
