/* Merten APPS — App-Switcher v4 (Mockup-Redesign 07.08.2026).
   Chip-basierter Look mit grünem M-Logo-Square + zweizeiligem Textblock. */

.mws-switcher-wrap {
  position: fixed;
  top: 10px; left: 12px;
  z-index: 10500;   /* über Modul-Header/Chip-Bar (10000) und Account-Slot (10001) */
  font-family: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* Der Chip selbst */
.mws-brand {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  background: var(--mws-brand-bg, rgba(255,255,255,0.94));
  backdrop-filter: blur(10px);
  border: 1px solid var(--mws-brand-border, rgba(15,15,10,0.10));
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.05);
  color: var(--mws-brand-text, #1b1f17);
  transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
  font-family: inherit;
}
.mws-brand:hover {
  background: var(--mws-brand-bg-hover, #f5f6f2);
  border-color: var(--mws-brand-border-hover, rgba(15,15,10,0.18));
  box-shadow: 0 2px 4px rgba(0,0,0,0.06), 0 6px 16px rgba(0,0,0,0.08);
}
.mws-brand:focus-visible {
  outline: 2px solid #6EB221; outline-offset: 2px;
}

/* v4.2: Offizielles PWA-App-Icon (`/icons/icon-192.png`) im Chip — buntes M&M-Icon */
.mws-logo {
  width: 34px; height: 34px;
  border-radius: 8px;
  flex: 0 0 auto;
  object-fit: cover;
  display: block;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  user-select: none;
  -webkit-user-drag: none;
}

/* Textblock: Titel + Untertitel */
.mws-brand-text {
  min-width: 0;
  text-align: left;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.mws-brand-text h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: inherit;
  letter-spacing: -0.01em;
}
.mws-brand-text p {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--mws-brand-muted, #7a7974);
}

/* Chevron rechts */
.mws-chevron {
  color: var(--mws-brand-muted, #7a7974);
  flex: 0 0 auto;
  transition: transform 200ms ease;
  margin-left: 2px;
}
.mws-brand[aria-expanded="true"] .mws-chevron { transform: rotate(180deg); }

/* Dark-Mode via data-theme (Live-Kalender) UND .dark-Klasse (Legacy-Module) */
html[data-theme="dark"] .mws-switcher-wrap,
.dark .mws-switcher-wrap {
  --mws-brand-bg: rgba(28, 27, 21, 0.94);
  --mws-brand-bg-hover: rgba(38, 37, 31, 1);
  --mws-brand-border: rgba(255, 255, 255, 0.10);
  --mws-brand-border-hover: rgba(255, 255, 255, 0.18);
  --mws-brand-text: #E8E6DC;
  --mws-brand-muted: #8A897E;
}

/* Dropdown-Menu */
.mws-menu {
  position: absolute;
  top: calc(100% + 8px); left: 0;
  min-width: 380px; max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--mws-menu-bg, #ffffff);
  border: 1px solid var(--mws-menu-border, rgba(0,0,0,0.08));
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.08), 0 12px 32px rgba(0,0,0,0.06);
  padding: 8px;
}
html[data-theme="dark"] .mws-menu,
.dark .mws-menu {
  --mws-menu-bg: #1C1B15;
  --mws-menu-border: rgba(255, 255, 255, 0.10);
}
.mws-menu[hidden] { display: none; }

@media (max-width: 600px) {
  .mws-menu {
    max-height: calc(100dvh - 80px);
  }
}

/* Section-Header („MODUL WECHSELN") */
.mws-section {
  padding: 6px 10px;
  font-size: 10.5px;
  color: var(--mws-menu-muted, #7a7974);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
html[data-theme="dark"] .mws-section,
.dark .mws-section { color: #8A897E; }

/* Item */
.mws-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--mws-item-text, #1b1f17);
  transition: background-color 120ms ease;
  min-height: 56px;
}
html[data-theme="dark"] .mws-item,
.dark .mws-item { color: #E8E6DC; }

.mws-item:hover { background: rgba(0,0,0,0.04); }
html[data-theme="dark"] .mws-item:hover,
.dark .mws-item:hover { background: rgba(255,255,255,0.04); }

.mws-item:focus-visible { outline: 2px solid #6EB221; outline-offset: -2px; }
.mws-item.is-active { background: rgba(110, 178, 33, 0.10); }

.mws-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex: 0 0 auto;
  background: rgba(110, 178, 33, 0.14); color: #558818;
}
.mws-icon svg { width: 20px; height: 20px; }
.mws-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mws-title { font-size: 14.5px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.mws-desc  {
  font-size: 12px;
  font-weight: 500;
  color: var(--mws-menu-muted, #7a7974);
  line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
html[data-theme="dark"] .mws-desc,
.dark .mws-desc { color: #8A897E; }
.mws-check { color: #6EB221; font-weight: 700; font-size: 16px; min-width: 16px; text-align: right; }

@media (max-width: 767px) {
  /* v4.7: Chip ist fixed mit hohem z-index; Modul-Topbars/Header müssen padding-top: 56px haben */
  .mws-switcher-wrap {
    top: 8px; left: 8px; right: auto;
    pointer-events: none;
  }
  .mws-switcher-wrap > * { pointer-events: auto; }
  .mws-menu {
    min-width: 0;
    max-width: calc(100vw - 16px);
    left: 0;
  }
  /* v4.4 (07.08.2026): Auf Mobile Icon + Modulname zeigen (statt nur Icon).
     Der Chip fungiert als klarer „Wo bin ich?“-Anzeiger, der eigene Modul-Titel wird
     dadurch überflüssig (und ist über Media-Query in Modulen ausgeblendet). */
  .mws-brand {
    padding: 4px 10px 4px 4px !important;
    min-height: 40px;
    border-radius: 10px;
    gap: 8px;
    max-width: calc(100vw - 190px); /* Platz für Account-Menu + evtl. weitere Buttons rechts */
  }
  /* Untertitel weg, aber Titel zeigen */
  .mws-brand-text { display: block !important; min-width: 0; overflow: hidden; }
  .mws-brand-text p { display: none !important; }
  .mws-brand-text h1 {
    font-size: 14px !important;
    font-weight: 700 !important;
    line-height: 1.2 !important;
    letter-spacing: -0.01em !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 !important;
  }
  /* v4.8 (08.08.2026): Chevron auf Mobile wieder zeigen — signalisiert, dass der Chip öffnet */
  .mws-chevron { display: inline-flex !important; font-size: 12px; opacity: 0.7; margin-left: 2px; flex-shrink: 0; }
  .mws-logo { width: 32px; height: 32px; border-radius: 7px; }
}

/* Kategorie-Header (v3.2 klappbar) */
.mws-cat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px 6px;
  margin-top: 4px;
  width: 100%;
  background: none; border: none;
  cursor: pointer; text-align: left;
  border-radius: 8px;
  font-family: inherit;
  transition: background-color 120ms ease;
}
.mws-cat-header:first-of-type { margin-top: 0; }
.mws-cat-header:hover { background: rgba(0,0,0,0.03); }
html[data-theme="dark"] .mws-cat-header:hover,
.dark .mws-cat-header:hover { background: rgba(255,255,255,0.04); }
.mws-cat-header:focus-visible { outline: 2px solid #6EB221; outline-offset: -2px; }

.mws-cat-icon {
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.mws-cat-icon svg { width: 14px; height: 14px; stroke-width: 2.5; }
.mws-cat-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: #7a7974;
  flex: 1 1 auto;
}
html[data-theme="dark"] .mws-cat-label,
.dark .mws-cat-label { color: #8A897E; }

.mws-cat-count {
  font-size: 11px; font-weight: 600; color: #8A897E;
  padding: 2px 8px; background: rgba(0,0,0,0.05); border-radius: 999px;
  flex: 0 0 auto;
}
html[data-theme="dark"] .mws-cat-count,
.dark .mws-cat-count { background: rgba(255,255,255,0.06); color: #8A897E; }

.mws-cat-chevron {
  color: #8A897E; flex: 0 0 auto;
  transition: transform 200ms ease;
}
.mws-cat-header.is-collapsed .mws-cat-chevron { transform: rotate(-90deg); }

.mws-cat-group {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 240ms ease, opacity 200ms ease;
}
.mws-cat-group.is-collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .mws-brand, .mws-chevron, .mws-cat-chevron, .mws-cat-group { transition: none; }
}



@media (max-width: 900px) {
  /* v4.7 (07.08.2026, 21:37): Global Platz für den fixen App-Switcher-Chip reservieren.
     Der Chip ist ~230px breit + 8px left + 8px right-Buffer. Modul-Topbars müssen mind. 244px
     Platz links haben, damit ihre Buttons nicht in eine zweite Zeile fallen. */
  header.topbar,
  header.app-header,
  header.va-head,
  header.tabs-header {
    padding-left: var(--mws-chip-space, 244px) !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
    padding-right: 12px !important;
    min-height: 56px;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow-x: hidden !important;
    gap: 6px !important;
  }
  /* Alle direkten Kinder-Elemente in einer Zeile halten und nicht wrappen */
  header.topbar > *,
  header.app-header > *,
  header.va-head > *,
  header.tabs-header > * {
    flex-shrink: 0 !important;
  }
  /* Ausnahme: Spacer-Divs (spacer, flex-1) dürfen wachsen */
  header.topbar > .spacer,
  header.topbar > [style*="flex:1"],
  header.topbar > [style*="flex: 1"],
  header.app-header > .spacer,
  header.app-header > [style*="flex:1"],
  header.app-header > [style*="flex: 1"] {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  /* Wenn Topbar ein .topbar-inner-Kind hat, müssen wir das statt der Topbar padden */
  header.topbar > .topbar-inner {
    padding-left: 0 !important;
    padding-top: 0 !important;
    flex-direction: row !important;
    align-items: center !important;
  }
  /* Voice-Agent hat va-head-inner statt topbar-inner */
  header.va-head > .va-head-inner {
    padding-left: 0 !important;
    padding-top: 0 !important;
    flex-direction: row !important;
    align-items: center !important;
  }
  /* v4.7.3: Vault und andere Module haben eigenen .page-Wrapper mit padding-top für Chip.
     Wir reduzieren das, damit die Topbar direkt neben dem Chip startet. */
  main.page,
  .page {
    padding-top: 8px !important;
  }
  /* Wenn ein Modul einen Content-Container hat, dessen h1 zu weit oben liegt (Belegkonto, Vault) */
  body > .container:first-of-type,
  body > main:first-of-type,
  body > .app-content:first-of-type {
    padding-top: 8px !important;
  }
  /* Account-Menu kompakter auf Mobile: nur Avatar zeigen, Name + Role verstecken.
     Spart Platz, damit alles in eine Zeile passt. Auf Tap öffnet sich das Menü,
     dort sind Name und Rolle sichtbar. */
  .mk-account__trigger {
    padding: 4px !important;
    gap: 6px !important;
  }
  .mk-account__label,
  .mk-account__name,
  .mk-account__role,
  .mk-account__chev {
    display: none !important;
  }

  /* Muster 1: .topbar-title (adressbuch, beschwerde, betriebsarzt, dienstplan) */
  .topbar-title { display: none !important; }
  /* Muster 2: .app-title (compliance) */
  .app-title { display: none !important; }
  /* Muster 3: h1+subtitle in .topbar > div (dokuwacht, controlling) */
  .topbar > div > h1,
  .topbar > div > .subtitle { display: none !important; }
  /* Muster 4: voice-agent Hero (.va-head .title + .subtitle) */
  .va-head .title,
  .va-head .subtitle { display: none !important; }
  /* Muster 5: belegkonto (.container > h1:first-of-type + .subtitle direkt danach) */
  .container > h1:first-of-type,
  .container > h1:first-of-type + .subtitle { display: none !important; }

  /* Muster 6: Vault hat keine Topbar sondern nur Theme+Account rechts. Der Chip kollidiert.
     Lösung: min-height am body oben — aber nicht generisch. Vault ist speziell, siehe body class. */
  body.vault-body { padding-top: 60px; }
  /* Zusätzlich: eigenständige h1 direkt in .topbar / .app-header / header */
  .topbar > h1,
  .app-header > h1,
  header > h1 { display: none !important; }
  /* Generische Hero-Klassen falls in Zukunft verwendet */
  .page-header,
  .module-hero,
  .hero-title { display: none !important; }
}

/* Native iOS-App (12.08.2026): Chip unter die Statusleiste rücken.
   Die Bridge (merten-native.v1.js) setzt html.mk-native-ios; der fixe Chip
   bei top 8-10px würde sonst vom Statusleisten-Scrim übermalt. */
html.mk-native-ios .mws-switcher-wrap { top: calc(env(safe-area-inset-top) + 10px); }
@media (max-width: 767px) {
  html.mk-native-ios .mws-switcher-wrap { top: calc(env(safe-area-inset-top) + 8px); }
}
