/* MelonTables Frontend Styles */

.melontable-container {
    margin: 20px 0;
    clear: both;
}

/* Search Functionality */
.melontable-search-wrapper {
    position: relative;
    margin-bottom: 15px;
    max-width: 300px;
}

.melontable-search {
    width: 100%;
    padding: 10px 35px 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    background-color: #fff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.melontable-search:focus {
    outline: none;
    border-color: #1271d1;
    box-shadow: 0 0 0 3px rgba(18, 113, 209, 0.1);
}

.melontable-search-clear {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: none;
}

.melontable-search-clear:hover {
    color: #666;
}

/* Pagination Styles */
.melontable-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    padding: 15px 0;
    border-top: 1px solid #eee;
    flex-wrap: wrap;
    gap: 15px;
}

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

.pagination-per-page {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    color: #666;
}

.pagination-per-page-select {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

.pagination-nav {
    display: flex;
    align-items: center;
    gap: 5px;
}

.pagination-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    color: #333;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: #f5f5f5;
    border-color: #1271d1;
}

.pagination-btn:disabled {
    background: #f8f8f8;
    color: #ccc;
    cursor: not-allowed;
    border-color: #eee;
}

.pagination-btn.active {
    background: #1271d1;
    color: white;
    border-color: #1271d1;
}

.pagination-pages {
    display: flex;
    gap: 2px;
}

/* Mobile responsive pagination */
@media (max-width: 768px) {
    .melontable-pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .pagination-nav {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .pagination-info,
    .pagination-per-page {
        text-align: center;
        justify-content: center;
    }
    
    .pagination-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}

.melontable-responsive-wrapper {
    overflow-x: auto;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    width: 100%;
}

/* Ensure table uses full width and columns are distributed properly */
.melontable-responsive .melontable {
    min-width: 100%;
    table-layout: auto;
}

/* Specific column width controls for better distribution */
.melontable th:nth-child(1),
.melontable td:nth-child(1) {
    min-width: 150px;
    max-width: 200px;
}

.melontable th:nth-child(2),
.melontable td:nth-child(2) {
    min-width: 250px;
    max-width: 350px;
}

.melontable th:nth-child(3),
.melontable td:nth-child(3) {
    min-width: 80px;
    max-width: 120px;
}

.melontable th:nth-child(4),
.melontable td:nth-child(4) {
    min-width: 100px;
    max-width: 150px;
}

.melontable th:nth-child(5),
.melontable td:nth-child(5) {
    min-width: 120px;
    max-width: 180px;
}

.melontable th:nth-child(6),
.melontable td:nth-child(6) {
    min-width: 200px;
    max-width: 300px;
}

.melontable {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background-color: #fff;
    table-layout: fixed; /* Helps with consistent column widths */
}

/* Ensure HTML content displays properly */
.melontable td a {
    color: #1271d1;
    text-decoration: underline;
    word-break: break-all;
}

.melontable td a:hover {
    color: #0f5aa8;
}

.melontable th,
.melontable td {
    padding: 12px 15px;
    text-align: left;
    vertical-align: top;
    border-top: 1px solid #ddd;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    max-width: 250px;
    min-width: 120px;
}

.melontable th {
    background-color: #1271d1;
    color: #fff;
    font-weight: 600;
    border-top: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.melontable-striped tbody tr:nth-child(odd) {
    background-color: #f8f9fa;
}

.melontable-bordered {
    border: 1px solid #ddd;
}

.melontable-bordered th,
.melontable-bordered td {
    border: 1px solid #ddd;
}

.melontable-hover tbody tr:hover {
    background-color: #e8f4f8;
    transition: background-color 0.15s ease-in-out;
}

.melontable-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 12px;
    color: #666;
    border-top: 1px solid #eee;
    margin-top: 10px;
}

.melontable-name {
    font-weight: 600;
    color: #333;
}

.melontable-stats {
    color: #888;
}

.melontable-type {
    background-color: #1271d1;
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
}

.melontable-error {
    background-color: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .melontable {
        font-size: 13px;
    }
    
    .melontable th,
    .melontable td {
        padding: 8px 10px;
    }
    
    .melontable-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
}

@media (max-width: 576px) {
    .melontable-responsive-wrapper {
        border: none;
        border-radius: 0;
    }
    
    .melontable {
        font-size: 12px;
        min-width: 800px; /* Increased to ensure all columns visible */
    }
    
    .melontable th,
    .melontable td {
        padding: 6px 8px;
        white-space: normal; /* Changed from nowrap to allow wrapping */
        word-wrap: break-word;
    }
    
    /* Adjust column widths for mobile */
    .melontable th:nth-child(1),
    .melontable td:nth-child(1) {
        min-width: 120px;
        max-width: 160px;
    }
    
    .melontable th:nth-child(2),
    .melontable td:nth-child(2) {
        min-width: 200px;
        max-width: 280px;
    }
}

/* Loading State */
.melontable-loading {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.melontable-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top: 2px solid #1271d1;
    border-radius: 50%;
    animation: melontable-spin 1s linear infinite;
    margin-left: 10px;
}

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

/* Print Styles */
@media print {
    .melontable-responsive-wrapper {
        overflow: visible;
        border: none;
    }
    
    .melontable {
        break-inside: avoid;
    }
    
    .melontable th {
        background-color: #f5f5f5 !important;
        color: #000 !important;
    }
    
    .melontable-info {
        display: none;
    }
}