/**
 * CKAN Data Preview CSS
 */

/* Preview Modal */
.ckan-preview-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 20px;
    box-sizing: border-box;
}

.ckan-preview-modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.ckan-preview-modal-content {
    background-color: white;
    border-radius: 8px;
    width: 100%;
    max-width: 90%;
    max-height: 90vh;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ckan-preview-modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #6b7280;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    z-index: 10;
}

.ckan-preview-modal-close:hover {
    color: #1e3a8a;
}

.ckan-preview-modal-title {
    margin: 0;
    padding: 15px 20px;
    border-bottom: 1px solid #e5e7eb;
    color: #1e3a8a;
    font-weight: 600;
    font-size: 16px;
    line-height: 1.4;
    word-break: break-word;
    max-width: calc(100% - 100px); /* Leave space for close button and DATA API button */
}

/* DATA API Button */
.data-api-btn {
    position: absolute;
    top: 15px;
    right: 50px;
    background-color: #f97316;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.data-api-btn:hover {
    background-color: #ea580c;
}

/* Preview Modal Body */
.ckan-preview-modal-body {
    flex: 1;
    padding: 20px;
    overflow: auto;
}

/* Loading indicator */
.ckan-preview-loading {
    text-align: center;
    padding: 50px;
    color: #6b7280;
    font-size: 16px;
}

.ckan-preview-loading i {
    font-size: 24px;
    margin-right: 10px;
}

/* Preview Data Container */
.ckan-preview-data {
    width: 100%;
}

/* Error message */
.ckan-preview-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 15px;
    border-radius: 4px;
    text-align: center;
}

.ckan-preview-error i {
    margin-right: 8px;
}

/* Table preview styles */
.ckan-preview-table-wrapper {
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}

.ckan-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.ckan-preview-table thead {
    background-color: #f3f4f6;
}

.ckan-preview-table th {
    padding: 10px 15px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
}

.ckan-preview-table td {
    padding: 8px 15px;
    border-bottom: 1px solid #e5e7eb;
}

.ckan-preview-table tbody tr:hover {
    background-color: #f9fafb;
}

.ckan-preview-table tbody tr:last-child td {
    border-bottom: none;
}

/* Note for limited preview */
.ckan-preview-note {
    margin-top: 10px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
    font-style: italic;
}

/* Excel preview styles */
.ckan-preview-excel-wrapper {
    overflow: auto;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}

.ckan-preview-excel-wrapper table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.ckan-preview-excel-wrapper td,
.ckan-preview-excel-wrapper th {
    border: 1px solid #e5e7eb;
    padding: 6px 10px;
}

.ckan-preview-sheet-name {
    background-color: #1e3a8a;
    color: white;
    padding: 8px 15px;
    font-weight: 500;
}

/* PDF preview styles */
.ckan-preview-pdf-wrapper {
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.ckan-preview-pdf-wrapper iframe {
    border: none;
}

/* Text preview styles */
.ckan-preview-text-wrapper {
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background-color: #f9fafb;
    padding: 15px;
    overflow: auto;
    max-height: 500px;
}

.ckan-preview-text-wrapper pre {
    margin: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* PDF Preview Fallback */
.ckan-preview-pdf-fallback {
    margin-top: 10px;
    text-align: center;
}

.ckan-pdf-direct-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.ckan-pdf-direct-link:hover {
    text-decoration: underline;
}

/* Filter info text */
.ckan-preview-info {
    font-size: 13px;
    color: #6b7280;
    font-style: italic;
    margin-left: auto;
}

/* Responsive styles */
@media (max-width: 768px) {
    .ckan-preview-modal-content {
        max-width: 95%;
        max-height: 95vh;
    }
    
    .data-api-btn {
        position: static;
        margin: 10px 20px;
        display: block;
        width: calc(100% - 40px);
    }
    
    .ckan-preview-modal-body {
        padding: 10px;
    }
    
    .ckan-preview-info {
        display: block;
        margin-top: 10px;
        margin-left: 0;
    }
}

/* UTF-8 Support */
.ckan-preview-table,
.ckan-preview-excel-wrapper table,
.ckan-preview-text-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", "Arial", "Noto Sans", "Noto Sans Thai", sans-serif;
}