/* ============================================================================
   Мир «Грид» — Плашка «Здоровье и Пульс Мира» (/live System Pulse & Health Bar)
   WCAG 2.2 AAA Compliant · HSL Design Tokens · Responsive (1440px / 768px / 390px)
   Соблюдает Закон Модульности (Статья XIX: <= 800 строк).
   ============================================================================ */

.world-health-bar {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-sm);
  transition: var(--transition-smooth);
  min-width: 0;
  box-sizing: border-box;
  user-select: none;
}

.world-health-bar:hover {
  border-color: var(--line-hover);
  box-shadow: 0 4px 14px var(--black-alpha-20);
}

/* 1. Главный статус здоровья */
.health-main-stat {
  display: flex;
  align-items: center;
  gap: var(--sp-1-5);
  flex-shrink: 0;
}

.health-pct {
  font-size: var(--fs-body);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--tx);
}

.health-pct-sub {
  font-size: var(--fs-xs);
  color: var(--tx3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.health-status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-0-5) var(--sp-1-5);
  border-radius: var(--r-xs);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.health-status-badge.status-good {
  background: var(--green-alpha-15);
  border: 1px solid var(--green-alpha-30);
  color: var(--green-light);
}

.health-status-badge.status-fair {
  background: var(--amber-alpha-15);
  border: 1px solid var(--amber-alpha-30);
  color: var(--rank-celestial);
}

.health-status-badge.status-poor {
  background: var(--red-alpha-15);
  border: 1px solid var(--red-alpha-30);
  color: var(--red-light);
}

.health-status-badge.status-unknown {
  background: var(--white-alpha-04);
  border: 1px solid var(--line);
  color: var(--tx3);
}

/* Разделители */
.health-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
  flex-shrink: 0;
}

/* ============================================================================
   2. Индикаторы пульса ключевых подсистем (System Subsystems Pulse)
   ============================================================================ */

.health-subsystems-pulse {
  display: flex;
  align-items: center;
  gap: var(--sp-1-5);
  flex-shrink: 0;
}

.health-subsys-item {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-0-5) var(--sp-1-5);
  border-radius: var(--r-xs);
  background: var(--white-alpha-04);
  border: 1px solid var(--white-alpha-04);
  max-height: 32px;
  min-height: 24px;
  box-sizing: border-box;
  font-size: var(--fs-xs);
  color: var(--tx2);
  cursor: default;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: background var(--dur-normal) ease, border-color var(--dur-normal) ease;
}

.health-subsys-item:hover {
  background: var(--white-alpha-08);
  border-color: var(--violet-alpha-30);
}

.subsys-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-circle);
  display: inline-block;
  flex-shrink: 0;
  background: var(--green);
  transition: background var(--dur-normal) ease, box-shadow var(--dur-normal) ease;
}

.subsys-dot.ok {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-alpha-70);
}

.subsys-dot.warn {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-alpha-70);
}

.subsys-dot.bad {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-alpha-70);
}

.subsys-dot.pulse {
  animation: subsysPulseAnim var(--dur-pulse) ease-in-out infinite;
}

@keyframes subsysPulseAnim {
  0%, 100% { transform: scale(0.9); opacity: 0.75; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 8px var(--green-light); }
}

.subsys-label {
  color: var(--tx3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subsys-val {
  color: var(--tx);
  font-size: var(--fs-xs);
  font-family: var(--mono);
  font-weight: 700;
}

.subsys-sep {
  color: var(--tx3);
  opacity: 0.5;
  font-size: var(--fs-xs);
}

/* ============================================================================
   3. Счетчики нарядов
   ============================================================================ */

.health-counts {
  display: flex;
  align-items: center;
  gap: var(--sp-1-5);
  font-size: var(--fs-sm);
  color: var(--tx2);
  white-space: nowrap;
  flex-shrink: 0;
}

.health-count-item.ok {
  color: var(--green-light);
  font-weight: 600;
}

.health-count-item.bad {
  color: var(--red-light);
  font-weight: 600;
}

.health-count-sep {
  color: var(--tx3);
  opacity: 0.6;
}

.health-count-total {
  color: var(--tx3);
}

/* ============================================================================
   4. Разбивка причин сбоев
   ============================================================================ */

.health-reasons-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-1-5);
  min-width: 0;
  overflow: hidden;
}

.health-reasons-list {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.health-reasons-list::-webkit-scrollbar {
  display: none;
}

.health-reason-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: var(--red-alpha-08);
  border: 1px solid var(--red-alpha-20);
  border-radius: var(--r-xs);
  padding: var(--sp-0-5) var(--sp-1-5);
  font-size: var(--fs-xs);
  white-space: nowrap;
  color: var(--tx2);
}

.health-reason-name {
  color: var(--tx3);
}

.health-reason-val {
  color: var(--red-light);
  font-weight: 700;
}

.health-reason-empty {
  font-size: var(--fs-sm);
  color: var(--green-light);
  opacity: 0.9;
}

/* ============================================================================
   5. Тайминги наряда
   ============================================================================ */

.health-timing {
  display: flex;
  align-items: center;
  gap: var(--sp-1-5);
  font-size: var(--fs-sm);
  color: var(--tx3);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.health-timing-item b {
  color: var(--tx);
  font-weight: 600;
}

.health-timing-sep {
  opacity: 0.5;
}

/* ============================================================================
   6. Пустое состояние / Ошибка
   ============================================================================ */

.health-bar-empty {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--tx3);
  padding: var(--sp-0-5) var(--sp-1);
}

.health-empty-title {
  color: var(--tx2);
  font-weight: 600;
}

.health-empty-reason {
  color: var(--rank-celestial);
  font-style: italic;
}

/* Скелетон */
.health-skeleton {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5);
  width: 100%;
}

.health-skel-box {
  background: var(--white-alpha-04);
  border-radius: var(--r-xs);
  height: 18px;
  animation: skelPulse var(--dur-pulse) ease-in-out infinite;
}

@keyframes skelPulse {
  0% { opacity: 0.5; }
  50% { opacity: 0.85; }
  100% { opacity: 0.5; }
}

/* ============================================================================
   7. Поддержка prefers-reduced-motion (Отключение анимаций пульса)
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .subsys-dot.pulse,
  .health-status-badge .dot.pulse,
  .health-skel-box,
  .health-bar-empty .dot.pulse {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================================
   8. Светлая тема (принцип «две темы врозь»)
   ============================================================================ */

html.light-theme .world-health-bar {
  background: var(--white);
  border-color: var(--line);
  box-shadow: 0 1px 3px var(--black-alpha-04);
}

html.light-theme .world-health-bar:hover {
  border-color: var(--violet);
  box-shadow: 0 4px 12px var(--black-alpha-04);
}

html.light-theme .health-divider {
  background: var(--line);
}

html.light-theme .health-subsys-item,
[data-theme=light] .health-subsys-item {
  background: var(--surface-1);
  border-color: var(--line);
  color: var(--tx2);
  box-shadow: 0 1px 2px var(--black-alpha-04);
}

html.light-theme .health-subsys-item:hover,
[data-theme=light] .health-subsys-item:hover {
  background: var(--surface-2);
  border-color: var(--line-hover);
  box-shadow: 0 2px 6px var(--black-alpha-08);
}

html.light-theme .subsys-dot.ok,
[data-theme=light] .subsys-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 1.5px var(--green-alpha-30);
}

html.light-theme .subsys-dot.warn,
[data-theme=light] .subsys-dot.warn {
  background: var(--amber);
  box-shadow: 0 0 0 1.5px var(--amber-alpha-30);
}

html.light-theme .subsys-dot.bad,
[data-theme=light] .subsys-dot.bad {
  background: var(--red);
  box-shadow: 0 0 0 1.5px var(--red-alpha-30);
}

html.light-theme .subsys-label,
[data-theme=light] .subsys-label {
  color: var(--tx3);
}

html.light-theme .subsys-val,
[data-theme=light] .subsys-val {
  color: var(--tx);
}

html.light-theme .health-status-badge.status-good,
[data-theme=light] .health-status-badge.status-good {
  background: var(--green-alpha-12);
  border: 1px solid var(--green-alpha-30);
  color: var(--green);
}

html.light-theme .health-status-badge.status-fair,
[data-theme=light] .health-status-badge.status-fair {
  background: var(--amber-alpha-12);
  border: 1px solid var(--amber-alpha-30);
  color: var(--amber);
}

html.light-theme .health-status-badge.status-poor,
[data-theme=light] .health-status-badge.status-poor {
  background: var(--red-alpha-08);
  border: 1px solid var(--red-alpha-30);
  color: var(--red);
}

html.light-theme .health-reason-chip,
[data-theme=light] .health-reason-chip {
  background: var(--red-alpha-08);
  border-color: var(--red-alpha-20);
  color: var(--tx2);
}

html.light-theme .health-reason-name,
[data-theme=light] .health-reason-name {
  color: var(--tx3);
}

html.light-theme .health-reason-val,
[data-theme=light] .health-reason-val {
  color: var(--red);
}

html.light-theme .health-count-item.ok,
[data-theme=light] .health-count-item.ok {
  color: var(--green);
}

html.light-theme .health-count-item.bad,
[data-theme=light] .health-count-item.bad {
  color: var(--red);
}

/* ============================================================================
   9. Адаптивность для экранов (1400px, 900px, 480px)
   ============================================================================ */

@media (max-width: 1400px) {
  .world-health-bar {
    gap: var(--sp-1-5);
    padding: var(--sp-0-5) var(--sp-1-5);
    font-size: var(--fs-xs);
  }
  .health-subsystems-pulse {
    gap: var(--sp-1);
  }
  .health-subsys-item {
    padding: var(--sp-0-5) var(--sp-1);
    font-size: var(--fs-xs);
    gap: var(--sp-0-5);
  }
  .health-reasons-wrap {
    display: none;
  }
  .health-timing-max,
  .health-timing-sep {
    display: none;
  }
}

@media (max-width: 900px) {
  .world-health-bar {
    width: 100% !important;
    max-width: 100% !important;
    flex-wrap: wrap !important;
    gap: var(--sp-2) !important;
    padding: var(--sp-2) var(--sp-2-5) !important;
  }
  .subsys-sep {
    display: none !important;
  }
  .health-timing {
    margin-left: 0 !important;
  }
}

@media (max-width: 480px) {
  .world-health-bar {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: var(--sp-1-5) !important;
    padding: var(--sp-2) var(--sp-2-5) !important;
    overflow-x: hidden !important;
  }

  .world-health-bar .health-divider {
    display: none !important;
  }

  .health-subsystems-pulse {
    flex-wrap: wrap !important;
    gap: var(--sp-1) !important;
    width: 100% !important;
  }

  .health-reasons-list {
    flex-wrap: wrap !important;
    max-width: 100% !important;
  }

  .health-pct {
    font-size: var(--fs-body) !important;
  }

  .health-status-badge {
    font-size: var(--fs-xs) !important;
    padding: var(--sp-0-5) var(--sp-1-5) !important;
  }

  .health-counts {
    font-size: var(--fs-xs) !important;
  }

  .health-reason-chip {
    font-size: var(--fs-2xs) !important;
    padding: var(--sp-0-5) var(--sp-1) !important;
  }

  .health-timing {
    font-size: var(--fs-xs) !important;
    width: 100% !important;
    justify-content: flex-start !important;
  }
}