/* bpm-mobile.css — Handy-Bausteine (Phase 2 des Handy-Konzepts, .planning/KONZEPT-MOBIL-DESIGN-2026-11-05.md).
 * Nur Klassen im Namensraum m-, nur Handy, kein [style*=]. Animation nur transform/opacity, reduced-motion beachtet.
 *
 * Baustein 1: m-filter (Filter-Sheet): ein Panel mit der Klasse m-filter-panel wird am Handy zum Bottom-Sheet. */
.m-sheet-head, #m-sheet-backdrop { display: none; }

@media (max-width: 768px) {
  :root { --m-ease: cubic-bezier(0.23, 1, 0.32, 1); }

  #m-sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: var(--z-modal);
    opacity: 0; pointer-events: none;
    transition: opacity 200ms ease-out;
  }
  body.m-sheet-open #m-sheet-backdrop { opacity: 1; pointer-events: auto; }
  body.m-sheet-open { overflow: hidden; }
  body.m-sheet-open #mobile-fab { display: none !important; }

  .m-filter-panel {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: calc(var(--z-modal) + 1);
    max-height: 82vh; max-height: 82dvh;
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
    padding: 0 16px calc(16px + env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    border-top: 1px solid var(--border) !important;
    box-sizing: border-box;
  }
  .m-filter-panel.is-open { animation: m-sheet-in 280ms var(--m-ease) both; }

  /* Im Sheet: Zeilen schrumpfen nicht, Pillen umbrechen statt seitlich zu scrollen (alles auf einen Blick). */
  .m-filter-panel > * { flex-shrink: 0; }
  .m-filter-panel .mob-scroll-pills, .m-filter-panel .filter-pills, .m-filter-panel .flex-row-wrap, .m-filter-panel > div {
    flex-wrap: wrap !important; overflow: visible !important;
  }
  .m-filter-panel select { width: 100% !important; }

  .m-sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1;
    background: var(--surface);
    padding: 22px 0 10px;
  }
  .m-sheet-head::before {
    content: ""; position: absolute; top: 8px; left: 50%;
    width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--border);
  }
  .m-sheet-title {
    font-family: var(--font-h); font-size: var(--t-lg);
    letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold);
  }
  .m-sheet-done { min-height: 40px; padding: 0 18px; }
}

@keyframes m-sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .m-filter-panel.is-open { animation: none; }
  #m-sheet-backdrop { transition: none; }
}

/* Baustein 2: m-editor-bar (feste Aktionsleiste im Dokument-Editor). Sitzt direkt ueber der unteren Navigation (52 px).
 * Gleicher Schwellwert wie das Ausblenden der Knopf-Gruppen im Kopf (max-width 900). */
.m-editor-bar { display: none; }

@media (max-width: 900px) {
  .m-editor-bar {
    display: flex; align-items: stretch; gap: 8px;
    position: fixed; left: 0; right: 0;
    bottom: calc(52px + env(safe-area-inset-bottom));
    z-index: 5;
    padding: 8px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
  }
  .m-editor-bar .m-bar-primary {
    flex: 1 1 auto; min-width: 0; width: auto; margin: 0;
    min-height: 44px; padding: 0 14px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-editor-bar .m-bar-more {
    flex: 0 0 auto; min-width: 52px; min-height: 44px; padding: 0 16px; margin: 0;
    font-size: var(--t-lg);
  }
  .m-editor-bar .m-bar-more:only-child { flex: 1 1 auto; font-size: inherit; }
  /* Beim Anlegen sitzt "Speichern" in der Leiste, nicht zusaetzlich im Kopf. */
  .dok-topbar-actions .dok-save-zone { display: none; }
  /* Inhalt endet nicht hinter der Leiste. */
  .dok-wrap { padding-bottom: 72px; }
  /* Der gelbe Plus-Knopf wuerde die Leiste verdecken. */
  body:has(.m-editor-bar) #mobile-fab { display: none !important; }
}

/* Baustein 4a: m-detail (Dokument-Kopf). Die Portal-Kacheln standen am Handy nebeneinander (je min. 220 px) und
 * ueberlappten sich - jetzt eine Spalte in voller Breite, jede Kachel darf schrumpfen. */
@media (max-width: 900px) {
  .dok-topbar-right { flex-direction: column; flex-wrap: nowrap; }
  .dok-topbar-right > .dok-portal-card { flex: 0 0 auto; width: 100%; min-width: 0; box-sizing: border-box; }
  .dok-topbar-right .dok-portal-card-t { overflow-wrap: break-word; }
}

/* Baustein 3: m-table (Tabellen mit Eingabefeldern, class table-stack, z. B. Einstellungen > Preise).
 * Beschriftung oben ueber die volle Breite, darunter Feld und Hinweis; Feld nicht mehr auf 45 px gequetscht. */
@media (max-width: 768px) {
  .table-stack td:has(input, select, textarea) { flex-wrap: wrap; align-items: center; row-gap: 6px; }
  .table-stack td:has(input, select, textarea)::before { flex: 1 0 100%; min-width: 0; }
  .table-stack td:has(input, select, textarea) input,
  .table-stack td:has(input, select, textarea) select { width: auto !important; flex: 0 1 132px; min-width: 0; max-width: none; }
  .table-stack td .ep-brutto { flex: 1 1 140px; min-width: 0; white-space: normal; margin: 0; }
}

/* Baustein 3b: Wochenraster (Kennenlerngespraech, bpm-kennenlern.js). Quelle: Zeilen = Wochentage, Zellen = Stunden 8 bis 20.
 * Am Handy per Grid mit Spaltenfluss gedreht: Tage werden Spalten, Stunden Zeilen (erste Zeile = Tageskopf, erste Spalte = Stunden).
 * Nur Darstellung, DOM und Speicherlogik bleiben unveraendert. 13 = Anzahl KG_STUNDEN. */
@media (max-width: 768px) {
  .kg-raster { overflow: visible; }
  .kg-raster table {
    display: grid; grid-auto-flow: column;
    grid-template-rows: auto repeat(13, 44px);
    grid-template-columns: 36px repeat(7, minmax(0, 1fr));
    gap: 4px; border-spacing: 0; min-width: 0; width: 100%;
  }
  .kg-raster tbody, .kg-raster tr { display: contents; }
  .kg-raster th, .kg-raster td { display: flex; align-items: center; justify-content: center; min-width: 0; }
  .kg-raster th[scope="row"] { justify-content: center; }
  .kg-zelle { width: 100%; height: 100%; }
}

/* Baustein 4b: Verknuepfte Dokumente im Dokument-Kopf. Gruppe, Knopfreihe und Chips duerfen umbrechen (lange Status-Schilder
 * wie "Angebotsfrist abgelaufen" sprengten sonst die Breite um bis zu 20 px). */
@media (max-width: 900px) {
  .dok-topbar-actions .dok-cluster { flex-wrap: wrap; min-width: 0; }
  .dok-topbar-actions .dok-cluster-label { flex: 1 0 100%; width: auto; min-width: 0; }
  .dok-topbar-actions .dok-cluster-btns { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  .dok-topbar-actions .dok-chip { flex-wrap: wrap; max-width: 100%; min-width: 0; white-space: normal; }
}

/* Baustein 5: Dashboard-Kopf. Der Knopf "Auswertung" ist ein Flex-Container ohne align-items; bei 44 px Mindesthoehe klebte der
 * Text oben. Gemessen ueber 10 Ansichten: der einzige Knopf mit diesem Zustand. */
@media (max-width: 900px) {
  .dash-kopf-rechts > button { align-items: center; justify-content: center; }
}

/* Baustein 6: Zeilen mit Aktionsknopf (.asl-row, Admin-Einstellungen). Der Knopf wurde vom Flex-Layout zusammengedrueckt
 * (Text 67 px in 59 px). Feste Mindestbreite, schrumpft nicht; die Beschreibung davor darf stattdessen kuerzen. */
@media (max-width: 900px) {
  .asl-row > .btn-sx { flex: 0 0 auto; min-width: 96px; white-space: nowrap; }
  .asl-row > :not(.btn-sx):not(:first-child) { min-width: 0; }
}

/* Baustein 7: Admin-Einstellungen. Aktionsknoepfe (.card-actions) gleich breit, Beschreibungszeilen (.asl-desc) umbrechen statt
 * mit Ellipse zu kuerzen, serverseitiger Papierkorb als Karten (Tabelle war 657 px breit, Aktionen nur per Wischen erreichbar).
 * Reihenfolge der Karte: Typ + Datum, Nummer, Kunde, Aktionen. */
@media (max-width: 900px) {
  .admin-tab-content .card-actions > button { flex: 1 1 calc(50% - 6px); min-width: 140px; justify-content: center; }
  .asl-row .asl-desc { white-space: normal; overflow-wrap: break-word; text-overflow: clip; overflow: visible; }
  #papierkorb-list .set-table-wrap { overflow: visible; }
  #papierkorb-list .set-table { display: block; width: 100%; min-width: 0; border: 0; }
  #papierkorb-list .set-table thead { display: none; }
  #papierkorb-list .set-table tbody { display: block; }
  #papierkorb-list .set-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px;
    padding: 12px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  }
  #papierkorb-list .set-table td { display: block; padding: 0; border: 0; min-width: 0; text-align: left; }
  #papierkorb-list .set-table td:nth-child(1) { grid-column: 1; grid-row: 1; color: var(--muted); }
  #papierkorb-list .set-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  #papierkorb-list .set-table td:nth-child(4) { grid-column: 2; grid-row: 1; text-align: right; }
  #papierkorb-list .set-table td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
  #papierkorb-list .set-table td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; margin-top: 6px; }
  #papierkorb-list .set-row-actions { display: flex; gap: 8px; }
  #papierkorb-list .set-row-actions .btn-sx { flex: 1 1 auto; }
}

/* Baustein 8: Dokumentenkarte. Typ und Nummer duerfen umbrechen; vorher wurde die Nummer langer Typen
 * (Auftragsbestaetigung AB-202...) mit Ellipse abgeschnitten. */
@media (max-width: 768px) {
  .dc-meta { flex-wrap: wrap; gap: 2px 8px; overflow: visible; }
  .dc-nummer { overflow: visible; text-overflow: clip; }
}

/* Baustein 9 (Handy-Pruefung 05.11.): Vermittlungs-Karten, Status-Leiste der Anfrage, Schilder im Auftragskopf.
 * a) Vermittlungen: die Mittelspalte (flex:1;min-width:0) schrumpfte auf 0 und lag unter dem Betrag; die Zeile bricht jetzt um:
 *    Pfeil + Datum, dann Text, Betrag und Status je volle Breite.
 * b) .wf-pb-step: fuenf Schritte brauchten 77-93 px bei 77 px Platz (ABGERECHNET links abgeschnitten); ohne Buchstabenabstand
 *    und mit Breite nach Inhalt passt es in 386 px.
 * c) .dok-auftrag-chip war ein Block mit 44 px Mindesthoehe, der Text klebte oben. */
@media (max-width: 768px) {
  .verm-zeile { flex-wrap: wrap !important; gap: 6px 12px !important; }
  .verm-zeile .verm-text { flex: 1 1 100% !important; order: 3; }
  .verm-zeile .verm-betrag { flex: 1 1 100% !important; order: 4; text-align: left !important; min-width: 0 !important; }
  .verm-zeile .verm-status { flex: 1 1 100% !important; order: 5; flex-direction: row !important; flex-wrap: wrap; justify-content: flex-start !important; align-items: center !important; min-width: 0 !important; text-align: left !important; }
  .wf-pb-step { flex: 1 1 auto !important; min-width: 0; letter-spacing: 0 !important; padding-left: 2px !important; padding-right: 2px !important; gap: 2px !important; white-space: nowrap; }
  .dok-auftrag-chip { display: inline-flex !important; align-items: center; }
}

/* Baustein 10 (Handy-Pruefung 05.11.): Einstellungen > Preise.
 * .st-stufen war ein 3-Spalten-Raster, in dem die Trennpunkte eigene Zellen belegten (Zickzack); jetzt Fliesstext mit Einheiten.
 * .abf-stufe-row: Eingaben 72 px, damit das Loeschen-Kreuz in der Zeile bleibt.
 * .ep-hp-sub: Zusatztext beim Homepage-Richtwert bekam 0 px Breite und ragte als Streifen heraus; eigene Zeile. */
@media (max-width: 768px) {
  .st-stufen { display: block; line-height: 1.7; }
  .st-stufen .st-stufe-anzeige { display: inline-block; max-width: 100%; }
  .abf-stufe-row { flex-wrap: nowrap; gap: 8px; align-items: center; }
  .abf-stufe-row .w-xs { flex: 0 0 72px; width: 72px; min-width: 0; }
  .abf-stufe-row .set-icon-btn { flex: 0 0 44px; }
  .table-stack td:has(.ep-hp-wert) { flex-wrap: wrap; row-gap: 2px; }
  .table-stack .ep-hp-sub { flex: 1 1 100%; order: 3; text-align: left; white-space: normal; }
}

/* Baustein 11 (Handy-Pruefung 05.11.): Summenleiste der Ausgaben. Betraege bleiben einzeilig (das Euro-Zeichen stand allein in der
 * Folgezeile), die drei Betraege verteilen sich ueber die Kartenbreite, Schrift 19 px (wie im festen Kopf). */
@media (max-width: 768px) {
  .stat-bar strong { white-space: nowrap; }
  .stat-bar > div[style*="margin-left:auto"] { margin-left: 0 !important; width: 100%; justify-content: space-between; }
  .stat-bar > div[style*="margin-left:auto"] strong { font-size: 19px !important; }
  .stat-bar > div[style*="margin-left:auto"] > div[style*="padding:0 0 0 24px"] { padding-left: 12px !important; }
}

/* Baustein 12 (Handy-Pruefung 05.11.): a) .set-toggle mit Test-Knoepfen: Knoepfe umbrechen unter den Text (Text war auf 55 % Breite
 * gequetscht). b) Geschwindigkeits-Knoepfe (.card-actions .btn-ghost) drei gleich breit. c) Automatik-Uebersicht: jede Zeile war ein
 * eigenes Raster 2fr 3fr auto, die Knopfspalte wanderte je Zeile; jetzt Regel + Ausloeser links, Knopf fest 124 px rechts. */
@media (max-width: 768px) {
  .set-toggle:has(> .flex-gap-6-center) { flex-wrap: wrap; }
  .set-toggle > .flex-gap-6-center { flex: 1 1 100%; padding-left: 36px; }
  .card-actions > .btn-sx.btn-ghost { flex: 1 1 calc(33.3% - 8px); min-width: 0; justify-content: center; padding-left: 6px; padding-right: 6px; white-space: nowrap; gap: 4px; }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"]:has(button) {
    grid-template-columns: minmax(0, 1fr) 124px !important; grid-template-areas: "r k" "a k"; gap: 2px 12px !important;
  }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"]:has(button) > :nth-child(1) { grid-area: r; font-weight: 600; }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"]:has(button) > :nth-child(2) { grid-area: a; color: var(--muted); }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"]:has(button) > :nth-child(3) { grid-area: k; align-self: center; }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"] button { width: 100%; justify-content: center; white-space: nowrap; }
  #auto-tab-uebersicht div[style*="grid-template-columns:2fr 3fr auto"]:not(:has(button)) { display: none !important; }
}

/* Baustein 13 (Nachbesserung zu 10/12): #view-einstellungen .st-stufen (ID-Vorrang) setzte das Raster wieder; hier mit gleichem Vorrang.
 * Gleiches fuer den Richtwert-Zusatztext, falls dort eine ID-Regel gilt. */
@media (max-width: 768px) {
  #view-einstellungen .st-stufen { display: block; line-height: 1.7; }
  #view-einstellungen .st-stufen .st-stufe-anzeige { display: inline-block; max-width: 100%; }
  #view-einstellungen .table-stack td:has(.ep-hp-wert) { flex-wrap: wrap; row-gap: 2px; }
  #view-einstellungen .table-stack .ep-hp-sub { flex: 1 1 100%; order: 3; text-align: left; white-space: normal; }
}

/* Baustein 14 (Handy-Pruefung 05.11., Reste): Titel in der oberen Leiste der Detailseiten mit Vor-Zurueck entfaellt (war auf
 * einen Buchstaben gekuerzt); abgeschnittene Eingabetexte enden mit Ellipse; Suchfeld im Postfach mit sichtbarem Platzhalter
 * (war transparent); Knopfreihen (.card-actions) in den Einstellungen gleich breit, ausser den Geschwindigkeits-Knoepfen. */
@media (max-width: 768px) {
  #topbar:has([id^="topbar-"][id$="-prev"]) #topbar-title { display: none; }
  input, textarea { text-overflow: ellipsis; }
  #postfach-search::placeholder { color: var(--muted) !important; opacity: 1 !important; -webkit-text-fill-color: var(--muted) !important; }
  #view-einstellungen .card-actions > button:not(.btn-ghost) { flex: 1 1 calc(50% - 6px); min-width: 140px; justify-content: center; }
}
