/* 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 */
   display: inline-flex; /* Damit Button daneben passt */
   align-items: center; /* Vertikal zentrieren */
}
.controls input[type="number"] {
  /* Breite wird unten bei button, select, input gesetzt */
}
.controls .calc-btn { /* Spezifischer Stil für Calc-Button */
    min-height: 0; /* Kleinere Höhe erlauben */
    height: 30px;
    width: 30px;
    padding: 2px;
    font-size: 16px; /* Größeres Icon */
    margin-left: 3px; /* Kleiner Abstand zum Input */
    line-height: 1; /* Verhindert vertikalen Versatz */
}
.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, #export-choice-modal, #accessory-choice-modal, #calculator-modal { 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 */
}

/* Styling für den Export-Auswahl-Dialog */
#export-choice-modal {
  position: fixed; /* Über allem */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* Zentrieren */
  background: #fff;
  padding: 25px 35px;
  border-radius: 8px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2); /* Deutlicher Schatten */
  z-index: 20; /* Über anderen Elementen */
  text-align: center;
  border: 1px solid #ccc;
}

#export-choice-modal h4 {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 1.2em;
}

#export-choice-modal div { /* Container für A/R Buttons */
  margin-bottom: 10px;
}

#export-choice-modal button {
  margin: 5px 8px; /* Etwas Abstand zwischen Buttons */
  min-width: 110px; /* Mindestbreite */
  cursor: pointer;
}

/* Styling für Zubehör-Modal */
#accessory-choice-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 25px 35px;
  border-radius: 8px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  z-index: 20;
  text-align: center;
  border: 1px solid #ccc;
  max-width: 400px;
}

#accessory-choice-modal h4 {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 1.2em;
}

#accessory-item-buttons {
  display: flex;
  flex-wrap: wrap; /* Buttons umbrechen lassen */
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
}

#accessory-item-buttons button {
  margin: 0;
  min-width: 130px;
  cursor: pointer;
}

/* NEUES STYLING FÜR TASCHENRECHNER */
#calculator-modal {
    position: fixed;
    top: 100px; /* Position anpassen, z.B. unter den Controls */
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    z-index: 30; /* Über anderen Modals */
    border: 1px solid #ccc;
    width: 260px;
}
#calculator-modal h4 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    text-align: center;
}
#calc-display {
    width: 100%;
    box-sizing: border-box;
    text-align: right;
    font-size: 1.4em;
    padding: 8px;
    margin-bottom: 10px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
}
.calc-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.calc-buttons button {
    min-height: 40px; /* Feste Höhe */
    margin: 0; /* Gap nutzen */
    font-size: 1.1em;
}
.calc-buttons .calc-equal {
    grid-column: span 2; /* Nimmt 2 Spalten ein */
    background-color: #0b66ff;
    color: white;
}
.calc-buttons .calc-equal:hover {
    background-color: #0056d6;
}
.calc-buttons .calc-use {
    grid-column: span 2; /* Nimmt 2 Spalten ein */
    background-color: #28a745;
    color: white;
}
.calc-buttons .calc-use:hover {
    background-color: #218838;
}