/* ===================================================================
   SAMS-AG Mobile-Friendly Tables
   Transforms standard HTML tables into card-based layouts on mobile.
   Each <tr> becomes a card, each <td> shows its column label.
   =================================================================== */

@media (max-width: 767.98px) {

  /* ── Core Table Transformation ────────────────────────────────── */

  /* Hide table header on mobile */
  .table-mobile-cards thead {
    display: none !important;
  }

  /* Table itself becomes a simple block container */
  .table-mobile-cards,
  .table-mobile-cards tbody {
    display: block;
    width: 100%;
  }

  /* Each row becomes a card */
  .table-mobile-cards tbody tr {
    display: block;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }

  /* Each cell becomes a row within the card */
  .table-mobile-cards tbody td {
    display: flex;
    align-items: flex-start;
    padding: 0.4rem 0.75rem !important;
    border: none !important;
    border-bottom: 1px solid #f0f0f0 !important;
    text-align: left !important;
    white-space: normal !important;
    min-height: 0 !important;
    word-break: break-word;
  }

  /* Last td in card - no bottom border */
  .table-mobile-cards tbody td:last-child {
    border-bottom: none !important;
  }

  /* Label from data-label attribute */
  .table-mobile-cards tbody td::before {
    content: attr(data-label);
    display: inline-block;
    font-weight: 600;
    color: #495057;
    min-width: 120px;
    flex-shrink: 0;
    font-size: 0.82rem;
    padding-right: 0.5rem;
  }

  /* If td has no data-label, skip the pseudo-element width */
  .table-mobile-cards tbody td:not([data-label])::before,
  .table-mobile-cards tbody td[data-label=""]::before {
    display: none;
  }

  /* ── Action Column Styling ────────────────────────────────────── */

  /* Action cells: full-width with centered buttons */
  .table-mobile-cards tbody td.mobile-actions {
    display: flex;
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.6rem 0.75rem !important;
    background: #f8f9fa;
    border-radius: 0 0 0.5rem 0.5rem;
    border-bottom: none !important;
    flex-wrap: wrap;
  }

  .table-mobile-cards tbody td.mobile-actions::before {
    display: none;
  }

  .table-mobile-cards tbody td.mobile-actions .btn {
    min-width: auto;
  }

  /* ── DataTables Controls ──────────────────────────────────────── */

  /* Make DataTables controls stack vertically */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    text-align: left !important;
    margin-bottom: 0.5rem;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    margin-left: 0 !important;
    margin-top: 0.25rem;
  }

  .dataTables_wrapper .dataTables_info {
    text-align: center;
    font-size: 0.8rem;
  }

  .dataTables_wrapper .dataTables_paginate {
    text-align: center;
    margin-top: 0.5rem;
  }

  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.8rem;
  }

  /* ── Dashboard Widget Tables ──────────────────────────────────── */

  /* Dashboard tables inside cards (smaller variant) */
  .widget-card .table-mobile-cards tbody td::before {
    min-width: 100px;
    font-size: 0.78rem;
  }

  .widget-card .table-mobile-cards tbody tr {
    margin-bottom: 0.5rem;
    border-radius: 0.35rem;
  }

  .widget-card .table-mobile-cards tbody td {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.85rem;
  }

  /* ── Opname Detail Table (inside modal) ──────────────────────── */
  
  .table-mobile-cards tbody td select.form-select-sm,
  .table-mobile-cards tbody td input.form-control-sm {
    flex: 1;
    min-width: 0;
  }

  /* ── Empty State Rows ─────────────────────────────────────────── */

  .table-mobile-cards tbody tr td[colspan] {
    display: block;
    text-align: center !important;
  }

  .table-mobile-cards tbody tr td[colspan]::before {
    display: none;
  }

  /* ── Badge & Status Adjustments ───────────────────────────────── */

  .table-mobile-cards .badge {
    font-size: 0.75rem;
  }

  /* ── Footer Time Display ──────────────────────────────────────── */

  footer .container small {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.7rem;
  }
}
