/* =============================================
   TABLE CONTAINER
   ============================================= */
.m-table-container {
    background: #FFFFFF;
    border-radius: 1rem;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.03), 0 4px 6px -4px rgba(0,0,0,0.02);
    overflow: hidden;
    border: 1px solid #F3F4F6;
    margin-bottom: 2rem;
    width: 100%;
    box-sizing: border-box;
}

/* =============================================
   TABLE BASE — FIXED LAYOUT IS THE KEY
   table-layout: fixed forces the browser to
   distribute all columns within 100% width.
   Columns never overflow. Text truncates.
   ============================================= */
.m-table,
.m-responsive-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: fixed;   /* ← THE critical rule */
}

/* =============================================
   TABLE HEADER
   ============================================= */
.m-table thead,
.m-responsive-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.m-table thead th,
.m-responsive-table thead th {
    background: #FFFFFF;
    padding: 1.25rem 1.5rem;
    text-align: left;
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6B7280;
    border-bottom: 1px solid #E5E7EB;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =============================================
   TABLE BODY ROWS
   ============================================= */
.m-table tbody tr,
.m-responsive-table tbody tr {
    transition: background 0.2s ease;
    border-bottom: 1px solid #F3F4F6;
    background-color: transparent;
}

.m-table tbody tr:last-child,
.m-responsive-table tbody tr:last-child {
    border-bottom: none;
}

.m-table tbody tr:hover td,
.m-responsive-table tbody tr:hover td {
    background-color: #F8FAFC !important;
}

.m-table tbody tr.selected td,
.m-responsive-table tbody tr.selected td {
    background-color: #F0F9FF !important;
}

/* =============================================
   TABLE CELLS
   ============================================= */
.m-table tbody td,
.m-responsive-table tbody td {
    padding: 1.25rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.2s ease;
}

/* =============================================
   ACTION BUTTONS
   ============================================= */
.m-table-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    justify-content: flex-end;
}

.m-table-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    color: #9CA3AF;
    transition: all 0.2s ease;
    background: transparent;
    flex-shrink: 0;
    text-decoration: none;
}

.m-table-action:hover { background: #F3F4F6; color: #111827; }
.m-table-action.edit:hover  { background: rgb(var(--color-primary-50)); color: rgb(var(--color-primary-600)); }
.m-table-action.delete:hover { background: #FEF2F2; color: #DC2626; }

/* =============================================
   STATUS / BOOLEAN PILLS
   ============================================= */
.m-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    white-space: nowrap;
}

.m-status-pill.true  { background:#F0FDF4; color:#16A34A; border:1px solid #BBF7D0; }
.m-status-pill.true::before  { content:''; display:inline-block; width:5px; height:5px; border-radius:50%; background:#22C55E; }
.m-status-pill.false { background:#F9FAFB; color:#6B7280; border:1px solid #E5E7EB; }
.m-status-pill.false::before { content:''; display:inline-block; width:5px; height:5px; border-radius:50%; background:#9CA3AF; }

/* =============================================
   SORTABLE COLUMNS
   ============================================= */
.m-table thead th.sortable,
.m-responsive-table thead th.sortable { cursor:pointer; user-select:none; }
.m-table thead th.sort-asc::after  { content:' ↑'; opacity:0.5; }
.m-table thead th.sort-desc::after { content:' ↓'; opacity:0.5; }

/* =============================================
   EMPTY STATE
   ============================================= */
.m-table-empty {
    padding: 5rem 2rem;
    text-align: center;
    color: #9CA3AF;
    font-size: 0.875rem;
    font-weight: 600;
}

/* =============================================
   TYPOGRAPHY UTIL
   ============================================= */
.main-table-header-title {
    font-family: 'Sitka Heading', 'Outfit', sans-serif;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* =============================================
   TABLET COMPRESSION (641px – 900px)
   ============================================= */
@media (max-width: 900px) and (min-width: 641px) {
    .m-table thead th,
    .m-responsive-table thead th {
        padding: 1rem 1rem;
        font-size: 0.6rem;
    }

    .m-table tbody td,
    .m-responsive-table tbody td {
        padding: 1rem 1rem;
        font-size: 0.8rem;
    }
}

/* =============================================
   MOBILE CARD LAYOUT (≤ 640px)
   ============================================= */
@media (max-width: 640px) {

    .overflow-x-auto { overflow-x: visible !important; }
    .m-table-container { overflow: visible !important; border: none !important; box-shadow: none !important; background: transparent !important; }

    .m-table,
    .m-responsive-table {
        display: block !important;
        width: 100% !important;
        table-layout: auto !important;
    }

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

    .m-table tbody,
    .m-responsive-table tbody {
        display: block !important;
        width: 100% !important;
    }

    /* Each <tr> → card */
    .m-table tbody tr,
    .m-responsive-table tbody tr {
        display: block !important;
        margin-bottom: 1rem !important;
        background: #FFFFFF !important;
        border-radius: 1rem !important;
        border: 1px solid #F3F4F6 !important;
        padding: 1rem 1.25rem !important;
        box-shadow: 0 10px 25px -5px rgba(0,0,0,0.03) !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    }

    .m-table tbody tr:hover,
    .m-responsive-table tbody tr:hover {
        transform: translateY(-2px) !important;
        box-shadow: 0 15px 30px -5px rgba(0,0,0,0.06) !important;
        background: #FFFFFF !important;
    }

    /* Each <td> → label : value row */
    .m-table tbody td,
    .m-responsive-table tbody td {
        display: flex !important;
        align-items: flex-start !important;
        justify-content: space-between !important;
        padding: 0.75rem 0 !important;
        border-bottom: 1px solid #F9FAFB !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        text-align: right !important;
        overflow: visible !important;
        text-overflow: unset !important;
        box-sizing: border-box !important;
        font-size: 0.85rem !important;
        color: #111827 !important;
        background: transparent !important;
    }

    .m-table tbody td:last-child,
    .m-responsive-table tbody td:last-child {
        border-bottom: none !important;
        padding-top: 1rem !important;
        padding-bottom: 0.25rem !important;
        justify-content: center !important;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Column label from data-label */
    .m-table tbody td::before,
    .m-responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: 800;
        color: #9CA3AF;
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        white-space: nowrap;
        flex-shrink: 0;
        text-align: left;
        margin-right: auto;
        padding-right: 1rem;
    }

    .m-table tbody td:last-child::before,
    .m-responsive-table tbody td:last-child::before { display: none !important; }

    /* Inner elements align right */
    .m-table tbody td > .flex,
    .m-table tbody td > div,
    .m-responsive-table tbody td > .flex,
    .m-responsive-table tbody td > div {
        justify-content: flex-end;
        min-width: 0 !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }

    .m-table tbody td > .flex-col,
    .m-responsive-table tbody td > .flex-col { align-items: flex-end; }

    .m-table tbody td:last-child > .flex,
    .m-table tbody td:last-child > div,
    .m-responsive-table tbody td:last-child > .flex,
    .m-responsive-table tbody td:last-child > div { justify-content: center; }
}

/* =============================================
   DARK MODE OVERRIDES FOR TABLES
   ============================================= */
.dark .m-table-container {
    background: #1E1E1E;
    border-color: rgba(255, 255, 255, 0.1);
}

.dark .m-table thead th,
.dark .m-responsive-table thead th {
    background: #29292E;
    color: #D4D4D8;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.dark .m-table tbody tr,
.dark .m-responsive-table tbody tr {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.dark .m-table tbody tr:hover td,
.dark .m-responsive-table tbody tr:hover td {
    background-color: rgba(255, 255, 255, 0.03) !important;
}

.dark .m-table tbody tr.selected td,
.dark .m-responsive-table tbody tr.selected td {
    background-color: rgba(var(--color-primary-500), 0.15) !important;
}

.dark .m-table tbody td,
.dark .m-responsive-table tbody td {
    color: #F8FAFC;
}

.dark .m-table-action:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #F8FAFC;
}

.dark .m-status-pill.true {
    background: rgba(34, 197, 94, 0.15);
    color: #4ADE80;
    border-color: rgba(34, 197, 94, 0.25);
}

.dark .m-status-pill.false {
    background: rgba(255, 255, 255, 0.05);
    color: #A1A1AA;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Mobile card layout overrides for dark mode */
@media (max-width: 640px) {
    .dark .m-table tbody tr,
    .dark .m-responsive-table tbody tr {
        background: #1E1E1E !important;
        border-color: rgba(255, 255, 255, 0.1) !important;
    }
    
    .dark .m-table tbody tr:hover,
    .dark .m-responsive-table tbody tr:hover {
        background: #2A2A2D !important;
    }
    
    .dark .m-table tbody td,
    .dark .m-responsive-table tbody td {
        color: #F8FAFC !important;
        border-bottom-color: rgba(255, 255, 255, 0.05) !important;
    }
}

/* =============================================
   MOBILE EMPTY STATE ROW OVERRIDES
   ============================================= */
@media (max-width: 640px) {
    .m-table tbody tr.m-table-empty-row,
    .m-responsive-table tbody tr.m-table-empty-row {
        display: block !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .m-table tbody tr.m-table-empty-row:hover,
    .m-responsive-table tbody tr.m-table-empty-row:hover {
        transform: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    .m-table tbody tr.m-table-empty-row td,
    .m-responsive-table tbody tr.m-table-empty-row td {
        display: block !important;
        text-align: center !important;
        border: none !important;
    }

    .m-table tbody tr.m-table-empty-row td::before,
    .m-responsive-table tbody tr.m-table-empty-row td::before {
        display: none !important;
    }

    .m-table tbody tr.m-table-empty-row td > div,
    .m-responsive-table tbody tr.m-table-empty-row td > div {
        justify-content: center !important;
    }
}
