/* ── Reset & base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f2f6f3;
  color: #424242;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: #298F69;
  color: white;
  padding: 18px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 18px; font-weight: 600; letter-spacing: 0.3px; }
header .header-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
header .last-updated { font-size: 12px; opacity: 0.65; }

/* ── Tab nav ────────────────────────────────────────────────────────────────── */
.tab-nav {
  background: #424242;
  display: flex;
  gap: 0;
  padding: 0 28px;
  border-bottom: 2px solid #333;
}

.tab-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 13px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.2px;
}
.tab-btn:hover  { color: rgba(255,255,255,0.9); background: none; }
.tab-btn.active { color: white; border-bottom-color: #4BB861; }

/* ── Tab sections ───────────────────────────────────────────────────────────── */
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Layout container ───────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

/* ── Controls row ───────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-primary {
  background: #298F69;
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
}
.btn-primary:hover    { background: #4BB861; }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }

.btn-secondary {
  background: #555;
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
}
.btn-secondary:hover    { background: #444; }
.btn-secondary:disabled { background: #aaa; cursor: not-allowed; }

.btn-export {
  background: none;
  border: 1px solid #298F69;
  color: #298F69;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s;
}
.btn-export:hover { background: #298F69; color: white; }

/* ── Status text ────────────────────────────────────────────────────────────── */
.status       { font-size: 12px; color: #666; }
.status.error { color: #c0392b; }

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

.kpi {
  background: white;
  border-radius: 10px;
  padding: 20px 24px;
  border-left: 4px solid #298F69;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.kpi .label { font-size: 11px; color: #828282; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px; }
.kpi .value { font-size: 28px; font-weight: 700; color: #298F69; }
.kpi .sub   { font-size: 11px; color: #bbb; margin-top: 4px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
  margin-bottom: 16px;
}
.card-header h2 { font-size: 15px; font-weight: 600; color: #298F69; }

/* ── Chart legend ───────────────────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-size: 12px;
  color: #555;
  flex-wrap: wrap;
}
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.legend-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.legend-toggle input[type="checkbox"] { cursor: pointer; accent-color: #298F69; width: 14px; height: 14px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.legend-line   { width: 20px; height: 3px; border-radius: 2px; display: inline-block; }

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

/* ── Chart select/clear controls ────────────────────────────────────────────── */
.chart-select-controls {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.btn-chart-toggle {
  background: none;
  border: 1px solid #ddd;
  color: #666;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-chart-toggle:hover { background: #f0f5f1; border-color: #298F69; color: #298F69; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  background: #298F69;
  color: white;
  padding: 10px 14px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
thead th:not(:first-child) { text-align: right; }

tbody tr:nth-child(even) { background: #f6faf7; }
tbody tr:hover            { background: #C3EDCE; }

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
}
tbody td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Pills ──────────────────────────────────────────────────────────────────── */
.pill       { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; margin-left: 6px; }
.pill.up    { background: #C3EDCE; color: #298F69; }
.pill.down  { background: #ffebee; color: #c62828; }

/* ── Loader ─────────────────────────────────────────────────────────────────── */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: #888;
  gap: 16px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #e0e0e0;
  border-top-color: #298F69;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Coming soon placeholder ────────────────────────────────────────────────── */
.coming-soon {
  text-align: center;
  padding: 80px 24px;
  color: #999;
}
.coming-soon .icon { font-size: 40px; margin-bottom: 16px; }
.coming-soon h3    { font-size: 18px; font-weight: 600; color: #555; margin-bottom: 8px; }
.coming-soon p     { font-size: 13px; max-width: 380px; margin: 0 auto; line-height: 1.6; }

/* ── Subtab layout ──────────────────────────────────────────────────────────── */
.subtab-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.subtab-nav {
  width: 172px;
  flex-shrink: 0;
  background: white;
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  position: sticky;
  top: 20px;
}

.subtab-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #424242;
  padding: 9px 12px;
  text-align: left;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.subtab-btn:hover  { background: #f0f5f1; color: #298F69; }
.subtab-btn.active { background: #C3EDCE; color: #298F69; font-weight: 600; }

.subtab-content  { flex: 1; min-width: 0; }
.subtab-section  { display: none; }
.subtab-section.active { display: block; }

/* ── Scrollable wide tables ─────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 700px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  header { padding: 14px 20px; }
  .tab-btn { padding: 12px 14px; font-size: 12px; }
  .container { padding: 20px 16px; }
  .subtab-layout { flex-direction: column; }
  .subtab-nav { width: 100%; position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .subtab-btn { width: auto; flex: 1 1 auto; text-align: center; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
