:root {
  --bg: #f1f5f9;
  --bg-accent: linear-gradient(165deg, #fef2f2 0%, #f8fafc 45%, #f1f5f9 100%);
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --brand: #e60000;
  --brand-hover: #c40000;
  --brand-soft: #fef2f2;
  --accent: #e60000;
  --accent-hover: #c40000;
  --accent-soft: #fef2f2;
  --healthy: #059669;
  --healthy-soft: #d1fae5;
  --healthy-border: #6ee7b7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --warning-border: #fcd34d;
  --critical: #dc2626;
  --critical-soft: #fee2e2;
  --critical-border: #fca5a5;
  --offline: #64748b;
  --offline-soft: #f1f5f9;
  --offline-border: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-hover: 0 8px 20px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --gap: 0.875rem;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.75rem;
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  margin-bottom: var(--gap);
  padding: 0.875rem 1.125rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-logo {
  display: block;
  width: auto;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(230, 0, 0, 0.15));
  transition: transform 0.2s ease;
}

.brand:hover .brand-logo {
  transform: scale(1.03);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.alerts-header-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.2s, color 0.2s;
}

.alerts-header-badge--none {
  background: var(--healthy-soft);
  color: var(--healthy);
  border-color: var(--healthy-border);
}

.alerts-header-badge--warn {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: var(--warning-border);
}

.alerts-header-badge--crit {
  background: var(--critical-soft);
  color: var(--critical);
  border-color: var(--critical-border);
  animation: alert-pulse 2s ease-in-out infinite;
}

@keyframes alert-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
  50% { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15); }
}

.status-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-loading { background: var(--offline-soft); color: var(--offline); border-color: var(--offline-border); }
.status-loading .status-dot { animation: pulse 1.2s ease-in-out infinite; }
.status-ok { background: var(--healthy-soft); color: var(--healthy); border-color: var(--healthy-border); }
.status-error { background: var(--critical-soft); color: var(--critical); border-color: var(--critical-border); }

.last-updated { font-size: 0.6875rem; color: var(--text-muted); font-weight: 500; }

@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  font-size: 0.8125rem;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(230, 0, 0, 0.25);
}

.btn-primary:hover {
  background: var(--brand-hover);
  box-shadow: 0 4px 10px rgba(230, 0, 0, 0.3);
  transform: translateY(-1px);
}

.btn:active { transform: scale(0.98) translateY(0); }

/* Layout */
.main { display: flex; flex-direction: column; gap: var(--gap); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.card:hover { box-shadow: var(--shadow); }

/* Summary grid */
.summary-grid {
  display: grid;
  grid-template-columns: 1.6fr repeat(4, 1fr);
  gap: var(--gap);
}

/* Health card */
.health-card {
  padding: 1rem 1.125rem;
  grid-column: span 1;
}

.health-card--healthy { border-color: var(--healthy-border); background: linear-gradient(135deg, #fff 0%, #f0fdf4 100%); }
.health-card--warning { border-color: var(--warning-border); background: linear-gradient(135deg, #fff 0%, #fffbeb 100%); }
.health-card--critical { border-color: var(--critical-border); background: linear-gradient(135deg, #fff 0%, #fef2f2 100%); }
.health-card--offline,
.health-card--loading { border-color: var(--offline-border); }

.health-card__main {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.health-indicator {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}

.health-indicator__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--offline-border);
  transition: border-color 0.3s;
}

.health-card--healthy .health-indicator__ring { border-color: var(--healthy); animation: health-ring 2.5s ease-in-out infinite; }
.health-card--warning .health-indicator__ring { border-color: var(--warning); }
.health-card--critical .health-indicator__ring { border-color: var(--critical); animation: health-ring 1.2s ease-in-out infinite; }

@keyframes health-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.2); }
  50% { box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
}

.health-indicator__core {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--offline-soft);
  transition: background 0.3s;
}

.health-card--healthy .health-indicator__core { background: var(--healthy); }
.health-card--warning .health-indicator__core { background: var(--warning); }
.health-card--critical .health-indicator__core { background: var(--critical); }
.health-card--offline .health-indicator__core { background: var(--offline); }

.health-card__content { flex: 1; min-width: 0; }

.health-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.health-card h2 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.health-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.health-badge--healthy { background: var(--healthy-soft); color: var(--healthy); }
.health-badge--warning { background: var(--warning-soft); color: var(--warning); }
.health-badge--critical { background: var(--critical-soft); color: var(--critical); }
.health-badge--offline,
.health-badge--gray { background: var(--offline-soft); color: var(--offline); }

.health-score-label {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.health-summary {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.health-factors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.health-factor {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.45rem;
  border-radius: 5px;
  border: 1px solid transparent;
}

.health-factor--ok { background: var(--healthy-soft); color: var(--healthy); border-color: var(--healthy-border); }
.health-factor--warn { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.health-factor--crit { background: var(--critical-soft); color: var(--critical); border-color: var(--critical-border); }
.health-factor--off { background: var(--offline-soft); color: var(--offline); border-color: var(--offline-border); }

/* KPI cards */
.kpi-card {
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-card:hover { transform: translateY(-2px); }

.kpi-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.kpi-card h2 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-badge {
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.kpi-badge--healthy { background: var(--healthy-soft); color: var(--healthy); }
.kpi-badge--warning { background: var(--warning-soft); color: var(--warning); }
.kpi-badge--critical { background: var(--critical-soft); color: var(--critical); }
.kpi-badge--gray { background: var(--offline-soft); color: var(--offline); }

.kpi-card__value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.kpi-value {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.kpi-meta {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trend {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  white-space: nowrap;
}

.trend--up { background: #fee2e2; color: #b91c1c; }
.trend--down { background: var(--healthy-soft); color: var(--healthy); }
.trend--up-good { background: var(--healthy-soft); color: var(--healthy); }
.trend--down-bad { background: #fee2e2; color: #b91c1c; }
.trend--neutral { background: var(--offline-soft); color: var(--offline); }

/* Panels */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: var(--gap);
}

.tables-grid,
.activity-panel { gap: 0; }

.panel { padding: 1rem 1.125rem; }

.panel-head { margin-bottom: 0.75rem; }

.panel-head--row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-desc {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.panel-badge {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--border-soft);
  border: 1px solid var(--border);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

/* Charts */
.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap-donut {
  height: 220px;
  max-width: 280px;
  margin: 0 auto;
}

.chart-wrap--loading canvas { opacity: 0.25; }

.chart-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
  background: rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
}

.chart-wrap--loading .chart-loading { display: flex; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  z-index: 1;
  background: var(--border-soft);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.chart-empty[hidden] { display: none !important; }

.chart-wrap--has-data .chart-empty { display: none; }

.chart-empty__icon {
  width: 40px;
  height: 40px;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  opacity: 0.7;
}

.chart-empty__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.chart-empty__desc {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 220px;
}

/* Activity feed */
.activity-panel { padding: 1rem 1.125rem; }

.activity-feed {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--surface);
  transition: background 0.12s, border-color 0.12s;
}

.activity-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.activity-item__icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 8px;
}

.activity-item--healthy .activity-item__icon { background: var(--healthy-soft); color: var(--healthy); }
.activity-item--warning .activity-item__icon { background: var(--warning-soft); color: var(--warning); }
.activity-item--critical .activity-item__icon { background: var(--critical-soft); color: var(--critical); }
.activity-item--info .activity-item__icon { background: var(--accent-soft); color: var(--accent); }
.activity-item--offline .activity-item__icon { background: var(--offline-soft); color: var(--offline); }

.activity-item__body { min-width: 0; flex: 1; }

.activity-item__title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.activity-item__meta {
  margin: 0.1rem 0 0;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.activity-item__time {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Tables */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.data-table thead {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1.25rem;
  font-weight: 500;
}

.location-tag {
  display: inline-block;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  font-size: 0.6875rem;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-weight: 600;
  font-size: 0.6875rem;
}

.count-badge--excellent { background: #d1fae5; color: #047857; }
.count-badge--good { background: #dbeafe; color: #1d4ed8; }
.count-badge--average { background: #fef3c7; color: #b45309; }
.count-badge--poor { background: #ffedd5; color: #c2410c; }
.count-badge--very-poor { background: #fee2e2; color: #b91c1c; }

.total-cell { font-weight: 700; }
.pm-cell--good { color: var(--healthy); font-weight: 600; }
.pm-cell--moderate { color: var(--warning); font-weight: 600; }
.pm-cell--poor { color: var(--critical); font-weight: 600; }

.footer {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer p { margin: 0; }

/* Responsive */
@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .health-card {
    grid-column: span 2;
  }
}

@media (max-width: 768px) {
  .summary-grid { grid-template-columns: 1fr; }
  .health-card { grid-column: span 1; }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app { padding: 0.75rem; }
  .header-actions { width: 100%; justify-content: space-between; }
  .status-group { align-items: flex-start; }
  .kpi-value { font-size: 1.2rem; }
}
