/* ============================================================
 * GLOBAL RESPONSIVE TABLES
 * Auto-applied to any table inside a dashboard when width ≤ 800px
 * Skip conversion with: <table data-no-responsive>
 * ============================================================ */

/* ---------- Desktop: ensure tables never overflow their wrapper ---------- */
.dashboard-main .table,
.dashboard-main table {
  width: 100%;
  border-collapse: collapse;
}

/* ---------- Mobile: convert to cards ---------- */
@media (max-width: 800px) {

  /* 1. Table becomes a block container */
  .responsive-mobile {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    border-collapse: separate !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* 2. Hide all header rows (thead OR auto-detected first <th> row) */
  .responsive-mobile thead,
  .responsive-mobile tr.auto-thead {
    display: none !important;
  }

  /* 3. Body becomes block */
  .responsive-mobile tbody {
    display: block !important;
    width: 100% !important;
  }

  /* 4. Each row becomes a card */
  .responsive-mobile tbody tr {
    display: block !important;
    background: #fff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 14px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .03);
    transition: box-shadow .15s;
  }
  .responsive-mobile tbody tr:hover {
    background: #fff !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .06);
  }

  /* 5. Each cell becomes a labeled flex row */
  .responsive-mobile tbody td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 8px 0 !important;
    border-bottom: 1px dashed #f1f5f9 !important;
    text-align: left !important;
    white-space: normal !important;
    font-size: .88rem !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    color: #0f172a !important;
    background: transparent !important;
  }
  .responsive-mobile tbody td:last-child {
    border-bottom: none !important;
  }

  /* 6. Show data-label as a heading */
  .responsive-mobile tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #64748b;
    flex-shrink: 0;
    min-width: 90px;
    line-height: 1.4;
    display: block;
  }

  /* 7. Hide labels where there is none */
  .responsive-mobile tbody td:not([data-label])::before,
  .responsive-mobile tbody td[data-label=""]::before {
    display: none !important;
  }

  /* 8. First cell — usually the "name" / "title" — becomes card header */
  .responsive-mobile tbody td:first-child {
    display: block !important;
    padding: 0 0 14px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    margin-bottom: 4px !important;
    font-size: .95rem !important;
    font-weight: 600 !important;
  }
  .responsive-mobile tbody td:first-child::before {
    display: none !important;
  }
  /* If first cell already has a <strong>/name structure, keep it */
  .responsive-mobile tbody td:first-child > div {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  /* 9. Action buttons cell — full width, no label */
  .responsive-mobile tbody td.has-actions {
    display: block !important;
    padding: 14px 0 0 !important;
    border-top: 1px solid #f1f5f9 !important;
    border-bottom: none !important;
    margin-top: 6px !important;
    text-align: left !important;
  }
  .responsive-mobile tbody td.has-actions::before {
    display: none !important;
  }

  /* 10. Buttons in action cell — wrap responsively */
  .responsive-mobile tbody td.has-actions .btn,
  .responsive-mobile tbody td.has-actions button,
  .responsive-mobile tbody td.has-actions a.btn {
    flex: 1 1 auto;
    min-height: 44px;
    padding: 10px 14px;
    font-size: .86rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 4px 4px 0 0;
    min-width: calc(50% - 4px);
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }

  /* 11. Empty state (colspan rows) — full width */
  .responsive-mobile tbody td[colspan] {
    display: block !important;
    text-align: center !important;
    border-bottom: none !important;
    padding: 40px 20px !important;
  }
  .responsive-mobile tbody td[colspan]::before {
    display: none !important;
  }

  /* 12. Clean up parent wrapper */
  .has-responsive-table {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    min-width: 0 !important;
    width: 100% !important;
  }

  /* 13. Long text wrapping */
  .responsive-mobile tbody td a {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* 14. Preserve inline pill/emoji cells */
  .responsive-mobile tbody td .pill {
    white-space: nowrap;
  }
}

/* ---------- Very small screens: stack labels above values ---------- */
@media (max-width: 400px) {
  .responsive-mobile tbody td {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 4px !important;
    padding: 10px 0 !important;
  }
  .responsive-mobile tbody td::before {
    min-width: 0 !important;
  }
  .responsive-mobile tbody td:first-child {
    flex-direction: row !important;
  }
  .responsive-mobile tbody td.has-actions .btn {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    margin: 4px 0 0;
  }
}