:root {
  --bg: #e8ece7;
  --panel: #f8faf8;
  --panel-strong: #ffffff;
  --ink: #1c2c2a;
  --muted: #60706c;
  --line: #c8d2cc;
  --canal: #1f6f9a;
  --canal-dark: #155170;
  --lateral: #4b9cba;
  --field: #5d8b59;
  --field-soft: rgba(93, 139, 89, 0.28);
  --earth: #967248;
  --hazard: #b64f3c;
  --warning: #c9852b;
  --slate: #2f4545;
  --deep: #152625;
  --shadow: 0 16px 34px rgba(37, 52, 48, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(21, 38, 37, 0.08), transparent 220px),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 16px;
  background:
    linear-gradient(135deg, #142524 0%, #213333 54%, #18435a 100%);
  color: #f5faf7;
  border-bottom: 1px solid #132322;
  box-shadow: 0 10px 30px rgba(21, 38, 37, 0.22);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 340px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  border: 1px solid rgba(69, 198, 214, 0.52);
  background: rgba(69, 198, 214, 0.12);
  color: #bff5f2;
  font-weight: 900;
  font-size: 13px;
}

h1 {
  font-size: 20px;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand-block p {
  margin-top: 2px;
  color: #c4d2cf;
  font-size: 12px;
}

.top-tools {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(132px, 170px) auto auto auto;
  align-items: end;
  gap: 9px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-tools label {
  color: #cbdad5;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
}

.top-tools input,
.top-tools select {
  border-color: #4d6360;
  background: #172727;
  color: #fff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--canal);
  box-shadow: 0 0 0 3px rgba(31, 111, 154, 0.16);
}

.lookup-row,
.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.top-tools button,
.stacked-form button,
.inline-control button,
.inspector-actions button {
  min-height: 36px;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--canal);
  color: #fff;
  font-weight: 850;
}

.design-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: end;
  padding: 0 12px;
  border: 1px solid rgba(196, 210, 207, 0.35);
  border-radius: 6px;
  color: #f5faf7;
  text-decoration: none;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.design-link:hover {
  border-color: #45c6d6;
  color: #bff5f2;
}

.top-tools button:hover,
.stacked-form button:hover,
.inline-control button:hover,
.inspector-actions button:hover {
  background: var(--canal-dark);
}

.session-pill,
.feature-type,
.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 0 9px;
  background: #e0e8e3;
  color: #263f3d;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.top-tools .session-pill {
  align-self: end;
  min-height: 36px;
  background: #2d4644;
  color: #d8e8e3;
}

.mode-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 14px;
  background: #d9e3de;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  min-width: 92px;
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: #344845;
  font-weight: 850;
}

.tab.is-active {
  background: var(--panel-strong);
  color: var(--canal-dark);
  box-shadow: inset 0 0 0 1px var(--line);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 210px minmax(480px, 1fr) minmax(340px, 430px);
  gap: 10px;
  padding: 10px;
}

.ops-summary {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1.35fr repeat(3, minmax(170px, 1fr));
  gap: 10px;
}

.ops-summary article {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(238, 246, 242, 0.92)),
    var(--panel-strong);
  box-shadow: 0 12px 28px rgba(37, 52, 48, 0.1);
}

.ops-summary span {
  color: var(--canal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ops-summary strong {
  color: var(--deep);
  font-size: clamp(20px, 2.4vw, 28px);
  line-height: 1;
}

.ops-summary strong b {
  font: inherit;
}

.ops-summary p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.layer-rail,
.map-pane,
.inspector-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.layer-rail {
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 9px;
}

.rail-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.rail-heading span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.layer-toggle {
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #354743;
  text-transform: none;
  font-size: 13px;
}

.layer-toggle:hover {
  border-color: var(--line);
  background: #fff;
}

.layer-toggle input {
  width: 15px;
  min-height: 15px;
}

.swatch {
  width: 18px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.swatch.field {
  background: var(--field-soft);
  border-color: var(--field);
}

.swatch.canal {
  background: var(--canal);
}

.swatch.gate {
  background: var(--earth);
}

.swatch.flow {
  background: #fff;
  border-color: var(--canal);
  position: relative;
}

.swatch.flow::after {
  content: ">";
  position: absolute;
  left: 5px;
  top: -5px;
  color: var(--canal);
  font-weight: 900;
}

.swatch.issue {
  background: var(--hazard);
}

.swatch.basemap {
  background: #d7d1c2;
}

.map-pane {
  display: grid;
  grid-template-rows: auto minmax(460px, 1fr) auto;
}

.map-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  background:
    linear-gradient(90deg, #ffffff, #f1f7f4);
  border-bottom: 1px solid var(--line);
}

.map-status strong {
  display: block;
  font-size: 15px;
}

.map-status span,
.flow-strip,
.notice {
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.line-sample {
  width: 24px;
  height: 0;
  border-top: 4px solid var(--canal);
}

.line-sample.lateral {
  border-top-width: 3px;
  border-top-style: dashed;
  border-top-color: var(--lateral);
}

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

.dot.gate {
  background: var(--earth);
}

.dot.issue {
  background: var(--hazard);
}

.map-canvas {
  width: 100%;
  min-height: 460px;
  background: #cdd8cf;
}

.map-fallback {
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: var(--slate);
}

.flow-strip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #eef6f2;
  font-weight: 750;
}

.inspector-panel {
  overflow-y: auto;
}

.inspector-card,
.tool-panel {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.inspector-card {
  background: linear-gradient(180deg, #ffffff, #f7fbf9);
}

.tool-panel {
  display: none;
}

.tool-panel.is-active {
  display: block;
}

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

.eyebrow {
  color: var(--canal-dark);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

h2 {
  margin-top: 2px;
  font-size: 19px;
}

h3 {
  font-size: 14px;
}

.feature-details {
  display: grid;
  gap: 8px;
  margin: 0;
}

.feature-details div {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
}

.feature-details dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.feature-details dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 12px;
}

.notice {
  padding: 10px;
  border: 1px solid #d3dad4;
  border-left: 4px solid var(--earth);
  border-radius: 6px;
  background: #fffdf6;
  line-height: 1.4;
}

.stacked-form {
  display: grid;
  gap: 11px;
}

.grid-2,
.filter-row,
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.primary-action {
  margin-top: 3px;
}

.filter-row {
  margin-bottom: 11px;
}

.queue-list,
.source-list {
  display: grid;
  gap: 8px;
}

.source-list article {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
}

.source-list p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.report-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  overflow: hidden;
}

.card-button {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.report-card.is-selected {
  border-color: var(--canal);
  box-shadow: inset 0 0 0 2px rgba(31, 111, 154, 0.2);
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.card-title {
  font-size: 13px;
}

.card-meta,
.card-address {
  color: var(--muted);
  font-size: 12px;
}

.work-form {
  margin-top: 13px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #edf3f0;
}

.metrics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metrics-grid article {
  min-height: 70px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #ffffff, #f6fbf8);
}

.metrics-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.metrics-grid strong {
  font-size: 20px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 9px;
  border-bottom: 1px solid #e4ece7;
  text-align: left;
  font-size: 13px;
}

th {
  color: #40504b;
  background: #edf3ef;
  font-size: 11px;
  text-transform: uppercase;
}

.gate-marker,
.flow-marker {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--earth);
  color: #fff;
  box-shadow: 0 2px 6px rgba(22, 38, 36, 0.3);
  font-size: 12px;
  font-weight: 900;
}

.gate-marker.valve {
  background: #6f7d4d;
}

.flow-marker {
  width: 22px;
  height: 22px;
  border-color: var(--canal);
  background: #fff;
  color: var(--canal);
  box-shadow: 0 1px 4px rgba(22, 38, 36, 0.2);
}

.issue-marker {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 4px;
  background: var(--hazard);
  color: #fff;
  box-shadow: 0 3px 8px rgba(22, 38, 36, 0.35);
  transform: rotate(-45deg);
  font-size: 14px;
  font-weight: 900;
}

.issue-marker span {
  transform: rotate(45deg);
}

.leaflet-popup-content {
  margin: 10px 12px;
}

@media (max-width: 1180px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-block {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 180px minmax(420px, 1fr);
  }

  .ops-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .inspector-card,
  .tool-panel {
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .topbar,
  .mode-tabs,
  .workspace {
    padding-left: 8px;
    padding-right: 8px;
  }

  .top-tools,
  .lookup-row,
  .inline-control,
  .grid-2,
  .filter-row,
  .metrics-grid,
  .inspector-actions {
    grid-template-columns: 1fr;
  }

  .top-tools {
    gap: 8px;
  }

  .design-link {
    align-self: stretch;
  }

  .top-tools .session-pill {
    display: none;
  }

  .brand-block p {
    display: none;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
  }

  .tab {
    min-width: 0;
    padding: 0 4px;
    font-size: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .ops-summary {
    grid-template-columns: 1fr;
  }

  .layer-rail {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding: 8px;
  }

  .rail-heading {
    min-width: 110px;
    border-bottom: 0;
    padding-bottom: 0;
  }

  .layer-toggle {
    min-width: max-content;
  }

  .map-pane {
    grid-template-rows: auto 410px auto;
  }

  .map-status,
  .flow-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-canvas {
    min-height: 410px;
  }

  .inspector-panel {
    display: block;
  }

  .inspector-card,
  .tool-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

.legal-badge {
  position: fixed;
  right: 14px;
  bottom: 10px;
  z-index: 1200;
  padding: 5px 9px;
  border: 1px solid rgba(28, 44, 42, 0.16);
  border-radius: 6px;
  background: rgba(248, 250, 248, 0.88);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  text-align: right;
  box-shadow: 0 8px 20px rgba(37, 52, 48, 0.12);
  pointer-events: none;
}

@media (max-width: 720px) {
  .legal-badge {
    left: 10px;
    right: 10px;
    bottom: 8px;
    text-align: center;
  }
}
