/* ══════════════════════════════════════════════════════════════════
   responsive.css - Tablet & mobile enhancements (loaded after site.css)
   Desktop (>=992px) is untouched. 768-991px: data tables scroll inside
   their cards, toolbars stay pinned, controls grow. <768px: data tables
   become stacked cards with bold labels (data-label injected by site.js).
   ══════════════════════════════════════════════════════════════════ */

/* ── Tablet: 768 - 991px ── */
@media (max-width: 991.98px) {

  /* Wide tables scroll inside their cards instead of clipping (site.css
     sets overflow:hidden on these containers) */
  .md-card,
  .rp-wrap,
  .dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Keep tables at intrinsic width so columns never squeeze */
  .md-table,
  .rp-table,
  .md-plain-table,
  .md-inner-table { min-width: max-content; }

  /* Pin search / pagination while the table scrolls */
  .md-tbar,
  .md-bbar { position: sticky; left: 0; z-index: 3; }

  /* Touch-friendly controls */
  .md-tbar-l select,
  .md-tbar-r .dataTables_filter input,
  .rp-pagesize select { height: 42px; }
  .md-tbar-r .dataTables_filter input { width: 220px !important; }
}

/* ── Mobile: < 768px ── */
@media (max-width: 767.98px) {

  /* No horizontal scroll needed once tables become cards */
  .md-card,
  .md-table-wrap,
  .rp-wrap,
  .dataTables_wrapper,
  .md-grid-scroll { overflow-x: visible; }
  .tdx-card .table-responsive { overflow-x: visible; }

  /* Tables render as stacked cards */
  .md-table,
  .rp-table,
  .md-plain-table,
  .md-inner-table {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .md-table thead,
  .rp-table thead,
  .md-plain-table thead,
  .md-inner-table thead { display: none; }
  .md-table tbody,
  .rp-table tbody,
  .md-plain-table tbody,
  .md-inner-table tbody { display: block; }

  .md-table tbody tr,
  .rp-table tbody tr,
  .md-plain-table tbody tr,
  .md-inner-table tbody tr {
    display: block;
    background: var(--card-bg) !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px;
    margin: 0 0 10px;
    padding: 6px 14px 10px;
    box-shadow: 0 6px 18px -12px rgba(15, 23, 42, 0.25);
  }

  .md-table tbody td,
  .rp-table tbody td,
  .md-plain-table tbody td,
  .md-inner-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 8px 0 !important;
    text-align: right;
    border: none !important;
    border-bottom: 1px dashed var(--table-row-border) !important;
  }
  .md-table tbody td:last-child,
  .rp-table tbody td:last-child,
  .md-plain-table tbody td:last-child,
  .md-inner-table tbody td:last-child { border-bottom: none !important; }
  .md-table tbody td:first-child { border-left: none !important; }

  /* Bold uppercase column label (from data-label attribute) */
  .md-table tbody td[data-label]::before,
  .rp-table tbody td[data-label]::before,
  .md-plain-table tbody td[data-label]::before,
  .md-inner-table tbody td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-weight: 700;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
  }

  /* Full-width rows: empty state / colspan / DT "no records" */
  .md-table tbody td[colspan],
  .rp-table tbody td[colspan],
  .md-plain-table tbody td[colspan],
  .md-inner-table tbody td[colspan] {
    display: block;
    text-align: center;
    padding: 14px !important;
  }
  .md-table tbody td[colspan]::before,
  .rp-table tbody td[colspan]::before,
  .md-plain-table tbody td[colspan]::before,
  .md-inner-table tbody td[colspan]::before { display: none; }

  /* Actions column: right-aligned, no label */
  .md-table tbody td:has(.md-actions) { justify-content: flex-end; }
  .md-table tbody td:has(.md-actions)::before { display: none; }

  /* Editable inputs fill their card cell (Sales grids) */
  .md-inner-table tbody td input[type="text"],
  .md-inner-table tbody td input.form-control-sm {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
  }
  .md-inner-table tbody td input[type="checkbox"],
  .md-plain-table input[type="checkbox"] { width: 22px; height: 22px; }

  /* DataTables toolbar stacks full-width */
  .md-tbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 0.9rem 1rem;
  }
  .md-tbar-l,
  .md-tbar-r { width: 100%; }
  .md-tbar-r .dataTables_filter { width: 100%; }
  .md-tbar-r .dataTables_filter input { width: 100% !important; height: 42px; }

  .md-bbar {
    position: static;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }
  .md-bbar-l { text-align: center; }

  /* Page header: title + action button stack */
  .md-head { flex-direction: column; align-items: stretch; }
  .md-head-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .md-head .md-btn-primary,
  .md-head .md-btn-secondary,
  .md-head .md-btn-danger,
  .md-head-actions .md-btn-primary,
  .md-head-actions .md-btn-secondary,
  .md-head-actions .md-btn-danger { flex: 1 1 auto; }

  /* Report toolbar stacks */
  .rp-toolbar { flex-direction: column; align-items: stretch; }
  .rp-pagesize { justify-content: space-between; }

  /* Report / search filter forms: col-auto children go full-width */
  form.row.g-3 > .col-auto { width: 100%; }
  form.row.g-3 > .col-auto .form-control,
  form.row.g-3 > .col-auto .form-select { width: 100%; }

  /* Key/value info table (Confirmed Task Details) */
  .md-info-table,
  .md-info-table tbody,
  .md-info-table tr,
  .md-info-table td { display: block; width: 100%; }
  .md-info-table tr {
    margin-bottom: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  .md-info-table td { padding: 3px 0 !important; border: none !important; }
  .md-info-table tr td:first-child {
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
  }
}

/* ══════════════════════════════════════════════════════════════════
   Sidebar collapsed rail (<=1200px) — bug fix
   site.css turns the sidebar into an 80px icon rail by hiding every
   nav group header (`.sidebar .sidebar-group-header { display:none }`),
   which also hides each group's icon, and hides the sub-link bullets
   (`.sidebar-link i.fa-circle`). Fix: keep ALL icons visible in the
   rail; hide only the text labels. Desktop (>1200px) and mobile
   offcanvas (<=900px) behavior is untouched.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  /* Group headers become centered rail icon buttons (was display:none) */
  .sidebar .sidebar-group-header { display: flex; justify-content: center; padding: 10px; }
  /* Hide only the chevron + label; the group icon stays visible */
  .sidebar .sidebar-group-header .sidebar-group-chevron { display: none; }
  .sidebar .sidebar-group-header span { display: none; }
  /* Groups stay force-expanded in the rail; keep the sub-link bullets
     so every nav item icon is still visible (was display:none) */
  .sidebar .sidebar-link i.fa-circle { display: inline-block; }
}
