/* ============ Handy-Ansicht (wird zuletzt geladen) ============ */
html, body { max-width: 100%; overflow-x: clip; }
img, video, svg, canvas { max-width: 100%; }

@media (max-width: 640px) {
  /* Grundraster */
  .container { padding: 18px 16px 72px; }
  .btn { white-space: normal; text-align: center; line-height: 1.25; }
  .btn-lg { padding: 13px 18px; font-size: 15px; }
  h1 { font-size: 26px; }
  :is(.row, .hero, .section-head, .post-meta, .chips, .cal-toolbar, .an-filters, .news-head, .viz-head) > * { min-width: 0; }

  /* Kopfzeile: kompakt, alles in einer Zeile */
  .topbar-in { padding: 10px 16px; gap: 8px; }
  .brand { gap: 8px; font-size: 15px; min-width: 0; }
  .brand > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-mark { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; flex: none; }
  .who { gap: 0; }
  .who-name { display: none; }
  .iconbtn { width: 36px; height: 36px; border-radius: 11px; flex: none; }
  .topbar .avatar { width: 30px; height: 30px; font-size: 12px; }

  /* Begrüßung */
  .hero { margin-bottom: 18px; gap: 14px; }
  .hero p.muted { font-size: 14.5px; margin-top: 6px; }
  .hero .eyebrow { font-size: 11px; margin-bottom: 4px; }
  .hero-actions { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: 10px; }
  .hero-actions .btn:only-child { grid-column: 1 / -1; }

  /* Kennzahlen 2 × 2, kompakt */
  .stats, .stats.three { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
  .stats.three .stat:last-child { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px; }
  .stat { padding: 13px 14px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .stat .ic { width: 32px; height: 32px; border-radius: 10px; }
  .stat .ic svg { width: 16px; height: 16px; }
  .stat b { font-size: 22px; }
  .stat span { font-size: 12.5px; line-height: 1.3; }

  /* Bereichs-Navigation: wischbar, mit Hinweis rechts */
  .tabs { width: 100%; margin-bottom: 18px; }
  .tabs:has(.tab:nth-child(6)) { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .tabs:has(.tab:nth-child(6)) .tab { padding: 9px 13px; font-size: 13.5px; }
  .section-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .section-head .tabs { margin: 0; }
  .search { max-width: none; width: 100%; }

  /* Filter-Chips: eine wischbare Zeile statt vieler Zeilen */
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 16px; padding: 2px 16px; }
  .filters::-webkit-scrollbar { display: none; }
  .filter { flex: none; padding: 7px 12px; }

  /* Kundenseite (Agentur) */
  .cust-head { gap: 12px; margin-bottom: 16px; }
  .cust-head .cust-logo { width: 46px; height: 46px; font-size: 17px; border-radius: 14px; }
  .cust-head .cust-logo.logo-clear { width: auto; height: 52px; }
  .cust-head h1 { font-size: 23px; }
  .cust-head > div:nth-child(2) { min-width: 0 !important; flex: 1; }
  .cust-head > .btn { width: 100%; }
  .cust-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Neuigkeiten */
  .news-grid { gap: 12px; margin-bottom: 22px; }
  .news-head { flex-wrap: wrap; gap: 6px; }
  .news-head .btn { padding: 5px 8px; font-size: 12.5px; }
  .news-item, .news-appt { padding: 10px 4px; gap: 10px; }
  .news-appt .cd-chip { display: none; }

  /* Beiträge */
  .focus { padding: 16px; gap: 12px; border-radius: 18px; }
  .focus .big { font-size: 30px; }
  .focus b { font-size: 15px; } .focus p { font-size: 13.5px; }
  .next-appt { padding: 12px 14px; gap: 12px; flex-wrap: wrap; }
  .next-appt .na-ico { font-size: 22px; }
  .next-appt .cd-chip { margin-left: 0; }
  .post { padding: 14px; gap: 14px; border-radius: 20px; }
  .post-media { max-width: none; }
  .phone { border-radius: 20px; }
  .post-body h3 { font-size: 17px; }
  .caption { font-size: 14.5px; padding: 12px 13px; }
  .decide { grid-template-columns: 1fr; }
  .post-actions .btn { flex: 1 1 auto; }

  /* Dialoge als Blatt von unten */
  .overlay { align-items: end; padding: 0; }
  .modal { max-width: none; border-radius: 24px 24px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; animation: sheet .28s cubic-bezier(.2,.9,.3,1) both; }
  .modal.wide { border-radius: 24px 24px 0 0; }
  .modal-head h2 { font-size: 19px; }
  .modal-foot { position: sticky; bottom: -18px; background: inherit; padding-top: 12px; margin-top: 16px; }
  .modal-foot .btn { flex: 1 1 auto; }
  .composer { max-height: 92vh; }
  .composer-form { padding: 20px 18px; }
  .grid2 { grid-template-columns: 1fr; }

  /* Login */
  .auth { padding: 16px; place-items: start center; padding-top: 64px; }
  .auth-card { padding: 26px 20px; gap: 16px; }
  .auth-card h1 { font-size: 25px; }
  .auth-theme { top: 14px; right: 14px; }

  /* Kalender / Auswertung / Chat */
  .cal-toolbar { gap: 8px; }
  .cal-toolbar .seg-tabs { flex: 1; }
  .cal-toolbar .seg-tabs button { flex: 1; justify-content: center; }
  .cal-toolbar #cal-sub, .cal-toolbar #cal-new, .cal-toolbar select { flex: 1 1 100%; }
  .an-filters .seg-tabs { width: 100%; }
  .an-filters select, .an-filters .btn { flex: 1 1 auto; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contact { padding: 12px 14px; }
  .contact .info { min-width: 0; flex-basis: 100%; }
  .settings, .danger-zone { padding: 18px; }
}

@media (max-width: 380px) {
  .brand > span:last-child { display: none; }
  .stat span { font-size: 12px; }
  h1 { font-size: 24px; }
}

@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

@media (max-width: 640px) {
  /* Dialog-Blätter: deckender Hintergrund, Button-Leiste klar abgesetzt */
  .modal, .modal.wide { background: #fbfbfe; }
  .modal-foot, .composer-form .modal-foot { background: #fbfbfe; border-top: 1px solid var(--line); margin-left: -18px; margin-right: -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); bottom: -18px; }
  .composer-form .modal-foot { bottom: -20px; }
  .cal-toolbar .seg-tabs { flex-wrap: nowrap; }
  .cal-toolbar .check.small { flex: 1 1 100%; order: 3; }
}
@media (max-width: 640px) {
  :root[data-theme="dark"] .modal, :root[data-theme="dark"] .modal-foot { background: #181826; }
}
@media (max-width: 640px) and (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .modal, :root[data-theme="auto"] .modal-foot { background: #181826; }
}
