:root {
  color-scheme: light;
  font-family: "Roboto", Arial, sans-serif;
  color: #1d2935;
  background: #eef2f5;
  --brand: #1979cd;
  --brand-dark: #0c568f;
  --surface: #ffffff;
  --surface-muted: #f5f7f9;
  --border: #d6dde3;
  --border-strong: #aeb9c3;
  --text-muted: #60717f;
  --danger: #c53a32;
  --warning: #d98616;
  --purple: #7a4dc2;
  --bridge: #287bb5;
  --broken-bridge: #d12f72;
  --selected: #00a8b8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

.app-header {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  color: #ffffff;
  background: #163246;
  border-bottom: 3px solid var(--brand);
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-family: "Outfit", sans-serif;
  font-weight: 600;
  background: var(--brand);
  border-radius: 4px;
}

.app-title {
  min-width: 190px;
}

.app-title h1,
.inspector h2 {
  margin: 0;
  font-family: "Outfit", sans-serif;
  font-weight: 600;
  letter-spacing: 0;
}

.app-title h1 {
  font-size: 18px;
  line-height: 22px;
}

.app-title span {
  display: block;
  margin-top: 2px;
  color: #c7d3dc;
  font-size: 11px;
}

.header-metrics {
  display: flex;
  align-self: stretch;
  margin-left: auto;
}

.header-metrics div {
  min-width: 116px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 16px;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.header-metrics strong {
  font-size: 16px;
}

.header-metrics span {
  margin-top: 2px;
  color: #c7d3dc;
  font-size: 10px;
  text-transform: uppercase;
}

.status-pill {
  min-width: 90px;
  padding: 6px 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #d9f0ff;
  border: 1px solid #5782a0;
  border-radius: 4px;
}

.status-pill.error {
  color: #ffe1de;
  border-color: #d3766f;
}

.workspace {
  height: calc(100% - 64px);
  display: grid;
  grid-template-columns: minmax(430px, 42%) minmax(360px, 1fr) 310px;
  background: var(--border);
  gap: 1px;
}

.table-pane,
.map-pane,
.inspector {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.table-pane {
  grid-column: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.map-pane {
  grid-column: 2;
}

.inspector {
  grid-column: 3;
}

.workspace.table-hidden {
  grid-template-columns: minmax(360px, 1fr) 310px;
}

.workspace.table-hidden .table-pane,
.workspace.inspector-hidden .inspector {
  display: none;
}

.workspace.table-hidden .map-pane {
  grid-column: 1;
}

.workspace.table-hidden .inspector {
  grid-column: 2;
}

.workspace.inspector-hidden {
  grid-template-columns: minmax(430px, 42%) minmax(360px, 1fr);
}

.workspace.inspector-hidden .map-pane {
  grid-column: 2;
}

.workspace.table-hidden.inspector-hidden {
  grid-template-columns: minmax(360px, 1fr);
}

.workspace.table-hidden.inspector-hidden .map-pane {
  grid-column: 1;
}

.dataset-toolbar,
.filter-toolbar,
.table-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.dataset-toolbar label,
.eyebrow {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.dataset-toolbar select {
  min-width: 0;
  flex: 1;
  font-weight: 500;
}

select,
input {
  height: 32px;
  min-width: 0;
  padding: 0 9px;
  color: #263744;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  outline: none;
}

select:focus,
input:focus,
button:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(25, 121, 205, 0.18);
}

.search-field {
  min-width: 150px;
  flex: 1;
  position: relative;
}

.search-field svg {
  width: 15px;
  height: 15px;
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 9px;
  color: var(--text-muted);
}

.search-field input {
  width: 100%;
  padding-left: 30px;
}

#filter-column {
  width: 118px;
}

#filter-operator {
  width: 92px;
}

#filter-value {
  width: 100px;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  color: #405461;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  color: var(--brand-dark);
  background: #edf6fd;
  border-color: var(--brand);
}

.icon-button:disabled {
  color: #aab5bd;
  background: var(--surface-muted);
  cursor: default;
}

.icon-button svg {
  width: 16px;
  height: 16px;
}

.data-table {
  min-height: 0;
}

.table-footer {
  min-height: 48px;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  border-bottom: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 5px;
}

#page-label {
  min-width: 90px;
  text-align: center;
}

.map-pane {
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #e7ecef;
}

.map-layer-panel,
.map-state {
  position: absolute;
  z-index: 500;
  padding: 8px 10px;
  color: #30424f;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(20, 42, 56, 0.12);
}

.map-layer-panel {
  top: 12px;
  right: 12px;
  width: 250px;
  max-height: calc(100% - 72px);
  overflow-y: auto;
  display: grid;
  gap: 3px;
  font-size: 11px;
}

.map-layer-panel strong {
  padding: 1px 3px 5px;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
}

.map-layer-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 3px;
  cursor: pointer;
  flex: 1;
}

.map-layer-row {
  display: flex;
  align-items: center;
  min-width: 0;
}

.map-layer-row:hover {
  background: var(--surface-muted);
}

.map-layer-panel input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--brand);
}

.map-layer-panel label > span:nth-of-type(2) {
  flex: 1;
}

.map-layer-panel svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.layer-download {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  color: var(--brand-dark);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.layer-download:hover:not(:disabled) {
  color: #ffffff;
  background: var(--brand);
}

.layer-download:disabled {
  color: #aeb9c3;
  cursor: default;
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 3px solid;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-area {
  width: 16px;
  height: 11px;
  border: 2px solid;
}

.legend-line.orphaned {
  border-color: #6f42c1;
}

.legend-line.normal-no-fim {
  border-color: #d12a92;
}

.legend-line.normal-non-lake-no-fim {
  border-color: #008da8;
  border-top-style: dashed;
}

.legend-line.lake-hydro {
  border-color: #1d6fb8;
}

.legend-line.out-of-state {
  border-color: #7d8790;
  border-top-style: dashed;
}

.legend-line.broken-rating {
  border-color: #3f7f4c;
}

.legend-area.broken-fim {
  border-color: #e36d24;
  background: rgba(227, 109, 36, 0.28);
}

.legend-dot.bridge {
  background: var(--bridge);
}

.legend-dot.broken-bridge {
  background: var(--broken-bridge);
  transform: rotate(45deg);
  border-radius: 1px;
}

.legend-dot.on-lake-bridge {
  background: #f0b429;
  border: 1px solid #7b5a00;
}

.map-state {
  top: 12px;
  left: 52px;
  font-size: 11px;
}

.panel-controls {
  position: absolute;
  z-index: 500;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}

.panel-controls .icon-button {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 2px 8px rgba(20, 42, 56, 0.12);
}

.inspector {
  overflow: auto;
  padding-bottom: 16px;
}

.inspector header {
  min-height: 70px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 15px;
  border-bottom: 1px solid var(--border);
}

.inspector h2 {
  margin-top: 4px;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.spatial-state {
  margin: 12px 15px;
  padding: 8px 10px;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-left: 3px solid var(--border-strong);
  font-size: 11px;
}

.spatial-state.available {
  color: #27623b;
  border-left-color: #3d9b5e;
}

.inspector dl {
  display: grid;
  grid-template-columns: minmax(90px, 42%) minmax(0, 1fr);
  margin: 0;
  padding: 0 15px;
  font-size: 12px;
}

.inspector dt,
.inspector dd {
  margin: 0;
  padding: 8px 4px;
  border-bottom: 1px solid #e8ecef;
  overflow-wrap: anywhere;
}

.inspector dt {
  color: var(--text-muted);
  font-weight: 500;
}

.inspector dd {
  color: #20323f;
}

.loading-overlay {
  position: fixed;
  z-index: 2000;
  inset: 64px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #324956;
  background: rgba(245, 248, 250, 0.92);
  font-size: 13px;
}

.loading-overlay.hidden {
  display: none;
}

.loading-indicator {
  width: 24px;
  height: 24px;
  border: 3px solid #bed0de;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.cluster-marker {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #ffffff;
  background: #4d6170;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(20, 35, 45, 0.35);
  font-size: 10px;
  font-weight: 700;
}

.cluster-marker.bridge {
  background: var(--bridge);
}

.cluster-marker.broken-bridge {
  background: var(--broken-bridge);
}

.cluster-marker.on-lake-bridge {
  color: #3b2b00;
  background: #f0b429;
  border-color: #ffffff;
}

.point-marker {
  width: 11px;
  height: 11px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(20, 35, 45, 0.4);
}

.point-marker.bridge {
  background: var(--bridge);
}

.point-marker.broken-bridge {
  background: var(--broken-bridge);
  border-radius: 1px;
  transform: rotate(45deg);
}

.point-marker.on-lake-bridge {
  background: #f0b429;
  border-color: #5c4300;
}

.tabulator {
  height: 100%;
  border: 0;
  font-family: "Roboto", sans-serif;
  font-size: 11px;
}

.tabulator .tabulator-header {
  color: #314653;
  background: #edf1f4;
  border-bottom: 1px solid var(--border-strong);
}

.tabulator .tabulator-tableholder {
  background: var(--surface);
}

.tabulator .tabulator-header .tabulator-col,
.tabulator-row .tabulator-cell {
  border-right-color: #e1e6ea;
}

.tabulator-row.tabulator-selectable:hover,
.tabulator-row.tabulator-selected {
  background: #e2f1fb;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(410px, 44%) minmax(340px, 1fr);
    grid-template-rows: minmax(0, 1fr) 240px;
  }

  .inspector {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .workspace.table-hidden {
    grid-template-columns: minmax(340px, 1fr);
    grid-template-rows: minmax(0, 1fr) 240px;
  }

  .workspace.table-hidden .inspector {
    grid-column: 1;
  }

  .workspace.inspector-hidden {
    grid-template-columns: minmax(410px, 44%) minmax(340px, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .workspace.table-hidden.inspector-hidden {
    grid-template-columns: minmax(340px, 1fr);
  }

  .inspector header {
    grid-column: 1;
  }

  .spatial-state {
    grid-column: 1;
  }

  .inspector dl {
    grid-column: 2;
    grid-row: 1 / span 2;
    overflow: auto;
  }
}

@media (max-width: 760px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-header {
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .header-metrics {
    width: 100%;
    order: 3;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }

  .header-metrics div {
    min-width: 0;
    flex: 1;
    padding: 8px 6px 0;
  }

  .workspace {
    width: 100vw;
    max-width: 100vw;
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 600px 480px auto;
  }

  .workspace.table-hidden {
    grid-template-rows: 480px auto;
  }

  .workspace.inspector-hidden {
    grid-template-columns: 1fr;
    grid-template-rows: 600px 480px;
  }

  .workspace.table-hidden.inspector-hidden {
    grid-template-rows: 480px;
  }

  .table-pane,
  .map-pane,
  .inspector {
    width: 100%;
    max-width: 100vw;
    grid-column: 1;
  }

  .dataset-toolbar,
  .filter-toolbar,
  .table-footer {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  .dataset-toolbar select {
    width: 0;
  }

  .workspace.table-hidden .map-pane,
  .workspace.table-hidden .inspector,
  .workspace.inspector-hidden .map-pane {
    grid-column: 1;
  }

  .filter-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 32px;
  }

  .search-field {
    width: 100%;
    min-width: 0;
    grid-column: 1 / -1;
  }

  #filter-column,
  #filter-operator,
  #filter-value {
    flex: 1;
    width: auto;
  }

  .table-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
  }

  .map-layer-panel {
    width: min(250px, calc(100% - 24px));
  }

  .map-state {
    max-width: calc(100% - 116px);
  }

  #page-label {
    flex: 1;
  }

  .inspector {
    display: block;
  }

  .inspector dl {
    max-height: none;
  }

  .loading-overlay {
    inset: 0;
  }
}
