/* ═══════════════════════════════════════════════════════════════════════════
   Mobile-Layout (iPhone, Hochformat; Zielgerät iPhone 15 Pro Max = 430pt breit)
   Wird nach homeapp.css geladen und greift nur unter 769px - die Desktop-
   Ansicht bleibt unverändert. Ergänzt durch js/mobile.js (Bottom-Tabbar,
   Tabellen→Karten).
   ═══════════════════════════════════════════════════════════════════════════ */

/* Tabbar ist auf dem Desktop komplett unsichtbar */
.tabbar { display: none; }
.ctx-chip, .m-filter-toggle, .m-only { display: none; }

@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .content { overscroll-behavior: contain; padding: 12px 12px 20px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

  /* ── Kopfzeile: Zeile 1 = Menü | Titel | Status/Theme/User, Zeile 2 = Bereich + Haushalt ── */
  .topbar { flex-wrap: nowrap; column-gap: 8px; padding: 8px 12px 8px; padding-top: calc(8px + env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar-left { flex: 1 1 0; min-width: 0; }
  .topbar-right { display: contents !important; }
  .topbar h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hamburger { width: 40px; height: 40px; }
  #theme-toggle { order: 2; width: 40px; height: 40px; justify-content: center; }
  #api-label { display: none; }
  .api-badge { order: 3; padding: 0; border: none; background: none; }
  .user-info { order: 4; }
  .user-info #user-menu-btn { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .user-info #user-menu-btn span, .user-info #user-menu-btn .ti-chevron-down { display: none; }
  .user-info #user-menu-btn .ti-user-circle { font-size: 22px !important; }
  .user-menu { position: fixed; top: calc(52px + env(safe-area-inset-top)); right: 12px; min-width: 240px; }
  .user-menu-item { padding: 13px 12px; font-size: 15px; }
  .ctx-switcher { display: none !important; }   /* Auswahl über .ctx-chip (js/mobile.js) */
  .topbar-title { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
  .ctx-chip { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; padding: 2px 0; border: none; background: none; font-family: inherit; font-size: 12px; color: var(--text-3); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ctx-chip i { font-size: 12px; }

  /* ── Navigations-Schublade ── */
  .hamburger { display: inline-flex; }
  .sidebar-toggle { display: none; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 1600; transform: translateX(-100%); transition: transform .2s ease, visibility 0s .2s; box-shadow: 2px 0 16px rgba(0,0,0,.2); visibility: hidden; }
  .sidebar.open { transform: translateX(0); visibility: visible; transition: transform .2s ease; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1500; }
  .sidebar { width: min(86vw, 330px); min-width: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); overscroll-behavior: contain; }
  .nav-item { padding: 12px 16px; font-size: 15px; min-height: 44px; }
  .nav-childitem, .nav-subitem { padding-left: 36px; font-size: 14.5px; }
  .nav-item i { font-size: 18px; }
  .sidebar-section { padding-top: 20px; font-size: 11px; }
  .konto-drag-handle { display: none; }

  /* ── Bottom-Tabbar ── */
  .tabbar { display: flex; flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); z-index: 1400; }
  .tabbar:empty { display: none; }
  .tab-btn { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px; padding: 6px 2px 4px; border: none; background: none; color: var(--text-3); font-family: inherit; font-size: 11px; font-weight: 500; cursor: pointer; }
  .tab-btn i { font-size: 24px; }
  .tab-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab-btn.active { color: var(--accent); }
  .tab-btn.active i { transform: translateY(-1px); }
  .tab-btn:active { background: var(--bg); }
  /* Tastatur offen: Tabbar nicht über dem Eingabefeld halten */
  body.kb-open .tabbar { display: none; }

  /* ── Toast: mittig, über der Tabbar ── */
  #toast { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); max-width: none; justify-content: center; text-align: center; }

  /* ── Bedienelemente: Touch-Ziele ≥ 40pt ── */
  .btn { min-height: 40px; padding: 8px 14px; font-size: 14px; }
  .btn.sm { min-height: 40px; min-width: 40px; padding: 6px 10px; justify-content: center; }
  .btn i { font-size: 17px; }
  .section-header { margin-bottom: 12px; }
  .section-header h2 { font-size: 15px; }
  .section-header > .btn.primary { margin-left: auto; }
  .row-actions { gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
  .checkbox-row input[type=checkbox] { width: 22px; height: 22px; }
  .checkbox-row label { font-size: 15px; }
  .field label { font-size: 13px; }
  .field input, .field select, .field textarea { font-size: 16px; min-height: 44px; padding: 9px 12px; }
  .field textarea { min-height: 88px; }
  select, input:not([type=checkbox]):not([type=radio]):not([type=file]), textarea { font-size: 16px; }   /* verhindert iOS-Zoom auch bei Inline-Feldern */

  /* Tabs/Register: horizontal wischbar statt umbrechen */
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; margin-left: -12px; margin-right: -12px; padding: 0 12px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 11px 14px; font-size: 14px; }

  /* Filterleiste: zwei Spalten */
  .filter-bar { gap: 8px; display: none; margin-bottom: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
  .filter-bar.m-open { display: flex; }
  .filter-bar .field:first-child { flex-basis: 100%; }
  .filter-bar .checkbox-row:has(#kd-filter-zeilen) { display: none; }
  .m-filter-toggle { display: inline-flex; margin-bottom: 10px; }
  .m-filter-toggle.active { background: var(--accent-bg); color: var(--accent-text); border-color: var(--accent); }
  .filter-bar .field { min-width: 0; flex: 1 1 calc(50% - 8px); }

  /* ── Formulare / Layouts stapeln ── */
  .form-grid { grid-template-columns: 1fr; }
  .field.span2 { grid-column: span 1; }
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .resizable-split { grid-template-columns: 1fr !important; }
  .split-handle { display: none; }
  .split-left { position: static; }

  /* ── Modal → Bottom-Sheet ── */
  .overlay { align-items: flex-end; padding: 0; z-index: 1700; }
  .modal, .modal.wide, .modal.xwide { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 16px 16px 0 0; border-bottom: none; padding: 0; display: flex; flex-direction: column; overflow: hidden; animation: sheet-up .22s ease-out; }
  .modal-title { margin: 0; padding: 16px 16px 12px; font-size: 17px; flex-shrink: 0; border-bottom: 1px solid var(--border); }
  .modal-title .btn { min-width: 40px; }
  #modal-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px; }
  .modal-footer { margin: 0; padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); flex-shrink: 0; flex-wrap: nowrap; background: var(--surface); }
  .modal-footer .btn { flex: 1; justify-content: center; min-height: 46px; font-size: 15px; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

  /* ── Tabellen ── */
  .table-card { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; }                       /* Fallback: Pivot-/Spezialtabellen wischbar */
  .report-table, .plan-sticky-col { font-size: 12.5px; }

  /* Karten-Ansicht (js/mobile.js setzt .m-cards auf passende Tabellen) */
  .table-card:has(> table.m-cards) { background: none; border: none; border-radius: 0; overflow: visible; }
  table.m-cards { min-width: 0; display: block; font-size: 14px; }
  table.m-cards thead { display: none; }
  table.m-cards tbody { display: flex; flex-direction: column; gap: 10px; }
  table.m-cards tr { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
  table.m-cards tr:hover td { background: none; }
  table.m-cards td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0; border: none; text-align: right !important; min-width: 0; word-break: break-word; }
  table.m-cards td::before { content: attr(data-label); flex-shrink: 0; max-width: 40%; text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--text-3); }
  table.m-cards td[data-label=""]::before { content: none; }
  table.m-cards td.m-empty { display: none; }
  table.m-cards td.m-skip { display: none; }
  table.m-cards td.m-title { order: -1; justify-content: flex-start; text-align: left !important; font-size: 15.5px; font-weight: 600; padding-bottom: 4px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
  table.m-cards td.m-title::before { content: none; }
  table.m-cards td.m-actions { order: 99; justify-content: flex-end; margin: 4px -6px -6px 0; }
  table.m-cards .m-val { min-width: 0; text-align: right; }
  table.m-cards td.m-actions::before { content: none; }
  table.m-cards tr.empty-row { border-style: dashed; background: none; }
  table.m-cards tr.empty-row td { justify-content: center; text-align: center !important; color: var(--text-3); padding: 20px 0; }
  table.m-cards tr.empty-row td::before { content: none; }
  table.m-cards .tree-cell { justify-content: flex-start; }

  /* Saldo-Verlauf im Kontodetail: flacher, damit die Buchungen schneller erreichbar sind */
  .table-card svg[preserveAspectRatio="none"] { height: 110px !important; }
  .table-card:has(> svg), .table-card[style*="padding"] { padding: 12px 14px !important; }

  /* Gruppenkopf (Tag) in Kontodetail-Listen */
  table.m-cards tr.m-group { flex-direction: row; justify-content: space-between; align-items: baseline; gap: 8px; background: none; border: none; border-radius: 0; padding: 8px 2px 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
  table.m-cards tr.m-group td { display: block; padding: 0; text-align: left !important; background: none !important; border: none; }
  table.m-cards tr.m-group td:last-child:not(:first-child) { text-align: right !important; font-size: 12px; }
  table.m-cards tr.m-group td:empty { display: none; }
  table.m-cards tr.m-group td::before { content: none; }

  /* Kompakte Buchungskarte: Payee + Betrag / Kategorie + Datum. Alles Weitere
     (Typ, Konto, Notiz, Status, Zeilen) steht erst im Bearbeiten-Dialog. */
  table.m-buchungen tbody { gap: 6px; }
  table.m-buchungen tr:not(.m-group) { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "payee betrag" "kat datum"; column-gap: 12px; row-gap: 2px; padding: 11px 14px; border-radius: 10px; cursor: pointer; }
  table.m-buchungen tr:not(.m-group):active { background: var(--bg); }
  table.m-buchungen tr:not(.m-group) td { display: none; padding: 0; text-align: left !important; }
  table.m-buchungen tr:not(.m-group) td::before { content: none; }
  table.m-buchungen tr:not(.m-group) td[data-label="Payee"]    { display: block; grid-area: payee; font-size: 15px; font-weight: 600; color: var(--text) !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  table.m-buchungen tr:not(.m-group) td[data-label="Betrag"]   { display: block; grid-area: betrag; font-size: 15px; font-weight: 600; text-align: right !important; white-space: nowrap; }
  table.m-buchungen tr:not(.m-group) td[data-label="Kategorie"] { display: block; grid-area: kat; font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  table.m-buchungen tr:not(.m-group) td[data-label="Datum"]    { display: block; grid-area: datum; font-size: 12.5px; color: var(--text-3); text-align: right !important; }
  table.m-buchungen tr:not(.m-group) td.m-empty { display: none !important; }
  table.m-buchungen tr[data-status="soll"] { border-left: 4px solid var(--warning); }
  table.m-buchungen tr[data-status="geplant"] { border-left: 4px solid var(--accent); }

  /* Kompakte Kontokarte: Name + Saldo, Tippen öffnet das Konto */
  table.m-konten tr:not(.m-group) { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name saldo" "typ saldo"; align-items: center; column-gap: 12px; row-gap: 4px; padding: 14px; cursor: pointer; }
  table.m-konten tr:not(.m-group):active { background: var(--bg); }
  table.m-konten td { display: none; padding: 0; }
  table.m-konten td::before { content: none; }
  table.m-konten tr:not(.m-group) td.m-title { display: block; grid-area: name; order: 0; border: none; padding: 0; margin: 0; }
  table.m-konten tr:not(.m-group) td[data-label="Typ"] { display: block; grid-area: typ; text-align: left !important; }
  table.m-konten tr:not(.m-group) td[data-label="Aktueller Saldo"] { display: block; grid-area: saldo; font-size: 17px; font-weight: 600; text-align: right !important; white-space: nowrap; }
  table.m-konten tr:not(.m-group) td.m-empty { display: none !important; }

  /* Belegscan: Hauptusecase auf dem Handy ist "Foto aufnehmen -> Scannen" -
     beide Schritte als große, volle-Breite-Buttons übereinander. */
  .belegscan-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .belegscan-foto-btn { order: 1; font-size: 17px; padding: 18px; justify-content: center; }
  .belegscan-datei-btn { order: 2; align-self: center; }
  .belegscan-ordner-btn { display: none; }   /* Ordnerauswahl gibt es auf iOS nicht sinnvoll */
  #scan-filename { order: 3; text-align: center; }
  .belegscan-scan-btn { order: 4; font-size: 17px; padding: 16px; justify-content: center; }
  #scan-status { order: 5; text-align: center; }

  /* Info-/Hinweisboxen, Notfallblatt */
  .info-banner { font-size: 14px; }
  .notfallblatt-card { padding: 14px; }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}

@media (max-width: 768px) {
  .m-only { display: block; }
  .m-konto-filter { margin-bottom: 12px; }
  .m-konto-filter select { width: 100%; min-height: 44px; padding: 9px 12px; font-size: 16px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font-family: inherit; }
}

/* Dauerauftrags-KPI (KPI-Seite/Vorlagen): Gesamtsumme und "Summe je Ausfuehrungsdatum" untereinander
   statt nebeneinander, damit die Termin-Tabelle die volle Breite hat und nicht abgeschnitten wird. */
@media (max-width: 768px) {
  .kpi-zeile-dauerauftrag { flex-direction: column; }
  .kpi-zeile-dauerauftrag > * { flex: none; width: 100%; box-sizing: border-box; }
  /* globale Regel `table { min-width: 640px }` (Wischtabellen) wuerde die Termin-Tabelle breiter als den Bildschirm machen */
  .kpi-zeile-dauerauftrag table { min-width: 0; }
  .kpi-zeile-dauerauftrag td { padding: 7px 8px; }
}
