:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #627068;
  --surface: #f7f8f5;
  --panel: #ffffff;
  --line: #dce2dc;
  --high: #16794a;
  --medium: #d69e16;
  --low: #c4473d;
  --insufficient: #7a8490;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--surface);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  z-index: 500;
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
  padding: 28px 24px 20px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow,
.detail-kicker {
  margin: 0 0 7px;
  color: var(--high);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.13em;
}

h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 690;
  letter-spacing: -0.045em;
}

.intro {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-item {
  position: relative;
  padding: 12px 7px 10px;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  text-align: center;
  cursor: pointer;
}

.summary-item + .summary-item {
  border-left: 1px solid var(--line);
}

.summary-item::before {
  position: absolute;
  top: 0;
  right: 12px;
  left: 12px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  content: "";
}

.summary-item.high::before {
  background: var(--high);
}

.summary-item.medium::before {
  background: var(--medium);
}

.summary-item.low::before {
  background: var(--low);
}

.summary-item.insufficient::before {
  background: var(--insufficient);
}

.summary-item span {
  display: block;
  font-size: 1.05rem;
  font-weight: 720;
}

.summary-item small {
  color: var(--muted);
  font-size: 0.64rem;
}

.summary-item:hover,
.summary-item:focus-visible {
  background: #f2f5f1;
  outline: none;
}

.summary-item.active {
  background: #edf3ee;
}

.controls {
  display: grid;
  gap: 8px;
}

.controls > label,
.controls legend {
  color: #46534b;
  font-size: 0.72rem;
  font-weight: 720;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.basemap-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 8px;
}

.score-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

.basemap-switch button,
.score-mode-switch button,
.filter-actions button {
  padding: 8px 7px;
  border: 1px solid #cbd4cc;
  color: #46534b;
  background: #fff;
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

.basemap-switch button:first-child,
.score-mode-switch button:first-child,
.filter-actions button:first-child {
  border-radius: 6px 0 0 6px;
}

.basemap-switch button:last-child,
.score-mode-switch button:last-child,
.filter-actions button:last-child {
  border-radius: 0 6px 6px 0;
}

.basemap-switch button + button,
.score-mode-switch button + button,
.filter-actions button + button {
  border-left: 0;
}

.basemap-switch button.active,
.score-mode-switch button.active {
  color: #fff;
  border-color: var(--high);
  background: var(--high);
}

.basemap-switch button:hover:not(.active),
.score-mode-switch button:hover:not(.active),
.filter-actions button:hover {
  background: #f2f5f1;
}

.control-note {
  margin: -1px 0 7px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.35;
}

select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cbd4cc;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

fieldset {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 12px;
  margin: 10px 0 0;
  padding: 12px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

fieldset legend {
  padding: 0 0 7px;
}

fieldset label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.83rem;
}

.filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}

.plant-controls {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.plant-controls > label:not(.radius-toggle) {
  color: #46534b;
  font-size: 0.72rem;
  font-weight: 720;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.plant-controls > label:not(:first-child, .radius-toggle) {
  margin-top: 5px;
}

.plant-controls .radius-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 3px;
  font-size: 0.83rem;
}

.plant-controls p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--high);
}

.field-detail {
  padding-top: 17px;
  border-top: 1px solid var(--line);
}

.field-detail h2 {
  margin: 0 0 7px;
  font-size: 1.18rem;
}

.field-detail > p:not(.detail-kicker) {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.score-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 15px;
}

.score-line strong {
  font-size: 2rem;
  line-height: 1;
}

.band-pill {
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.06em;
}

.band-pill.high {
  background: var(--high);
}

.band-pill.medium {
  color: #372b05;
  background: var(--medium);
}

.band-pill.low {
  background: var(--low);
}

.band-pill.insufficient {
  background: var(--insufficient);
}

.metric-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  margin: 0;
  font-size: 0.78rem;
}

.metric-list dt {
  color: var(--muted);
}

.metric-list dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 640;
  text-align: right;
}

.component-breakdown {
  margin-top: 17px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.component-breakdown h3 {
  margin: 0 0 8px;
  font-size: 0.73rem;
  text-transform: uppercase;
}

.component-breakdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.69rem;
  font-variant-numeric: tabular-nums;
}

.component-breakdown th,
.component-breakdown td {
  padding: 6px 3px;
  border-bottom: 1px solid #e5e9e5;
  text-align: right;
  white-space: nowrap;
}

.component-breakdown th:first-child {
  padding-left: 0;
  text-align: left;
  white-space: normal;
}

.component-breakdown td:last-child {
  padding-right: 0;
}

.component-breakdown thead th {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.component-breakdown tbody th {
  color: #38453d;
  font-weight: 650;
}

.component-breakdown tr.missing {
  color: var(--muted);
}

.breakdown-total {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  margin: 10px 0 0;
  font-size: 0.72rem;
}

.breakdown-total dt {
  color: var(--muted);
}

.breakdown-total dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

.component-breakdown p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.component-breakdown p.pseudo-warning {
  margin-top: 10px;
  padding: 8px 9px;
  border-left: 3px solid var(--medium);
  color: #5b4a13;
  background: #fff9e6;
  font-size: 0.69rem;
  line-height: 1.4;
}

.pseudo-scenario-range {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 11px 0 0;
  font-size: 0.72rem;
}

.pseudo-scenario-range dt {
  color: var(--muted);
}

.pseudo-scenario-range dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 680;
  text-align: right;
}

.reason-block {
  margin-top: 15px;
}

.reason-block h3 {
  margin: 0 0 6px;
  font-size: 0.73rem;
  text-transform: uppercase;
}

.reason-block ul {
  margin: 0;
  padding-left: 17px;
  color: #46534b;
  font-size: 0.76rem;
  line-height: 1.4;
}

.plant-list {
  margin: 8px 0 0;
  padding-left: 17px;
  color: #46534b;
  font-size: 0.76rem;
  line-height: 1.4;
}

footer {
  margin-top: auto;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.map-wrap,
#map {
  width: 100%;
  height: 100%;
}

.map-wrap {
  position: relative;
  min-width: 0;
}

.map-note {
  position: absolute;
  z-index: 450;
  right: 12px;
  bottom: 12px;
  max-width: 260px;
  padding: 7px 10px;
  border: 1px solid rgba(23, 33, 27, 0.16);
  border-radius: 5px;
  color: #46534b;
  background: rgba(255, 255, 255, 0.92);
  font-size: 0.68rem;
}

.leaflet-container {
  background: #e9ede9;
}

.leaflet-control-attribution {
  font-size: 9px;
}

.field-score-popup .leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.field-score-popup .leaflet-popup-content {
  margin: 15px 17px;
  max-height: min(70vh, 620px);
  overflow-y: auto;
  padding-right: 4px;
}

.field-popup-card {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.popup-kicker {
  margin: 0 0 6px;
  color: var(--high);
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.1em;
}

.popup-score-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.popup-score-line strong {
  font-size: 1.75rem;
  line-height: 1;
}

.popup-location {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.field-popup-card .component-breakdown {
  margin-top: 12px;
  padding-top: 11px;
}

.ethanol-plant-marker {
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: #285276;
  box-shadow: 0 1px 4px rgba(23, 33, 27, 0.48);
}

.leaflet-tooltip.field-tooltip {
  padding: 5px 7px;
  border: 0;
  border-radius: 4px;
  color: #fff;
  background: #17211b;
  font-size: 0.72rem;
}

.leaflet-tooltip.field-tooltip::before {
  border-top-color: #17211b;
}

.leaflet-tooltip.plant-tooltip {
  padding: 5px 7px;
  border: 0;
  border-radius: 4px;
  color: #fff;
  background: #285276;
  font-size: 0.72rem;
}

.leaflet-tooltip.plant-tooltip::before {
  border-top-color: #285276;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    overflow: visible;
    padding: 20px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .field-detail {
    display: none;
  }

  .map-wrap {
    min-height: 62vh;
  }
}

.h3-legend {
  position: absolute;
  z-index: 450;
  left: 12px;
  bottom: 36px;
  width: 248px;
  padding: 9px 11px;
  border: 1px solid rgba(23, 33, 27, 0.18);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 2px 8px rgba(23, 33, 27, 0.12);
  font-size: 0.69rem;
}

.h3-legend.hidden {
  display: none;
}

.h3-legend-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}

.h3-legend-head strong {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
}

.h3-legend-head span {
  color: var(--muted);
  font-size: 0.64rem;
}

.h3-gradient-bar {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    #c4473d 0%,
    #d96b27 25%,
    #d69e16 50%,
    #3b9c5e 78%,
    #16794a 100%
  );
  border: 1px solid rgba(23, 33, 27, 0.14);
}

.h3-gradient-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 600;
}

.h3-zoom-btn {
  margin-top: 12px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--high);
  border-radius: 5px;
  background: var(--high);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 650;
  cursor: pointer;
}

.h3-zoom-btn:hover {
  background: #12633c;
}
