/**
 * CKAN Data Preview CSS
 */

/* ============ Modal Styles ============ */
.ckan-preview-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    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: 800px;
    height: 80vh;
    max-height: 80vh;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    animation: previewModalAnimation 0.3s;
    display: flex;
    flex-direction: column;
}

@keyframes previewModalAnimation {
    from { opacity: 0; transform: translateY(-30px); }
    to { opacity: 1; transform: translateY(0); }
}

.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: 1;
}

.ckan-preview-modal-close:hover {
    color: #1e3a8a;
}

.ckan-preview-modal-title {
    margin: 0;
    padding: 15px 20px;
    border-bottom: 1px solid #e5e7eb;
    color: #1e3a8a; /* Dark blue */
    font-weight: 600;
    flex-shrink: 0;
}

.ckan-preview-modal-body {
    padding: 20px;
    overflow: auto;
    flex-grow: 1;
}

/* ============ Preview Button ============ */
.ckan-preview-btn {
    background-color: #2563eb; /* Blue */
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-right: 8px;
}

.ckan-preview-btn:hover {
    background-color: #1d4ed8; /* Darker blue */
}

/* ============ Loading and Messages ============ */
.ckan-preview-loading {
    text-align: center;
    padding: 30px;
    color: #6b7280;
}

.ckan-preview-error {
    padding: 15px;
    background-color: #fee2e2;
    color: #dc2626;
    border-radius: 4px;
    margin-bottom: 15px;
}

/* ============ Table Controls ============ */
.ckan-preview-controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    align-items: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.ckan-preview-controls-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.ckan-preview-filter-btn {
    background-color: #166e87;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    font-weight: normal;
}

.ckan-preview-filter-btn:hover {
    background-color: #12596e;
}

.ckan-preview-pagination {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #333;
}

.ckan-preview-pagination span {
    margin: 0 5px;
}

.ckan-preview-pagination input {
    width: 35px;
    text-align: center;
    padding: 4px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    margin: 0 5px;
    font-size: 13px;
}

.ckan-preview-search {
    display: flex;
    align-items: center;
}

.ckan-preview-search .search-icon {
    margin-right: 5px;
    color: #666;
}

.ckan-preview-search input {
    padding: 5px 10px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    margin-right: 5px;
    width: 180px;
    font-size: 13px;
}

.ckan-preview-search button {
    padding: 5px 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background-color: #f8f9fa;
    cursor: pointer;
    margin-right: 5px;
    font-size: 13px;
    color: #333;
}

.ckan-preview-search .filters-btn {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
}

/* ============ Table Styling ============ */
.ckan-preview-table-container {
    border: 1px solid #dee2e6;
    margin-top: 5px;
    overflow-x: auto;
    background-color: #fff;
}

.ckan-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.ckan-preview-table thead {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10;
}

.ckan-preview-table th {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 8px 10px;
    text-align: left;
    font-weight: 500;
    color: #333;
}

.ckan-preview-table td {
    border: 1px solid #dee2e6;
    padding: 8px 10px;
    text-align: left;
    color: #333;
}

.ckan-preview-table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.ckan-preview-table tbody tr:hover {
    background-color: #f1f9fe;
}

/* Excel table specific styling */
#excel-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
}

#excel-preview-table thead {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10;
}

#excel-preview-table th {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 8px 10px;
    text-align: left;
    font-weight: 500;
    color: #333;
}

#excel-preview-table td {
    border: 1px solid #dee2e6;
    padding: 8px 10px;
    text-align: left;
    color: #333;
}

#excel-preview-table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

#excel-preview-table tbody tr:hover {
    background-color: #f1f9fe;
}

/* ============ JSON and Text Preview ============ */
.ckan-preview-json,
.ckan-preview-text {
    font-family: monospace;
    white-space: pre-wrap;
    padding: 15px;
    background-color: #f9fafb;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
    overflow: auto;
    max-height: 100%;
}

/* ============ Excel Sheet Selector ============ */
.ckan-excel-sheet-selector {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f3f4f6;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    color: #333;
}

.ckan-excel-sheet-selector label {
    font-weight: 500;
    font-size: 14px;
}

.ckan-excel-sheet-selector select {
    margin-left: 10px;
    padding: 5px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background-color: white;
    color: #374151;
    font-size: 14px;
}

.ckan-excel-sheet-selector select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* ============ Responsive Adjustments ============ */
@media (max-width: 768px) {
    .ckan-preview-modal-content {
        max-width: 95%;
        height: 90vh;
        max-height: 90vh;
    }
    
    .ckan-preview-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .ckan-preview-search {
        width: 100%;
    }
    
    .ckan-preview-search input {
        flex-grow: 1;
    }
    
    .ckan-preview-table th,
    .ckan-preview-table td,
    #excel-preview-table th,
    #excel-preview-table td {
        padding: 6px 8px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .ckan-preview-controls-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .ckan-preview-search {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .ckan-preview-search button {
        margin-top: 5px;
    }
}


/**
 * CSS สำหรับปุ่ม Data API
 * สามารถนำไปใส่ในไฟล์ CSS ที่มีอยู่หรือสร้างไฟล์ใหม่
 */

/* ปุ่ม Data API */
.data-api-btn {
    background-color: #e91e63;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    position: absolute;
    right: 45px;
    top: 15px;
    z-index: 10;
    font-size: 14px;
    font-weight: normal;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    transition: background-color 0.3s;
}

.data-api-btn:hover {
    background-color: #c2185b;
}

/* API Tabs */
.ckan-api-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.ckan-api-tab {
    padding: 8px 15px;
    cursor: pointer;
    border: 1px solid #e5e7eb;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    margin-right: 5px;
    margin-bottom: -1px;
    background-color: #f3f4f6;
    font-weight: 500;
    transition: all 0.2s;
}

.ckan-api-tab:hover {
    background-color: #e5e7eb;
}

.ckan-api-tab.active {
    background-color: white;
    border-color: #e5e7eb;
    border-bottom: 1px solid white;
    color: #2563eb;
}

/* Tab Content */
.ckan-api-tab-content {
    display: none;
    padding: 15px;
    border: 1px solid #e5e7eb;
    border-top: none;
    margin-bottom: 20px;
    background-color: white;
}

.ckan-api-tab-content.active {
    display: block;
}

/* API Table */
.ckan-api-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 14px;
}

.ckan-api-table th,
.ckan-api-table td {
    padding: 10px;
    border: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
    word-break: break-word;
}

.ckan-api-table th {
    background-color: #f3f4f6;
    font-weight: 600;
}

.ckan-api-table tr:nth-child(even) {
    background-color: #f9fafb;
}

.ckan-api-table tr:hover {
    background-color: #f1f9fe;
}

/* API Examples */
.ckan-api-example {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
}

.ckan-api-example:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.ckan-api-example h3 {
    font-size: 15px;
    margin: 0 0 8px 0;
    color: #374151;
}

.ckan-api-code {
    background-color: #f3f4f6;
    padding: 10px 15px;
    border-radius: 4px;
    font-family: monospace;
    overflow-x: auto;
    white-space: nowrap;
    border: 1px solid #e5e7eb;
}

.ckan-api-code a {
    color: #2563eb;
    text-decoration: none;
    font-size: 13px;
}

.ckan-api-code a:hover {
    text-decoration: underline;
}

/* Code Blocks */
pre {
    margin: 0;
    padding: 15px;
    background-color: #1e293b;
    color: #e5e7eb;
    border-radius: 4px;
    overflow-x: auto;
    font-family: Monaco, Consolas, "Andale Mono", monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* สำหรับอุปกรณ์เคลื่อนที่ */
@media (max-width: 767px) {
    .data-api-btn {
        position: static;
        display: block;
        margin: 10px 0;
    }
    
    .ckan-api-tabs {
        flex-wrap: wrap;
    }
    
    .ckan-api-tab {
        margin-bottom: 5px;
        font-size: 13px;
        padding: 6px 10px;
    }
}


/**
 * 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;
}

/* 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;
}

/* 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;
    }
}

/* 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;
}