:root {
  --ink: #1c201d;
  --muted: #6b716b;
  --paper: #f5f1e8;
  --panel: #fffdf6;
  --line: #d8d0c2;
  --coal: #202522;
  --moss: #56745b;
  --sea: #2f6f73;
  --amber: #b7812d;
  --oxide: #a34835;
  --blueprint: #334f72;
  --shadow: 0 18px 42px rgba(32, 37, 34, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Aptos, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(32, 37, 34, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(32, 37, 34, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  background: var(--coal);
  color: #f7f2e8;
  border: 1px solid #0f1210;
  box-shadow: var(--shadow);
}

.topbar h1,
.panel h2,
.filter-panel h2,
.runbox h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.status-pill,
.soft-label {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #f7f2e8;
  font-size: 12px;
}

.status-pill.ready {
  border-color: rgba(121, 179, 128, 0.65);
  color: #b9e2bd;
}

.status-pill.error {
  border-color: rgba(217, 96, 73, 0.8);
  color: #ffb5a8;
}

.tool-button,
.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #f9f5ec;
  color: var(--ink);
  padding: 0 12px;
}

.topbar .tool-button {
  border-color: rgba(255, 255, 255, 0.28);
  background: transparent;
  color: #f7f2e8;
}

.tool-button:hover,
.tab:hover {
  border-color: var(--coal);
}

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

.kpi {
  min-height: 86px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(32, 37, 34, 0.06);
}

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

.kpi .value {
  margin-top: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.filter-panel,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.filter-panel {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.filter-heading,
.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.filter-heading span,
.soft-label {
  border-color: var(--line);
  color: var(--muted);
  background: #f7f2e8;
}

.compact-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: #f7f2e8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.compact-select select {
  min-height: 24px;
  border: 1px solid var(--line);
  background: #fffaf1;
  color: var(--ink);
}

.filter-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-panel select,
.filter-panel input[type="number"],
.filter-panel input[type="search"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fffaf1;
  color: var(--ink);
  padding: 0 9px;
}

.inline-checks {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f7f2e8;
  border: 1px solid var(--line);
}

.inline-checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 600;
}

.advanced-filters {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f7f2e8;
}

.advanced-filters summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.advanced-filters[open] summary {
  margin-bottom: 10px;
}

.advanced-filters .inline-checks {
  background: #fffaf1;
}

.advanced-filters label + label,
.advanced-filters label + .inline-checks {
  margin-top: 10px;
}

.runbox {
  padding: 12px;
  border: 1px dashed #a99f8d;
  background: #f9f5ec;
}

.runbox h3 {
  font-size: 16px;
}

.runbox code {
  display: block;
  margin-top: 8px;
  color: var(--blueprint);
  word-break: break-word;
}

.run-button {
  width: 100%;
  margin-top: 10px;
  background: var(--coal);
  color: #f7f2e8;
  border-color: var(--coal);
}

.run-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.refresh-status {
  display: block;
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.refresh-status.busy {
  color: var(--blueprint);
  font-weight: 800;
}

.refresh-status.ready {
  color: var(--moss);
  font-weight: 800;
}

.refresh-status.error {
  color: var(--oxide);
  font-weight: 800;
}

.main-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.main-panel > *,
.map-and-focus > *,
.tab-section > * {
  min-width: 0;
  max-width: 100%;
}

.map-and-focus {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.7fr);
  gap: 14px;
  align-items: stretch;
  min-width: 0;
  max-width: 100%;
}

.panel {
  padding: 14px;
  min-width: 0;
}

.map-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.map-panel .panel-title {
  padding: 14px 14px 0;
}

.map-surface {
  position: relative;
  flex: 1 1 auto;
  isolation: isolate;
  contain: layout paint;
  width: 100%;
  min-height: 640px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid #bfb6a7;
  background: #dfe6df;
}

.fallback-map {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(47, 111, 115, 0.12), rgba(183, 129, 45, 0.08)),
    #e8eadf;
}

.map-dot {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(32, 37, 34, 0.55);
  background: var(--sea);
  transform: translate(-50%, -50%);
}

.map-dot.hot {
  background: var(--oxide);
}

.detail-body {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(135px, 1fr));
  gap: 10px;
}

.detail-metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f9f5ec;
}

.detail-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.detail-metric strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.risk-note {
  margin-top: 12px;
  padding: 10px;
  border-left: 4px solid var(--oxide);
  background: #fbebe6;
  color: #6d2e24;
}

.risk-note.neutral {
  border-left-color: var(--blueprint);
  background: #eef2f4;
  color: #293f58;
}

.score-explainer {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f7f2e8;
  color: var(--ink);
}

.score-explainer h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.score-explainer p {
  margin: 0 0 10px;
  color: var(--muted);
}

.score-part-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(90px, 1fr));
  gap: 8px;
}

.score-part {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  background: #fffaf1;
}

.score-part span,
.score-part em {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.score-part strong {
  display: block;
  margin: 3px 0;
  font-size: 17px;
}

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

.tab.active {
  background: var(--coal);
  color: #f7f2e8;
  border-color: var(--coal);
}

.tab-section {
  display: none;
}

.tab-section.active {
  display: block;
}

.split-panels {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
}

.drilldown-panel {
  margin-top: 14px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
}

.table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.table-pager button {
  min-height: 30px;
  border: 1px solid var(--line);
  background: #f9f5ec;
  color: var(--ink);
  padding: 0 10px;
}

.table-pager button:disabled {
  cursor: default;
  opacity: 0.45;
}

.table-pager strong {
  color: var(--ink);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  background: #fffdf6;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid #e7dfd1;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--coal);
  color: #f7f2e8;
  font-size: 12px;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  width: 100%;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  font-weight: 800;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f2eadb;
}

.score-pill {
  display: inline-flex;
  min-width: 42px;
  justify-content: center;
  padding: 3px 7px;
  background: #e9f0e5;
  color: #254a2d;
  border: 1px solid #b8d1ba;
  font-weight: 800;
}

.score-pill.low {
  background: #f4eee1;
  color: #6d5a31;
  border-color: #d9c694;
}

.score-pill.reject {
  background: #f8e2dc;
  color: #7a2f20;
  border-color: #dda99b;
}

.auction-link {
  color: var(--blueprint);
  font-weight: 800;
  text-decoration: none;
  border-bottom: 1px solid rgba(51, 79, 114, 0.35);
}

.auction-link:hover {
  border-bottom-color: var(--blueprint);
}

.bar-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.bar-row {
  display: grid;
  gap: 5px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 12px;
  background: #ebe2d3;
  border: 1px solid #d8d0c2;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--moss), var(--amber));
}

.methodology-body {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.method-card {
  padding: 12px;
  border: 1px solid var(--line);
  background: #f9f5ec;
}

.method-card h3 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 14px;
}

.method-card p,
.method-card ul {
  margin: 6px 0 0;
}

.method-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
}

.audit-drawer {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #f5efe4;
}

.audit-drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.audit-drawer[open] summary {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

/* Local critical Leaflet layout rules. Keep the map stable even if CDN CSS is blocked. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  font: inherit;
  background: #dfe6df;
  outline-offset: 1px;
  touch-action: none;
}

.leaflet-container img,
.leaflet-container svg {
  max-width: none !important;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  border: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-map-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-control-container .leaflet-top.leaflet-left {
  margin: 10px;
}

.leaflet-control-zoom {
  border: 1px solid var(--line);
  background: #fffdf6;
  box-shadow: 0 6px 16px rgba(32, 37, 34, 0.12);
}

.leaflet-control-zoom a {
  display: block;
  width: 30px;
  height: 30px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  line-height: 30px;
  text-align: center;
  text-decoration: none;
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.leaflet-control-attribution {
  margin: 0;
  padding: 3px 7px;
  background: rgba(255, 253, 246, 0.88);
  color: var(--muted);
  font-size: 11px;
}

.leaflet-control-attribution a {
  color: var(--blueprint);
}

.leaflet-popup {
  position: absolute;
  margin-bottom: 20px;
  text-align: left;
}

.leaflet-popup-content-wrapper {
  padding: 10px;
  border: 1px solid var(--line);
  background: #fffdf6;
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 0;
}

.leaflet-popup-tip-container {
  position: absolute;
  left: 50%;
  width: 24px;
  height: 12px;
  margin-left: -12px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 12px;
  height: 12px;
  margin: -7px auto 0;
  border: 1px solid var(--line);
  background: #fffdf6;
  transform: rotate(45deg);
}

.map-popup {
  min-width: 220px;
}

.map-popup strong {
  display: block;
  margin-bottom: 4px;
}

.map-popup button {
  margin-top: 8px;
  min-height: 28px;
  border: 1px solid var(--line);
  background: #fffaf1;
}

@media (max-width: 1380px) {
  .map-and-focus {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: repeat(3, minmax(135px, 1fr));
  }

  .score-part-grid {
    grid-template-columns: repeat(3, minmax(90px, 1fr));
  }
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .workspace,
  .map-and-focus,
  .split-panels {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: repeat(3, minmax(135px, 1fr));
  }

  .filter-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .map-surface {
    min-height: 360px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .score-part-grid {
    grid-template-columns: 1fr;
  }
}
