/* ==========================================================================
   GEED GIS Carbon Tool
   Light theme only. Brand accent is reserved for chrome; data encoding uses
   the validated sequential, diverging and categorical ramps.
   ========================================================================== */

:root {
  --accent:        #ED7C30;
  --bg-header:     #ffffff;
  --text-main:     #1a1a1a;
  --text-nav:      #2c2c2c;
  --header-height: 89px;

  /* Chart chrome and ink */
  --surface-1:     #ffffff;
  --surface-2:     #f9f9f7;
  --surface-3:     #f3f3f0;
  --ink-primary:   #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted:     #898781;
  --gridline:      #e1e0d9;
  --baseline:      #c3c2b7;
  --hairline:      rgba(11, 11, 11, 0.10);

  /* Categorical slots, validated adjacent-pair order */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Sequential blue, light to dark, for the five Jenks classes.
     Re-stepped for legibility over a map rather than over a white chart
     surface: the original light end sat at 1.36:1 against the basemap, well
     under the 2:1 floor, which is why low-class buildings disappeared. These
     five steps clear every ordinal check against the muted basemap: monotone
     lightness, adjacent delta-L at or above 0.06, light end at 2.22:1, one hue. */
  --seq-1: #6da7ec;
  --seq-2: #3987e5;
  --seq-3: #256abf;
  --seq-4: #184f95;
  --seq-5: #0d366b;

  /* Diverging blue to red for Getis-Ord hot and cold spots */
  --div-cold-3: #104281;
  --div-cold-2: #3987e5;
  --div-cold-1: #9ec5f4;
  --div-mid:    #f0efec;
  --div-hot-1:  #f6bcbb;
  --div-hot-2:  #e34948;
  --div-hot-3:  #9e2020;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --sidebar-w: 400px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-size: 16px;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--surface-1);
  color: var(--text-main);
  overflow: hidden;
}

/* ---------- Header (GEED shared standard, fixed) ---------- */

.header-row {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  width: 100%;
}

.header-logo-left img {
  width: 180px;
  height: 70px;
  object-fit: contain;
  display: block;
}

.header-title-block {
  flex: 1;
  text-align: center;
  padding: 0 1rem;
}

.header-title-block h1 {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.header-title-block p {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-secondary);
  margin-top: 0.15rem;
}

.header-spacer { width: 180px; flex-shrink: 0; }

/* ---------- Layout ---------- */

.app {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0; bottom: 0;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--gridline);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--gridline);
  background: var(--surface-2);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 0.7rem 0.3rem;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tab:hover { background: rgba(237, 124, 48, 0.07); color: var(--text-main); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--surface-1); }

.panels { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.panel { display: none; padding: 1rem 1.15rem 2.5rem; }
.panel.active { display: block; }

/* ---------- Sections ---------- */

.section { margin-bottom: 1.4rem; }

.section h2 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  margin-bottom: 0.6rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--gridline);
}

.section h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0.9rem 0 0.45rem;
}

.hint {
  font-size: 0.73rem;
  line-height: 1.5;
  color: var(--ink-secondary);
  margin-bottom: 0.7rem;
}
.hint.small { font-size: 0.68rem; color: var(--ink-muted); }

/* ---------- Controls ---------- */

.btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.6rem 1rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
  width: 100%;
}
.btn:hover:not(:disabled) { filter: brightness(0.93); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.secondary { background: transparent; color: var(--accent); }
.btn.secondary:hover:not(:disabled) { background: rgba(237, 124, 48, 0.09); }

.btn.ghost {
  background: transparent;
  color: var(--ink-secondary);
  border-color: var(--baseline);
}
.btn.ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text-main); }

.btn-row { display: flex; gap: 0.5rem; }
.btn-row .btn { width: auto; flex: 1; }

.field { margin-bottom: 0.75rem; }
.field label {
  display: block;
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--ink-secondary);
  margin-bottom: 0.28rem;
}
.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%;
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.48rem 0.6rem;
  border: 1px solid var(--baseline);
  border-radius: 4px;
  background: var(--surface-1);
  color: var(--text-main);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(237, 124, 48, 0.16);
}
.field .unit { font-size: 0.68rem; color: var(--ink-muted); margin-top: 0.2rem; display: block; }

.field-row { display: flex; gap: 0.6rem; }
.field-row .field { flex: 1; }

/* ---------- Stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 0.65rem 0.7rem;
}
.tile.wide { grid-column: 1 / -1; }

.tile .label {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.tile .value {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink-primary);
  line-height: 1.15;
}
.tile.wide .value { font-size: 1.8rem; }
.tile .value .suffix {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-secondary);
  margin-left: 0.2rem;
}
.tile .sub {
  font-size: 0.67rem;
  color: var(--ink-secondary);
  margin-top: 0.25rem;
  line-height: 1.35;
}

/* ---------- Bar breakdown rows ---------- */

.bars { margin-bottom: 0.5rem; }

.bar-row { margin-bottom: 0.5rem; }

.bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}
.bar-name {
  font-size: 0.75rem;
  color: var(--ink-primary);
  display: flex;
  align-items: center;
  gap: 0.38rem;
  min-width: 0;
}
.bar-name .swatch {
  width: 9px; height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}
.bar-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-value {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.bar-track {
  height: 7px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.25s ease;
}

/* ---------- Data table ---------- */

table.dt {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
table.dt th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.dt td {
  padding: 0.38rem 0.4rem;
  border-bottom: 1px solid var(--surface-3);
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
}
table.dt td.num, table.dt th.num { text-align: right; }
table.dt tr:last-child td { border-bottom: none; }

/* ---------- Legend ---------- */

.legend {
  position: absolute;
  bottom: 1.5rem;
  right: 1rem;
  z-index: 10;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 0.65rem 0.75rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
  max-width: 230px;
}
.legend h4 {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 0.4rem;
  line-height: 1.3;
}
.legend .item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.68rem;
  color: var(--ink-secondary);
  margin-bottom: 0.22rem;
  font-variant-numeric: tabular-nums;
}
.legend .item i {
  width: 14px; height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  flex-shrink: 0;
}

/* ---------- Map overlays ---------- */

.map-toolbar {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 10;
  display: flex;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.96);
  padding: 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
}
.map-toolbar button {
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
}
.map-toolbar button:hover { background: var(--surface-3); color: var(--text-main); }
.map-toolbar button.active { background: var(--accent); color: #ffffff; }

.map-status {
  position: absolute;
  top: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 0.5rem 0.9rem;
  font-size: 0.76rem;
  color: var(--ink-primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  display: none;
  max-width: 70%;
}
.map-status.show { display: block; }
.map-status.error { border-left-color: var(--status-critical); }

.progress {
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  margin-top: 0.45rem;
  overflow: hidden;
}
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.25s; }

/* ---------- Tooltip ---------- */

.map-tip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 0.5rem 0.65rem;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-primary);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.13);
  display: none;
  max-width: 260px;
}
.map-tip.show { display: block; }
.map-tip b { font-weight: 600; }
.map-tip .k { color: var(--ink-muted); }

/* ---------- Badges and provenance ---------- */

.badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 500;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.badge.osm     { background: #e3f1e3; color: #0a5c0a; }
.badge.derived { background: #e2edfa; color: #17457e; }
.badge.rule    { background: #fdefe0; color: #8a4a11; }
.badge.default { background: #f0efec; color: #56544f; }

.conf-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 0.3rem;
}
.conf-bar i { display: block; height: 100%; border-radius: 3px; }

.kv {
  display: grid;
  grid-template-columns: 46% 54%;
  gap: 0.1rem 0.5rem;
  font-size: 0.73rem;
  margin-bottom: 0.8rem;
}
.kv dt { color: var(--ink-muted); padding: 0.2rem 0; }
.kv dd { color: var(--ink-primary); padding: 0.2rem 0; font-variant-numeric: tabular-nums; }

.callout {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  padding: 0.6rem 0.75rem;
  font-size: 0.71rem;
  line-height: 1.55;
  color: var(--ink-secondary);
  margin-bottom: 0.9rem;
}
.callout.warn { border-left-color: var(--status-warning); }
.callout.note { border-left-color: var(--series-1); }
.callout b { color: var(--ink-primary); font-weight: 600; }

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--ink-muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

/* ---------- Histogram ---------- */

.histo { display: flex; align-items: flex-end; gap: 1px; height: 68px; margin: 0.4rem 0 0.2rem; }
.histo i {
  flex: 1;
  background: var(--seq-3);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
}
.histo-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.63rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Scrollbar ---------- */

.panels::-webkit-scrollbar { width: 9px; }
.panels::-webkit-scrollbar-track { background: var(--surface-2); }
.panels::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 5px; }
.panels::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
  :root { --sidebar-w: 340px; }
  .header-logo-left img { width: 130px; height: 52px; }
  .header-spacer { width: 130px; }
}

@media (max-width: 768px) {
  html, body { overflow: auto; }
  .header-row { height: auto; padding: 0.7rem 1rem; }
  .header-title-block h1 { font-size: 1rem; }
  .header-spacer { display: none; }
  .app { position: static; display: block; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--gridline); }
  .panels { max-height: none; overflow: visible; }
  .map-wrap { position: relative; height: 62vh; }
}

/* ---------- Checkbox rows ---------- */

.field label.check {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ink-primary);
  cursor: pointer;
  margin-bottom: 0.3rem;
}
.field label.check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin-top: 0.08rem;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

/* ---------- Second map toolbar ---------- */

.map-toolbar-right {
  left: auto;
  right: 0.85rem;
}
