/* CSS-Variablen für bessere Wartbarkeit */
:root {
  --border-color: #000;
  --border-thin: 1.5px;
  --border-thick: 4px;
  --font-family: "Arial", sans-serif;
  --primary-bg: #007bff;
  --controls-height: 110px;
  --button-height: 36px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 18px;
}

/* Reset und Grundstyles */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  font-family: var(--font-family);
  background: #fff;
  color: #000;
  font-size: 14px;
}

body {
    padding-bottom: calc(var(--controls-height) + env(safe-area-inset-bottom, 0));
}

#app-root {
  padding-bottom: var(--controls-height);
  max-width: 900px;
  margin: 0 auto;
}

/* Layout-Container */
.container {
  max-width: 900px;
  margin: var(--spacing-md) auto;
  border: var(--border-thin) solid var(--border-color);
  padding: var(--spacing-md);
}

/* Header-Bereich */
.header {
  border-bottom: var(--border-thick) solid var(--border-color);
  padding: var(--spacing-sm);
}

.header h2 { margin: 0; }

.zusatzdaten-summary {
  font-size: 1.5rem;   /* Schriftgröße (z.B. ca. h2-Niveau) */
  font-weight: bold;   /* fett */
  margin-top: 1rem;    /* Abstand nach oben */
  cursor: pointer;     /* zeigt Handcursor beim Hover */
}

/* Versions-Popup */
.popup {
  display: none;              /* Start hidden */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10000;             /* Über allem */
}

.popup-content {
  background: #fff;
  padding: 24px;           /* größerer Innenabstand */
  border-radius: 8px;
  max-width: 600px;        /* breiter */
  width: 95%;              /* fast volle Breite, passt auf kleine Displays */
  max-height: 80vh;        /* maximal 80% der Bildschirmhöhe */
  overflow-y: auto;        /* scrollbar bei langen Inhalten */
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.popup input {
  width: 80px;
  text-align: center;
  margin: 1rem 0;
  padding: 0.5rem;
  font-size: 1rem;
  border-radius: 5px;
  border: 1px solid #666;
  background-color: #333;
  color: white;
}

.popup button {
  padding: 0.5rem 1rem;
  background-color: #444;
  border: none;
  border-radius: 5px;
  color: white;
  cursor: pointer;
}

.popup button:hover { background-color: #666; }
.popup .close-btn { background-color: red; }
.popup .close-btn:hover { background-color: darkred; }
.popup .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.top-row {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  margin-top: var(--spacing-sm);
}

/* Input-Bereiche */
/* Input-Gruppen für bessere Mobil-Darstellung */
.input-group {
  display: flex;
  flex-wrap: wrap;      /* Damit sie auf kleinen Displays umbrechen */
  gap: var(--spacing-sm);
  margin-top: var(--spacing-sm);
}

/* Input-Felder sollen flexibler werden */
.input-field {
  border: var(--border-thin) solid var(--border-color);
  padding: var(--spacing-sm);
  flex: 1 1 200px;       /* wächst flexibel, aber min. 200px breit */
  min-width: 150px;      /* nicht kleiner als 150px */
}

/* Schmale Felder */
.input-field--narrow { 
  flex: 1 1 120px;       /* flexibel, aber min. 120px */
  text-align: center;
}

/* Eingabefelder */
.input-field input,
.input-field select,
.input-field button {
  width: 100%;
  padding: 8px;
  margin-top: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}


.input-field input {
  width: 100%;
  padding: 6px;
  margin-top: 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

/* Konfigurationsbereich */
.config {
  margin-top: var(--spacing-md);
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-wrap: wrap;
}

.config select, .config button {
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

/* Sheet-Styling */
.sheet-wrap { margin-top: var(--spacing-md); }

.sheet {
  border: var(--border-thin) solid var(--border-color);
  padding: var(--spacing-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.sheet__title {
  font-weight: bold;
  margin-bottom: 6px;
}

.sheet table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

.sheet th, .sheet td {
  border: var(--border-thin) solid var(--border-color);
  padding: 6px;
  text-align: center;
  vertical-align: middle;
}

.sheet thead th {
  background: #fff;
  font-weight: bold;
}

/* Spaltenbreiten */
.col-pfeile { width: 8%; }
.col-arrow { width: 12%; }
.col-sum3 { width: 12%; }
.col-sum6 { width: 10%; }
.col-sum12 { width: 10%; }

/* Controls - KORRIGIERT für Mobile */
.controls {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0);
    left: env(safe-area-inset-left, 0);
    right: env(safe-area-inset-right, 0);
    z-index: 1000;
    padding: calc(15px + env(safe-area-inset-bottom, 0)) 10px 20px; /* unten extra Platz */
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    border-radius: 15px 15px 0 0;
    max-width: 100vw;
    width: 100vw;
    box-sizing: border-box;
}

.btn {
  height: var(--button-height);
  padding: 0 var(--spacing-md);
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #eee;
  cursor: pointer;
  user-select: none;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
  min-width: 60px;
}

.btn:hover { 
  opacity: 0.9; 
  transform: translateY(-1px);
}

.btn:active { 
  transform: translateY(1px); 
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

/* Button-Varianten */
.btn--gold { background: linear-gradient(#f6d365, #f2b705); color: #000; border-color: #b88800; }
.btn--red { background: linear-gradient(#ff9a9e, #ff4d4d); color: #fff; border-color: #b02e2e; }
.btn--blue { background: linear-gradient(#a0c4ff, #4682b4); color: #fff; border-color: #2f6b9a; }
.btn--black { background: #222; color: #fff; border-color: #000; }
.btn--white { background: #fff; color: #000; border: 2px solid #bbb; }
.btn--green { background: #8fd694; color: #000; border-color: #2e9a3a; }

.btn--undo {
  background: #fff;
  border: 2px dashed #666;
  font-weight: 700;
}

/* Button-Layout - KORRIGIERT */
#inputButtons {
  display: block;
}

.button-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
  width: 100%;
  overflow: hidden; /* Verhindert Überlauf */
}

.button-row:last-child {
  margin-bottom: 30px; /* z.B. extra Abstand */
}

.button-row .btn {
  flex: 1;
  min-width: 60px;
  max-width: 80px; /* Begrenzt maximale Breite */
  height: 50px;
  font-size: 20px;
  padding: 0 8px;
}

/* Spezielle Anpassung für die letzte Reihe mit 5 Buttons */
.button-row:last-child .btn {
  font-size: 18px;
  max-width: 65px; /* Etwas schmaler für 5 Buttons */
}

/* Toggle-Button */
#toggleControlsBtn {
  margin: 0 auto 20px;
  display: block;
  min-width: 80px;
  height: 40px;
  font-size: 20px;
  border-radius: 20px;
}

/* Zusammenfassung */
.summary {
  display: flex;
  gap: var(--spacing-md);
  align-items: center;
  margin-top: var(--spacing-md);
  flex-wrap: wrap;
}

.summary__box {
  border: 2px solid #000;
  padding: var(--spacing-sm);
  min-width: 140px;
  text-align: center;
  font-weight: bold;
  background: #fff;
}

/* Transfer Box */
.transfer-box {
  border: 3px solid #000;
  padding: 6px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

#schusszettel-footer {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0);
    left: env(safe-area-inset-left, 0);
    right: env(safe-area-inset-right, 0);
    width: auto; /* nicht 100%, damit die Insets wirken */
    padding: 8px;
    font-size: 12px;
    color: #555;
    text-align: center;
    background: #f8f8f8;
    border-top: 1px solid #ccc;
    z-index: 1000;
    box-sizing: border-box;
}

#schusszettel-footer a {
    color: #033780;
    text-decoration: none;
}

#schusszettel-footer a:hover {
    text-decoration: underline;
}

.alert-success {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success span.haken {
  font-size: 16px;
}

/* Responsive Design - KORRIGIERT */
@media (max-width: 600px) {
  .sheet th, .sheet td { padding: 4px; font-size: 12px; }
  .input-field--narrow { width: 130px; }
  .summary__box { min-width: 110px; }
  
  .controls {
    padding: 20px 15px;
    border-radius: 20px 20px 0 0;
  }
  
  #toggleControlsBtn {
    height: 45px;
    font-size: 22px;
    margin-bottom: 25px;
    min-width: 100px;
    border-radius: 25px;
  }
  
  .button-row {
    gap: 6px;
    margin-bottom: 15px;
  }
  
  .button-row .btn {
    height: 55px;
    font-size: 22px;
    min-width: 55px;
    max-width: 75px;
    padding: 0 4px;
  }
  
  .button-row:last-child .btn {
    font-size: 20px;
    max-width: 60px;
  }
}

@media (max-width: 420px) {
  html { font-size: 13px; }
  .col-arrow { width: 11%; }
  .col-sum3 { width: 14%; }
  
  .controls {
    padding: 15px 8px;
  }
  
  .button-row {
    gap: 4px;
  }
  
  .button-row .btn {
    height: 52px;
    font-size: 20px;
    min-width: 50px;
    max-width: 65px;
    padding: 0 2px;
  }
  
  .button-row:last-child .btn {
    font-size: 18px;
    max-width: 55px;
  }
}

@media (max-width: 360px) {
  .controls {
    padding: 15px 5px;
  }
  
  .button-row {
    gap: 2px;
  }
  
  .button-row .btn {
    height: 48px;
    font-size: 18px;
    min-width: 45px;
    max-width: 58px;
    padding: 0 1px;
  }
  
  .button-row:last-child .btn {
    font-size: 16px;
    max-width: 50px;
  }
}

/* Utility-Klassen */
.flex-spacer { flex: 1; }

#finalTotal { color: transparent; }