/* UX-MOB-01 — Mobile remediation layer (Tahap 3).
   Guarded entirely by max-width: 640px so the desktop table layout stays untouched.
   Loaded AFTER css/style.min.css so these declarations win at equal specificity. */

@media (max-width: 640px) {
  /* ---- 1. Transaction input tables (Inbound / Outbound multi-item rows) -> stacked cards ----
     Inbound columns: Barang | Qty | Harga Beli | Catatan | Aksi
     Outbound columns: Barang | Stok Ada | Jumlah Keluar | Catatan | Aksi */
  #inbound-items-body tr,
  #outbound-items-body tr {
    display: block;
    border: 1px solid #334155;            /* slate-700 */
    border-radius: 0.75rem;
    background: rgba(15, 23, 42, 0.6);    /* slate-900/60 */
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
  }
  #inbound-items-body td,
  #outbound-items-body td {
    display: block;
    width: auto !important;
    padding: 0.25rem 0;
    border: 0;
    text-align: left !important;
  }
  #inbound-items-body td:not(:first-child),
  #outbound-items-body td:not(:first-child) {
    border-top: 1px dashed #334155;
    margin-top: 0.375rem;
    padding-top: 0.5rem;
  }
  #inbound-items-body td > *:first-child,
  #outbound-items-body td > *:first-child {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }
  #inbound-items-body td::before,
  #outbound-items-body td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #94a3b8;
    margin-bottom: 0.25rem;
  }
  /* Delete button spans full width of the card, comfortable tap height. */
  #inbound-items-body td:last-child,
  #outbound-items-body td:last-child {
    text-align: center !important;
  }
  #inbound-items-body td:last-child button,
  #outbound-items-body td:last-child button {
    width: 100%;
  }

  /* ---- 2. Master data / report tables -> stacked record cards ---- */
  .responsive-cards thead { display: none; }
  .responsive-cards,
  .responsive-cards tbody,
  .responsive-cards tr,
  .responsive-cards td { display: block; width: 100%; box-sizing: border-box; }
  .responsive-cards tr {
    border: 1px solid #334155;
    border-radius: 0.75rem;
    background: rgba(15, 23, 42, 0.45);
    padding: 0.5rem 0.75rem;
    margin: 0 0.5rem 0.75rem;
  }
  .responsive-cards td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.25rem 0;
    border: 0;
    text-align: left !important;
  }
  .responsive-cards td::before {
    content: attr(data-label);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #94a3b8;                       /* slate-400 */
    flex: 0 0 42%;
  }
  .responsive-cards td:not(:last-child) {
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  }
  .responsive-cards td > *:first-child { flex: 1 1 auto; min-width: 0; }
  /* Cells that stack two block children (name + description) keep them vertical. */
  .responsive-cards td.stacked-cell { flex-direction: column; align-items: stretch; }
  .responsive-cards td.stacked-cell > *:first-child { flex: 0 1 auto; }
  /* Empty-state rows have no label semantics — render plain. */
  .responsive-cards td[colspan]:only-child {
    display: block;
    text-align: center !important;
  }
  .responsive-cards td[colspan]:only-child::before { content: none; }
}

/* ---- 3. Touch targets (WCAG 2.5.5 / task spec: aksi buttons min 44x44px) ----
   Scoped so the guarantee lands on real controls without inflating inline
   icon buttons inside card rows. */
@media (hover: none) and (pointer: coarse), (max-width: 640px) {
  /* Primary interactive controls: >= 44px height, comfortably tappable. */
  button,
  a[role="button"],
  select,
  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="email"],
  input[type="date"],
  input[type="search"],
  .touch-target {
    min-height: 44px;
  }
  button,
  a[role="button"],
  select,
  .touch-target {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Icon-only buttons inside card rows span the row width and reach 44px comfortably. */
  .responsive-cards td:last-child button,
  #inbound-items-body td:last-child button,
  #outbound-items-body td:last-child button {
    min-width: 44px;
  }
}

/* ---- 4. Modal + sheet ergonomics on small screens ---- */
@media (max-width: 640px) {
  /* Full-width bottom-sheet style modals, thumb-reachable action row. */
  #modal-item > div,
  #modal-trx-detail > div,
  #modal-import > div,
  #modal-form > div,
  #modal-confirm > div,
  #modal-audit > div {
    max-width: 100% !important;
    width: 100%;
    border-radius: 1rem;
  }
  /* Transaction grid forms collapse to a single readable column. */
  #tab-inbound .grid,
  #tab-outbound .grid,
  #tab-adjustment .grid {
    grid-template-columns: 1fr;
  }
  /* Form action buttons: full-width stack, >= 44px. */
  #tab-inbound .flex.justify-end,
  #tab-outbound .flex.justify-end,
  #tab-adjustment .flex.justify-end {
    flex-direction: column;
    gap: 0.5rem;
  }
  #tab-inbound .flex.justify-end > button,
  #tab-outbound .flex.justify-end > button,
  #tab-adjustment .flex.justify-end > button {
    width: 100%;
    min-height: 44px;
  }
}

/* R2 — keep the master item toolbar stacked on tablet widths where the
   search/category controls plus two action buttons exceed 768px. */
@media (max-width: 900px) {
  .items-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .items-toolbar > div,
  .items-toolbar-actions {
    width: 100% !important;
  }
  .items-toolbar-actions > button {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* R3 — Clean Canvas & Mobile Overhead suppression: hide background SVG grids & pulse animations */
@media (max-width: 767px) {
  #cyber-grid-bg,
  .cyber-grid-container,
  #cyber-grid-bg *,
  .cyber-grid-container * {
    display: none !important;
  }
}

