:root {
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --secondary: #48bb78;
    --accent: #f59e0b;
    --text-primary: #1a202c;
    --text-secondary: #718096;
    --border: #e2e8f0;
    --bg: #f7fafc;
    --bg-card: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --gradient: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 32px;
}

.hidden {
    display: none !important;
}

/* Header */
header {
    margin-bottom: 32px;
    text-align: center;
}

h1 {
    font-size: 36px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.loader-large {
    width: 56px;
    height: 56px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 24px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-stats {
    margin-top: 16px;
    font-size: 18px;
    color: var(--text-secondary);
}

#loadingProgress {
    font-weight: 700;
    color: var(--primary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 36px;
    opacity: 0.9;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    font-weight: 500;
}

/* Filter Panel */
.filter-panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 20px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.help-text {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Filter Tags */
.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 24px;
}

.filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--gradient);
    color: white;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.tag-remove {
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    opacity: 0.8;
    transition: opacity 0.2s;
    background: none;
    border: none;
    color: white;
    padding: 0;
    margin-left: 4px;
}

.tag-remove:hover {
    opacity: 1;
}

.input-field {
    height: 44px;
    padding: 0 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
    background: var(--bg-card);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Custom Select */
.custom-select {
    position: relative;
}

.select-search {
    width: 100%;
    height: 44px;
    padding: 0 40px 0 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s;
}

.select-search:focus {
    outline: none;
    border-color: var(--primary);
    cursor: text;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.custom-select::after {
    content: '▼';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-secondary);
    pointer-events: none;
}

.select-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.select-option {
    padding: 12px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--bg);
}

.select-option:last-child {
    border-bottom: none;
}

.select-option:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.08) 0%, transparent 100%);
}

.select-option.selected {
    background: rgba(102, 126, 234, 0.12);
    font-weight: 600;
    color: var(--primary);
}

/* Buttons */
.btn {
    height: 44px;
    padding: 0 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
}

.btn-export {
    background: var(--secondary);
    color: white;
}

.btn-export:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-icon {
    font-size: 16px;
}

/* Error Message */
.error-message {
    background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
    color: #742a2a;
    padding: 14px 18px;
    border-radius: 8px;
    border-left: 4px solid #fc8181;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
}

/* Content Layout */
.content-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 24px;
}

/* Results Panel */
.results-panel {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}

.results-header {
    padding: 18px 24px;
    border-bottom: 2px solid var(--border);
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-info {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.results-info strong {
    color: var(--primary);
    font-weight: 700;
}

.stat-small {
    font-size: 12px;
    opacity: 0.8;
    margin-left: 8px;
}

.export-actions {
    display: flex;
    gap: 10px;
}

/* Export Dropdown */
.export-dropdown {
    position: relative;
}

.btn-discrete {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-size: 13px;
}

.btn-discrete:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.export-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    z-index: 100;
}

.export-option {
    padding: 10px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--bg);
}

.export-option:last-child {
    border-bottom: none;
}

.export-option:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.08) 0%, transparent 100%);
    color: var(--primary);
}

/* Table */
.table-wrapper {
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
}

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

thead {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    z-index: 10;
}

th {
    text-align: left;
    padding: 14px 24px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
}

th.sortable:hover {
    background: rgba(102, 126, 234, 0.05);
    color: var(--primary);
}

th.sorted {
    color: var(--primary);
}

.sort-icon {
    margin-left: 6px;
    font-size: 11px;
}

td {
    padding: 14px 24px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

tbody tr {
    transition: background 0.15s;
}

tbody tr:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.03) 0%, transparent 100%);
}

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

td:nth-child(1) {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

td:nth-child(2) {
    color: var(--text-primary);
    font-weight: 500;
}

td:nth-child(3) {
    color: var(--text-secondary);
    font-weight: 500;
}

/* No Results */
.no-results td {
    padding: 60px !important;
    text-align: center;
    color: var(--text-secondary);
    font-size: 16px;
}

/* Pagination */
.pagination-section {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-top: 2px solid var(--border);
    background: var(--bg);
}

.pagination-numbers {
    display: flex;
    gap: 6px;
}

.page-number {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-primary);
}

.page-number:hover:not(.active) {
    border-color: var(--primary);
    color: var(--primary);
}

.page-number.active {
    background: var(--gradient);
    color: white;
    border-color: transparent;
}

.page-ellipsis {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-weight: bold;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.chart-card h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.chart-card canvas {
    min-height: 280px;
    width: 100%;
}

#distributionChart {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.distribution-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.distribution-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 100px;
}

.distribution-bar {
    flex: 1;
    height: 24px;
    background: var(--gradient);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.distribution-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2));
}

.distribution-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    min-width: 50px;
    text-align: right;
}

/* Footer */
.page-footer {
    margin-top: 48px;
    padding-top: 48px;
    border-top: 2px solid var(--border);
}

.api-docs {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.api-docs h3 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.api-intro {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.api-endpoint-section {
    margin-bottom: 32px;
}

.api-endpoint-section h4 {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.api-endpoint {
    margin-bottom: 12px;
}

.endpoint-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

.endpoint-url {
    display: block;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    padding: 16px 20px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    border: 2px solid var(--border);
}

.api-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.api-section h4 {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.api-section pre {
    background: #1a202c;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 12px;
}

.api-section code {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #a0aec0;
}

.api-section ul {
    list-style: none;
    padding: 0;
}

.api-section li {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
}

.api-section li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--primary);
    font-weight: bold;
}

.credits {
    text-align: center;
    padding: 24px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.credits p {
    margin: 8px 0;
}

.credits a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.credits a:hover {
    opacity: 0.7;
    text-decoration: underline;
}

.data-source {
    font-size: 13px;
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 1200px) {
    .content-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    h1 {
        font-size: 28px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        grid-column: 1;
    }

    .sidebar {
        grid-template-columns: 1fr;
    }

    .results-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .export-actions {
        flex-direction: column;
    }

    .table-wrapper {
        max-height: 400px;
    }

    th, td {
        padding: 12px 16px;
        font-size: 13px;
    }
}
