:root {
  color-scheme: light;
  --bg: #f3f5f1;
  --panel: #ffffff;
  --soft: #f8faf6;
  --ink: #1e2828;
  --muted: #637071;
  --line: #d8ded7;
  --accent: #1e776a;
  --accent-dark: #15584f;
  --blue: #336d9d;
  --gold: #b06a24;
  --red: #984238;
  --purple: #6863a4;
  --shadow: 0 12px 28px rgba(30, 40, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

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

button {
  border: 1px solid var(--accent-dark);
  border-radius: 7px;
  background: var(--accent-dark);
  color: #ffffff;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.5rem;
}

h2 {
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}

h3 {
  margin: 1rem 0 0.35rem;
  font-size: 0.94rem;
}

p {
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin-bottom: 0.2rem;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 0.45rem;
  min-width: 430px;
}

.top-stats div {
  padding: 0.58rem 0.64rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.top-stats span {
  display: block;
  color: var(--accent-dark);
  font-size: 1.28rem;
  font-weight: 800;
}

small {
  color: var(--muted);
}

.dashboard {
  display: grid;
  grid-template-columns: 330px minmax(500px, 1fr) 430px;
  grid-template-areas:
    "controls map detail"
    "controls ranking detail";
  gap: 1rem;
  padding: 1rem;
}

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

.controls-panel {
  grid-area: controls;
  padding: 1rem;
}

.map-section {
  grid-area: map;
  display: grid;
  grid-template-rows: auto minmax(440px, 56vh) auto;
  gap: 0.7rem;
}

.detail-panel {
  grid-area: detail;
  padding: 1rem;
}

.ranking-panel {
  grid-area: ranking;
  min-height: 330px;
}

.panel-heading {
  margin-bottom: 0.85rem;
}

.panel-heading p,
.map-toolbar p,
.ranking-heading p,
.detail-header p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.field-label,
.range-label {
  display: grid;
  gap: 0.34rem;
  margin-bottom: 0.72rem;
  color: var(--ink);
  font-weight: 700;
}

.field-label span,
.range-label {
  font-size: 0.9rem;
}

select,
input[type="search"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.5rem 0.58rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42rem;
  margin-bottom: 0.9rem;
}

.preset-button,
.secondary-button,
.tab-button {
  padding: 0.45rem 0.55rem;
  border-color: var(--line);
  background: var(--soft);
  color: var(--ink);
}

.preset-button.active,
.tab-button.active {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  color: #ffffff;
}

.weights {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.weight-row {
  margin-bottom: 0.62rem;
}

.weight-row header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.12rem;
  font-size: 0.86rem;
}

.filter-section {
  padding-top: 0.85rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  margin: 0.2rem 0 0.72rem;
  font-weight: 700;
}

.map-toolbar,
.ranking-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.82rem 0.95rem;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
}

.map-actions button,
.ranking-heading button,
.note-actions button {
  padding: 0.48rem 0.62rem;
}

.map-wrap {
  position: relative;
  min-height: 440px;
  overflow: hidden;
}

arcgis-map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 440px;
}

.map-error {
  position: absolute;
  inset: 1rem;
  display: grid;
  place-items: center;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--red);
  text-align: center;
}

.map-error[hidden] {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.preferred {
  background: var(--accent);
}

.well-above {
  background: #167a4e;
}

.above {
  background: var(--accent);
}

.near {
  background: var(--gold);
}

.below {
  background: var(--red);
}

.good {
  background: var(--blue);
}

.review {
  background: var(--gold);
}

.wildcard {
  background: var(--red);
}

.baseline {
  background: #555b65;
}

.selected {
  border: 2px solid var(--purple);
  background: transparent;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.85rem;
}

.big-score {
  min-width: 72px;
  color: var(--accent-dark);
  font-size: 2rem;
  text-align: right;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.metric-grid div,
.fact-list div {
  padding: 0.62rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.metric-grid span,
.fact-list span {
  display: block;
  margin-bottom: 0.16rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-grid strong,
.fact-list strong {
  display: block;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  padding-bottom: 0.55rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.tab-panel {
  display: none;
}

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

.score-bars {
  display: grid;
  gap: 0.42rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 138px minmax(90px, 1fr) 42px;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ede7;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

.fact-list {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.muted {
  color: var(--muted);
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.table-wrap {
  max-height: 380px;
  overflow: auto;
  padding: 0 0.85rem 0.85rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 0.52rem 0.55rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td:nth-child(1),
td:nth-child(3),
td:nth-child(4),
td:nth-child(7),
td:nth-child(8),
td:nth-child(9) {
  text-align: right;
}

tr {
  cursor: pointer;
}

tr.active {
  background: rgba(30, 119, 106, 0.08);
}

tr.baseline-row {
  background: rgba(85, 91, 101, 0.08);
}

tr.baseline-row.active {
  background: rgba(104, 99, 164, 0.13);
}

.pill {
  display: inline-block;
  max-width: 150px;
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.pill.good {
  background: var(--blue);
}

.pill.preferred {
  background: var(--accent);
}

.pill.review {
  background: var(--gold);
}

.pill.wildcard {
  background: var(--red);
}

.pill.baseline {
  background: #555b65;
}

.type-pill {
  display: inline-block;
  max-width: 150px;
  padding: 0.16rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.delta-pill {
  display: inline-block;
  min-width: 58px;
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.delta-pill.well-above {
  background: #167a4e;
}

.delta-pill.above {
  background: var(--accent);
}

.delta-pill.near {
  background: var(--gold);
}

.delta-pill.below {
  background: var(--red);
}

.delta-pill.baseline {
  background: #555b65;
}

@media (max-width: 1270px) {
  .dashboard {
    grid-template-columns: 320px minmax(430px, 1fr);
    grid-template-areas:
      "controls map"
      "controls ranking"
      "detail detail";
  }
}

@media (max-width: 880px) {
  .topbar,
  .map-toolbar,
  .ranking-heading,
  .detail-header {
    flex-direction: column;
  }

  .top-stats,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .dashboard {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "map"
      "ranking"
      "detail";
  }

  .map-section {
    grid-template-rows: auto 430px auto;
  }
}

@media (max-width: 540px) {
  .topbar,
  .dashboard {
    padding: 0.75rem;
  }

  .top-stats,
  .metric-grid,
  .button-grid {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 116px minmax(70px, 1fr) 36px;
  }
}
