*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:    #DC2626;
  --orange: #F97316;
  --green:  #16A34A;
  --blue:   #2563EB;
  --yellow: #D97706;
  --bg:     #F3F4F6;
  --card:   #FFFFFF;
  --header: #1E3A5F;
  --text:   #111827;
  --muted:  #6B7280;
  --border: #E5E7EB;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── HEADER ──────────────────────────────────────────────────── */
#stats-header {
  background: var(--header);
  color: #fff;
  padding: 16px 20px 14px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

#stats-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

#back-link {
  color: #93C5FD;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  display: block;
  margin-bottom: 4px;
}
#back-link:hover { color: #fff; }

#stats-header h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

#stats-sub {
  font-size: 12px;
  opacity: 0.65;
  margin-top: 2px;
}

#header-date {
  font-size: 12px;
  opacity: 0.7;
  text-align: right;
  padding-top: 4px;
}

/* ── MAIN ────────────────────────────────────────────────────── */
#stats-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── KPI CARDS ───────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(6, 1fr); }
}

.kpi-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-top: 4px solid var(--border);
}
.kpi-card.red    { border-top-color: var(--red); }
.kpi-card.orange { border-top-color: var(--orange); }
.kpi-card.green  { border-top-color: var(--green); }
.kpi-card.blue   { border-top-color: var(--blue); }
.kpi-card.yellow { border-top-color: var(--yellow); }

.kpi-num {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 6px;
}
.kpi-card.red    .kpi-num { color: var(--red); }
.kpi-card.orange .kpi-num { color: var(--orange); }
.kpi-card.green  .kpi-num { color: var(--green); }
.kpi-card.blue   .kpi-num { color: var(--blue); }
.kpi-card.yellow .kpi-num { color: var(--yellow); }

.kpi-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  line-height: 1.3;
}

/* ── CHARTS ──────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 768px) {
  .charts-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.chart-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 14px;
}

.chart-wrap {
  position: relative;
  height: 200px;
}

.donut-wrap { height: 220px; }

/* ── SECTION CARDS ───────────────────────────────────────────── */
.section-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.section-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── REGION GRID ─────────────────────────────────────────────── */
#region-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (min-width: 640px) {
  #region-grid { grid-template-columns: repeat(3, 1fr); }
}

.region-row {
  background: #F9FAFB;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.region-name {
  font-size: 13px;
  font-weight: 600;
}

.region-chips {
  display: flex;
  gap: 4px;
}

.region-chip {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
}

.rc-closed     { background: #FEE2E2; color: var(--red); }
.rc-critical { background: #FFEDD5; color: #C2410C; }
.rc-active     { background: #DCFCE7; color: #15803D; }

/* ── PRIORITY LIST ───────────────────────────────────────────── */
.priority-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.priority-item:last-child { border-bottom: none; }

.priority-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}

.priority-city {
  font-size: 12px;
  color: var(--muted);
}

.priority-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.flag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: #FEF3C7;
  color: #92400E;
  white-space: nowrap;
}

.empty-msg {
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: 14px;
}

/* ── ACTIVITY LIST ───────────────────────────────────────────── */
.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.activity-dot.closed     { background: var(--red); }
.activity-dot.critical { background: var(--orange); }
.activity-dot.active     { background: var(--green); }

.activity-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
}

.activity-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* ── SCORE HISTORY ─────────────────────────────────────────────── */
.hist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.hist-item:last-child { border-bottom: none; }

.hist-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hist-score {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.hist-delta {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

.delta-up   { background: #DCFCE7; color: #15803D; }
.delta-down { background: #FEE2E2; color: #DC2626; }

.hist-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
