/* Grundlegende Stile */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  margin: 0;
  padding: 12px;
  background: #f5f6f8;
  display: flex; /* Flexbox für Hauptlayout */
  flex-direction: column; /* Elemente untereinander */
  align-items: center; /* Zentriert Inhalt horizontal */
  min-height: 100vh; /* Mindesthöhe des Body */
}

h2 {
  margin: 6px 0 12px 0;
  text-align: center;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 1200px; /* Maximale Breite wie Canvas */
}

.tab {
  background: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  cursor: pointer;
  white-space: nowrap; /* Verhindert Umbruch in Tabs */
}

.tab.active {
  background: #0b66ff;
  color: #fff;
}

/* Hauptbereiche Skizze & Aufmaßblatt */
#skizze, #aufmassblatt {
  display: flex; /* Flexbox verwenden */
  flex-direction: column; /* Elemente untereinander */
  align-items: center; /* Inhalt zentrieren */
  width: 100%;
  max-width: 1200px; /* Maximale Breite begrenzen */
  margin-bottom: 20px; /* Abstand nach unten */
}
#aufmassblatt {
  display: none; /* Standardmäßig ausgeblendet */
  background: #fff;
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  width: 95%; /* Etwas schmaler als max-width */
  text-align: left;
}


/* Bedienelemente (.controls) */
.controls {
  display: flex; /* Flexbox für Anordnung */
  flex-wrap: wrap; /* Umbruch erlauben */
  justify-content: center; /* Zentrieren */
  align-items: center; /* Vertikal zentrieren */
  gap: 8px 10px; /* Abstand zwischen Elementen (vertikal horizontal) */
  background: #fff;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  margin-bottom: 10px;
  width: 100%; /* Volle Breite des Elternelements (#skizze) */
  box-sizing: border-box; /* Padding in Breite einrechnen */
}
.controls label, .controls button {
  margin: 0; /* Alte Margins entfernen, gap nutzen */
}
.controls label {
   white-space: nowrap; /* Verhindert Umbruch in Labels */
}
.controls input[type="number"] {
  /* Breite wird unten bei button, select, input gesetzt */
}
.controls br {
  display: none; /* <br> wird nicht mehr gebraucht */
}
.actions {
  display: flex;
  gap: 15px; /* Mehr Abstand zwischen Checkboxen */
  align-items: center;
  margin-left: 10px; /* Kleiner Abstand zu den Buttons */
}
.small {
  font-size: 13px; /* Etwas größer für Touch */
  color: #444;
}


/* Canvas Container */
.canvas-container {
  max-width: 100%; /* Nimmt die Breite des Elternelements an */
  overflow-x: auto; /* Horizontales Scrollen erlauben */
  border: 1px solid #ccc;
  background: #fff;
  display: flex; /* Verhindert Leerraum */
  justify-content: center; /* Zentriert Canvas, wenn schmaler */
  width: 100%; /* Volle Breite des Elternelements (#skizze) */
  box-sizing: border-box;
}
canvas {
  background: #fff;
  display: block; /* Stellt sicher, dass es keine extra Abstände gibt */
  margin: 0; /* Keine Ränder mehr nötig */
  max-width: none; /* Verhindert Schrumpfen durch CSS */
  cursor: grab;
}


/* Bearbeitungs-Panel (Zentriert) */
#edit-panel {
  display: none; /* Standardmäßig ausgeblendet */
  position: fixed; /* Position relativ zum Fenster */
  top: 50%; /* Vertikal mittig */
  left: 50%; /* Horizontal mittig */
  transform: translate(-50%, -50%); /* Exakte Zentrierung */
  width: auto; /* Automatische Breite */
  max-width: 90%; /* Maximale Breite auf kleinen Screens */
  min-width: 300px; /* Mindestbreite, damit es nicht zu schmal wird */
  text-align: left;
  background: #fff;
  padding: 15px; /* Etwas mehr Innenabstand */
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15); /* Deutlicherer Schatten */
  z-index: 10; /* Stellt sicher, dass es über dem Canvas liegt */
  margin-top: 0; /* Alten Abstand entfernen */
}
#edit-panel h4 { margin: 4px 0 8px 0; }
#edit-panel label { margin-right: 10px;}
#edit-panel button { margin-top: 8px; margin-right: 5px; }


/* Aufmaßblatt spezifisch */
#aufmassblatt > div:first-child { /* Header im Aufmaßblatt */
   width: 100%;
   display: flex;
   justify-content: space-between;
   align-items: center;
   margin-bottom: 10px;
   flex-wrap: wrap; /* Umbruch erlauben */
   gap: 10px; /* Abstand, wenn umgebrochen */
}
#aufmassblatt h3 { margin: 0; } /* Standard-Margin entfernen */

#skizzen-list { width: 100%; } /* Volle Breite für die Liste */

.skizze-block {
  border: 1px solid #e6e9ef;
  padding: 10px;
  margin-bottom: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #fafbff;
  border-radius: 6px;
}
.skizze-block img {
  width: 280px; /* Feste Breite für Konsistenz auf Desktop */
  height: 180px;
  object-fit: contain;
  border: 1px solid #ddd;
  background: #fff;
  flex-shrink: 0; /* Verhindert Schrumpfen des Bildes */
}
.skizze-meta {
  flex: 1; /* Nimmt restlichen Platz ein */
  min-width: 200px; /* Mindestbreite für die Tabelle */
}
table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 8px; /* Abstand nach unten */
}
th, td {
  border: 1px solid #ccc;
  padding: 6px 8px;
  text-align: center;
  font-size: 13px;
}
th {
  background: #f0f8ff; /* Blasses Blau */
}

/* Touch-Optimierung und Styling für Formularelemente */
button, select, input {
   padding: 8px 10px;
   min-height: 38px;
   font-size: 14px;
   margin: 4px; /* Standard-Margin beibehalten, wo `gap` nicht wirkt */
   border: 1px solid #ccc; /* Einheitlicher Rahmen für alle */
   border-radius: 8px; /* Abrundung für alle */
   background-color: #fff; /* Standardhintergrund */
   box-sizing: border-box; /* Padding und Border in Größe einrechnen */
}

/* Spezifische Input-Breiten (falls nötig) */
input[type="number"] {
  width: 70px; /* Breite für Nummernfelder beibehalten */
}

/* Button-Styling (angepasst, Radius wird oben gesetzt) */
button {
  background-color: #f8f9fa; /* Hintergrund für Buttons */
  cursor: pointer; /* Zeigt an, dass der Button klickbar ist */
  color: #212529; /* Dunkle Schriftfarbe für Kontrast */
  transition: background-color 0.15s ease-in-out; /* Kleiner Hover-Effekt */
}
button:hover {
  background-color: #e9ecef; /* Etwas dunkler beim Hovern */
}
button:disabled {
  opacity: 0.65; /* Angepasste Deckkraft für bessere Lesbarkeit */
  cursor: not-allowed;
  background-color: #f8f9fa; /* Hintergrund bleibt gleich */
}
/* === ENDE: Einheitliches Formular-Styling === */


/* ================================
   Responsive Anpassungen
   ================================ */

/* Tablet & kleiner (< 900px) */
@media (max-width: 900px) {
    .skizze-block {
        flex-direction: column; /* Untereinander */
        align-items: center; /* Zentrieren */
    }
    .skizze-block img {
        width: 100%; /* Volle Breite */
        max-width: 400px; /* Max. Breite begrenzen */
        height: auto; /* Höhe automatisch */
        margin-bottom: 10px;
    }
    .skizze-meta {
        width: 100%; /* Volle Breite für Meta-Daten */
        max-width: 450px; /* Max. Breite begrenzen */
    }
     #edit-panel {
        min-width: 280px; /* Kleinere Mindestbreite auf Tablets */
     }
}


/* Kleines Tablet & Smartphone (< 600px) */
@media (max-width: 600px) {
  body { padding: 8px; }
  h2 { font-size: 1.3em; }
  .tabs { gap: 5px; }
  .tab { padding: 6px 10px; font-size: 0.9em;}

  .controls { padding: 8px; gap: 5px; } /* Weniger Abstand */
  .controls label, .controls button, .controls select, .controls input { font-size: 13px; } /* Schriftgröße vereinheitlicht */
  .controls input[type="number"] { width: 60px; } /* Noch schmaler */
  .actions { width: 100%; justify-content: center; margin-left: 0; margin-top: 8px;}

  #edit-panel {
     width: 90%; /* Breite anpassen */
     min-width: 0; /* Mindestbreite entfernen */
     padding: 10px; /* Weniger Padding */
   }
  #edit-panel label { display: block; margin-bottom: 5px; } /* Labels über die Felder */

  #aufmassblatt { width: 100%; padding: 8px; box-sizing: border-box;}
  #aufmassblatt > div:first-child { justify-content: center; text-align: center;} /* Header zentrieren */

  table, th, td { font-size: 12px; padding: 4px 6px; }
  .skizze-block img { max-width: 100%; }
}


/* PDF Export Hilfsklasse */
.hide-for-export button {
    display: none !important;
}

/* Druckstile (weitgehend unverändert) */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }
  html, body {
    width: 210mm;
    height: 297mm;
    margin: 0 auto;
    background: white;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  * { box-sizing: border-box; max-width: 100%; }
  button, nav, .no-print, .tabs, .controls, #edit-panel { display: none !important; } /* Mehr Elemente ausblenden */
  h2 { display: none; } /* Titel auch ausblenden */
  #skizze { display: none !important; } /* Skizzenbereich komplett ausblenden */
  #aufmassblatt {
      display: block !important; /* Sicherstellen, dass Aufmaßblatt sichtbar ist */
      box-shadow: none;
      border: none;
      width: 100%;
      padding: 0;
      margin: 0;
  }
   .skizze-block {
      page-break-inside: avoid; /* Verhindert Umbruch innerhalb eines Blocks */
      border: 1px solid #ccc; /* Rahmen im Druck beibehalten */
      background: #fff; /* Sicherstellen, dass Hintergrund weiß ist */
   }
   .skizze-block img { border: 1px solid #bbb; }
   /* Kein Umbruch vor jedem Block mehr, der Header kümmert sich drum */
}