:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0ea;
  --blue: #004aad;
  --teal: #0f766e;
  --red: #dc2626;
  --amber: #b45309;
  --purple: #7c3aed;
  --shadow: 0 14px 36px rgba(19, 32, 55, 0.09);
}

/* Critical Leaflet layout rules. Keeping these local prevents broken tile
   positioning when the CDN stylesheet is slow or unavailable. */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  left: 0;
  position: absolute;
  top: 0;
}

.leaflet-container {
  -webkit-tap-highlight-color: transparent;
  background: #dce5ea;
  font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
  overflow: hidden;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  -webkit-user-drag: none;
  user-select: none;
}

.leaflet-tile {
  border: 0;
  filter: inherit;
  max-width: none;
  visibility: hidden;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-pane > svg path,
.leaflet-tile-container {
  pointer-events: none;
}

.leaflet-overlay-pane svg,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  pointer-events: auto;
}

.leaflet-control {
  float: left;
  pointer-events: auto;
  position: relative;
  z-index: 800;
}

.leaflet-top,
.leaflet-bottom {
  pointer-events: none;
  position: absolute;
  z-index: 1000;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 7px;
  box-shadow: 0 6px 18px rgba(19, 32, 55, 0.12);
  margin-left: 12px;
  margin-top: 12px;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: #ffffff;
  color: var(--ink);
  display: block;
  font-size: 18px;
  font-weight: 700;
  height: 30px;
  line-height: 30px;
  text-align: center;
  text-decoration: none;
  width: 30px;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 11px;
  margin: 0;
  padding: 2px 6px;
}

.leaflet-popup {
  margin-bottom: 20px;
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(19, 32, 55, 0.18);
  padding: 1px;
  text-align: left;
}

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

.leaflet-popup-tip-container {
  height: 20px;
  left: 50%;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  width: 40px;
}

.leaflet-popup-tip {
  background: #ffffff;
  box-shadow: 0 8px 28px rgba(19, 32, 55, 0.18);
  height: 14px;
  margin: -8px auto 0;
  transform: rotate(45deg);
  width: 14px;
}

.leaflet-tooltip {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(19, 32, 55, 0.14);
  color: var(--ink);
  padding: 5px 8px;
  position: absolute;
  white-space: nowrap;
}

.leaflet-interactive {
  cursor: pointer;
}

* {
  box-sizing: border-box;
}

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

.sigma-navbar {
  align-items: center;
  background: linear-gradient(90deg, #00337a 0%, #004aad 100%);
  box-shadow: 0 2px 10px rgba(0, 30, 70, 0.25);
  display: flex;
  gap: 14px;
  min-height: 62px;
  padding: 10px 22px;
  position: sticky;
  top: 0;
  z-index: 2000;
}

.sigma-navbar-logo img {
  display: block;
  height: 40px;
}

.sigma-navbar-title {
  color: #ffffff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-decoration: none;
  white-space: nowrap;
}

.sigma-navbar-title small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  opacity: 0.75;
  text-transform: uppercase;
}

.sigma-navbar-links {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.sigma-nav-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  text-decoration: none;
  transition: background 0.2s ease;
}

.sigma-nav-pill:hover {
  background: rgba(255, 255, 255, 0.28);
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 86px;
  padding: 18px clamp(18px, 4vw, 44px);
}

.eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 4px;
  text-transform: uppercase;
}

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

h1 {
  font-size: 30px;
  line-height: 1.05;
  margin-bottom: 0;
}

h2 {
  font-size: 15px;
  margin-bottom: 14px;
}

main {
  display: grid;
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 44px) 36px;
}

.topbar-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: flex-end;
}

.topbar-controls label {
  display: grid;
  gap: 5px;
}

.topbar-controls label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.topbar-controls select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  min-width: min(360px, 36vw);
  padding: 9px 12px;
}

.metric-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compact-grid {
  margin-bottom: 14px;
}

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

.metric {
  min-height: 118px;
  padding: 16px;
}

.metric span,
.metric small,
.kpa-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
  margin: 10px 0 5px;
}

.metric.danger strong {
  color: var(--red);
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: 280px minmax(0, 1fr);
}

.side-panel {
  align-self: stretch;
  display: grid;
  gap: 8px;
  grid-template-rows: min-content 1fr;
  padding: 18px;
}

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

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section label {
  align-items: center;
  display: flex;
  font-size: 14px;
  gap: 8px;
  margin: 12px 0;
}

.panel-section .stacked-control {
  align-items: stretch;
  display: grid;
  gap: 6px;
}

.stacked-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.stacked-control select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  padding: 8px 9px;
  width: 100%;
}

.panel-button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 720;
  margin-top: 8px;
  padding: 9px 11px;
  width: 100%;
}

.panel-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

input[type="checkbox"] {
  accent-color: var(--blue);
}

.kpa-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.kpa-list div {
  display: grid;
  gap: 4px;
}

.kpa-list dd {
  font-size: 18px;
  font-weight: 760;
  margin: 0;
}

.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  padding: 16px;
}

.detail-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.detail-group {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.detail-group h3 {
  font-size: 13px;
  margin: 0;
  text-transform: uppercase;
}

.detail-group .kpa-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-safety {
  border-top: 3px solid var(--red);
}

.detail-efficiency {
  border-top: 3px solid var(--teal);
}

.map-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  height: min(680px, 68vh);
  min-height: 540px;
  overflow: hidden;
  position: relative;
}

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

.map-info {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 16px;
  box-shadow: 0 10px 30px rgba(19, 32, 55, 0.14);
  display: grid;
  gap: 8px;
  left: 16px;
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  position: absolute;
  z-index: 700;
}

.map-info strong {
  font-size: 13px;
}

.map-info span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.comparison-panel,
.traceability-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  overflow: hidden;
  padding: 16px;
}

.comparison-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
}

.comparison-header h2 {
  margin-bottom: 0;
}

.comparison-header label {
  align-items: center;
  display: flex;
  gap: 10px;
}

.comparison-header label span,
.comparison-summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

#run-select,
#day-select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  min-width: min(460px, 48vw);
  padding: 9px 12px;
}

.table-wrap {
  overflow-x: auto;
}

.comparison-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 1180px;
  width: 100%;
}

.traceability-table {
  min-width: 1080px;
}

.comparison-table th,
.comparison-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: right;
  white-space: nowrap;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  max-width: 340px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
}

.traceability-table th,
.traceability-table td {
  text-align: left;
  white-space: normal;
}

.traceability-table td {
  vertical-align: top;
}

.traceability-table .traceability-group-row td {
  background: #eef2f7;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: left;
}

.comparison-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.comparison-table tr.average-row {
  background: #f8fafc;
  font-weight: 760;
}

.comparison-table tr.mvp-row {
  background: #f0fdfa;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.map-legend span {
  align-items: center;
  color: var(--ink);
  display: inline-flex;
  gap: 6px;
  white-space: nowrap;
}

.legend-swatch {
  border-radius: 999px;
  display: inline-block;
  height: 8px;
  width: 22px;
}

.legend-volume-low {
  background: #38bdf8;
}

.legend-volume-medium {
  background: #f59e0b;
}

.legend-volume-high {
  background: #dc2626;
}

.legend-planned {
  background: repeating-linear-gradient(90deg, #111827 0 6px, transparent 6px 10px);
}

.legend-heat {
  background: linear-gradient(90deg, #2dd4bf, #2563eb, #f59e0b, #dc2626);
}

.legend-atd {
  background: linear-gradient(90deg, #14b8a6, #facc15, #f97316, #dc2626);
}

.legend-complexity {
  background: #a855f7;
}

.legend-lowc {
  background: #ef4444;
}

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

.chart-section {
  border-top: 3px solid var(--line);
  display: grid;
  gap: 12px;
  padding-top: 16px;
}

.safety-section {
  border-top-color: #dc2626;
}

.efficiency-section {
  border-top-color: #0f766e;
}

.context-section {
  border-top-color: #64748b;
}

.section-heading h2 {
  font-size: 18px;
  margin-bottom: 0;
}

.chart-card {
  overflow: hidden;
  padding: 16px;
}

.chart-card img {
  aspect-ratio: 2.5 / 1;
  display: block;
  height: auto;
  width: 100%;
}

.leaflet-popup-content {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

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

  .topbar-controls {
    justify-content: flex-start;
    width: 100%;
  }

  .topbar-controls label,
  .topbar-controls select {
    width: 100%;
  }

  .metric-grid,
  .charts,
  .side-panel,
  .detail-grid,
  .detail-group .kpa-list {
    grid-template-columns: 1fr;
  }

  .comparison-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .comparison-header label,
  #day-select,
  #run-select {
    width: 100%;
  }

  .workspace,
  .map-stage {
    height: 520px;
    min-height: 520px;
  }
}
