:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #d8e0ea;
  --panel: #ffffff;
  --soft: #f4f7fb;
  --header: #203044;
  --blue: #2563eb;
  --teal: #0f766e;
  --amber: #f59e0b;
  --red: #dc2626;
  --green: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef3f8;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

.topbar {
  align-items: center;
  background: #111827;
  color: #fff;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
}

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

h1 {
  font-size: 20px;
  font-weight: 700;
}

h2 {
  font-size: 15px;
}

.meta {
  color: #bac6d8;
  font-size: 12px;
  margin-top: 4px;
}

.login,
.session-info {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: auto 260px auto;
}

.session-info {
  align-items: center;
  grid-template-columns: auto auto;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 5px;
}

input,
select,
button {
  border-radius: 6px;
  font: inherit;
  min-height: 34px;
}

input,
select {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: var(--ink);
  padding: 7px 9px;
}

button {
  background: var(--blue);
  border: 1px solid var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 7px 12px;
}

button.secondary {
  background: #fff;
  color: var(--blue);
}

button.danger {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

button.small-button {
  font-size: 12px;
  min-height: 24px;
  padding: 2px 7px;
}

.login-page {
  background: #111827;
}

.login-shell {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 20px;
  place-items: center;
}

.login-card {
  background: #fff;
  border: 1px solid #d8e0ea;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.35);
  display: grid;
  gap: 14px;
  max-width: 380px;
  padding: 24px;
  width: 100%;
}

.login-card h1 {
  color: var(--ink);
}

.login-card p {
  color: var(--muted);
  margin: 6px 0 0;
}

main {
  padding: 14px 18px 24px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tab {
  background: #dbe6f3;
  border: 1px solid #bfcede;
  color: #243449;
}

.tab.is-active {
  background: #fff;
  border-color: #fff;
  color: var(--blue);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.filter-grid {
  align-items: end;
  background: #d8eafd;
  border: 1px solid #b8d5f3;
  display: grid;
  gap: 6px;
  grid-auto-flow: row;
  grid-template-columns: repeat(7, minmax(90px, 1fr));
  grid-template-rows: repeat(2, auto);
  overflow-x: auto;
  padding: 6px;
}

.filter-grid label {
  font-size: 11px;
  gap: 2px;
  min-width: 0;
}

.filter-grid > * {
  min-width: 0;
}

.filter-grid select,
.filter-grid button {
  font-size: 12px;
  min-height: 28px;
  min-width: 0;
  padding: 4px 7px;
  width: 100%;
}

.filter-grid button {
  align-self: end;
  line-height: 1.1;
}

.kpi-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  margin: 12px 0;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.kpi span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.kpi strong {
  display: block;
  font-size: 18px;
  margin-top: 6px;
}

.band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.chart-band {
  margin-bottom: 12px;
}

.section-head {
  align-items: center;
  background: var(--header);
  color: #fff;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 36px;
  padding: 8px 10px;
}

.visual-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.visual-actions button {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1f2937;
  min-height: 26px;
  padding: 3px 8px;
}

.visual-actions button[data-width] {
  font-size: 15px;
  line-height: 1;
  min-width: 26px;
  padding: 2px 7px;
}

.section-head span {
  color: #cbd5e1;
  font-size: 12px;
}

.section-head.standalone {
  border-radius: 8px;
  margin-bottom: 10px;
}

.dashboard-grid {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: 1.1fr 1.25fr 1fr;
}

.visual-card {
  min-width: 0;
}

.visual-card.is-wide {
  grid-column: span 2;
}

.visual-card.is-narrow {
  justify-self: start;
  width: min(100%, 430px);
}

.table-wrap {
  overflow: auto;
}

.table-wrap.tall {
  max-height: 520px;
}

.table-wrap.compact {
  max-height: 230px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

th {
  background: #e5edf7;
  border-bottom: 1px solid var(--line);
  color: #1f2937;
  font-size: 12px;
  position: sticky;
  text-align: left;
  top: 0;
  z-index: 1;
}

th[data-key] {
  cursor: pointer;
}

th[data-key]::after {
  color: #64748b;
  content: " ⇅";
  font-weight: 400;
}

td,
th {
  border-bottom: 1px solid #edf1f6;
  padding: 7px 8px;
  vertical-align: middle;
  white-space: nowrap;
}

td.num,
th.num {
  text-align: right;
}

.action-cell {
  text-align: center;
}

.table-filter-button {
  background: #eef6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
  font-size: 12px;
  min-height: 24px;
  padding: 2px 7px;
}

.centered-table th,
.centered-table td {
  text-align: center;
}

tr:hover td {
  background: #f8fafc;
}

tfoot td {
  background: #e5edf7;
  border-top: 1px solid #cbd5e1;
  bottom: 0;
  font-weight: 700;
  position: sticky;
  z-index: 1;
}

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

.chart {
  min-height: 170px;
  padding: 10px 12px 0;
}

.chart svg {
  display: block;
  height: 170px;
  width: 100%;
}

.ach {
  font-weight: 700;
  text-align: right;
}

.ach.low {
  background: #fee2e2;
  color: #991b1b;
}

.ach.mid {
  background: #fdecc8;
  color: #92400e;
}

.ach.high {
  background: #dcfce7;
  color: #166534;
}

.ach.neutral {
  color: #64748b;
}

.ppg.positive {
  color: #15803d;
  font-weight: 700;
}

.ppg.negative {
  color: #dc2626;
  font-weight: 700;
}

.ppg.neutral {
  color: #64748b;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #e0f2fe;
}

.clickable-row.is-selected td {
  background: #dbeafe;
  box-shadow: inset 0 0 0 9999px rgba(37, 99, 235, 0.05);
}

.regional-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(420px, 1.2fr) minmax(320px, 0.9fr) minmax(320px, 0.9fr);
}

.map-panel {
  min-height: 520px;
}

.region-map {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  padding: 16px;
}

.region-tile {
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  color: #111827;
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 10px;
  text-align: left;
}

.region-tile strong {
  font-size: 15px;
}

.region-tile span {
  font-size: 12px;
  font-weight: 400;
}

.region-tile.positive {
  background: #86efac;
}

.region-tile.negative {
  background: #f87171;
}

.region-tile.neutral {
  background: #e2e8f0;
}

.region-tile.is-selected {
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

.legend-row {
  align-items: center;
  color: #334155;
  display: flex;
  gap: 8px;
  padding: 0 16px 16px;
}

.legend {
  border-radius: 3px;
  display: inline-block;
  height: 14px;
  width: 28px;
}

.legend.positive {
  background: #86efac;
}

.legend.negative {
  background: #f87171;
}

.legend.neutral {
  background: #e2e8f0;
}

.fullscreen-overlay {
  background: rgba(15, 23, 42, 0.62);
  inset: 0;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.fullscreen-panel {
  height: calc(100vh - 48px);
  margin: 0 auto;
  max-width: 1480px;
}

.fullscreen-table {
  max-height: calc(100vh - 112px);
}

.region-stack {
  display: grid;
  gap: 12px;
}

.region-title {
  align-items: center;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 9px 10px;
}

.region-title strong {
  font-size: 15px;
}

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

.upload-panel,
.access-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  max-width: 520px;
  padding: 16px;
}

.upload-grid {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(320px, 520px) minmax(520px, 1fr);
}

.report-list {
  min-width: 0;
}

.access-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(420px, 1fr) 380px;
}

.status {
  color: var(--muted);
  min-height: 22px;
}

.status.error {
  color: var(--red);
}

.status.ok {
  color: var(--green);
}

@media (max-width: 1180px) {
  .kpi-grid,
  .dashboard-grid,
  .access-grid,
  .upload-grid,
  .regional-layout {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .tabs {
    align-items: stretch;
    flex-direction: column;
  }

  .login,
  .session-info,
  .kpi-grid,
  .dashboard-grid,
  .access-grid,
  .upload-grid,
  .regional-layout,
  .region-map {
    grid-template-columns: 1fr;
  }

  main {
    padding: 10px;
  }

  .visual-card.is-wide,
  .visual-card.is-narrow {
    grid-column: span 1;
    width: 100%;
  }
}
