/* Helloworkflow Hub – PWA-Chat-Modus und Mobile-Fixes
 * Einbinden NACH styles.css:
 *   <link rel="stylesheet" href="css/pwa-mobile.css?v=2.2.0">
 */

/* =========================================================
   Teil A: Mobile-Fixes für alle Seiten (Befunde Test 23.11.)
   ========================================================= */

/* A1: Seite darf nie seitlich scrollen. clip statt hidden, damit position:sticky erhalten bleibt */
html, body { overflow-x: clip; }

/* A2: Benachrichtigungs-Panel lag mit right:-390px rechts neben der Seite und hat
       die Seitenbreite auf 735px aufgeblasen. Off-Canvas per transform verstecken. */
.inbox-panel {
  right: 0 !important;
  max-width: 100vw;
  transform: translateX(100%);
  transition: transform .22s ease;
  visibility: hidden;
}
.inbox-panel.open,
.inbox-panel.is-open,
.inbox-panel.active {
  transform: none;
  visibility: visible;
}
@media (prefers-reduced-motion: reduce) { .inbox-panel { transition: none; } }

@media (max-width: 768px) {
  /* A3: Seitenkopf (Kalender, Cases, CRM, Wissen, App Factory, Outreach, Admin):
         Titel bekommt die erste Zeile, Buttons umbrechen darunter. */
  .page-header,
  .calendar-header {
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .page-header h1,
  .calendar-header h1 {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: normal;
    word-break: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .page-header > .header-actions,
  .calendar-header > .header-actions {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }
  .page-date { display: none; }

  /* A3b: Kalender – styles.css erzwingt mit
         body.calendar-page .page-header.calendar-header { flex-flow: row !important }
         eine einzige Zeile. Dadurch wurde „Calendar“ auf 28px gequetscht.
         Gleich spezifische Gegenregel: */
  body.calendar-page .page-header.calendar-header { flex-wrap: wrap !important; row-gap: 10px; }
  body.calendar-page .page-header.calendar-header .calendar-header-title { flex: 1 1 100% !important; }
  body.calendar-page .page-header.calendar-header .header-actions {
    flex: 0 0 auto !important; width: 100% !important; justify-content: flex-start;
  }

  /* A4: Kartenköpfe dürfen umbrechen, wenn Buttons daneben stehen */
  .card-header,
  .inbox-panel-header { flex-wrap: wrap; gap: 8px; }

  /* A5: iOS zoomt in Eingabefelder mit Schrift < 16px automatisch hinein */
  input, select, textarea { font-size: 16px !important; }

  /* A6: Tippflächen mindestens 40px */
  .btn, button.tab, .chat-icon-btn, .icon-btn { min-height: 40px; }
  .chat-icon-btn, .icon-btn { min-width: 40px; }

  /* A7: Tabellen scrollen in ihrem Rahmen, nicht die ganze Seite */
  .hub-table { min-width: 560px; }
  .hub-table-wrap, .table-wrap, .table-container,
  .hub-table:not(.table-wrap *) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* A8: Tab-Leisten (Finanzen, Admin, Marketplace) horizontal wischbar */
  .tabs, .tab-bar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .tab-bar::-webkit-scrollbar { display: none; }

  /* A9: Kalender – Filter nicht über den Rand, Tage wischbar statt abgeschnitten */
  .calendar-toolbar, .calendar-controls { flex-wrap: wrap; gap: 8px; }
  .calendar-toolbar select, .calendar-controls select { max-width: 100%; flex: 1 1 100%; }

  /* A10: KI-Button verdeckt das Chat-Suchfeld und den Senden-Button */
  .ai-fab { bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* Briefing: Dateien und Links untereinander, große Tippflächen */
  .briefing-drop { padding: .7rem; }
  .briefing-drop-btn { min-height: 44px; padding: .45rem .2rem; }
  .briefing-drop-title,
  .briefing-drop-hint { overflow-wrap: anywhere; }
  .briefing-file-chip { min-height: 44px; }
  .briefing-file-chip .btn { min-width: 40px; min-height: 40px; }
  .briefing-link-row {
    grid-template-columns: 1fr;
    gap: .5rem;
  }
  .briefing-link-row .btn { justify-self: end; min-width: 44px; min-height: 44px; }
}

/* =========================================================
   Teil B: Chat-Modus (installierte App, ?app=chat)
   ========================================================= */
html.chat-app,
html.chat-app body { height: 100%; overscroll-behavior: none; background: #fff; }

/* Alles ausblenden, was nicht Chat ist */
html.chat-app .sidebar,
html.chat-app .mobile-menu-btn,
html.chat-app .page-header,
html.chat-app .ai-fab,
html.chat-app .dash-board-col > .card:not(.dash-chat-card),
html.chat-app .dash-board > :not(.dash-board-col),
html.chat-app .page-body > :not(.dash-board) { display: none !important; }
html.chat-app .dash-board-col:not(:has(.dash-chat-card)) { display: none !important; }

html.chat-app .app-layout,
html.chat-app .main-content,
html.chat-app .page-body,
html.chat-app .dash-board,
html.chat-app .dash-board-col {
  display: block;
  margin: 0; padding: 0;
  width: 100%; max-width: none;
  height: 100%;
}

/* Chat-Karte füllt den Bildschirm, mit Abstand zu Notch und Home-Leiste */
html.chat-app .dash-chat-card {
  position: fixed;
  inset: 0;
  margin: 0 !important;      /* mobile styles.css setzt negative Seitenränder */
  width: 100% !important;
  display: flex;
  flex-direction: column;
  border: 0; border-radius: 0; box-shadow: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  height: 100dvh;
}
html.chat-app .dash-chat-card > .card-header {
  flex: 0 0 auto;
  position: sticky; top: 0;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding-left: 16px;
  padding-right: 12px;
}
html.chat-app #dash-side-chat {
  padding: 8px 12px 12px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none !important;
  height: auto !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
html.chat-app #dash-chat-compose {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 8px 12px;
}
html.chat-app #dash-chat-input { font-size: 16px; }

button.chat-attachment-file {
  border: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

/* Hinweisleiste aus pwa.js */
#pwa-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 9999;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: #1e3a8a; color: #fff;
  border-radius: 14px;
  font: 15px/1.4 Inter, system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(30, 58, 138, .28);
}
#pwa-bar .pwa-bar-text { flex: 1; }
#pwa-bar .pwa-bar-action {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px;
  border: 0; border-radius: 10px;
  background: #fff; color: #1e3a8a; font-weight: 600; font-size: 15px;
}
#pwa-bar .pwa-bar-close {
  flex: 0 0 auto; width: 36px; height: 36px;
  border: 0; background: transparent; color: #fff; font-size: 22px; line-height: 1;
}
#pwa-bar button:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
