/* ==========================================================================
   Final UI polish layer
   ==========================================================================

   Loaded after third-party Leaflet/Bootstrap styles so the scientific map keeps
   one coherent visual signature across legends, panels, popups and measuring UI.
   ========================================================================== */

:root {
  --app-ink: #0f172a;
  --app-muted: #526275;
  --app-panel: #ffffff;
  --app-soft: #f6fafb;
  --app-line: rgba(15, 23, 42, 0.12);
  --app-brand: #0f766e;
  --app-brand-dark: #0b525b;
  --app-blue: #113f67;
  --app-accent: #99f6e4;
  --app-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
  --app-radius: 8px;
  --app-signature: linear-gradient(135deg, #0b525b 0%, #113f67 64%, #2563eb 100%);
}

.delivery-report {
  display: grid;
  gap: 14px;
}

.delivery-report__lead {
  margin: 0;
  color: var(--app-muted);
  font-size: 14px;
  line-height: 1.55;
}

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

.delivery-metric {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  background: var(--app-soft);
}

.delivery-metric strong,
.delivery-metric span {
  display: block;
}

.delivery-metric strong {
  color: var(--app-ink);
  font-size: 18px;
  line-height: 1.1;
}

.delivery-metric span {
  margin-top: 4px;
  color: var(--app-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.delivery-metric--success strong {
  color: var(--app-brand);
}

.delivery-metric--warning strong {
  color: #b45309;
}

.delivery-metric--info strong {
  color: #2563eb;
}

.delivery-check-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.delivery-check {
  display: grid;
  grid-template-columns: minmax(130px, 0.35fr) 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--app-line);
  border-left-width: 4px;
  border-radius: var(--app-radius);
  background: #ffffff;
}

.delivery-check strong {
  color: var(--app-ink);
  font-size: 12px;
}

.delivery-check span {
  color: var(--app-muted);
  font-size: 12px;
  line-height: 1.45;
}

.delivery-check--success {
  border-left-color: var(--app-brand);
}

.delivery-check--warning {
  border-left-color: #d97706;
}

.delivery-check--error {
  border-left-color: #dc2626;
}

.delivery-check--info {
  border-left-color: #2563eb;
}

.delivery-samples {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--app-radius);
  background: #fff7ed;
  border: 1px solid rgba(217, 119, 6, 0.22);
}

.delivery-samples strong {
  color: #92400e;
  font-size: 12px;
}

.delivery-samples span {
  color: #7c2d12;
  font-size: 12px;
  line-height: 1.45;
}

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

.delivery-action-button {
  min-height: 36px;
  padding: 8px 12px;
  color: #344054;
  background: #ffffff;
  border: 1px solid var(--app-line);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 850;
}

.delivery-action-button--primary {
  color: #ffffff;
  background: var(--app-brand);
  border-color: var(--app-brand);
}

.delivery-share-url {
  width: 100%;
  min-height: 92px;
  padding: 10px 12px;
  color: var(--app-ink);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  resize: vertical;
}

body.dark-mode .delivery-report__lead,
body.dark-mode .delivery-check span,
body.dark-mode .delivery-metric span {
  color: #cbd5e1;
}

body.dark-mode .delivery-metric,
body.dark-mode .delivery-check,
body.dark-mode .delivery-action-button,
body.dark-mode .delivery-share-url {
  color: #e5e7eb;
  background: #1f2937;
  border-color: rgba(148, 163, 184, 0.22);
}

body.dark-mode .delivery-check strong,
body.dark-mode .delivery-metric strong {
  color: #f8fafc;
}

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

  .delivery-check {
    grid-template-columns: 1fr;
  }
}

.isterre-header {
  background: var(--app-signature) !important;
  border-bottom: 1px solid rgba(153, 246, 228, 0.28) !important;
}

.isterre-header .header-main-icon {
  color: var(--app-accent) !important;
}

.isterre-header .header-subtitle i {
  color: var(--app-accent);
}

.isterre-header .header-left,
.isterre-header .header-text {
  min-width: 0;
}

.isterre-header .header-right {
  flex: 0 1 auto;
  justify-content: flex-end;
  min-width: 0;
}

.isterre-header .header-summary {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
  min-height: 32px;
  padding: 7px 13px;
  color: #e6fffb;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(153, 246, 228, 0.28);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  white-space: nowrap;
}

.isterre-header .header-summary-value {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.isterre-header .header-summary-updated {
  gap: 4px;
}

.isterre-header .header-summary-separator {
  color: rgba(153, 246, 228, 0.78);
  font-weight: 900;
}

.isterre-header .header-institutions {
  display: inline-flex;
  align-items: center;
  margin-left: 0;
}

.isterre-header .institution-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: 0;
}

.isterre-header .institution-link {
  color: inherit;
  border-radius: 6px;
  margin: -2px -4px;
  padding: 2px 4px;
  text-decoration: none;
  transition: color 0.18s ease, background 0.18s ease;
}

.isterre-header .institution-link:hover,
.isterre-header .institution-link:focus-visible {
  color: #ffffff;
  background: rgba(153, 246, 228, 0.14);
  outline: none;
  text-decoration: none;
}

.isterre-header .institution-link:focus-visible {
  box-shadow: 0 0 0 3px rgba(153, 246, 228, 0.24);
}

.isterre-header .institution-separator {
  color: rgba(153, 246, 228, 0.78);
  font-weight: 900;
}

.isterre-header .language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
  padding: 2px;
  border: 1px solid rgba(153, 246, 228, 0.28);
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.35);
}

.isterre-header .language-switcher__button {
  min-width: 30px;
  height: 24px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #d9fffb;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.isterre-header .language-switcher__button:hover,
.isterre-header .language-switcher__button:focus-visible {
  color: #ffffff;
  background: rgba(153, 246, 228, 0.14);
  outline: none;
}

.isterre-header .language-switcher__button:focus-visible {
  box-shadow: 0 0 0 3px rgba(153, 246, 228, 0.24);
}

.isterre-header .language-switcher__button.is-active {
  color: #063a36;
  background: #99f6e4;
}

@media (max-width: 980px) {
  .isterre-header .header-summary {
    gap: 6px;
    padding: 6px 10px;
    font-size: 11px;
  }
}

@media (max-width: 820px) {
  .isterre-header .header-subtitle {
    display: none;
  }
}

@media (max-width: 700px) {
  .isterre-header .header-summary-updated,
  .isterre-header .header-summary-separator--before-update,
  .isterre-header .header-institutions,
  .isterre-header .header-summary-separator--before-institutions {
    display: none;
  }
}

@media (max-width: 560px) {
  .isterre-header .header-summary {
    display: inline-flex;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .isterre-header .header-summary > :not(.language-switcher) {
    display: none;
  }
}

.project-map-signature {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 820;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(176px, 20vw, 238px);
  height: 58px;
  padding: 8px 13px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.2);
  pointer-events: none;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.project-map-signature img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

body.dark-mode .project-map-signature {
  background: rgba(248, 250, 252, 0.92);
  border-color: rgba(153, 246, 228, 0.22);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.32);
}

@media (max-width: 820px) {
  .project-map-signature {
    top: 10px;
    width: 168px;
    height: 48px;
    padding: 7px 10px;
  }
}

@media (max-width: 640px) {
  .project-map-signature {
    display: none;
  }
}

/* Station days legend: native, reliable collapse through details/summary. */
.station-days-legend {
  min-width: 196px;
  max-width: 238px;
  color: var(--app-ink);
  background: var(--app-panel);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  transform: none !important;
}

.station-days-legend__details {
  display: block;
}

.station-days-legend .legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  color: #ffffff;
  background: var(--app-signature);
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  list-style: none;
  user-select: none;
}

.station-days-legend .legend-header::-webkit-details-marker {
  display: none;
}

.station-days-legend .legend-header span {
  flex: 1;
}

.station-days-legend__chevron {
  color: var(--app-accent);
  transition: transform 0.18s ease;
}

.station-days-legend__details:not([open]) .station-days-legend__chevron {
  transform: rotate(-90deg);
}

.station-days-legend .legend-body {
  display: grid;
  gap: 5px;
  padding: 9px;
  background: #ffffff;
}

.station-days-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 6px 24px 6px 8px;
  color: #344054;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 750;
  text-align: left;
}

.station-days-legend .legend-item:hover,
.station-days-legend .legend-item:focus-visible {
  color: var(--app-brand);
  background: #ecfdf5;
  border-color: rgba(15, 118, 110, 0.18);
  outline: none;
  transform: none;
}

.station-days-legend .legend-item.disabled {
  background: #f8fafc;
  opacity: 0.45;
}

/* Geoprocessing panel: same language as the station inspector. */
.geotools-panel {
  background: var(--app-panel);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
}

.geotools-header {
  min-height: 58px;
  padding: 16px 18px;
  background: var(--app-signature);
  border-bottom: 1px solid rgba(153, 246, 228, 0.22);
}

.geotools-header h3 {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
}

.geotools-header h3 i,
.geotools-close i {
  color: var(--app-accent);
}

.geotools-close {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(153, 246, 228, 0.22);
  border-radius: 999px;
}

.geotools-body {
  background: var(--app-soft);
}

.geotools-section,
.geotools-control-card,
.geotools-results-card {
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: var(--app-radius);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.geotools-section h4,
.geotools-control-card__header strong,
.geotools-results-header h4 {
  color: var(--app-ink);
  font-weight: 850;
  letter-spacing: 0;
}

.geotool-btn {
  color: #344054;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 7px;
  font-weight: 800;
}

.geotool-btn i {
  color: var(--app-brand);
}

.geotool-btn:hover,
.geotool-btn:focus-visible {
  color: var(--app-brand);
  background: #ecfdf5;
  border-color: rgba(15, 118, 110, 0.24);
  outline: none;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.12);
}

.geotool-btn.active {
  color: #ffffff;
  background: var(--app-signature);
  border-color: transparent;
}

.geotool-btn.active i {
  color: var(--app-accent);
}

.geotools-status {
  color: var(--app-blue);
  background: #ecfdf5;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--app-radius);
  font-weight: 800;
}

/* Leaflet measure prompt. */
.leaflet-control-measure .leaflet-control-measure-interaction {
  color: var(--app-ink);
  background: var(--app-panel);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  overflow: hidden;
}

.leaflet-control-measure .js-startprompt,
.leaflet-control-measure .js-measuringprompt {
  padding: 0 !important;
  background: #ffffff;
}

.leaflet-control-measure h3,
.leaflet-measure-resultpopup h3 {
  margin: 0 !important;
  padding: 12px 14px !important;
  color: #ffffff !important;
  background: var(--app-signature) !important;
  border: 0 !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  line-height: 1.25 !important;
}

.leaflet-control-measure .js-starthelp,
.leaflet-control-measure .results {
  margin: 0 !important;
  padding: 12px 14px !important;
  color: var(--app-muted);
  background: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.leaflet-control-measure .results .group {
  margin-top: 8px !important;
  padding-top: 8px !important;
  border-top: 1px solid rgba(15, 23, 42, 0.1) !important;
}

.leaflet-control-measure .tasks,
.leaflet-measure-resultpopup .tasks {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 !important;
  padding: 10px 14px 14px !important;
  background: #f8fafc;
  border-top: 1px solid rgba(15, 23, 42, 0.08) !important;
  text-align: left !important;
}

.leaflet-control-measure .tasks li,
.leaflet-measure-resultpopup .tasks li {
  display: block !important;
  margin: 0 !important;
}

.leaflet-control-measure a.start,
.leaflet-control-measure a.cancel,
.leaflet-control-measure a.finish,
.leaflet-measure-resultpopup a.zoomto,
.leaflet-measure-resultpopup a.deletemarkup {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 32px !important;
  width: auto !important;
  padding: 0 11px !important;
  color: #ffffff !important;
  background: var(--app-brand) !important;
  border: 0 !important;
  border-radius: 7px !important;
  font-size: 11px !important;
  font-weight: 850 !important;
  line-height: 1 !important;
  text-decoration: none !important;
}

.leaflet-control-measure a.cancel,
.leaflet-measure-resultpopup a.deletemarkup {
  background: #be123c !important;
}

.leaflet-control-measure a.finish,
.leaflet-measure-resultpopup a.zoomto {
  background: #2563eb !important;
}

/* Generic Leaflet popup shell. */
.leaflet-popup-content-wrapper {
  border: 1px solid var(--app-line) !important;
  border-radius: var(--app-radius) !important;
  background: #ffffff !important;
  box-shadow: var(--app-shadow) !important;
}

.leaflet-popup-tip {
  background: #ffffff !important;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14) !important;
}

.popup-header,
.station-overlap-popup__header {
  background: var(--app-signature) !important;
}

.popup-header.station {
  background: linear-gradient(135deg, #0f766e 0%, #113f67 100%) !important;
}

body.dark-mode .station-days-legend,
body.dark-mode .geotools-panel,
body.dark-mode .leaflet-popup-content-wrapper,
body.dark-mode .leaflet-control-measure .leaflet-control-measure-interaction {
  color: #e5e7eb;
  background: #111827 !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
}

body.dark-mode .station-days-legend .legend-body,
body.dark-mode .geotools-body,
body.dark-mode .leaflet-control-measure .js-starthelp,
body.dark-mode .leaflet-control-measure .results,
body.dark-mode .leaflet-control-measure .tasks {
  background: #111827 !important;
}

body.dark-mode .station-days-legend .legend-item,
body.dark-mode .geotool-btn {
  color: #dbeafe;
}
