/* ==========================================================================
   GKM – Mobile/Tablet overrides  v0.1
   Load AFTER output.css and growe_neu.css.
   Scope:  < 1024px  = phones + tablet portrait (sidebar is off-canvas)
           < 640px   = phones (dashboard tables become cards)
           < 1280px  = table layout fix (iPad landscape included)
   Desktop (>= 1280px) is untouched.
   ========================================================================== */


/* ---------- Tablet + phone (< 1024px) ----------------------------------- */
@media (max-width: 1023.98px) {

  /* 1. Page shell – footer back in normal flow, no overlap */
  #pageWrapper { display: flex; flex-direction: column; min-height: 100vh; }
  #mainBody    { height: auto !important; flex: 1 0 auto;
                 padding-top: 56px !important; padding-bottom: 0 !important; }
  #footer      { position: static !important; margin-top: 0; }

  /* 2. Compact single-row header, fixed 56px high */
  header > div {
    flex-direction: row !important;
    height: 56px;
    padding: 0 .75rem !important;
    gap: .75rem !important;
  }
  header > div > div:first-child,
  header > div > div:first-child .-mx-5 { margin-left: 0 !important; margin-right: 0 !important; min-width: 0; }
  header > div > div:first-child .px-3 { padding-left: 0 !important; padding-right: .5rem !important; }
  header img { height: 24px !important; width: auto; }

  header > div > div:last-child {          /* icons + hamburger */
    width: auto !important;
    flex-grow: 1;
    justify-content: flex-end !important;
  }
  header > div > div:last-child > a {      /* hamburger to the far right */
    order: 2;
    margin: 0 0 0 .75rem !important;
    padding: .5rem !important;
  }
  header .ml-4 { margin-left: .75rem !important; }

  /* 3. Sidebar sits directly under the 56px header, slides in */
  #mainBody > aside        { top: 56px !important; transition: left .2s ease; }
  #mainBody > aside.left-0 { box-shadow: 8px 0 24px rgba(0,0,0,.25); }
  #mainBody > aside a.flex { min-height: 44px; }          /* touch targets */

  /* 4. Content spacing + page title */
  #mainContent        { padding: 1.25rem 1.25rem 2rem !important; }
  #mainContent h1     { font-size: 1.375rem; line-height: 1.25; }
  #mainContent h1 strong { display: block; margin-top: .375rem; font-size: .75rem; line-height: 1.2; }

  /* 5. Card headers wrap instead of squashing the title */
  #mainContent .shadow-md > .flex.justify-between { flex-wrap: wrap; gap: .75rem; }
  #mainContent .shadow-md > .flex.justify-between > .flex.gap-2 { flex-wrap: wrap; }
  #mainContent a.border-green-500 {
    display: inline-flex; align-items: center;
    min-height: 40px; padding: .5rem .875rem !important;
  }

  /* 6. Stop iOS zooming into form fields (anything < 16px triggers zoom) */
  input:not([type=checkbox]):not([type=radio]):not([type=file]),
  select, textarea, .select2-search__field { font-size: 16px !important; }
}


/* ---------- Tables up to iPad landscape (< 1280px) ---------------------- */
@media (max-width: 1279.98px) {
  #mainContent .table-fixed { table-layout: auto !important; }
  #mainContent .dokumente,
  #mainContent .angebote    { overflow: auto !important; padding-right: 0 !important; }
}


/* ---------- Phones (< 640px) -------------------------------------------- */
@media (max-width: 639.98px) {

  #mainContent        { padding: 1rem .75rem 1.5rem !important; }
  #mainContent h1     { font-size: 1.2rem; }
  #mainContent h1 strong { display: none; }               /* breadcrumb filler */
  #mainContent .shadow-md { padding: 1rem !important; }

  /* Card buttons: full-width row */
  #mainContent .shadow-md > .flex.justify-between > .flex.gap-2 { width: 100%; }
  #mainContent .shadow-md > .flex.justify-between > .flex.gap-2 > a {
    flex: 1 1 auto; justify-content: center; text-align: center;
  }

  /* Forms: label above input */
  .form-input-boxes .form-group { flex-direction: column; align-items: stretch; gap: .25rem; }

  /* Fixed widths from growe_neu.css */
  .panel-body img.tuch-lg { width: 100%; height: auto; }
  .artikelcontainer       { width: 100%; }

  /* ---- Dashboard tables -> stacked cards ----------------------------- */
  #mainContent > .grid :is(.dokumente, .angebote) {
    max-height: none !important; overflow: visible !important;
  }
  #mainContent > .grid :is(.dokumente, .angebote) :is(table, tbody) {
    display: block; width: 100%; min-width: 0 !important;
  }
  #mainContent > .grid :is(.dokumente, .angebote) thead { display: none; }

  #mainContent > .grid :is(.dokumente, .angebote) tbody > tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .375rem 1rem;
    padding: .875rem 1.75rem .875rem 0;
    position: relative;
  }
  #mainContent > .grid :is(.dokumente, .angebote) tbody > tr > td {
    display: flex; flex-direction: column;
    padding: 0 !important;
    white-space: normal !important;
    text-align: left !important;
    min-width: 0; overflow-wrap: anywhere;
  }
  #mainContent > .grid :is(.dokumente, .angebote) td::before {
    font-size: .6875rem; line-height: 1rem;
    text-transform: uppercase; letter-spacing: .03em; color: #818181;
  }

  /* Hide empty fields (no number, no commission, not yet ordered …) */
  #mainContent > .grid :is(.dokumente, .angebote) td:empty,
  #mainContent > .grid :is(.dokumente, .angebote) td:has(> a:empty) { display: none; }

  /* "Neu" star: top-right corner */
  #mainContent > .grid :is(.dokumente, .angebote) td:first-child {
    position: absolute; top: .875rem; right: 0;
  }

  /* Actions: full-width bar with 44px tap targets */
  #mainContent > .grid :is(.dokumente, .angebote) td:last-child {
    grid-column: 1 / -1;
    border-top: 1px solid #e0e0e0;
    margin-top: .25rem; padding-top: .25rem !important;
  }
  #mainContent > .grid :is(.dokumente, .angebote) td:last-child > span { gap: .25rem !important; }
  #mainContent > .grid :is(.dokumente, .angebote) td:last-child :is(a, button)[class*="icon-"] {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px;
  }

  /* Labels – Aufträge (Nummer, Datum, Kommission, Betrag, Nutzer, Bestellt am) */
  #mainContent > .grid .dokumente td:nth-child(2)::before { content: "Nummer"; }
  #mainContent > .grid .dokumente td:nth-child(3)::before { content: "Datum"; }
  #mainContent > .grid .dokumente td:nth-child(4)::before { content: "Kommission"; }
  #mainContent > .grid .dokumente td:nth-child(5)::before { content: "Betrag"; }
  #mainContent > .grid .dokumente td:nth-child(6)::before { content: "Nutzer"; }
  #mainContent > .grid .dokumente td:nth-child(7)::before { content: "Bestellt am"; }
  #mainContent > .grid .dokumente td:nth-child(6) { grid-column: 1 / -1; }

  /* Labels – Angebote (Nummer, Datum, Endkunde, Kommission, Original, Endkunde-Betrag, Gewinn, Nutzer) */
  #mainContent > .grid .angebote td:nth-child(2)::before { content: "Nummer"; }
  #mainContent > .grid .angebote td:nth-child(3)::before { content: "Datum"; }
  #mainContent > .grid .angebote td:nth-child(4)::before { content: "Endkunde"; }
  #mainContent > .grid .angebote td:nth-child(5)::before { content: "Kommission"; }
  #mainContent > .grid .angebote td:nth-child(6)::before { content: "Original-Betrag"; }
  #mainContent > .grid .angebote td:nth-child(7)::before { content: "Betrag Endkunde"; }
  #mainContent > .grid .angebote td:nth-child(8)::before { content: "Gewinn"; }
  #mainContent > .grid .angebote td:nth-child(9)::before { content: "Nutzer"; }
  #mainContent > .grid .angebote td:nth-child(9) { grid-column: 1 / -1; }

  /* Show latest 5 per list on phones; "Zur …übersicht" has the rest.
     Delete this rule to show all rows. */
  #mainContent > .grid :is(.dokumente, .angebote) tbody > tr:nth-child(n+6) { display: none; }
}
