:root {
  --bg: #f4f7f9;
  --panel: #ffffff;
  --panel-2: #eef3f5;
  --text: #172126;
  --muted: #61707a;
  --line: #d9e2e7;
  --accent: #176c8f;
  --accent-2: #1f8f67;
  --warn: #b36b12;
  --bad: #a23b3b;
  --shadow: 0 10px 30px rgba(31, 45, 54, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.auth-loading .app-shell,
body.auth-signed-out .app-shell,
body.auth-ready #auth-screen {
  display: none;
}

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

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

.auth-screen {
  align-items: center;
  background: var(--bg);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 390px;
  padding: 24px;
  width: 100%;
}

.auth-brand {
  margin-bottom: 2px;
}

.auth-provider,
.auth-submit {
  align-items: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 750;
  gap: 9px;
  height: 42px;
  justify-content: center;
  width: 100%;
}

.auth-provider {
  background: #18323d;
  color: #fff;
}

.auth-provider svg {
  height: 18px;
  width: 18px;
}

.auth-provider path:nth-child(1) { fill: #4285f4; }
.auth-provider path:nth-child(2) { fill: #34a853; }
.auth-provider path:nth-child(3) { fill: #fbbc05; }
.auth-provider path:nth-child(4) { fill: #ea4335; }

.auth-email-form {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding-top: 16px;
}

.auth-submit {
  background: var(--accent);
  color: #fff;
}

.auth-link-button,
.text-button {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  padding: 0;
}

.auth-message {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  min-height: 18px;
}

.auth-message.error {
  color: var(--bad);
}

.auth-message.ok {
  color: #176147;
}

.control-panel,
.results-panel {
  background: var(--panel);
  border-color: var(--line);
  border-style: solid;
  padding: 20px;
}

.control-panel {
  border-width: 0 1px 0 0;
}

.results-panel {
  border-width: 0 0 0 1px;
  overflow-y: auto;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  align-items: center;
  background: #18323d;
  border-radius: 6px;
  color: #fff;
  display: flex;
  font-size: 14px;
  font-weight: 800;
  height: 38px;
  justify-content: center;
  width: 38px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.2;
}

.brand p,
.topbar p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.topbar .assessment-summary {
  border-left: 3px solid transparent;
  font-weight: 700;
  line-height: 1.35;
  margin-top: 7px;
  max-width: 760px;
  padding-left: 9px;
}

.assessment-summary.assessment-ok {
  border-color: var(--accent-2);
  color: #176147;
}

.assessment-summary.assessment-warn {
  border-color: var(--warn);
  color: #7b4a0b;
}

.topbar .coverage-summary {
  color: var(--accent);
  font-weight: 800;
  margin-top: 7px;
}

.control-form {
  display: grid;
  gap: 14px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 650;
  gap: 7px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 0 10px;
}

input,
select {
  height: 38px;
}

textarea {
  line-height: 1.35;
  min-height: 72px;
  padding-bottom: 8px;
  padding-top: 8px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid rgba(23, 108, 143, 0.28);
  outline-offset: 2px;
}

.control-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.checkbox-row {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 9px;
}

.checkbox-row input {
  height: 16px;
  width: 16px;
}

.run-button,
.secondary-button,
.icon-button {
  align-items: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
}

.run-button {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  gap: 8px;
  height: 42px;
  margin-top: 4px;
}

.secondary-button {
  background: #18323d;
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
}

.run-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.run-button svg {
  fill: currentColor;
  height: 17px;
  width: 17px;
}

.secondary-button svg,
.icon-button svg {
  fill: none;
  height: 17px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 17px;
}

.save-panel {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 18px;
}

.save-panel h2 {
  font-size: 14px;
  margin-bottom: 12px;
}

.save-form {
  display: grid;
  gap: 12px;
}

.save-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  min-height: 16px;
}

.status-block {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 24px;
  padding: 12px;
}

.status-line {
  align-items: center;
  display: flex;
  font-size: 12px;
  justify-content: space-between;
  padding: 6px 0;
}

.status-line span {
  color: var(--muted);
}

.status-line strong {
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 18px 22px;
}

.topbar h2,
.section-toggle span {
  font-size: 18px;
  line-height: 1.2;
}

.legend {
  align-items: center;
  display: flex;
  gap: 14px;
}

.session-bar {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.session-bar span {
  color: var(--muted);
  font-size: 11px;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend span {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 6px;
}

.legend i {
  border-radius: 99px;
  display: inline-block;
  height: 10px;
  width: 26px;
}

.legend-low { background: #414487; }
.legend-mid { background: #2a788e; }
.legend-high { background: #7ad151; }

.map-section {
  padding: 18px;
  position: relative;
}

.map {
  background: #e7edf0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: block;
  height: calc(100vh - 92px);
  min-height: 520px;
  width: 100%;
}

.map-controls {
  display: grid;
  gap: 10px;
  left: 30px;
  position: absolute;
  top: 30px;
  width: min(210px, calc(100% - 60px));
  z-index: 2;
}

.layer-control {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(31, 45, 54, 0.11);
  display: grid;
  gap: 8px;
  padding: 11px;
}

.layer-control h3 {
  font-size: 13px;
  line-height: 1.2;
  margin: 0 0 2px;
}

.layer-control label {
  align-items: center;
  color: var(--text);
  display: flex;
  flex-direction: row;
  font-size: 12px;
  font-weight: 700;
  gap: 8px;
}

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

.disabled-layer {
  color: var(--muted) !important;
  cursor: not-allowed;
  opacity: 0.62;
}

.zoom-control {
  display: flex;
  gap: 8px;
}

.zoom-control .icon-button {
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 22px rgba(31, 45, 54, 0.11);
}

.zoom-control .icon-button:disabled {
  cursor: default;
  opacity: 0.48;
}

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

.contour-line {
  stroke: rgba(69, 82, 88, 0.42);
  stroke-linecap: round;
  stroke-width: 1.35;
  vector-effect: non-scaling-stroke;
}

.road-shadow {
  fill: none;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 10;
}

.road {
  fill: none;
  stroke: #6b7e87;
  stroke-dasharray: 10 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.target {
  fill: rgba(23, 108, 143, 0.08);
  stroke: #176c8f;
  stroke-dasharray: 8 6;
  stroke-width: 3;
}

.target-center circle {
  fill: #f4f7f9;
  stroke: #a23b3b;
  stroke-width: 3;
}

.target-center path {
  fill: none;
  stroke: #a23b3b;
  stroke-linecap: round;
  stroke-width: 3;
}

.target-center text {
  fill: #702525;
  paint-order: stroke;
  stroke: #f4f7f9;
  stroke-width: 4;
}

.candidate-marker {
  cursor: pointer;
  filter: drop-shadow(0 4px 7px rgba(18, 32, 39, 0.28));
}

.candidate-marker:focus {
  outline: none;
}

.candidate-marker.selected circle {
  fill: #176c8f;
  stroke: #d9f0f7;
  stroke-width: 5;
}

.panel-section-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-section.collapsed .panel-section-header {
  margin-bottom: 0;
}

.section-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  min-height: 34px;
  min-width: 0;
  padding: 0;
  text-align: left;
}

.section-toggle:hover,
.section-toggle:focus {
  color: var(--accent);
}

.section-toggle span {
  font-weight: 800;
}

.section-chevron {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transform: rotate(90deg);
  transition: transform 120ms ease;
  width: 18px;
}

.panel-section.collapsed .section-chevron {
  transform: rotate(0deg);
}

.icon-button {
  background: var(--panel-2);
  color: var(--text);
  height: 34px;
  width: 34px;
}

.saved-panel {
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  padding-bottom: 18px;
}

.saved-list {
  display: grid;
  gap: 8px;
}

.saved-list[hidden],
.candidate-list[hidden] {
  display: none;
}

.saved-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.incident-folder {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.incident-folder.expanded {
  border-color: rgba(23, 108, 143, 0.35);
}

.incident-toggle {
  align-items: center;
  background: #fff;
  border: 0;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 8px;
  grid-template-columns: 16px 18px 1fr;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.incident-toggle:hover,
.incident-toggle:focus {
  background: var(--panel-2);
  outline: none;
}

.folder-chevron,
.folder-icon {
  fill: none;
  height: 17px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 17px;
}

.folder-chevron {
  color: var(--muted);
  transform: rotate(0deg);
  transition: transform 120ms ease;
}

.incident-folder.expanded .folder-chevron {
  transform: rotate(90deg);
}

.folder-icon {
  color: var(--accent);
}

.incident-label {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.incident-label strong {
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.incident-label small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.incident-analyses {
  background: #f8fbfc;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 7px;
  padding: 8px;
}

.incident-analyses[hidden] {
  display: none;
}

.saved-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 3px;
  padding: 10px;
  text-align: left;
}

.saved-item:hover,
.saved-item:focus,
.saved-item.active {
  border-color: rgba(23, 108, 143, 0.55);
  outline: none;
}

.saved-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.saved-item strong {
  font-size: 12px;
  line-height: 1.25;
}

.saved-item span,
.saved-item small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.search-results-panel {
  min-width: 0;
}

.candidate-list {
  display: grid;
  gap: 10px;
}

.search-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: 0;
}

.empty-state circle {
  fill: rgba(23, 108, 143, 0.08);
  stroke: rgba(23, 108, 143, 0.22);
  stroke-width: 2;
}

.empty-state text {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 800;
}

.candidate {
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 12px;
}

.candidate:hover,
.candidate:focus {
  border-color: rgba(23, 108, 143, 0.45);
  outline: none;
}

.candidate.selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.candidate-head {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.rank {
  align-items: center;
  background: #18323d;
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  height: 26px;
  justify-content: center;
  min-width: 26px;
}

.candidate h3 {
  font-size: 14px;
  margin: 0 0 3px;
}

.candidate small {
  color: var(--muted);
  display: block;
  font-size: 11px;
}

.score {
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
}

.service-status {
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  margin-top: 10px;
  padding: 7px 8px;
  text-transform: uppercase;
}

.service-status.ok {
  background: #e7f3ee;
  color: #176147;
}

.service-status.warn {
  background: #fff3df;
  color: var(--warn);
}

.candidate-brief {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.candidate-brief section {
  border-left: 3px solid var(--line);
  padding-left: 9px;
}

.candidate-brief h4 {
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0;
  line-height: 1.2;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.candidate-brief p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: 3px 0 0;
}

.metric-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin: 12px 0;
}

.operational-metrics {
  margin-bottom: 10px;
}

.metric {
  background: var(--panel-2);
  border-radius: 6px;
  padding: 8px;
}

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

.metric strong {
  display: block;
  font-size: 13px;
  margin-top: 2px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: #e7f3ee;
  border-radius: 999px;
  color: #176147;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  line-height: 1.25;
  max-width: 100%;
}

.tag.caution {
  background: #fff3df;
  color: var(--warn);
}

.tag.ok {
  background: #e7f3ee;
  color: #176147;
}

.tag.warn {
  background: #fff3df;
  color: var(--warn);
}

.candidate p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 10px;
}

.candidate-details {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 8px;
}

.candidate-details summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.candidate-details p {
  margin-top: 8px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 260px 1fr;
  }

  .results-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .control-panel,
  .results-panel {
    border-width: 0 0 1px;
  }

  .topbar,
  .legend {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-bar {
    align-items: flex-start;
  }

  .map {
    height: min(58vh, 620px);
    min-height: 420px;
  }

  .map-controls {
    left: 28px;
    top: 28px;
    width: min(190px, calc(100% - 56px));
  }
}
