/* ESG regional sales map — internal instrument.
   Neutral gray chrome on white panels; the choropleth is the only color. */

:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #d9dde2;
  --line-soft: #eceff2;
  --ink: #191d22;
  --ink-2: #5f6771;
  --blue-deep: #12406e;   /* ESG brand blue: selection, focus, active */
  --blue-bar: #2f6ca3;    /* inline bars */
  --warn-bg: #faf4df;
  --warn-line: #d8c37a;
  --warn-ink: #6b5710;
}

* { box-sizing: border-box; }

/* author display rules (e.g. .empty's flex) must never beat the hidden attr */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

/* nothing should ever push the page sideways — if a cell cannot fit it
   truncates, it does not drag the whole layout off screen */
body { overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 "Segoe UI", system-ui, -apple-system, Sylfaen,
        "Noto Sans Georgian", Arial, sans-serif;
}

button, input, select {
  font: inherit;
  color: inherit;
}

/* ---- top bar ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 14px;
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-mark {
  width: 24px;
  height: 24px;
  background: var(--blue-deep);
  display: inline-block;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: .04em; }
.brand-sub { font-size: 11px; color: var(--ink-2); }

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.f-date {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .05em;
}

input[type="date"], select {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  padding: 3px 6px;
  font-size: 12.5px;
}

/* category names run long; without a cap the select alone ate 400px and
   pushed the whole bar onto a third row */
.filters select { max-width: 172px; }

.presets { display: inline-flex; }

.presets button {
  border: 1px solid var(--line);
  border-left-width: 0;
  background: var(--panel);
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.presets button:first-child { border-left-width: 1px; border-radius: 2px 0 0 2px; }
.presets button:last-child { border-radius: 0 2px 2px 0; }
.presets button:hover { background: var(--panel-2); }

.presets button.active {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
  color: #fff;
}

/* ---- unmapped-cities chip + popover ------------------------------------- */

.chip {
  margin-left: auto;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 2px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

/* coverage is good — state it neutrally rather than as a warning */
.chip.chip-good {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--ink-2);
}

.pop {
  position: absolute;
  right: 14px;
  top: 46px;
  z-index: 30;
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px rgba(20, 30, 40, .14);
  font-size: 12.5px;
}

.pop-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-weight: 600;
}

.pop-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.pop-row span { color: var(--ink-2); white-space: nowrap; }

.pop-note {
  padding: 8px 12px;
  color: var(--ink-2);
  font-size: 11.5px;
}

/* ---- KPI strip ---------------------------------------------------------- */

/* A wrapping grid rather than one rigid row — eight metrics never fit on a
   laptop, and forcing them to made the sub-lines collide. */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(174px, 1fr));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.kpi {
  padding: 8px 14px 9px;
  border-right: 1px solid var(--line-soft);
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;             /* lets the cell shrink instead of overflowing */
  min-height: 56px;
}

.kpi:nth-child(-n + 4) { border-top: 0; }

.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* the headline number carries more weight than the rest */
.kpi.kpi-hero { background: var(--panel-2); }
.kpi.kpi-hero .kpi-value { font-size: 22px; }

/* full text is always available via the cell's title tooltip, so clipping
   here loses nothing and keeps every cell the same height */
.kpi-sub {
  font-size: 10.5px;
  color: var(--ink-2);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.delta.up { color: var(--blue-deep); }
.delta.down { color: #a3502b; }
.muted { color: var(--ink-2); }

/* the resolved period belongs beside the date controls, not as a stray
   ninth cell in the metric grid */
.kpi-range {
  margin-left: 10px;
  color: var(--ink-2);
  font-size: 11.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- layout ------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 384px;
  gap: 10px;
  padding: 10px;
  align-items: start;
  min-width: 0;
}

.map-panel, .side > * { background: var(--panel); border: 1px solid var(--line); }

.panel-head {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-soft);
  padding: 7px 12px;
}

.panel-head-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 5px;
  padding-bottom: 5px;
}

/* Right-rail view switcher. Five Georgian labels never fit on one line in a
   350px rail, so these wrap instead of being sliced off the page edge. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  text-transform: none;
  letter-spacing: normal;
  width: 100%;
}

.tabs button {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink);
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.tabs button:hover { background: var(--panel-2); }

.tabs button.active {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
  color: #fff;
}

.owner-clear {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: #eef3f8;
  color: var(--blue-deep);
  padding: 6px 12px;
  font-size: 11.5px;
  cursor: pointer;
}

.owner-clear:hover { background: #e3ecf5; }

.rank-empty { padding: 14px 12px; color: var(--ink-2); font-size: 12px; }

/* transaction feed */
.feed-day {
  padding: 5px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-2);
  position: sticky;
  top: 0;
}

.feed-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) max-content;
  gap: 1px 8px;
  padding: 5px 12px 6px;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
}

.feed-time { color: var(--ink-2); font-size: 11px; grid-row: 1 / -1; padding-top: 1px; }
.feed-name { font-size: 12.5px; overflow-wrap: anywhere; }
.feed-gel { text-align: right; font-weight: 600; white-space: nowrap; }
.feed-prod {
  grid-column: 2 / -1;
  font-size: 11px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sortbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 10.5px;
  color: var(--ink-2);
}

.sortbar button {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink);
  padding: 2px 7px;
  font-size: 10.5px;
  cursor: pointer;
}

.sortbar button:hover { background: var(--panel-2); }
.sortbar button.active {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
  color: #fff;
}

/* ---- explanations -------------------------------------------------------- */

.mode-help {
  border-top: 1px solid var(--line-soft);
  padding: 7px 12px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-2);
  background: var(--panel-2);
}

.mode-help b { color: var(--ink); font-weight: 650; }

.tab-help {
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
}

/* data age — quiet when current, amber once it is worth noticing */
.freshness {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  cursor: help;
}

/* brief confirmation that new data just landed */
.freshness.just-updated {
  color: var(--blue-deep);
  font-weight: 600;
}

@media (prefers-reduced-motion: no-preference) {
  .freshness { transition: color .3s; }
}

.freshness.stale {
  color: var(--warn-ink);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 2px;
  padding: 2px 7px;
}

/* the chip no longer needs to claim the free space */
.chip { margin-left: 8px; }

.help-toggle {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  margin-left: 8px;
  flex: none;
}

.help-toggle:hover { background: var(--blue-deep); border-color: var(--blue-deep); color: #fff; }

.help-panel {
  position: absolute;
  right: 14px;
  top: 46px;
  z-index: 40;
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(20, 30, 40, .18);
  padding: 6px 20px 20px;
}

.help-panel h2 { font-size: 15px; margin: 12px 0 4px; }
.help-panel h3 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
  margin: 18px 0 6px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 4px;
}
.help-panel p { font-size: 12px; line-height: 1.6; margin: 0 0 9px; color: var(--ink-2); }
.help-panel p b { color: var(--ink); font-weight: 650; }

.help-close {
  position: sticky;
  top: 0;
  float: right;
  border: 0;
  background: var(--panel);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
}

/* stale receivables — a call list, so it reads as rows of names not buttons */
.stale-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.stale-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 1px 10px;
  padding: 6px 12px 7px;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
}

.stale-gel { text-align: right; font-weight: 600; white-space: nowrap; color: #a3502b; }
.stale-meta {
  font-size: 11px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.stale-days { font-size: 11px; color: var(--ink-2); text-align: right; white-space: nowrap; }

.risk { color: #a3502b; }

/* key accounts / concentration */
.conc-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.conc-head b { color: var(--ink); font-weight: 650; }

.cust-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) max-content;
  gap: 1px 8px;
  padding: 6px 12px 7px;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
}

.cust-rank { grid-row: 1 / -1; color: var(--ink-2); font-size: 11px; padding-top: 2px; }

/* the secondary line spans the full width instead of sitting in a column,
   which is what was squeezing the name into one-word-per-line wrapping */
.cust-sub {
  grid-column: 2 / -1;
  font-size: 11px;
  color: var(--ink-2);
  line-height: 1.45;
}

/* Customer names are the point of these lists — a truncated name cannot be
   phoned. Let them wrap onto a second line rather than clipping. */
.cust-row .rk-name-text,
.stale-row .rk-name-text {
  font-size: 12.5px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.3;
}
.cust-gel { text-align: right; font-weight: 600; white-space: nowrap; }
.cust-meta {
  font-size: 11px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cust-cum { font-size: 11px; color: var(--ink-2); text-align: right; white-space: nowrap; }

.fading-row .cust-rank {
  color: #a3502b;
  font-weight: 650;
  font-size: 10.5px;
}

/* map metric switcher — same wrapping treatment as the tabs */
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  text-transform: none;
  letter-spacing: normal;
}

.modes button {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink);
  padding: 3px 9px;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
}

.modes button:hover { background: var(--panel-2); }

.modes button.active {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
  color: #fff;
}

/* ---- map ---------------------------------------------------------------- */

.map-wrap { position: relative; padding: 4px; }

#map { display: block; width: 100%; height: auto; }

.region {
  stroke: #fff;
  stroke-width: 1;
  cursor: pointer;
  transition: fill .12s;
  outline: none;
}

.region.hl { stroke: var(--blue-deep); stroke-width: 1.6; }

.region.pinned,
.region:focus-visible { stroke: var(--blue-deep); stroke-width: 2.2; }

.region.no-data { cursor: default; }

.tb-hit { fill: transparent; cursor: pointer; }

/* our focus style is the stroke on .region — kill the UA focus rectangle
   for everything inside the map svg */
#map :focus { outline: none; }

.tb-leader {
  stroke: var(--ink-2);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  fill: none;
}

.tb-label {
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink);
  cursor: pointer;
}

.tb-callout.hl .tb-label,
.tb-callout.pinned .tb-label { fill: var(--blue-deep); text-decoration: underline; }

/* ---- legend ------------------------------------------------------------- */

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line-soft);
  padding: 7px 12px;
  font-size: 11px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.lg-title {
  text-transform: uppercase;
  letter-spacing: .07em;
  font-size: 10.5px;
}

.lg-item { display: inline-flex; align-items: center; gap: 5px; }

.lg-note { color: var(--ink-2); font-style: normal; margin-left: auto; }

.lg-swatch {
  width: 16px;
  height: 11px;
  display: inline-block;
  border: 1px solid rgba(20, 30, 40, .18);
}

.lg-hatch {
  background: repeating-linear-gradient(45deg,
    #eef0f2 0 3px, #c1c8cf 3px 4.5px);
}

/* ---- tooltip + region detail -------------------------------------------- */

.tooltip {
  position: absolute;
  z-index: 20;
  width: 268px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px rgba(20, 30, 40, .14);
  padding: 10px 12px;
  pointer-events: none;
  font-size: 12px;
}

.dt-name { font-weight: 700; font-size: 13.5px; }

.dt-nodata { color: var(--ink-2); margin-top: 3px; }

/* names the metric the big number belongs to, so it can never be mistaken
   for revenue when the map is coloured by something else */
.dt-metric-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--blue-deep);
  margin-top: 4px;
}

.dt-amount {
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin: 1px 0 3px;
}

.dt-factsbox {
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 7px;
}

.dt-facts {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.dt-facts b { color: var(--ink); font-weight: 600; }

.spark { display: block; width: 100%; height: 34px; }

.spark-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ink-2);
  margin-top: 1px;
}

.dt-debtor {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}

.dt-debtor-gel { color: #a3502b; font-weight: 600; white-space: nowrap; }

.dt-top-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-2);
  margin: 8px 0 4px;
}

.dt-prod {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 10px;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.dt-prod-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dt-prod-gel { color: var(--ink-2); white-space: nowrap; }

.dt-prod-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--line-soft);
}

.dt-prod-bar i { display: block; height: 100%; background: var(--blue-bar); }

/* ---- empty state --------------------------------------------------------- */

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  background: rgba(255, 255, 255, .82);
  font-size: 14.5px;
  color: var(--ink);
  z-index: 10;
}

/* ---- right rail ---------------------------------------------------------- */

.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.side .panel-head { border-top: 0; }

.side > .panel-head,
.side > .ranking { border: 1px solid var(--line); }

.side > .panel-head { border-bottom: 0; }

.ranking { background: var(--panel); }

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  grid-template-areas: "name gel" "bar share";
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  padding: 6px 12px 7px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.rank-row:last-child { border-bottom: 0; }
.rank-row:hover, .rank-row.hl { background: #eef3f8; }
.rank-row.pinned { box-shadow: inset 3px 0 0 var(--blue-deep); }

.rank-row:focus-visible {
  outline: 2px solid var(--blue-deep);
  outline-offset: -2px;
}

.rk-name {
  grid-area: name;
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.rk-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rk-gel { grid-area: gel; font-weight: 600; text-align: right; white-space: nowrap; }

.rk-bar { grid-area: bar; height: 5px; background: var(--line-soft); }
.rk-bar i { display: block; height: 100%; background: var(--blue-bar); }
.rk-bar i.neg { background: #a3502b; }

.rk-badge { font-size: 10.5px; white-space: nowrap; }
.rk-badge.up { color: var(--blue-deep); }
.rk-badge.down { color: #a3502b; }

.rk-share { grid-area: share; color: var(--ink-2); text-align: right; font-size: 11.5px; }

.pinned-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--blue-deep);
  padding: 10px 12px;
  font-size: 12px;
}

.pin-close {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 0;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
}

.pin-close:hover { color: var(--ink); }

/* ---- misc ---------------------------------------------------------------- */

.load-error {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-line);
  color: var(--warn-ink);
  padding: 10px 14px;
}

button:focus-visible, input:focus-visible, select:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--blue-deep);
  outline-offset: 1px;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .kpis { flex-wrap: wrap; }
  .kpi { min-width: 120px; }
  .kpi-range { width: 100%; padding: 4px 14px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .region { transition: none; }
}
