:root {
  --red: #D32F2F;
  --warn: #FF0000;
  --ok: #4CAF50;
  --blue: #1976D2;
  --yellow: #FFEB3B;
  --yellow-border: #FBC02D;
}

/* Base styles */
* { 
  box-sizing: border-box; 
}

body { 
  margin: 0; 
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; 
  color: #111; 
  background: #fff; 
}

#errorOverlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.96);
  z-index: 99999;
  padding: 20px;
  color: #b00020;
  font-family: monospace;
  overflow: auto;
  white-space: pre-wrap;
  border-top: 6px solid #b00020;
  display: none;
}

#appRoot { 
  background: #fff; 
}

/* Header styles */
.app-header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  padding: 10px 16px; 
  background: var(--red); 
  color: white; 
}

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

.brand h1 { 
  margin: 0; 
  font-size: 20px; 
}

.brand .subline { 
  margin-top: 2px; 
  font-size: .95rem; 
  opacity: .9; 
  white-space: nowrap; 
}

.logo { 
  height: 40px; 
  width: auto; 
}

.params { 
  display: flex; 
  gap: 12px; 
  align-items: center; 
  flex-wrap: wrap;
  margin-right: 200px; /* Make space for export buttons */
}

.params label { 
  font-size: 14px; 
}

.params input, 
.params select { 
  padding: 4px; 
  border-radius: 4px; 
  border: 1px solid #ccc; 
}

.params input[type=number] { 
  width: 80px; 
}

.pdf-btn { 
  padding: 8px 12px; 
  border: none; 
  border-radius: 6px; 
  background: #263238; 
  color: #fff; 
  cursor: pointer;
  transition: all 0.2s ease;
}

.pdf-btn:hover {
  background-color: #f5f5f5 !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  opacity: 1;
  transform: none;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.pdf-btn:active {
  transform: translateY(1px);
}

/* Loading indicator for PDF generation */
.loading::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.8) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="38" height="38" viewBox="0 0 38 38" stroke="%232196f3"><g fill="none" fill-rule="evenodd"><g transform="translate(1 1)" stroke-width="2"><circle stroke-opacity=".5" cx="18" cy="18" r="18"/><path d="M36 18c0-9.94-8.06-18-18-18"><animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite"/></path></g></g></svg>') center center no-repeat;
  z-index: 9999;
}

/* Toolbar styles */
.toolbar { 
  display: flex; 
  gap: 8px; 
  padding: 8px 16px; 
  background: #fff; 
  border-bottom: 1px solid #eee; 
  flex-wrap: wrap; 
  align-items: center; 
}

.toolbar button { 
  padding: 8px 12px; 
  border: none; 
  border-radius: 6px; 
  background: var(--red); 
  color: white; 
  cursor: pointer; 
}

.toolbar .success { 
  background: #2e7d32; 
}

.toolbar .danger { 
  background: var(--warn); 
}

.toolbar button:hover { 
  opacity: 0.9; 
}

.toolbar .ghost { 
  background: #eee; 
  color: #333; 
}

.basemap { 
  display: flex; 
  gap: 6px; 
  align-items: center; 
  margin-right: 8px; 
}

.basemap label { 
  font-size: 14px; 
}

.basemap select { 
  padding: 6px; 
}

/* Routing controls (next to basemap) */
.routing-controls{
  display:flex;
  gap:6px;
  align-items:center;
  margin-right:8px;
}
.routing-controls label{
  font-size:14px;
}
.routing-controls select{
  padding:6px;
}

/* WMS configuration panel */
.bm-config { 
  padding: 8px 16px; 
}

.bm-grid { 
  display: grid; 
  grid-template-columns: repeat(5, minmax(120px, 1fr)); 
  gap: 10px; 
  align-items: center; 
}

.bm-actions { 
  grid-column: 1 / -1; 
  display: flex; 
  gap: 10px; 
  align-items: center; 
}

/* Map container */
#map { height: 100%; width: 100%; position: relative; min-height: 320px; }

.leaflet-container {
  background: #eef3fb;
}

/* Table styling - optimized for 4 pumps without scroll */
.table-section table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 11px; /* Smaller font for more content */
}

.table-section th, 
.table-section td { 
  padding: 4px 6px; /* Reduced padding */
  border-bottom: 1px solid #eee; 
  text-align: right; 
  line-height: 1.2;
}

.table-section th:first-child, 
.table-section td:first-child { 
  text-align: left; 
}

.table-section th {
  font-size: 10px; /* Even smaller for headers */
  font-weight: 600;
}

.table-section table tfoot .totals-row td {
  font-weight: 700;
  border-top: 1px solid rgba(255,255,255,0.2);
  padding-top: 8px;
}

/* Elevation profile */
#elevContainer { 
  overflow-x: auto; 
}

#elevContainer canvas { 
  max-width: 100%; 
  height: auto; 
  border: 1px solid #eee; 
  border-radius: 6px; 
}

/* Footer */
.app-footer { 
  padding: 8px 16px; 
  color: #555; 
  border-top: 1px solid #eee; 
  background: #fafafa; 
  text-align: center; 
}

/* Map overlays */
.legend, 
.map-stats {
  position: absolute; 
  background: rgba(10,15,30,0.92);
  border: 1px solid #2a355e;
  border-radius: 12px; 
  padding: 10px 12px; 
  font-size: 12px;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

.legend {
  width: 200px; 
  bottom: 16px; 
  left: 16px; 
}

.map-stats { 
  top: 16px; 
  right: 16px; 
}

/* Segment badge */
.seg-badge {
  display: flex;
  align-items: center; 
  justify-content: center;
  width: 28px; 
  height: 28px; 
  border-radius: 50%;
  background: var(--yellow);
  border: 2px solid var(--yellow-border);
  color: #000;
  font-weight: 900; 
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* Icon styling */
.tint-red { 
  filter: invert(16%) sepia(98%) saturate(7486%) hue-rotate(3deg) brightness(99%) contrast(122%); 
}

.pin-img { 
  position: relative; 
  width: 32px; 
  height: 32px; 
  display: inline-block; 
}

.pin-img img { 
  width: 32px; 
  height: 32px; 
  display: block; 
}

.pin-img .badge {
  position: absolute; 
  right: -6px; 
  bottom: -6px;
  background: #D32F2F; 
  color: #fff; 
  border-radius: 50%;
  width: 18px; 
  height: 18px; 
  font-size: 11px; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  border: 2px solid #fff;
}

/* Export-Button */
.export-btn{ margin-left:.5rem; padding:.45rem .7rem; border-radius:.5rem;
  border:1px solid rgba(255,255,255,.25); background:rgba(255,255,255,.08); color:#fff; cursor:pointer; }
.export-btn:hover{ background:rgba(255,255,255,.15); }

/* === v0_9_3 layout: left map, right top profile, right bottom sections === */
#appRoot {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-header { flex: 0 0 auto; }
.toolbar, .bm-config { flex: 0 0 auto; }

.content-split {
  flex: 1 1 auto;
  min-height: 0; /* allow children to size */
  display: grid;
  grid-template-columns: 2fr 1.1fr;
  gap: 0;
}

.map-pane {
  min-height: 320px;
  position: relative;
}
#map.map-pane { height: 100%; width: 100%; }

.sidepanes {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px 12px;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border-left: 1px solid #eee;
}

.sidepanes .profile-section,
.sidepanes .table-section,
.sidepanes .gps-section {
  min-height: 0;
  overflow: auto;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #eee;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

/* Remove max-height constraint to use flex space */

.gps-coordinates-table {
  width: 100%;
  border-collapse: collapse;
  font-family: monospace;
  font-size: 10px; /* Smaller font for GPS coordinates */
  flex: 1;
}

.gps-coordinates-table th,
.gps-coordinates-table td {
  padding: 2px 4px; /* Reduced padding */
  border-bottom: 1px solid #eee;
  text-align: left;
  line-height: 1.1;
}

.gps-coordinates-table th {
  background: #f5f5f5;
  font-weight: 600;
  font-size: 9px; /* Even smaller for headers */
}

.gps-actions {
  margin-top: 4px; /* Reduced margin */
  display: flex;
  gap: 4px; /* Smaller gaps */
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.gps-copy-btn {
  padding: 4px 8px; /* Smaller buttons */
  border: none;
  border-radius: 4px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  font-size: 10px; /* Smaller font */
}

.gps-copy-btn:hover {
  opacity: 0.9;
}

#qrCodeContainer {
  margin-top: 12px;
  text-align: center;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #dee2e6;
}

#qrCodeCanvas {
  display: block;
  margin: 0 auto 8px auto;
}

.qr-info {
  margin: 0;
  font-size: 11px;
  color: #666;
  font-style: italic;
}

@media (max-width: 1100px) {
  .content-split {
    grid-template-columns: 1fr;
  }
  .sidepanes {
    grid-template-rows: auto auto;
  }
}

.app-footer { flex: 0 0 auto; }

/* v0_9_4: smaller section titles on right side, better layout fit */
.sidepanes .profile-section h2,
.sidepanes .table-section h2,
.sidepanes .gps-section h2 {
  font-size: 12px; /* Smaller title */
  line-height: 1.1;
  font-weight: 600;
  margin: 2px 0 6px 0; /* Reduced margins */
  flex: 0 0 auto;
}

/* Make profile-section, table-section and gps-section fill available height cleanly */
.sidepanes .profile-section,
.sidepanes .table-section {
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow children to grow/shrink */
}

.sidepanes .gps-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 0; /* Equal size with other sections */
}

#elevContainer {
  flex: 1 1 auto;
  overflow: hidden; /* avoid double scroll */
  display: flex;
  align-items: stretch;
}

#segmentsTable {
  flex: 1 1 auto;
  overflow: auto;
}

/* Canvas should scale to container width (JS will set pixel size) */
#elevContainer canvas {
  width: 100%;
  height: auto;
  display: block;
}
/* Individual QR Code Overlays */
#individualQROverlays {
  position: fixed;
  bottom: 10px;
  left: 10px;
  right: 10px;
  z-index: 1000;
  display: none;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

.individual-qr-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: white;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 8px;
  min-width: 120px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.individual-qr-canvas {
  width: 80px;
  height: 80px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.individual-qr-label {
  font-size: 11px;
  font-weight: bold;
  color: #333;
  margin-top: 5px;
  text-align: center;
}

.qr-overlay-controls {
  position: fixed;
  bottom: 220px;
  right: 10px;
  z-index: 1001;
  display: none;
}

.close-qr-overlay-btn {
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.close-qr-overlay-btn:hover {
  background: #cc0000;
}

.gps-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  font-size: 12px;
}

.gps-btn:hover {
  opacity: 0.9;
}
.pdf-btn.half-width {
  width: calc(50% - 4px);
  display: inline-block;
  margin-right: 4px;
}

.pdf-btn.half-width:last-child {
  margin-right: 0;
}
.export-buttons {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 10px;
  z-index: 1000;
}

.export-buttons .pdf-btn {
  white-space: nowrap;
  min-width: 90px;
}

.leaflet-control.pump-ov.hydrant-ov { margin-top: 8px; }
.leaflet-control.pump-ov .ov-title { font-weight: 600; margin-bottom: 2px; }
.leaflet-control.pump-ov .ov-line { font-size: 13px; }


/* === Unified Header Font Style === */
header button,
header input,
header select,
header .btn,
header .params button,
header .overlay-header button {
  font-size: 12.5px !important;
  font-weight: normal !important;
  line-height: 1.2;
  vertical-align: middle;
}


/* === Unified Header Hover Effekt === */
header button:hover,
header .btn:hover,
header input[type="button"]:hover,
header select:hover {
  background-color: #f5f5f5 !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}


/* QR-Liste für Druckausgabe (unterhalb des Inhaltsbereichs) */
.print-qr-list {
  display: none;
}

.print-qr-list-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.print-qr-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-right: 8px;
}

.print-qr-item canvas {
  display: block;
}

.print-qr-item-label {
  margin-top: 4px;
  font-size: 11px;
}


/* Info-Zeilen nur für den Ausdruck (Hydrant / Pumpendruck) */
.print-info-section {
  display: none;
}

.print-info-line {
  font-size: 13px;
  margin-bottom: 4px;
}

/* =========================================
   Zusätzliche starke Mobile-Fixes (Layout)
   ========================================= */
@media (max-width: 768px) {

  /* Grundlayout: kein Vollbild-Flex mehr, Seite darf normal wachsen */
  #appRoot {
    display: block !important;
    min-height: 0 !important;
    height: auto !important;
  }

  .content-split {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
  }

  /* Karte: fester sichtbarer Bereich oben */
  .map-pane {
    position: relative !important;
    height: 320px !important;
    min-height: 320px !important;
    margin-bottom: 12px !important;
  }

  #map,
  #map.map-pane {
    position: relative !important;
    height: 100% !important;
    width: 100% !important;
  }

  /* Rechte Spalte unter der Karte, volle Höhe nach Inhalt */
  .sidepanes {
    position: static !important;
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    margin-top: 8px !important;
    padding: 8px !important;
    border-left: none !important;
    border-top: 1px solid #eee !important;
  }

  .sidepanes .profile-section,
  .sidepanes .table-section,
  .sidepanes .gps-section {
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    margin-bottom: 16px !important;
  }

  #elevContainer {
    display: block !important;
    height: auto !important;
    min-height: 180px !important;
    overflow: visible !important;
  }

  #segmentsTable {
    max-height: none !important;
    height: auto !important;
  }
}

/* =========================================
   Mobile: Leaflet-Overlays unter der Karte
   ========================================= */
@media (max-width: 768px) {

  /* Map-Container soll so hoch sein wie Karte + Controls */
  .map-pane {
    height: auto !important;
    min-height: 0 !important;
  }

  /* Sichtbarer Kartenbereich fix, darunter Platz für Overlays */
  .map-pane .leaflet-container {
    height: 520px !important;
  }

  /* Leaflet-Controls (inkl. Pumpen-Overlay) in den normalen Fluss setzen */
  .leaflet-control-container {
    position: static !important;
  }

  .leaflet-top,
  .leaflet-bottom {
    position: static !important;
    z-index: auto !important;
  }

  .leaflet-top .leaflet-control,
  .leaflet-bottom .leaflet-control {
    margin-top: 8px !important;
    margin-right: 8px !important;
    margin-left: 8px !important;
  }

  /* Pumpen-Overlay auf Smartphone als Block unter der Karte darstellen */
  .leaflet-control.pump-ov {
    width: 100% !important;
    max-width: 360px !important;
    margin: 8px auto 0 auto !important;
    text-align: right;
  }
}

/* =========================================
   Mobile: Sichere Kartenhöhe (sichtbare Karte)
   ========================================= */
@media (max-width: 768px) {

  /* Map-Element explizit mit fixer Höhe */
  #map,
  #map.map-pane {
    height: 520px !important;
    min-height: 520px !important;
  }

  /* Map-Container darf wachsen, mindestens Kartengröße */
  .map-pane {
    min-height: 520px !important;
  }
}

/* =========================================
   Mobile: Overlays auf Karte ausblenden / Leaflet-Controls normalisieren
   ========================================= */
@media (max-width: 768px) {

  /* Alle Karten-Overlays, die die Sicht stören, auf dem Smartphone ausblenden */
  .map-overlay,           /* Pumpendruck-Overlay */
  .map-qr-overlay,        /* QR-Code-Overlay */
  .leaflet-control.pump-ov,
  .legend,                /* Hinweisfeld auf der Karte */
  #individualQROverlays,
  .qr-overlay-controls {
    display: none !important;
  }

  /* Leaflet-Controls wieder wie gewohnt in den Ecken anzeigen */
  .leaflet-control-container {
    position: absolute !important;
  }

  .leaflet-top,
  .leaflet-bottom {
    position: absolute !important;
    z-index: 1000 !important;
  }
}


/* Hide reset button (not needed for manual entry) */
#resetBtn{display:none !important;}
