/* mobile.css — Gemeinsame Mobile-Optimierung für alle Seiten mit Sidebar.
   Wird per <link> in jede Seite eingebunden, damit Anpassungen nur an
   EINER Stelle gemacht werden müssen statt in 20+ Dateien einzeln.
   sidebar.js fügt automatisch den Hamburger-Button und die Overlay-Logik hinzu. */

/* ---- Hamburger-Button: nur auf schmalen Bildschirmen sichtbar ---- */
#mobileMenuToggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line, #e1e5f7);
  background: var(--surface, #fff);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#mobileMenuToggle svg { width: 20px; height: 20px; color: var(--ink, #1a1d29); }

#mobileSidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,20,25,.4);
  z-index: 150;
}
#mobileSidebarOverlay.open { display: block; }

@media (max-width: 860px) {
  body { display: block !important; }

  #mobileMenuToggle { display: flex; }

  .sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    height: 100vh !important;
    z-index: 160;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }

  .app-main {
    padding: 70px 16px 24px !important;
    max-width: 100% !important;
    width: 100%;
    box-sizing: border-box;
  }

  /* Toolbar-Zeilen: Suchfeld/Filter/Buttons untereinander statt nebeneinander */
  .toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
  }
  .toolbar > div {
    flex-wrap: wrap;
    width: 100%;
  }
  .toolbar h2 { margin-bottom: 4px; }
  .search-input, .toolbar select, .toolbar input {
    width: 100% !important;
    box-sizing: border-box;
  }
  .toolbar > div > * { flex: 1 1 auto; min-width: 0; }
  .toolbar a.btn, .toolbar button.btn { flex: 1 1 100%; text-align: center; }

  /* Stat-Karten (Dashboard): 2 pro Zeile statt 4 nebeneinander */
  #stats, .stats-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* Tabellen: horizontal scrollbar statt Layout-Bruch */
  #tableWrap, .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 640px; }

  /* Modale: praktisch Vollbild auf Mobile, mit Innenabstand */
  .modal-overlay { padding: 12px; align-items: flex-start !important; }
  .modal, .modal-overlay .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    margin-top: 12px;
  }

  /* Formulare: zweispaltige Grids (.row2 usw.) werden einspaltig */
  .row2, .row3, .item-row {
    grid-template-columns: 1fr !important;
  }

  /* Item-Zeilen (Rechnungs-/Angebotspositionen): auf Mobile als Karte statt enge Tabellenzeile */
  .item-row {
    border: 1px solid var(--line, #e1e5f7);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px !important;
    background: var(--surface2, #f4f6fe);
  }

  .row-actions { justify-content: flex-start !important; }

  /* Grössere Touch-Ziele */
  button, .btn, select, input, a.btn { min-height: 40px; }
  .row-actions button, .row-actions a, .row-actions select { min-height: 34px; }

  /* Live-Vorschau (Rechnung/Angebot/Lieferschein/Abo/Gutschrift/Brief):
     auf kleinen Bildschirmen ausblenden — zu wenig Platz fuer zwei Spalten.
     Das Formular nimmt dann die volle Breite ein.

     ACHTUNG: Frueher stand hier "div:has(#livePreview)". Das trifft aber
     JEDEN uebergeordneten Container, der die Vorschau enthaelt — also auch
     #splitContainer mit dem gesamten Formular. Auf dem Handy verschwand
     dadurch die ganze Bearbeitungsmaske; Belege liessen sich weder erfassen
     noch aendern. Deshalb hier gezielt nur die Vorschauspalte. */
  #livePreview,
  #previewColumn,
  #resizeHandle {
    display: none !important;
  }
  #splitContainer {
    display: block !important;
  }
  #formColumn {
    flex: 1 1 100% !important;
    padding-right: 0 !important;
  }
}

@media (max-width: 480px) {
  #stats, .stats-row { grid-template-columns: 1fr !important; }
  .app-main { padding: 66px 12px 20px !important; }
}
