:root {
  --bg: #ececec;
  --panel: #ffffff;
  --panel-alt: #f6f6f6;
  --border: #d6d6d6;
  --text: #2b2b2b;
  --muted: #6b6b6b;
  --accent: #0b6fb1;
  --warn-bg: #fff4d6;
  --warn-border: #e0b84c;
  --select: #dc18d9;
  --gap: 6px;
  font-family: "Avenir Next", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 38px; width: auto; }
.brand h1 { font-size: 1.25rem; font-weight: 600; margin: 0; white-space: nowrap; }
.demo-pill {
  font-size: .72rem; font-weight: 700; letter-spacing: .08em; color: #7a5400;
  background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 4px; padding: 2px 7px;
}
.selectors { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.sel { display: flex; flex-direction: column; gap: 2px; font-size: .75rem; color: var(--muted); border: 0; padding: 0; margin: 0; }
.sel legend { padding: 0; margin-bottom: 2px; }
.sel select, .sel input {
  font: inherit; font-size: .85rem; color: var(--text); padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 3px; background: #fff; min-width: 9rem;
}
.sel.range { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
.sel.range legend { width: 100%; }
.sel.range input { min-width: 0; width: 5.2rem; }
.btn {
  font: inherit; font-size: .85rem; padding: 5px 12px; border-radius: 3px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: #fff; color: var(--accent); }
.btn-small { padding: 2px 8px; font-size: .78rem; }

.disclaimer {
  background: var(--warn-bg); border-bottom: 1px solid var(--warn-border);
  padding: 6px 14px; font-size: .85rem; line-height: 1.35;
}

/* ---------- layout ---------- */
.layout {
  flex: 1; display: grid; grid-template-columns: 55fr 45fr; gap: var(--gap);
  padding: var(--gap); min-height: 0;
}
.col-left, .col-right { display: flex; flex-direction: column; gap: var(--gap); min-height: 0; min-width: 0; }

.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); }
.tile, .ind {
  background: var(--panel); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 8px 6px; min-height: 84px;
}
.tile .cap, .ind .cap { font-size: .85rem; font-weight: 600; }
.tile .val { font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.tile .sub, .ind .unit { font-size: .75rem; color: var(--muted); }
.tile-demo { background: var(--warn-bg); border-color: var(--warn-border); }
.demo-badge { font-size: .8rem; font-weight: 700; color: #7a5400; line-height: 1.25; text-transform: uppercase; letter-spacing: .04em; }

.map-wrap { position: relative; flex: 1; min-height: 420px; border: 1px solid var(--border); background: var(--panel); }
arcgis-map { position: absolute; inset: 0; }
.map-overlay {
  /* top of the map, right of the zoom/home buttons, clear of the legend/layers buttons */
  position: absolute; left: 60px; top: 15px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px;
  max-width: calc(100% - 130px); pointer-events: none;
}
.map-overlay > * { pointer-events: auto; }
.search { display: flex; gap: 4px; }
.search input {
  font: inherit; font-size: .85rem; padding: 5px 8px; width: 19rem; max-width: 60vw;
  border: 1px solid var(--border); border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.theme {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px; background: #fff;
  border: 1px solid var(--border); border-radius: 4px; padding: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.2);
  font-size: .8rem;
}
.theme-label { color: var(--muted); padding: 0 6px; }
.theme .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.theme button {
  font: inherit; border: 1px solid transparent; background: transparent; padding: 3px 8px;
  border-radius: 3px; cursor: pointer; color: var(--text);
}
.theme button.on { background: var(--accent); color: #fff; }
.selection-chip {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 2px solid var(--select); border-radius: 4px; padding: 4px 8px;
  display: flex; align-items: center; gap: 10px; font-size: .85rem; box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.selection-chip[hidden] { display: none; }
.map-reset {
  position: absolute; right: 12px; bottom: 26px; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.loading {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.85);
  font-weight: 600; z-index: 5;
}
.loading.done { display: none; }

/* ---------- right column ---------- */
.indicators { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.ind .val { font-size: 2.2rem; font-weight: 700; line-height: 1.15; }
.ind:nth-child(odd) { background: var(--panel); }
.tabs { flex: 1; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); min-height: 320px; }
.tab-bar { display: flex; border-bottom: 1px solid var(--border); }
.tab-bar button {
  font: inherit; font-size: .9rem; padding: 8px 14px; border: 0; background: transparent; cursor: pointer;
  border-bottom: 3px solid transparent; color: var(--muted);
}
.tab-bar button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px; }
.tab-panel[hidden] { display: none; }
.chart { flex: 1; min-height: 260px; position: relative; overflow: hidden; }
.chart svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart .bar:hover { opacity: .85; }
.table-meta { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.table-scroll { flex: 1; overflow: auto; min-height: 0; max-height: 62vh; }
table { border-collapse: collapse; width: 100%; font-size: .8rem; }
th, td { border: 1px solid var(--border); padding: 4px 6px; white-space: nowrap; }
th { position: sticky; top: 0; background: #f0f0f0; text-align: left; cursor: pointer; user-select: none; border-bottom: 3px solid #bdbdbd; }
th.num, td.num { text-align: right; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: .7em; }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: .7em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #eef5fb; }
tbody tr.row-selected { background: #fbe3fb; }

/* ---------- popup bits ---------- */
.pp-note { font-size: .78rem; font-style: italic; color: #7a5400; background: var(--warn-bg); padding: 4px 6px; border-radius: 3px; }
.pp-chart h4 { margin: 0 0 2px; font-size: .9rem; }
.pp-chart .desc { font-size: .75rem; color: var(--muted); margin-bottom: 6px; }
.pp-bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; border-bottom: 1px solid #999; padding-top: 14px; }
.pp-bar { flex: 1; position: relative; min-width: 14px; }
.pp-bar span { position: absolute; top: -14px; left: 0; right: 0; text-align: center; font-size: .68rem; }
.pp-labels { display: flex; gap: 6px; font-size: .66rem; color: var(--muted); margin-top: 2px; }
.pp-labels div { flex: 1; text-align: center; }
.pp-link a { font-weight: 700; }

/* ---------- dialog ---------- */
dialog { max-width: 620px; border: 1px solid var(--border); border-radius: 6px; padding: 18px 22px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
dialog .small { font-size: .8rem; color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile-demo { grid-column: span 2; min-height: 44px; }
  .map-wrap { min-height: 60vh; flex: none; height: 60vh; }
  .map-overlay { left: 60px; top: 15px; max-width: calc(100% - 120px); }
  .search input { width: 100%; }
}
@media (max-width: 600px) {
  .app-header { padding: 8px 10px; }
  .brand h1 { font-size: 1rem; }
  .selectors { width: 100%; }
  .sel select { min-width: 0; width: 100%; }
  .sel { flex: 1 1 45%; }
  .ind .val { font-size: 1.6rem; }
}
