/* ════════════════════════════════════════════════════════════════════
 *  VERLAG-OS — MOBILE UTILITIES   (v0.19.7.0)
 * ════════════════════════════════════════════════════════════════════
 *
 *  Familie-Modul, portiert aus ImmoOS v6.5.0+ (io-m-*).
 *  Prefix umbenannt von `io-m-` auf `m-`, damit das Modul produkt-
 *  neutral in allen Familie-OS-Branchen (GHOS, Verlag-OS, ImmoOS, OS
 *  Suite) ohne App-Lock-in verwendet werden kann. Companion-JS:
 *  `os-mobile.js` (globales Objekt `osMobile`).
 *
 *  Design-Tokens stammen aus BrandingService::cssVariablesInline() —
 *  --c-primary, --c-secondary, --c-text, --c-bg, --font-body. Damit
 *  passt sich das Modul automatisch an die jeweilige Verlags-CI an,
 *  ohne dass eigene Farbwerte dupliziert werden.
 *
 *  Breakpoints (synchron mit site.css):
 *    Phone:   ≤ 767px
 *    Tablet:  768px – 1024px
 *    Desktop: ≥ 1025px
 *
 *  Aufbau:
 *    1. iOS-Autozoom-Fix (global, unkritisch)
 *    2. Bottom-Sheet         .m-sheet
 *    3. Drawer (Off-Canvas)  .m-drawer
 *    4. Sticky Action-Bar    .m-sticky-bar
 *    5. Tabelle als Karten   .m-table-cards
 *    6. Touch-Target         .m-touch-target
 *    7. Safe-Area            .m-safe-*
 *    8. Visibility-Helpers   .m-only-mobile / .m-hide-mobile etc.
 *    9. Form-Touch-Container .m-form
 *
 * ════════════════════════════════════════════════════════════════════ */


/* ── 1. iOS-Autozoom-Fix ──────────────────────────────────────────────
   Safari zoomt beim Fokus eines Input mit font-size < 16px hinein und
   zoomt nie wieder zurück, bis der User pinch-out macht. Globaler Fix:
   alle Form-Inputs mindestens 16px auf Touch-Geräten. Unsichtbar auf
   Desktop. */
@media (max-width: 767px) {
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="password"], input[type="search"],
  input[type="url"], input[type="date"], input[type="datetime-local"],
  input[type="time"], textarea, select {
    font-size: 16px;
  }
}


/* ── 2. Bottom-Sheet ──────────────────────────────────────────────────
   Slide-up-Sheet von unten, mit Backdrop. Wird per JS geöffnet:
     osMobile.openSheet('#sheetId')                  (deklarativ)
     osMobile.openSheet({ title, options:[...] })    (programmatisch)
   Backdrop schließt per Tap, ESC schließt per Tastatur.
*/
.m-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.m-sheet-backdrop.m-is-open {
  opacity: 1;
  pointer-events: auto;
}

.m-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: var(--c-bg, #fff);
  color: var(--c-text, #1a1a1a);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  padding: 0.75rem 1rem calc(env(safe-area-inset-bottom, 0) + 1rem);
  font-family: var(--font-body, system-ui, sans-serif);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.m-sheet.m-is-open {
  transform: translateY(0);
}

/* Drag-Handle oben am Sheet — rein optisch, kein echter Drag-Gesture
   (das wäre eine separate Erweiterung). */
.m-sheet::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  background: #d1d5db;
  border-radius: 999px;
  margin: 0 auto 0.75rem;
}

.m-sheet-title {
  font-family: var(--font-heading, Georgia, serif);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  padding: 0 0.25rem;
  color: var(--c-text, #1a1a1a);
}

/* Option-Zeile im Sheet: Icon links, Label + Hint rechts, ganze Zeile
   klickbar. Touch-Target ≥ 56px für komfortable Daumenführung. */
.m-sheet-option {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.85rem 0.25rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  text-align: left;
  min-height: 56px;
  transition: background 0.12s ease;
}
.m-sheet-option:last-child { border-bottom: 0; }
.m-sheet-option:hover,
.m-sheet-option:focus-visible {
  background: #f8fafc;
  outline: none;
}
.m-sheet-option--danger { color: #b91c1c; }
.m-sheet-option--danger:hover { background: #fef2f2; }

.m-sheet-option-icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-primary, #a31c2c);
}
.m-sheet-option-icon svg {
  width: 24px;
  height: 24px;
}

.m-sheet-option-text {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.m-sheet-option-label {
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.25;
}
.m-sheet-option-hint {
  font-size: 0.82rem;
  color: #6b7280;
  line-height: 1.3;
}

.m-sheet-cancel {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.85rem;
  background: #f1f5f9;
  border: 0;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--c-text, #1a1a1a);
  cursor: pointer;
  min-height: 44px;
}
.m-sheet-cancel:hover { background: #e2e8f0; }


/* ── 3. Drawer (Off-Canvas) ──────────────────────────────────────────
   Slide-in von links oder rechts. Vom Sheet unterscheidet sich der
   Drawer dadurch, dass er typischerweise eine längere Navigations-
   oder Filter-Hierarchie hält und volle Höhe einnimmt.
*/
.m-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.m-drawer-backdrop.m-is-open {
  opacity: 1;
  pointer-events: auto;
}

.m-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(85vw, 360px);
  z-index: 9999;
  background: var(--c-bg, #fff);
  color: var(--c-text, #1a1a1a);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
  padding: calc(env(safe-area-inset-top, 0) + 1rem) 1rem
          calc(env(safe-area-inset-bottom, 0) + 1rem);
  font-family: var(--font-body, system-ui, sans-serif);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.m-drawer--left {
  left: 0;
  transform: translateX(-100%);
  border-radius: 0 16px 16px 0;
}
.m-drawer--right {
  right: 0;
  transform: translateX(100%);
  border-radius: 16px 0 0 16px;
}
.m-drawer--left.m-is-open,
.m-drawer--right.m-is-open {
  transform: translateX(0);
}

.m-drawer-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 0.5rem);
  right: 0.5rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--c-text, #1a1a1a);
  font-size: 1.5rem;
  line-height: 1;
}
.m-drawer-close:hover { background: #f1f5f9; }


/* ── 4. Sticky Action-Bar ────────────────────────────────────────────
   Persistente Aktionsleiste am unteren Bildschirmrand. Nur auf Phone
   sichtbar — auf Tablet/Desktop steht der primäre CTA ohnehin im
   Lesefluss. Safe-Area-Bottom für iPhones mit Home-Indicator.
*/
.m-sticky-bar {
  display: none; /* Default: aus, wird per Phone-Breakpoint aktiviert */
}
@media (max-width: 767px) {
  .m-sticky-bar {
    display: flex;
    gap: 0.5rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    padding: 0.65rem 1rem calc(env(safe-area-inset-bottom, 0) + 0.65rem);
    background: var(--c-bg, #fff);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    /* Wird vom Verbraucher bei Bedarf um body-padding-bottom kompensiert,
       damit der Page-Content nicht von der Bar verdeckt wird. */
  }
  /* Body-Padding kompensiert Content-Verdeckung, opt-in via Body-Klasse.
     Verbraucher setzt `<body class="m-has-sticky-bar">` wenn nötig. */
  body.m-has-sticky-bar {
    padding-bottom: calc(env(safe-area-inset-bottom, 0) + 64px);
  }
}

.m-sticky-bar-btn {
  flex: 1 1 auto;
  padding: 0.85rem 1rem;
  background: var(--c-primary, #a31c2c);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.m-sticky-bar-btn:hover {
  filter: brightness(0.95);
  color: #fff;
  text-decoration: none;
}
.m-sticky-bar-btn--secondary {
  background: #f1f5f9;
  color: var(--c-text, #1a1a1a);
}
.m-sticky-bar-btn--secondary:hover {
  background: #e2e8f0;
  color: var(--c-text, #1a1a1a);
}


/* ── 5. Tabelle → Karten ─────────────────────────────────────────────
   `<table class="m-table-cards">` wird ≤767px zu einer Card-Liste
   umformatiert. Pflicht-Markup: jede `<td>` braucht ein `data-label`,
   das vor dem Wert als kleines Label angezeigt wird.
*/
@media (max-width: 767px) {
  .m-table-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .m-table-cards, .m-table-cards tbody, .m-table-cards tr, .m-table-cards td {
    display: block;
    width: 100%;
  }
  .m-table-cards tr {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.85rem;
    background: var(--c-bg, #fff);
  }
  .m-table-cards td {
    padding: 0.4rem 0;
    border: 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
  }
  .m-table-cards td:first-child {
    /* Erste Zelle als Card-Titel: links bündig, größer, ohne data-label */
    font-weight: 600;
    font-size: 1.05rem;
    padding-top: 0;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
  }
  .m-table-cards td:first-child::before { content: ""; }
  .m-table-cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: #6b7280;
    font-size: 0.85rem;
    font-weight: 500;
  }
}


/* ── 6. Touch-Target ─────────────────────────────────────────────────
   Auf Touch-Geräten (hover:none + pointer:coarse) Minimum 44×44px,
   konform mit WCAG 2.5.5 und Apple HIG. Desktop unverändert.
*/
@media (hover: none) and (pointer: coarse) {
  .m-touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}


/* ── 7. Safe-Area ────────────────────────────────────────────────────
   iPhones mit Notch/Home-Indicator brauchen explizites Safe-Area-
   Padding. Über env(safe-area-inset-*) — Browser ohne Unterstützung
   bekommen 0px, kein Bruch.
*/
.m-safe-top    { padding-top:    env(safe-area-inset-top, 0); }
.m-safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0); }
.m-safe-sides {
  padding-left:  env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}


/* ── 8. Visibility-Helpers ───────────────────────────────────────────
   Pragmatisches Show/Hide pro Viewport. Klassen sind defensiv mit
   `!important`, weil sie über bestehende display-Werte des Konsumenten
   hinweg greifen müssen.
*/
@media (max-width: 767px) {
  .m-hide-mobile { display: none !important; }
}
@media (min-width: 768px) {
  .m-only-mobile { display: none !important; }
}
@media (max-width: 1024px) {
  .m-hide-desktop { display: revert; }
}
@media (min-width: 1025px) {
  .m-only-desktop { display: revert; }
  .m-hide-desktop { display: none !important; }
}
/* Default-Verbergen von -only-mobile auf Desktop, -only-desktop auf Mobile */
.m-only-mobile  { display: none; }
.m-only-desktop { display: none; }
@media (max-width: 767px)  { .m-only-mobile  { display: revert; } }
@media (min-width: 1025px) { .m-only-desktop { display: revert; } }


/* ── 9. Form-Touch-Container ─────────────────────────────────────────
   Opt-in-Wrapper für Formulare. Setzt alle Inputs/Selects/Textareas
   innerhalb auf 44px Mindesthöhe und 16px Mindest-Font-Size. Sicherer
   als globaler Override, weil bestehende Admin-Formulare nicht
   tangiert werden.
*/
.m-form input[type="text"],
.m-form input[type="email"],
.m-form input[type="tel"],
.m-form input[type="number"],
.m-form input[type="password"],
.m-form input[type="search"],
.m-form input[type="url"],
.m-form input[type="date"],
.m-form input[type="datetime-local"],
.m-form input[type="time"],
.m-form select,
.m-form textarea {
  min-height: 44px;
  font-size: 16px;
}
.m-form button,
.m-form input[type="submit"],
.m-form input[type="button"] {
  min-height: 44px;
}
