/* =========================================================
   SPARK – Handy & Tablet
   Gilt nur bis 860px Breite. Am PC ändert sich nichts.
   ========================================================= */
.burger, .nav-backdrop { display: none; }

@media (max-width: 860px) {
  html, body { height: auto; min-height: 100%; }
  body { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
  /* iOS zoomt bei Eingabefeldern unter 16px automatisch hinein */
  .input, .select, .textarea, input, select, textarea { font-size: 16px !important; }

  /* ---------- Gerüst: Menü als Ausklapp-Leiste ---------- */
  .shell { display: block; height: auto; min-height: 100dvh; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 150;
    width: min(300px, 86vw); overflow-y: auto;
    padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateX(-102%); transition: transform .28s var(--ease);
    box-shadow: 20px 0 60px rgba(0, 0, 0, .5);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 140; background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav a { padding: 11px 12px; }

  .main { height: auto; min-height: 100dvh; }
  .topbar {
    position: sticky; top: 0; z-index: 60;
    height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; gap: 8px;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px);
  }
  .burger { display: grid; }
  .icon-btn { width: 38px; height: 38px; border-radius: 11px; flex: none; }
  .icon-btn svg { width: 19px; height: 19px; }
  .crumbs { min-width: 0; flex: 1; font-size: 15px; }
  .crumbs > span { display: none; }
  .crumbs b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-search { width: 38px; height: 38px; padding: 0; justify-content: center; margin-left: 0; border-radius: 11px; flex: none; }
  .top-search span, .top-search kbd { display: none; }
  .top-search svg { width: 18px; height: 18px; }
  .banner { margin: 10px 12px 0; }

  .view { overflow: visible; padding: 16px 14px calc(40px + env(safe-area-inset-bottom)); }

  /* ---------- Seitenkopf ---------- */
  .page-head { margin-bottom: 16px; gap: 12px; align-items: stretch; }
  .page-head > div:first-child { width: 100%; }
  .page-head h1 { font-size: 27px; }
  .page-head .sub { font-size: 13.5px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions > .btn, .page-head .actions > .seg { flex: 1 1 auto; justify-content: center; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .btn.icon { width: 40px; }
  .btn.sm.icon { width: 34px; }

  /* ---------- Raster ---------- */
  .g-2, .g-3, .g-main { grid-template-columns: 1fr !important; }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .grid { gap: 12px; }
  .row { grid-template-columns: 1fr !important; }
  .row > .field[style*="grid-column"] { grid-column: auto !important; }
  .row > div:empty { display: none; }
  .card.pad { padding: 16px; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  .card-head .right { flex-wrap: wrap; }
  .kpi { padding: 14px; min-height: 0 !important; gap: 4px; }
  .kpi .value { font-size: 22px !important; margin-top: 8px; word-break: break-word; }
  .kpi .label { font-size: 12px; }
  .kpi .foot { font-size: 11px; }
  .list-item { padding: 12px 14px; flex-wrap: wrap; }
  .list-item .grow { flex-basis: 50%; }
  .kv { grid-template-columns: 110px 1fr; }

  /* ---------- Filterleiste ---------- */
  .toolbar { gap: 8px; }
  .toolbar > * { flex: 1 1 100%; width: auto !important; max-width: 100%; }
  .toolbar .input-icon { width: 100%; }
  .toolbar .input, .toolbar .select { height: 42px !important; }
  .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; height: 32px; }

  /* ---------- Tabellen → Karten ---------- */
  .table-wrap { overflow: visible; }
  table.table, table.table tbody, table.table tfoot { display: block; width: 100%; }
  table.table thead { display: none; }
  table.table tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
    padding: 14px 16px; border-bottom: 1px solid var(--line);
  }
  table.table tbody tr:last-child { border-bottom: 0; }
  table.table td { display: block; padding: 0 !important; border: 0 !important; text-align: left !important; min-width: 0; }
  table.table td::before { content: attr(data-label); display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 2px; }
  table.table td[data-label=""]::before, table.table td:not([data-label])::before { display: none; }
  table.table td:empty { display: none; }
  /* Spalten ohne Überschrift (Aktionen, Icons) rechts oben in der Karte */
  table.table td[data-label=""] { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
  table.table td .cell-2 b, table.table td .cell-2 span { max-width: none; white-space: normal; }
  table.table tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 12px 16px; border-top: 1px solid var(--line); }
  table.table tfoot td { display: block; }
  table.table tfoot td:empty, table.table tfoot td[colspan]:empty { display: none; }
  /* Aktions-Spalte (…, Büroklammer) oben rechts in der Karte */
  table.table tbody tr { position: relative; }
  table.table tbody tr:has(> td[data-label=""]:last-child) { padding-right: 52px; }
  table.table tbody tr > td[data-label=""]:last-child { position: absolute; top: 10px; right: 8px; grid-column: auto; }

  /* Positionen im Rechnungs-/Angebots-Editor: jede Position eine Karte */
  .items-table, .items-table tbody { display: block; width: 100%; }
  .items-table thead { display: none; }
  .items-table tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    padding: 14px 0; border-bottom: 1px solid var(--line); position: relative;
  }
  .items-table tr:first-child { padding-top: 4px; }
  .items-table td { display: block; padding: 0 !important; min-width: 0; }
  .items-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--text-3); margin-bottom: 4px; }
  .items-table td:first-child { grid-column: 1 / -1; padding-right: 44px !important; }
  .items-table .input, .items-table .select { height: 44px; }
  .items-table .line-total { padding: 0 !important; text-align: left; display: flex; flex-direction: column; justify-content: flex-end; font-size: 17px; }
  .items-table td:last-child { position: absolute; top: 22px; right: 0; }
  .items-table tr:first-child td:last-child { top: 12px; }
  .items-table .del { opacity: 1 !important; width: 36px; height: 36px; }

  /* Übersicht: Begrüßung */
  .hello { flex-wrap: wrap; gap: 14px; margin-bottom: 18px; align-items: stretch; }
  .hello > div:first-child { width: 100%; }
  .hello h1 { font-size: 34px; }
  .hello .actions { margin-left: 0; width: 100%; }
  .hello .actions .btn { flex: 1; justify-content: center; }

  /* Ausgabe erfassen: Beleg-Foto zuerst (Scannen ist der schnellste Weg) */
  .modal-body > .row > .field:has(#drop) { order: -1; }

  /* ---------- Fenster: von unten, volle Breite ---------- */
  .overlay { padding: 0 !important; align-items: flex-end !important; place-items: end center !important; }
  .modal, .modal.wide, .modal.sm {
    width: 100% !important; max-width: 100%; max-height: 94dvh; border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom); animation: sheetUp .3s var(--ease);
  }
  .modal-head { padding: 18px 16px 0; }
  .modal-head h2 { font-size: 18px; }
  .modal-sub { padding: 4px 16px 0; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot > .btn { flex: 1 1 auto; justify-content: center; }
  .modal-foot .left { width: 100%; margin-right: 0; order: 2; }
  .modal-foot .left:empty { display: none; }
  .modal-foot .left .btn { flex: 1; justify-content: center; }
  .modal-body > .row[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .img-drop { height: 200px !important; }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

  .drawer { width: 100% !important; }
  .drawer-head { padding: calc(52px + env(safe-area-inset-top)) 16px 14px; }
  .drawer-body { padding: 16px; }
  .drawer-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .drawer-foot > .btn { flex: 1 1 auto; justify-content: center; }

  .toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
  .palette-wrap { padding: 8vh 10px 0 !important; }
  .menu { max-width: calc(100vw - 20px); }
  .menu button { padding: 11px 12px; font-size: 14px; }

  /* ---------- Anmeldung ---------- */
  .auth { display: block; height: auto; min-height: 100dvh; }
  .auth-hero { border-right: 0; border-bottom: 1px solid var(--line); padding: calc(28px + env(safe-area-inset-top)) 22px 22px; min-height: 0; }
  .auth-hero .brand { display: none; }
  .auth-hero .mega-logo img { width: 170px; }
  .auth-hero .claim { font-size: 14px; margin-top: 10px; }
  .auth-hero .features, .auth-hero .orb { display: none; }
  .auth-side { padding: 26px 20px calc(30px + env(safe-area-inset-bottom)); place-items: start center; }
  .auth-card h2 { font-size: 26px; }
  .auth-card .sub { margin-bottom: 20px; }
  .mod-pick { grid-template-columns: 1fr; }
  .state-screen { padding: 24px 18px; }

  /* ---------- Einzelne Seiten ---------- */
  .settings { grid-template-columns: 1fr !important; gap: 14px; }
  .settings-nav { position: static !important; flex-direction: row !important; flex-wrap: nowrap !important; overflow-x: auto; gap: 6px; padding-bottom: 4px; scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav button { flex: none; white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }
  .settings-nav .sep { display: none; }
  .quick { grid-template-columns: repeat(2, 1fr); }
  .fleet-grid { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr !important; }
  .sum-card { position: static; }
  .catbar { grid-template-columns: 1fr auto !important; row-gap: 4px; }
  .catbar > div { grid-column: 1 / -1; grid-row: 2; }
  .tax-types, .einv-pick, .dun-steps, .ai-suggest { grid-template-columns: 1fr !important; }
  .mini-stats { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .q-row { grid-template-columns: 1fr !important; gap: 8px; }
  .agenda-day { grid-template-columns: 1fr; gap: 8px; padding: 14px 16px; }
  .le { grid-template-columns: 1fr !important; }
  .le-prev { position: static; }
  .ai { height: calc(100dvh - 54px - 40px - env(safe-area-inset-top)); }
  .switch-row { gap: 12px; }
  .tfa-codes code { font-size: 14px; }
  .legal-page { padding: 28px 18px 60px; }

  /* Kalender: Monatsansicht kompakt */
  .cal-head { flex-wrap: wrap; gap: 8px; }
  .cal-head h2 { min-width: 0; font-size: 19px; flex: 1 1 100%; }
  .cal-week > div { font-size: 10px; padding: 6px 2px !important; text-align: center; }
  .cal-grid { grid-auto-rows: minmax(70px, auto); }
  .cal-grid > div { padding: 4px 3px !important; min-width: 0; }
  .cal-grid .ev, .cal-grid [class*="ev"] { font-size: 10px !important; padding: 1px 3px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 380px) {
  .g-4 { grid-template-columns: 1fr !important; }
  .page-head h1 { font-size: 24px; }
}
