/* ════════════════════════════════════════════════════════════════════
   mobile.css — Dedizierte Mobile-/Tablet-Schicht für die Immergrün App
   Lädt ZULETZT (nach styles.css) → gewinnt die Kaskade bei gleicher
   Spezifität. Eine zentrale Datei, in sich konsistent, keine verstreuten
   Patches. Gilt für iPhone, Android-Phones und iPad.
   ════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────
   1. GLOBAL — gilt für alle Viewports ≤ 1024px
   ───────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {

  /* Kein horizontaler Seiten-Scroll, egal was passiert */
  html, body {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* iOS: Inputs < 16px lösen Auto-Zoom aus → immer 16px */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: 16px;
  }

  /* ---- KRITISCH: keine Phantom-Sidebar-Spalte ----
     styles.css erzwingt per !important eine .app-shell-Grid-Spalte
     von 272px für die Sidebar — auch auf Mobile/Tablet, wo die
     Sidebar aber off-canvas (position:fixed) ist. Folge: der
     Hauptinhalt ist nur ~70% breit, rechts ein leerer Streifen,
     alles wirkt gequetscht. DAS war die Hauptursache. Hier wird
     das Grid für iPhone + iPad plattgemacht → volle Breite. */
  .app-shell {
    display: block !important;
    grid-template-columns: none !important;
  }
  .main-content {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ─────────────────────────────────────────────────────────────────────
   2. BACKOFFICE — Phones (≤ 767px)
   ───────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* ---- Topbar: kompakt, sticky ---- */
  .topbar {
    padding: 10px 14px;
    gap: 10px;
    min-height: 0;
  }
  .topbar h1 {
    font-size: 16px;
    line-height: 1.2;
  }
  .topbar-subtitle {
    font-size: 11px;
  }
  .brand-logo {
    width: 34px;
    height: 34px;
  }

  /* ---- Hero: nur Titel, kein Ballast ---- */
  .hero {
    padding-block: 6px 2px;
    margin-bottom: 6px;
    gap: 6px;
    min-height: 0;
  }
  .hero h2,
  .hero #sectionTitle {
    font-size: 19px;
    font-weight: 800;
    margin: 0;
    line-height: 1.25;
  }
  .hero-subtitle,
  .hero-chip {
    display: none;
  }
  .hero-copy {
    gap: 2px;
  }
  /* Hero-Aktionen (Buttons) volle Breite, untereinander */
  .hero-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .hero-actions > * {
    flex: 1 1 auto;
  }

  /* ---- Hauptinhalt: angenehmer Abstand, Platz für Bottom-Nav ---- */
  .main-content {
    padding: 10px 14px calc(96px + env(safe-area-inset-bottom, 0px));
  }

  /* ---- Panel-Karten: konsistente, ruhige Abstände ---- */
  .panel-card,
  .content-section > .panel-card {
    padding: 16px 14px;
    border-radius: 14px;
    margin-bottom: 12px;
  }

  /* ---- Sektions-Tabs (Arbeitszeiten / Urlaube / …) ---- */
  .tabs-row {
    gap: 8px;
    flex-wrap: wrap;
  }
  .tab-chip {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 44px;
    font-size: 13px;
  }

  /* ---- KPI-Karten Dashboard: 2 pro Reihe ---- */
  .db-kpi-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .db-kpi-card {
    padding: 12px;
  }
  .db-kpi-value {
    font-size: 22px;
  }

  /* ---- Tabellen: sauberer horizontaler Scroll statt Layout-Bruch ---- */
  .table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border, #e3e8e3);
    /* dezenter Schatten als Scroll-Hinweis am rechten Rand */
    background:
      linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
      linear-gradient(to right, rgba(255,255,255,0), #fff 70%) 100% 0,
      radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.12), rgba(0,0,0,0)),
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.12), rgba(0,0,0,0)) 100% 0;
    background-repeat: no-repeat;
    background-size: 32px 100%, 32px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
  }
  .table-wrapper table {
    margin: 0;
  }
  /* Erste Spalte (meist Name) bleibt beim Scrollen sichtbar */
  .table-wrapper table thead th:first-child,
  .table-wrapper table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
  }
  .table-wrapper table thead th:first-child {
    z-index: 3;
    background: var(--table-head-bg, #f4f7f4);
  }
  /* Zellen kompakter, aber lesbar */
  .table-wrapper table th,
  .table-wrapper table td {
    padding: 10px 12px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* ---- Formulare: einspaltig, große Touch-Felder ---- */
  .employee-form-grid,
  .absence-grid,
  .backoffice-user-grid,
  .export-grid,
  .grid-two,
  .inline-form,
  .filter-bar,
  .edit-grid,
  .edit-panel-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    min-height: 48px;
    width: 100%;
  }
  textarea {
    min-height: 96px;
  }
  label {
    font-size: 13px;
  }

  /* ---- Buttons: Touch-freundlich ---- */
  .btn, button.btn, a.btn,
  .primary-button, .secondary-button, .ghost-button {
    min-height: 46px;
  }

  /* ---- Toolbar (Suche + Aktionen): flach & kompakt ----
     styles.css definiert .toolbar an 15+ Stellen (teils als Grid,
     teils mit !important) → 196px hohe, verschachtelte Box.
     Hier wird das in der dedizierten Mobile-Schicht deterministisch
     mit !important plattgemacht. Bewusst zentral, nicht verstreut. */
  .toolbar {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    grid-template-columns: none !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    border-radius: 0 !important;
  }
  /* Aktions-Buttons nebeneinander (2 pro Reihe) statt gestapelt */
  .toolbar-actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    grid-template-columns: none !important;
    gap: 8px !important;
    justify-content: stretch !important;
  }
  .toolbar-actions > * {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 0 !important;
    width: auto !important;
  }

  /* ---- Section-Header: Titel-Block bleibt gestapelt, nur die
     Steuerelemente-Reihe bricht um. WICHTIG: den Kind-Containern
     NICHT display:flex aufzwingen — sonst landet der Eyebrow
     ("KASSE", "STORE AUFGABEN" …) neben dem Titel statt darüber. ---- */
  .section-header {
    width: 100% !important;
    max-width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px;
  }
  .section-header > div {
    flex-wrap: wrap !important;
    max-width: 100% !important;
  }
  /* Eyebrow + Titel immer als eigene Zeilen (Block-Layout) */
  .section-header .eyebrow,
  .section-header h2,
  .section-header h3 {
    display: block !important;
    width: 100% !important;
  }
  .section-header select,
  .section-header input,
  .section-header button,
  .section-header .primary-button,
  .section-header .secondary-button {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  /* ---- Status-Filter-Chips: EINE scrollbare Reihe statt 2 ---- */
  .emp-status-tabs,
  .status-filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 2px;
  }
  .emp-status-tabs::-webkit-scrollbar,
  .status-filter-row::-webkit-scrollbar {
    display: none;
  }
  .emp-status-tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* ---- Modale & Drawer: als Bottom-Sheet ---- */
  .modal-card,
  .edit-panel,
  .produkt-edit-drawer,
  .panel-card.modal {
    width: 100%;
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    margin: 0;
  }
}

/* ─────────────────────────────────────────────────────────────────────
   KIOSK-INVENTUR — Vollbild-Overlay ähnlich Kassenabschluss
   ───────────────────────────────────────────────────────────────────── */

/* Page-Container (versteckt bis inventur-mode aktiv) */
.kiosk-inventur-page {
  display: none;
}
body.inventur-mode #kioskInventurPage {
  display: flex !important;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #f8fafc;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Screens */
.ki-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0 16px 24px;
}
.ki-screen.hidden { display: none; }

/* Header-Zeile */
.ki-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 12px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 10;
}
.ki-header > div { flex: 1; }
.ki-header h2 { font-size: 1.1rem; font-weight: 800; margin: 0; color: #1a1a1a; }
.ki-back-btn {
  background: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
}
.ki-back-btn:active { background: #f0fdf4; border-color: #9BBE40; }
.ki-sub { font-size: 0.78rem; color: #6b7280; margin: 2px 0 0; }
.ki-scan-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.ki-scan-btn:active { background: #333; }

/* Session-Liste */
.ki-session-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.ki-session-card {
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s;
}
.ki-session-card:active { border-color: #9BBE40; background: #f9fef0; }
.ki-session-title { font-size: 1rem; font-weight: 700; color: #1a1a1a; }
.ki-session-meta { font-size: 0.78rem; color: #6b7280; margin: 3px 0 8px; }
.ki-start-btn {
  width: 100%;
  padding: 14px;
  background: #204A33;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}
.ki-start-btn:active { background: #153321; }

/* Progress-Bar (wiederverwendet in Sessions + Zonen) */
.ki-prog-bar-wrap {
  height: 5px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.ki-prog-bar {
  height: 100%;
  background: #9BBE40;
  border-radius: 3px;
  transition: width 0.3s;
}

/* Zonen-Raster */
.ki-zone-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.ki-zone-card {
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 12px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
}
.ki-zone-card:active { border-color: #9BBE40; background: #f9fef0; }
.ki-zone-card.done { border-color: #6ee7b7; background: #f0fdf4; }
.ki-zone-emoji { font-size: 1.6rem; display: block; margin-bottom: 6px; }
.ki-zone-label { font-size: 0.88rem; font-weight: 700; color: #1a1a1a; }
.ki-zone-sub { font-size: 0.75rem; color: #6b7280; margin-top: 2px; }

/* Artikel-Liste */
.ki-article-list { display: flex; flex-direction: column; gap: 8px; }
.ki-art-row {
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
}
.ki-art-row.counted { border-color: #6ee7b7; background: #f0fdf4; }
.ki-art-name { font-size: 0.9rem; font-weight: 700; color: #1a1a1a; margin-bottom: 2px; }
.ki-art-meta { font-size: 0.73rem; color: #6b7280; margin-bottom: 10px; }
.ki-art-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ki-art-step {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1.5px solid #204A33;
  background: #fff;
  color: #204A33;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.ki-art-step:active { background: #204A33; color: #fff; }
.ki-art-qty {
  width: 72px;
  height: 36px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}
.ki-art-qty:focus { outline: none; border-color: #9BBE40; }
.ki-art-unit { font-size: 0.75rem; color: #6b7280; min-width: 20px; }
.ki-confirm-btn {
  margin-left: auto;
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  background: #9BBE40;
  color: #143020;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.ki-confirm-btn.confirmed { background: #10b981; color: #fff; }
.ki-confirm-btn:active { opacity: 0.85; }

/* Utility */
.ki-loading, .ki-empty, .ki-error {
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
  padding: 32px 16px;
}
.ki-error { color: #dc2626; }

/* ─────────────────────────────────────────────────────────────────────
   3. KIOSK / COCKPIT — Phones (≤ 767px)
   ───────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Kiosk-Karte: volle Breite nutzen */
  .kiosk-shell {
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px));
    max-width: 100%;
  }
  .kiosk-card {
    padding: 16px 14px;
    border-radius: 18px;
  }

  /* Cockpit Stat-Karten: 2 pro Reihe, gleich hoch */
  .kiosk-progress {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .kiosk-progress-card,
  .timeclock-kpi-card,
  .kiosk-we-card {
    min-height: 84px;
    padding: 12px;
  }

  /* Cockpit Aktions-Buttons (Waste / Verzehr / Kasse): volle Breite,
     gut greifbar, untereinander */
  .action-button,
  .timeclock-action-button,
  .kiosk-waste-button,
  .kiosk-verzehr-button,
  .kiosk-cash-closing-button {
    min-height: 60px;
  }

  /* Zeiterfassungs-Buttons (Start/Pause/Ende): 2×2 Raster */
  .kiosk-actions,
  .timeclock-action-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* Waste-Modal: Touch-Targets ≥ 48px */
  .waste-qty-btn {
    width: 48px;
    height: 48px;
  }
  .waste-group-tile,
  .waste-portion-tile {
    min-height: 52px;
  }
}

/* ─────────────────────────────────────────────────────────────────────
   4. SEHR KLEINE PHONES (≤ 380px)
   ───────────────────────────────────────────────────────────────────── */
@media (max-width: 380px) {

  /* KPI / Stat-Karten einspaltig wenn sehr eng */
  .db-kpi-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }
  /* Cockpit-Stats bleiben 2-spaltig (kompakt genug) */

  /* Kassenabschluss-Zähler: 2 statt 3 Spalten */
  .cash-count-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
  }
  .cash-pdf-preview-actions {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────────────────────────────────────────────────
   5. iPad / Tablet Hochformat (768px – 1024px)
   ───────────────────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1024px) {

  /* Kiosk-Stats: 3 pro Reihe (genug Platz, nicht gedrängt) */
  .kiosk-progress {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  .kiosk-actions,
  .timeclock-action-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Backoffice Hero: Subtitle ok, Chips weg */
  .hero-chip {
    display: none;
  }
  .hero-subtitle {
    font-size: 13px;
  }

  /* KPI-Karten: 3 pro Reihe */
  .db-kpi-grid,
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Formular-Raster: 2-spaltig */
  .employee-form-grid,
  .absence-grid,
  .backoffice-user-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
