/*
 * Mobile Darstellung des Portals (Bootstrap-3-Seiten).
 * Greift nur unter 768 px - am Desktop ändert sich nichts.
 * Spec: docs/superpowers/specs/2026-10-05-portal-mobil-design.md
 *
 * Bausteine für Views:
 *   table.m-cards          Tabelle wird zu Karten
 *   th.m-primary           Hauptzeile der Karte (fett, ohne Beschriftung)
 *   th.m-hide              Spalte mobil ausblenden
 *   th.m-actions           Knopfzeile unten in der Karte
 *   th.m-check             Auswahl-Checkbox rechts oben
 *   th[data-m-label]       abweichende Beschriftung nur für die Karte
 *   table.m-cards.m-compact  kompakte Karte für lange Protokolle: Hauptzeile oben,
 *                          übrige Zellen klein in einer Zeile, ohne Beschriftungen
 * mobile.js überträgt Text und m-*-Klassen des <th> auf die Zellen.
 */

.m-only { display: none !important; }

@media (max-width: 767px) {

  .m-only { display: block !important; }

  /* ---------- Modals im Vollbild ---------- */
  .modal { padding: 0 !important; overflow: hidden !important; }

  .modal .modal-dialog,
  .modal.modal-glass .modal-dialog {
    width: 100% !important;
    max-width: none !important;
    height: 100%;
    margin: 0 !important;
  }

  .modal .modal-content,
  .modal.modal-glass .modal-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* !important gegen tag-input.css (`.modal-body { overflow: visible !important }`) */
  .modal .modal-content > .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 12px 15px 0; /* seitlich 15 wie Bootstraps .row-Rand; unten 0: sonst klebt die Fußleiste über dem Rand */
  }

  /* Views, die den Modal-Inhalt in ein <form> fassen: das Formular übernimmt die Flex-Spalte */
  .modal .modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }

  .modal .modal-content > form > .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .modal .modal-content > form > .modal-footer,
  .modal .modal-content > .modal-footer {
    flex: 0 0 auto;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  /* Fußleiste aus _global/modal_footer.php steht im Body und bleibt unten sichtbar */
  .modal .modal-body .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 12px -15px 0;
    background: #fff;
    box-shadow: 0 -1px 0 #e5e7eb;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .modal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
  }

  .modal-footer > .btn,
  .modal-footer > [class*="btn-glass"] {
    flex: 1 1 auto;
    min-height: 44px;
    margin: 0 !important;
  }

  .modal-footer > .modal-message { flex-basis: 100%; margin: 0; }

  /* Kurze Rückfragen (BootstrapDialog, .modal-sm) bleiben ein schwebendes Fenster -
     im Vollbild stünde „Wirklich löschen?“ allein auf einer weißen Seite */
  .modal.bootstrap-dialog { overflow-y: auto !important; }

  .modal.bootstrap-dialog .modal-dialog,
  .modal .modal-dialog.modal-sm {
    width: auto !important;
    height: auto;
    margin: 15vh 12px 20px !important;
  }

  .modal.bootstrap-dialog .modal-content,
  .modal .modal-dialog.modal-sm .modal-content {
    height: auto;
    border-radius: 8px !important;
  }

  .modal-draggable .modal-header { cursor: default; }

  /* Kopf der Detailansichten: Titel und Nummer umbrechen statt abschneiden */
  .cd-header-title { flex-wrap: wrap; row-gap: 2px; }
  .cd-modal-header { padding-bottom: 12px; margin-bottom: 12px; min-width: 0; }
  .cd-modal-header > * { min-width: 0; }

  /* FLINT-Chatknopf läge sonst über Speichern/Schließen */
  body.modal-open .flint-launcher { display: none !important; }
  /* … und auf Seiten mit fester Speicherleiste über „Speichern“ - dann rückt er darüber */
  body:has(.ts-submit-bar, .es-submit-bar, .vc-savebar, .le-save-bar, .be-save-bar) .flint-launcher { bottom: 88px !important; }

  /* ---------- Reiter wischbar ---------- */
  .nav-pills:not(.nav-stacked),
  .nav-tabs:not(.nav-stacked) {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav-pills:not(.nav-stacked)::-webkit-scrollbar,
  .nav-tabs:not(.nav-stacked)::-webkit-scrollbar { display: none; }

  .nav-pills:not(.nav-stacked) > li,
  .nav-tabs:not(.nav-stacked) > li {
    float: none;
    flex: 0 0 auto;
  }

  .nav-pills:not(.nav-stacked) > li > a,
  .nav-tabs:not(.nav-stacked) > li > a {
    white-space: nowrap;
    padding: 10px 12px;
  }

  /* ---------- Tabellen ---------- */
  .m-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 15px;
  }

  .m-scroll > table { margin-bottom: 0; }

  #result-table thead th { top: 56px; }

  /* Karten */
  table.m-cards,
  table.m-cards > tbody,
  table.m-cards > tbody > tr,
  table.m-cards > tbody > tr > td {
    display: block;
    width: 100% !important;
  }

  table.m-cards { border: 0; background: transparent; }

  table.m-cards > thead { display: none; }

  /* Bootstraps .table-responsive rahmt mobil ein - um Karten herum überflüssig */
  .table-responsive:has(> table.m-cards) { border: 0; overflow: visible; }

  table.m-cards > tbody > tr {
    position: relative;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff !important;
    border: 1px solid #e2e5e9;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  }

  table.m-cards > tbody > tr > td {
    padding: 4px 0 !important;
    border: 0 !important;
    text-align: left !important;
    white-space: normal !important;
    background: transparent !important; /* gestreifte Zellen färbten die Karte innen grau */
  }

  table.m-cards > tbody > tr > td[data-label]:not([data-label=""]):not(.m-primary):not(.m-actions):not(.m-check)::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: #8a919c;
  }

  table.m-cards > tbody > tr > td.m-primary { font-size: 15px; }

  table.m-cards > tbody > tr > td.m-hide,
  table.m-cards > tbody > tr > td.hidden-xs { display: none !important; }

  table.m-cards > tbody > tr > td.m-check {
    position: absolute;
    top: 10px;
    right: 12px;
    width: auto !important;
    padding: 0 !important;
  }

  table.m-cards > tbody > tr > td.m-check input[type="checkbox"] { width: 22px; height: 22px; }

  table.m-cards > tbody > tr > td.m-actions {
    margin-top: 6px;
    padding-top: 8px !important;
    border-top: 1px solid #eef0f2 !important;
  }

  table.m-cards > tbody > tr > td.m-actions .dropdown-toggle { width: 100%; }

  /* Kompakte Karten (Protokolle mit vielen Zeilen, z. B. Live-Einlass) */
  table.m-cards.m-compact > tbody > tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 12px;
    margin-bottom: 6px;
    padding: 8px 12px;
  }

  table.m-cards.m-compact > tbody > tr > td {
    width: auto !important;
    padding: 0 !important;
    font-size: 12px;
    color: #5f6b7a;
  }

  table.m-cards.m-compact > tbody > tr > td::before { display: none !important; }

  table.m-cards.m-compact > tbody > tr > td.m-primary {
    order: -1;
    flex-basis: 100%;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
  }

  /* Platz für die Checkbox rechts oben */
  table.m-cards > tbody > tr > td.m-check ~ td.m-primary { padding-right: 34px !important; }

  /* ---------- Formulare ---------- */
  /* Kein iOS-Zoom beim Antippen: regelt maximum-scale=1 im Viewport-Tag
     (_global/header.php, nur iOS) - die Schriftgröße der Felder bleibt */

  .form-control:not(textarea):not([multiple]):not([size]) { height: 40px; }

  .form-horizontal .control-label {
    padding-top: 0;
    margin-bottom: 4px;
    text-align: left;
  }

  .input-group[style*="width"],
  .form-control[style*="width"],
  select[style*="width"],
  input[style*="width"] { max-width: 100%; }

  /* ---------- Bedienung ---------- */
  /* Mindesthöhe nur mit Flex-Zentrierung: ein .btn ist inline-block, mit min-height allein
     klebte der Inhalt oben. gap ersetzt das Leerzeichen zwischen Icon und Text, das Flex
     am Rand eines Elements weglässt */
  .btn:not(.btn-xs) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35em;
    min-height: 40px;
  }

  .btn-block:not(.btn-xs) { display: flex; }

  .dropdown-menu > li > a { padding-top: 10px; padding-bottom: 10px; }

  .pagination > li > a,
  .pagination > li > span { min-width: 40px; padding: 9px 12px; }

  /* Knopfreihen (z. B. Adress-Übernahme im Kundenprofil) umbrechen */
  .cd-address-switch { display: flex; flex-wrap: wrap; gap: 8px; }
  .cd-address-switch > .btn { white-space: normal; margin: 0; }

  .modal .dropdown-menu { max-width: calc(100vw - 24px); }

  /* ---------- Filter-Klappbereich ---------- */
  .m-filter-toggle {
    display: flex !important;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    margin-bottom: 10px;
    text-align: left;
  }

  .m-filter-count {
    display: none;
    padding: 2px 8px;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
  }

  .m-filter-toggle .fas.m-filter-chevron { margin-left: auto !important; transition: transform .15s; }
  .m-filter-toggle.active .m-filter-chevron { transform: rotate(180deg); }

  .m-collapsible:not(.m-open) { display: none !important; }

  /* Alte Inline-Filter (Rechnungsjournal): Bootstrap stapelt sie mobil ohne Abstand */
  #search-filter.form-inline .form-control,
  #search-filter.form-inline select { margin-bottom: 8px; }

  /* Filterkopf klebt am Desktop unter der 80-px-Leiste - mobil nicht nötig */
  .modern-filter-bar .filter-header { position: static; }

  /* Knöpfe im Filterkopf (Kunden anlegen, Export, Alle öffnen/schließen) umbrechen */
  .modern-filter-bar .filter-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

  /* ---------- Aufträge ---------- */
  /* Beschriftung über dem Feld - 130 px daneben ließen lange Labels ins Feld laufen */
  .cd-form-row { flex-direction: column; align-items: stretch; }
  .cd-form-label { flex: 0 0 auto; padding-top: 2px; margin-bottom: 4px; }
  .cd-form-value { min-width: 0; }

  .cd-actions-group {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .cd-actions-group > .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    margin: 0 !important;
    white-space: normal;
  }

  /* ---------- Ticketsuche ---------- */
  #bulk-storno-bar {
    position: fixed !important;
    top: auto !important;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1030 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    padding-right: 84px !important; /* rechts sitzt der FLINT-Chatknopf */
  }
}
