/* ============================================================
   Valet Design System — Table (responsive)
   Requires: base-tokens.css, client-tokens.css

   Desktop: standard table layout
   Mobile:  card-per-row via data-label attributes

   Usage:
   <div class="table-wrap">
     <table class="table">
       <thead>...</thead>
       <tbody>
         <tr>
           <td data-label="Status">...</td>
         </tr>
       </tbody>
     </table>
   </div>
   ============================================================ */

/* ── Wrapper ─────────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  background-color: var(--color-surface);
}

/* ── Table ───────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
}

/* ── Head ────────────────────────────────────────────────── */
.table thead {
  background-color: color-mix(in oklch, var(--color-bg) 60%, var(--color-surface));
  border-block-end: 1px solid var(--color-border-light);
}

.table th {
  padding: var(--space-3) var(--space-5);
  text-align: start;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wider);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ── Body ────────────────────────────────────────────────── */
.table tbody tr {
  border-block-end: 1px solid var(--color-border-light);
  transition: background-color 100ms ease;
}

.table tbody tr:last-child {
  border-block-end: none;
}

.table tbody tr:hover {
  background-color: color-mix(in oklch, var(--color-primary) 4%, transparent);
}

.table td {
  padding: var(--space-4) var(--space-5);
  vertical-align: middle;
  line-height: var(--leading-normal);
}

/* ── Column alignment helpers ────────────────────────────── */
.table .col-right  { text-align: end;    }
.table .col-center { text-align: center; }
.table .col-num    { text-align: end; font-variant-numeric: tabular-nums; }

/* ── Row states ──────────────────────────────────────────── */
.table tr[aria-selected="true"] {
  background-color: color-mix(in oklch, var(--color-primary) 6%, transparent);
}

/* ── Empty state ─────────────────────────────────────────── */
.table-empty {
  padding: var(--space-16) var(--space-8);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ── Responsive — mobile card layout ────────────────────── */
@media (max-width: 640px) {
  .table-wrap {
    border: none;
    background-color: transparent;
    border-radius: 0;
    overflow-x: visible;
  }

  .table,
  .table thead,
  .table tbody,
  .table th,
  .table td,
  .table tr {
    display: block;
  }

  .table thead {
    /* Visually hidden — labels come from data-label */
    position: absolute;
    inset-inline-start: -9999px;
    inset-block-start: -9999px;
  }

  .table tbody tr {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    margin-block-end: var(--space-3);
    padding: var(--space-4);
  }

  .table tbody tr:hover {
    background-color: color-mix(in oklch, var(--color-primary) 4%, transparent);
  }

  .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-block-end: 1px solid var(--color-border-light);
    text-align: end;
  }

  .table td:last-child {
    border-block-end: none;
    padding-block-end: 0;
  }

  /* Label from data attribute */
  .table td::before {
    content: attr(data-label);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-wider);
    color: var(--color-text-muted);
    text-align: start;
    flex-shrink: 0;
  }

  /* Full-width cells (e.g. actions row) */
  .table td.col-full {
    justify-content: flex-end;
  }

  .table td.col-full::before {
    display: none;
  }
}
