/* Merged Table Component CSS for Cacao Framework */
/* Supports both simple native rendering and advanced DataTables.js functionality */

/* === Simple Table Styles (advanced=false) === */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
}

.table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
}

.table th.sortable:hover {
    background-color: #e9ecef;
}

.table th.sortable::after {
    content: "⇅";
    position: absolute;
    right: 8px;
    opacity: 0.5;
    font-size: 12px;
}

.table tr:hover {
    background-color: #f8f9fa;
}

.table tr:nth-child(even) {
    background-color: #fdfdfd;
}

/* Simple pagination styles */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-top: 1px solid #eee;
    background-color: #f8f9fa;
}

.pagination-info {
    color: #6c757d;
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    gap: 8px;
}

.pagination-controls button {
    padding: 8px 16px;
    border: 1px solid #dee2e6;
    background-color: #fff;
    color: #495057;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.pagination-controls button:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Advanced Table Styles (advanced=true) === */
.datatable-wrapper {
    width: 100%;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* DataTables integration styles */
.datatable-wrapper .dataTables_wrapper {
    padding: 16px;
}

.datatable-wrapper .dataTables_filter {
    float: right;
    text-align: right;
    margin-bottom: 16px;
}

.datatable-wrapper .dataTables_length {
    float: left;
    margin-bottom: 16px;
}

.datatable-wrapper .dataTables_filter input {
    margin-left: 8px;
    padding: 6px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
}

.datatable-wrapper .dataTables_length select {
    margin: 0 8px;
    padding: 6px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
}

.datatable-wrapper .dataTables_info {
    float: left;
    margin-top: 16px;
    color: #6c757d;
    font-size: 14px;
}

.datatable-wrapper .dataTables_paginate {
    float: right;
    margin-top: 16px;
}

.datatable-wrapper .dataTables_paginate .paginate_button {
    display: inline-block;
    padding: 6px 12px;
    margin: 0 2px;
    border: 1px solid #dee2e6;
    background-color: #fff;
    color: #495057;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.datatable-wrapper .dataTables_paginate .paginate_button:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.datatable-wrapper .dataTables_paginate .paginate_button.current {
    background-color: #007bff;
    border-color: #007bff;
    color: #fff;
}

.datatable-wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* DataTables buttons extension styles */
.datatable-wrapper .dt-buttons {
    margin-bottom: 16px;
}

.datatable-wrapper .dt-button {
    display: inline-block;
    padding: 6px 12px;
    margin: 0 4px 0 0;
    border: 1px solid #dee2e6;
    background-color: #fff;
    color: #495057;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.datatable-wrapper .dt-button:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

/* Responsive design */
@media (max-width: 768px) {
    .table-wrapper,
    .datatable-wrapper {
        margin: 0;
        border-radius: 0;
    }
    
    .table th,
    .table td {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .table-pagination {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .pagination-controls {
        justify-content: center;
    }
    
    .datatable-wrapper .dataTables_filter,
    .datatable-wrapper .dataTables_length {
        float: none;
        text-align: center;
        margin-bottom: 8px;
    }
    
    .datatable-wrapper .dataTables_info,
    .datatable-wrapper .dataTables_paginate {
        float: none;
        text-align: center;
        margin-top: 8px;
    }
}

/* Theme integration hooks */
.table-wrapper.theme-dark {
    background: #343a40;
    color: #fff;
}

.table-wrapper.theme-dark .table th {
    background-color: #495057;
    color: #fff;
}

.table-wrapper.theme-dark .table th.sortable:hover {
    background-color: #6c757d;
}

.table-wrapper.theme-dark .table tr:hover {
    background-color: #495057;
}

.table-wrapper.theme-dark .table tr:nth-child(even) {
    background-color: #3d4349;
}

.table-wrapper.theme-dark .table-pagination {
    background-color: #495057;
    color: #fff;
}

.table-wrapper.theme-dark .pagination-controls button {
    background-color: #6c757d;
    border-color: #6c757d;
    color: #fff;
}

.table-wrapper.theme-dark .pagination-controls button:hover {
    background-color: #5a6268;
}

/* Loading state */
.table-wrapper.loading,
.datatable-wrapper.loading {
    position: relative;
    opacity: 0.7;
}

.table-wrapper.loading::before,
.datatable-wrapper.loading::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error state */
.table-wrapper.error,
.datatable-wrapper.error {
    border: 1px solid #dc3545;
    background-color: #f8d7da;
}

.table-wrapper.error .table,
.datatable-wrapper.error .table {
    color: #721c24;
}

/* Success state */
.table-wrapper.success,
.datatable-wrapper.success {
    border: 1px solid #28a745;
    background-color: #d4edda;
}

.table-wrapper.success .table,
.datatable-wrapper.success .table {
    color: #155724;
}
