/* Manita mobile comfort — list cards, tap targets, user-role, forms */

@media (max-width: 767.98px) {
  /* ---- DataTables / list cards ---- */
  .table-responsive {
    display: block !important;
    width: 100% !important;
    overflow-x: hidden !important;
  }

  .table-responsive table.dataTable,
  .datatables .table-responsive table.table,
  table.dataTable {
    width: 100% !important;
    min-width: 0 !important;
  }

  .table-responsive thead,
  table.dataTable thead {
    display: none !important;
  }

  .table-responsive tbody tr,
  table.dataTable tbody tr {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 12px !important;
    padding: 12px 14px !important;
    border: 1px solid var(--bs-border-color, #dee2e6) !important;
    border-radius: 10px !important;
    background: var(--bs-body-bg, #fff) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  }

  .table-responsive tbody tr td,
  table.dataTable tbody tr td {
    display: flex !important;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
    width: 100% !important;
    max-width: 100% !important;
    text-align: left !important;
    padding: 8px 0 !important;
    border: none !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    white-space: normal !important;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--bs-body-color, #2a3547);
  }

  .table-responsive tbody tr td:last-child,
  table.dataTable tbody tr td:last-child {
    border-bottom: none !important;
    padding-top: 12px !important;
  }

  /* Label + value on the same line */
  .table-responsive tbody tr td::before,
  table.dataTable tbody tr td::before {
    content: attr(data-label);
    flex: 0 0 34%;
    max-width: 34%;
    width: 34%;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--bs-secondary-color, #6c757d);
    text-transform: capitalize;
    margin: 0;
    padding-top: 1px;
  }

  .table-responsive tbody tr td:not([data-label])::before,
  table.dataTable tbody tr td:not([data-label])::before,
  .table-responsive tbody tr td[data-label=""]::before,
  table.dataTable tbody tr td[data-label=""]::before {
    content: none;
    display: none;
    flex: 0;
    width: 0;
    max-width: 0;
  }

  /* Value takes remaining width, left-aligned (not right) — exclude action toolbar */
  .table-responsive tbody tr td > *:not(.manita-row-actions),
  table.dataTable tbody tr td > *:not(.manita-row-actions) {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left !important;
  }

  .table-responsive tbody tr td > .manita-row-actions,
  table.dataTable tbody tr td > .manita-row-actions {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }

  /* Let More menu escape card clipping on mobile */
  .table-responsive tbody tr:has(.manita-action-more.show),
  table.dataTable tbody tr:has(.manita-action-more.show) {
    z-index: 20;
    position: relative;
  }

  .table-responsive:has(.manita-action-more.show) {
    overflow: visible !important;
  }

  /* Action column: label on its own row, icons wrap below */
  .table-responsive tbody tr td:last-child,
  table.dataTable tbody tr td:last-child,
  .table-responsive tbody tr td[data-label="Actions"],
  .table-responsive tbody tr td[data-label="Action"],
  .table-responsive tbody tr td[data-label="actions"],
  table.dataTable tbody tr td[data-label="Actions"],
  table.dataTable tbody tr td[data-label="Action"],
  table.dataTable tbody tr td[data-label="actions"] {
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .table-responsive tbody tr td:last-child::before,
  table.dataTable tbody tr td:last-child::before,
  .table-responsive tbody tr td[data-label="Actions"]::before,
  .table-responsive tbody tr td[data-label="Action"]::before,
  .table-responsive tbody tr td[data-label="actions"]::before,
  table.dataTable tbody tr td[data-label="Actions"]::before,
  table.dataTable tbody tr td[data-label="Action"]::before,
  table.dataTable tbody tr td[data-label="actions"]::before {
    flex: 1 1 100%;
    max-width: 100%;
    width: 100%;
    margin-bottom: 2px;
  }

  .table-responsive tbody tr td .btn,
  table.dataTable tbody tr td .btn,
  .table-responsive tbody tr td a.btn,
  table.dataTable tbody tr td a.btn,
  .table-responsive tbody tr td a:not(.btn),
  table.dataTable tbody tr td a:not(.btn) {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0.5rem !important;
    margin: 0 6px 6px 0 !important;
    flex: 0 0 auto;
  }

  .table-responsive tbody tr td .btn i,
  table.dataTable tbody tr td .btn i {
    font-size: 1.15rem !important;
  }

  /* Filter row inputs in thead are hidden with thead; show length/search stacked */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    width: 100% !important;
    float: none !important;
    text-align: left !important;
    margin-bottom: 0.75rem;
  }

  .dataTables_wrapper .dataTables_filter label {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    min-height: 44px;
  }

  .dataTables_wrapper .dataTables_length label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .dataTables_wrapper .dataTables_paginate .paginate_button {
    min-height: 40px;
    min-width: 40px;
    padding: 0.4rem 0.65rem !important;
  }

  /* Create button full-width feel */
  .card-body > .row .col-sm-6[style*="right"] {
    text-align: left !important;
    margin-top: 0.5rem;
  }

  .card-body > .row .col-sm-6[style*="right"] .btn,
  .card-body > .row .col-sm-6.text-end .btn,
  .card-body > .row a[rel="tab"] .btn {
    min-height: 44px;
    width: 100%;
  }

  /* Customizer FAB — keep off list content */
  .customizer-btn {
    bottom: 16px !important;
    right: 12px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    opacity: 0.9;
  }

  .body-wrapper .container-fluid,
  .body-wrapper .datatables {
    padding-bottom: 64px;
  }

  /* Report filter / search chips */
  .card-body .btn-sm,
  .card .input-group .btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* Sticky save for long forms (top action card) */
  form .card.position-relative.overflow-hidden.mb-4 {
    position: sticky !important;
    top: 0;
    z-index: 40;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  form .card.position-relative.overflow-hidden.mb-4 .btn {
    min-height: 44px;
  }

  form .card.position-relative.overflow-hidden.mb-4 .ms-6 {
    margin-left: 0.5rem !important;
  }
}

/* ---- User Role permission grid ---- */
.user-role-perm {
  margin-top: 0.5rem;
}

.user-role-perm-head,
.user-role-perm-select-all,
.user-role-perm-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.25rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.user-role-perm-name {
  flex: 0 0 28%;
  max-width: 28%;
  font-weight: 500;
  padding-right: 0.5rem;
}

.user-role-perm-actions {
  display: flex;
  flex: 1;
  justify-content: space-between;
  gap: 0.25rem;
}

.user-role-perm-action {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  margin: 0;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--bs-secondary-color, #6c757d);
  text-align: center;
  user-select: none;
}

.user-role-perm-action .form-check-input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  cursor: pointer;
}

.user-role-perm-action span {
  line-height: 1.1;
}

.user-role-perm-head .user-role-perm-action {
  font-weight: 600;
  color: var(--bs-body-color);
}

.user-role-sticky-actions {
  display: none;
}

@media (max-width: 767.98px) {
  .user-role-perm-head {
    display: none !important;
  }

  .user-role-perm-select-all,
  .user-role-perm-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 10px;
    border-bottom-color: var(--bs-border-color, #dee2e6);
    background: var(--bs-body-bg, #fff);
  }

  .user-role-perm-name {
    flex: none;
    max-width: none;
    width: 100%;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0;
  }

  .user-role-perm-actions {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    width: 100%;
  }

  .user-role-perm-action {
    min-height: 56px;
    padding: 6px 2px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.03);
  }

  .user-role-perm-action .form-check-input {
    width: 1.35rem;
    height: 1.35rem;
  }

  .user-role-sticky-actions {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }

  .user-role-sticky-actions .btn {
    flex: 1;
    min-height: 48px;
  }

  body:has(#user_role) .body-wrapper .container-fluid {
    padding-bottom: 88px;
  }

  body:has(#user_role) .customizer-btn {
    bottom: 72px !important;
  }
}
