:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --text: #18202a;
  --muted: #667485;
  --border: #dfe5eb;
  --accent: #116466;
  --accent-strong: #0b5254;
  --positive: #177245;
  --negative: #b42318;
  --warning: #9a6700;
  --shadow: 0 14px 34px rgba(24, 32, 42, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111417;
  --surface: #1a1f24;
  --surface-muted: #242b31;
  --text: #ecf1f4;
  --muted: #a9b4bd;
  --border: #313941;
  --accent: #5ec4b6;
  --accent-strong: #83d6cb;
  --positive: #67d391;
  --negative: #ff8a7a;
  --warning: #f4c76d;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar h1,
.chart-panel h2,
.table-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subtle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.icon-button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.primary-button {
  padding: 0 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
}

.icon-button {
  width: 42px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.status-panel,
.kpi-card,
.controls-panel,
.chart-panel,
.table-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-panel {
  margin-bottom: 18px;
  padding: 14px 16px;
  color: var(--muted);
}

.status-panel.error {
  border-color: color-mix(in srgb, var(--negative) 45%, var(--border));
  color: var(--negative);
}

.hidden {
  display: none !important;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  min-height: 112px;
  padding: 16px;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 12px;
  overflow-wrap: anywhere;
  font-size: clamp(1.25rem, 2vw, 1.8rem);
  line-height: 1.08;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--negative);
}

.controls-panel {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, minmax(150px, 1fr)) auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px;
}

.controls-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.controls-panel input,
.controls-panel select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.checkbox-row {
  min-height: 42px;
  grid-auto-flow: column;
  align-items: center;
  justify-content: start;
  gap: 8px !important;
  padding-bottom: 7px;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.chart-panel {
  min-height: 390px;
  padding: 18px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 300px !important;
  margin-top: 14px;
}

.table-panel {
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1240px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.name-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.pill.active {
  background: color-mix(in srgb, var(--positive) 18%, transparent);
  color: var(--positive);
}

.pill.inactive {
  background: color-mix(in srgb, var(--warning) 18%, transparent);
  color: var(--warning);
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .controls-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  .kpi-grid,
  .charts-grid,
  .controls-panel {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    min-height: 340px;
  }

  .chart-panel canvas {
    height: 250px !important;
  }
}
