/**
 * Tables Manager Public/Frontend Styles
 * Responsive table-to-cards transformation
 *
 * @package BigBundle
 * @subpackage TablesManager
 */

/* ==========================================
   TABLE WRAPPER
   ========================================== */

.tm-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1.5rem 0;
}

/* Table Title and Description */
.tm-table-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #212529;
    margin: 0 0 0.5rem 0;
    line-height: 1.2;
}

.tm-table-description {
    font-size: 1rem;
    color: #6b7280;
    margin: 0 0 1rem 0;
    line-height: 1.5;
}

/* ==========================================
   DESKTOP TABLE STYLES
   ========================================== */

.tm-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
    /* Border, border-radius, and other styling via Custom CSS */
}

.tm-table thead {
    background: #f8f9fa;
}

.tm-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
    color: #212529;
    font-size: 14px;
}

.tm-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #dee2e6;
    color: #495057;
    font-size: 14px;
}

.tm-table tbody tr:last-child td {
    border-bottom: none;
}

.tm-table tbody tr:hover {
    background-color: #f5f5f5;
}

/* Link styles in table cells */
.tm-table a {
    color: #6B46C1;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.tm-table a:hover {
    color: #5a38a3;
    border-bottom-color: #6B46C1;
}

/* Empty state */
.tm-empty-message {
    text-align: center;
    padding: 2rem;
    color: #9ca3af;
    font-style: italic;
}

/* Error message */
.tm-error {
    padding: 1rem;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 4px;
    color: #c33;
}

/* Load More Button */
.tm-load-more-container {
    text-align: center;
    margin-top: 20px;
}

.tm-load-more-btn {
    background: #6B46C1;
    color: #ffffff;
    border: none;
    padding: 12px 32px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tm-load-more-btn:hover {
    background: #5a38a3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(107, 70, 193, 0.3);
}

.tm-load-more-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

/* Divider rows */
.tm-divider-row {
    background: #2c3e50;
    transition: opacity 0.2s ease;
}

.tm-divider-row:hover {
    opacity: 0.9;
}

.tm-divider-cell {
    padding: 14px 16px;
    text-align: left;
    font-weight: 700;
    color: #ffffff;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: none;
}

.tm-divider-cell:before {
    display: none !important; /* Keep - must hide labels on dividers */
}

/* ==========================================
   TABLE STYLES
   Note: Removed style variations to allow full theme control
   Use custom CSS for styling needs
   ========================================== */

/* ==========================================
   RESPONSIVE - MOBILE TRANSFORMATION
   This is the KEY feature - tables become cards
   ========================================== */

/* Applied when table has .tm-mobile-active class (set by JavaScript based on custom breakpoint) */
.tm-table-responsive.tm-mobile-active {
    border: none;
    background: transparent;
}

/* Hide table header */
.tm-table-responsive.tm-mobile-active thead {
    display: none;
}

/* Make table elements block-level (except divider rows) */
.tm-table-responsive.tm-mobile-active,
.tm-table-responsive.tm-mobile-active tbody,
.tm-table-responsive.tm-mobile-active tr:not(.tm-divider-row),
.tm-table-responsive.tm-mobile-active td:not(.tm-divider-cell) {
    display: block;
    width: 100%;
}

/* Style each row as a card (except dividers) */
.tm-table-responsive.tm-mobile-active tbody tr:not(.tm-divider-row) {
    margin-bottom: 20px;
    padding: 15px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Border and border-radius customizable via Custom CSS */
}

.tm-table-responsive.tm-mobile-active tbody tr:not(.tm-divider-row):hover {
    background-color: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Style table cells (except divider cells) */
.tm-table-responsive.tm-mobile-active td:not(.tm-divider-cell) {
    border: none;
    padding: 8px 0;
    position: relative;
    padding-left: 50%;
    text-align: right;
    color: #000000;
    font-weight: 500;
}

/* Add labels using data-label attribute (except divider cells) */
.tm-table-responsive.tm-mobile-active td:not(.tm-divider-cell):before {
    content: attr(data-label) ": ";
    position: absolute;
    left: 0;
    width: 45%;
    padding-right: 10px;
    white-space: nowrap;
    font-weight: 700;
    color: #000000;
    text-align: left;
}

/* First cell in card - make it prominent (except dividers) */
.tm-table-responsive.tm-mobile-active td:not(.tm-divider-cell):first-child {
    font-size: 1.1em;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 12px;
    text-align: center;
    padding-left: 0;
    color: #000000;
}

.tm-table-responsive.tm-mobile-active td:not(.tm-divider-cell):first-child:before {
    display: none;
}

/* Divider rows on mobile - keep as full-width headers */
.tm-table-responsive.tm-mobile-active .tm-divider-row {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0 0 20px 0;
    display: block;
    width: 100%;
}

.tm-table-responsive.tm-mobile-active .tm-divider-cell {
    padding: 16px;
    padding-left: 0;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    border-bottom: none;
    background: #fdc530;
    color: #000;
    border-radius: 8px;
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.tm-table-responsive.tm-mobile-active .tm-divider-row:hover {
    background: transparent;
}

/* Custom breakpoint support */
@media (max-width: 480px) {
    .tm-table-wrapper[data-breakpoint="480"] .tm-table-responsive {
        /* Triggers mobile layout at 480px */
    }
}

@media (max-width: 640px) {
    .tm-table-wrapper[data-breakpoint="640"] .tm-table-responsive {
        /* Triggers mobile layout at 640px */
    }
}

@media (max-width: 992px) {
    .tm-table-wrapper[data-breakpoint="992"] .tm-table-responsive {
        /* Triggers mobile layout at 992px */
    }
}

/* ==========================================
   COLUMN ALIGNMENT
   ========================================== */

.tm-table th[style*="text-align: center"],
.tm-table td[style*="text-align: center"] {
    text-align: center !important;
}

.tm-table th[style*="text-align: right"],
.tm-table td[style*="text-align: right"] {
    text-align: right !important;
}

.tm-table th[style*="text-align: left"],
.tm-table td[style*="text-align: left"] {
    text-align: left !important;
}

/* ==========================================
   PRINT STYLES
   ========================================== */

@media print {
    .tm-table {
        border: 1px solid #000;
    }

    .tm-table th,
    .tm-table td {
        border: 1px solid #000;
        padding: 8px;
    }

    .tm-table tbody tr {
        page-break-inside: avoid;
    }
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */

.tm-table th {
    font-weight: 600;
}

.tm-table caption {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #212529;
}

/* Focus styles for keyboard navigation */
.tm-table tr:focus-within {
    outline: 2px solid #6B46C1;
    outline-offset: 2px;
}

/* ==========================================
   DARK MODE SUPPORT
   ========================================== */

@media (prefers-color-scheme: dark) {
    .tm-table {
        background: #1a202c;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .tm-table thead {
        background: #2d3748;
    }

    .tm-table th {
        color: #cbd5e0;
        border-color: #4a5568;
    }

    .tm-table td {
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .tm-table tbody tr:hover {
        background-color: #2d3748;
    }

    .tm-table a {
        color: #9f7aea;
    }

    .tm-table a:hover {
        color: #b794f4;
        border-bottom-color: #9f7aea;
    }

    @media (max-width: 768px) {
        .tm-table-responsive tbody tr {
            background: #1a202c;
            border-color: #4a5568;
        }

        .tm-table-responsive td:before {
            color: #cbd5e0;
        }
    }
}
