/* ==================================================================
   RENAC DataViewer 2026 — Design tokens & Styles
   Based on ICBDSR DataViewer editorial design system
   ================================================================== */
:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --ring: rgba(11, 11, 11, .06);
  --ring-strong: rgba(11, 11, 11, .38);
  --s1: #2a78d6; /* Centro - Blue */
  --s2: #eb6834; /* Cuyo - Orange */
  --s3: #1baf7a; /* NEA - Green */
  --s4: #eda100; /* NOA - Gold */
  --s5: #e87ba4;
  --s6: #7656c9; /* Patagonia - Purple */
  --s7: #00a6a6;
  --s8: #a66b34;
  --s9: #65758b;
  --s10: #c44747;
  --accent: #2a78d6;
  --good: #0ca30c;
  --warn: #fab219;
  --land: #eceae4;
  --land-line: #fcfcfb;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --ring: rgba(255, 255, 255, .06);
  --ring-strong: rgba(255, 255, 255, .42);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #9a82e6;
  --s7: #25b9b9;
  --s8: #c58a4c;
  --s9: #91a0b5;
  --s10: #e56a6a;
  --accent: #3987e5;
  --good: #0ca30c;
  --warn: #fab219;
  --land: #262624;
  --land-line: #1a1a19;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--plane);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ---------- Header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--plane);
  border-bottom: 1px solid var(--border);
}

.hdr {
  max-width: 1560px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.brand img {
  height: 38px;
  width: auto;
  border-radius: 6px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand h1 {
  font-size: 16.5px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.demomark {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .06em;
  line-height: 1.25;
}

.brand .sub {
  font-size: 12px;
  color: var(--muted);
}

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

.headerperiod {
  display: flex;
  align-items: center;
  gap: 7px;
}

.headerperiod .periodlabel {
  font-size: 10.5px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .045em;
}

.periodpick {
  position: relative;
  display: inline-block;
}

.periodpick summary {
  list-style: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
}

.periodpick summary::-webkit-details-marker { display: none; }

.periodpick summary:after {
  content: "▾";
  font-size: 10px;
  color: var(--muted);
}

.periodmenu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px;
  min-width: 250px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.periodmenu button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.periodmenu button:hover {
  background: var(--surface-2);
}

.periodmenu button.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.periodmenu .custom-row {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  border-top: 1px solid var(--grid);
  margin-top: 4px;
}

.periodmenu .custom-row select {
  padding: 4px 6px;
  font-size: 12px;
  min-width: 70px;
}

.iconbtn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 11px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
}

.iconbtn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* ---------- Tabs Navigation ---------- */
nav.tabs {
  display: flex;
  gap: 2px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px;
}

nav.tabs button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--muted);
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .15s, border-bottom-color .15s;
}

nav.tabs button:hover {
  color: var(--ink);
}

nav.tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 650;
}

/* ---------- Views visibility ---------- */
section.view-tab {
  display: block;
}

section.view-tab.hidden {
  display: none;
}

/* ---------- Controls Bar ---------- */
.controls {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin: 18px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .045em;
}

select, input[type="search"], input[type="text"] {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 7px 11px;
  min-width: 160px;
}

select:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--axis);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  border: 0;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 12.5px;
  padding: 7px 12px;
  cursor: pointer;
  border-right: 1px solid var(--axis);
  transition: background .15s, color .15s;
}

.seg button:last-child {
  border-right: 0;
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card > .card-hd {
  padding: 14px 18px 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.card-hd h2 {
  font-size: 15px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -.005em;
}

.card-hd .note {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

.card-bd {
  padding: 14px 18px 18px;
}

.lede {
  color: var(--ink-2);
  font-size: 13px;
  margin: 0 0 12px;
  line-height: 1.55;
  max-width: 900px;
}

/* ---------- Stat Tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  box-shadow: var(--shadow);
}

.tile .k {
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .045em;
}

.tile .v {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -.02em;
  margin-top: 3px;
  line-height: 1.15;
}

.tile .u {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Split Layout ---------- */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 880px) {
  .split { grid-template-columns: 1fr; }
}

.psplit {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 900px) {
  .psplit { grid-template-columns: 1fr; }
}

/* ---------- Map ---------- */
.mapbox {
  position: relative;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

svg.map {
  display: block;
  width: 100%;
  aspect-ratio: 440 / 920;
  height: auto;
  min-height: 520px;
  cursor: default;
}

.map .prov-path {
  fill: var(--land);
  stroke: var(--surface);
  stroke-width: 0.8;
  cursor: pointer;
  transition: fill .15s, stroke .15s, stroke-width .15s;
}

.map .prov-path:hover {
  stroke: var(--ink);
  stroke-width: 1.5;
  filter: brightness(0.95);
}

.map .prov-path.selected {
  stroke: var(--accent);
  stroke-width: 2.2;
}

.mapctl {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mapctl button {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  padding: 0;
}

.mapctl button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  width: 100%;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  justify-content: space-between;
}

.legend .scale-bar {
  display: flex;
  height: 10px;
  width: 180px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.legend .scale-step {
  flex: 1;
}

.legend .lbl {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Charts ---------- */
svg.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .axis {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .rowlabel {
  fill: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
}

.chart .rowlabel:hover {
  fill: var(--ink);
  font-weight: 600;
}

.chart .group-label {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.chart .group-band {
  fill: var(--surface-2);
}

.chart .vallabel {
  fill: var(--ink-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .ci {
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: .65;
}

.chart .ref {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chart .reflbl {
  fill: var(--muted);
  font-size: 11px;
}

.chart .row-bg {
  fill: transparent;
  transition: fill .1s;
}

.chart .row-bg.hover {
  fill: var(--surface-2);
}

.chart .row-bg.selected {
  fill: color-mix(in srgb, var(--accent) 15%, transparent);
}

/* ---------- Legends & Chips ---------- */
.klegend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 6px 0 14px;
}

.klegend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
}

.klegend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ---------- Tables ---------- */
.tablewrap {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 14px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data th {
  text-align: left;
  font-weight: 650;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--axis);
  position: sticky;
  top: 0;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

table.data th.num, table.data td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.data td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--grid);
  color: var(--ink-2);
}

table.data tbody tr {
  cursor: pointer;
}

table.data tr:hover td {
  background: var(--surface-2);
}

table.data tr.selrow td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

table.data tr.region-row td {
  position: sticky;
  top: 33px;
  z-index: 1;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .035em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.ci-bar-mini {
  display: inline-block;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .7;
  vertical-align: middle;
}

/* ---------- Ask The Data View ---------- */
.ask-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 860px;
  margin: 0 auto 24px;
}

.ask-input-row {
  display: flex;
  gap: 8px;
}

.ask-input-row input {
  flex: 1;
  font-size: 15px;
  padding: 10px 14px;
  border-radius: 10px;
}

.ask-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  font-weight: 650;
  font-size: 13.5px;
  padding: 0 18px;
  border-radius: 10px;
  cursor: pointer;
}

.ask-btn:hover {
  filter: brightness(1.1);
}

.suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sugg-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}

.sugg-chip:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

.ask-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-width: 860px;
  margin: 0 auto;
}

.ask-result .res-head {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.ask-result .res-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
}

.ask-stat-big {
  font-size: 38px;
  font-weight: 750;
  letter-spacing: -.03em;
  color: var(--accent);
  line-height: 1.1;
  margin: 8px 0;
}

.ask-explanation {
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.5;
  margin: 12px 0 16px;
}

/* ---------- Tooltip ---------- */
#tip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--ink);
  color: var(--plane);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  display: none;
  max-width: 260px;
}

#tip .t {
  font-weight: 650;
  font-size: 13px;
  margin-bottom: 4px;
}

#tip .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: var(--axis);
}

#tip .row span:last-child {
  color: var(--plane);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
