:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --line: #d9e0e6;
  --text: #1b2733;
  --muted: #657384;
  --accent: #176c6a;
  --accent-dark: #0d4f4e;
  --warn: #b45309;
  --radius: 8px;
  --shadow: 0 8px 22px rgba(21, 34, 50, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 15px;
}

.status {
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.controls-panel,
.summary-card,
.map-panel,
.chart-panel,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.controls-panel {
  align-self: start;
  display: grid;
  gap: 18px;
  padding: 16px;
}

.control-section {
  display: grid;
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
button {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

select {
  padding: 0 10px;
}

button {
  cursor: pointer;
  font-weight: 700;
}

button:hover,
button:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(23, 108, 106, 0.16);
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.main-panel {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-card {
  padding: 14px 16px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.map-panel {
  overflow: hidden;
}

#basisMap {
  width: 100%;
  height: min(62vh, 620px);
  min-height: 430px;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
}

.chart-panel,
.table-panel {
  min-width: 0;
  padding: 14px;
}

.chart-panel canvas {
  display: block;
  width: 100% !important;
  height: 288px !important;
  max-height: 288px !important;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
}

.panel-title span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f5;
  color: #334253;
  font-size: 12px;
}

.basis-popup {
  min-width: 220px;
  line-height: 1.4;
}

.basis-popup strong {
  color: var(--accent-dark);
}

.basis-legend {
  min-width: 138px;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid rgba(27, 39, 51, 0.14);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(21, 34, 50, 0.18);
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}

.basis-legend-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
}

.basis-legend-items {
  display: grid;
  gap: 6px;
}

.basis-legend-row {
  display: grid;
  grid-template-columns: 14px 32px minmax(52px, auto);
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.basis-legend-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(27, 39, 51, 0.35);
  border-radius: 3px;
}

.basis-legend-label {
  color: var(--muted);
}

.basis-legend-value {
  font-weight: 700;
  text-align: right;
}

.basis-legend-empty {
  color: var(--muted);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1050px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  .app-header,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .dashboard-shell {
    padding: 12px;
  }

  .controls-panel,
  .summary-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  #basisMap {
    height: 520px;
    min-height: 360px;
  }

  .basis-legend {
    margin: 10px 10px 0 0 !important;
    padding: 8px 9px;
  }
}
