:root {
    /* Dark mode as default to prevent flash */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-primary: #60a5fa;
    --accent-hover: #3b82f6;
    --accent-light: #1e3a8a;
    --success: #22c55e;
    --danger: #ef4444;
    --table-header: #1e293b;
    --input-focus: #60a5fa;
}

/* Light mode override */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f9fc;
    --text-primary: #2d3748;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --success: #10b981;
    --danger: #ef4444;
    --table-header: #f8fafc;
    --input-focus: #3b82f6;
}

/* Dark mode (explicit, matches default) */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-primary: #60a5fa;
    --accent-hover: #3b82f6;
    --accent-light: #1e3a8a;
    --success: #22c55e;
    --danger: #ef4444;
    --table-header: #1e293b;
    --input-focus: #60a5fa;
}

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

body {
    font-family: 'Rubik', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background 0.2s ease, color 0.2s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

.container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem 2rem;
    flex: 1;
    position: relative;
    z-index: 2;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.logo-icon {
    width: 44px;
    height: 44px;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    font-style: italic;
    font-family: 'Quicksand', 'Rubik', sans-serif;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
}

.search-section {
    margin: 2rem 0;
}

.input-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.input-group > *:first-child {
    flex: 2;
}

.input-group > .select-wrapper {
    flex: 1.2;
}

.input-group > .btn {
    flex-shrink: 0;
}

input[type="text"], input[type="search"] {
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: 'Rubik', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    height: 48px;
}

input[type="text"]:focus, input[type="search"]:focus {
    outline: none;
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[type="text"]::placeholder, input[type="search"]::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Custom Searchable Dropdown */
.select-wrapper {
    position: relative;
    z-index: 200;
}

.custom-select {
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: 'Rubik', sans-serif;
    font-weight: 500;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    height: 48px;
}

.custom-select:hover {
    border-color: var(--input-focus);
}

.custom-select.active {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.select-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    max-height: 300px;
    overflow: hidden;
}

.select-dropdown.active {
    display: block;
}

.select-search {
    padding: 0.75rem 1rem;
    border: none;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    font-family: 'Rubik', sans-serif;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.select-search:focus {
    outline: none;
}

.select-options {
    max-height: 250px;
    overflow-y: auto;
}

.select-option {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.select-option:hover {
    background: var(--bg-secondary);
}

.select-option.hidden {
    display: none;
}

.btn {
    padding: 0.875rem 2rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Rubik', sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 48px;
    box-sizing: border-box;
}

.btn-primary {
    background: #0A415F;
    color: white;
    border-color: #2678ac;
}

.btn-primary:hover:not(:disabled) {
    background: #0d5477;
    border-color: #2678ac;
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Clear button - red styling */
#clearBtn {
    border-color: #eb0000;
    color: #eb0000;
}

#clearBtn:hover {
    background: rgba(235, 0, 0, 0.1);
    border-color: #eb0000;
    color: #eb0000;
}

/* Filter button - orange styling */
#filterBtn {
    border-color: #C96C36;
    color: #C96C36;
}

#filterBtn:hover {
    background: rgba(201, 108, 54, 0.1);
    border-color: #C96C36;
    color: #C96C36;
}

/* Query Loader Animation */
.loader-container {
    display: none;
    text-align: center;
    padding: 3rem 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.loader-container.active {
    display: block;
    opacity: 1;
}

.ajax-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 1rem;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Tabs */
.tabs-container {
    margin-top: 2rem;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.tabs-container.fade-in {
    opacity: 1;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    margin-bottom: 1.5rem;
    justify-content: space-between;
}

.tabs-left {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.tabs-right {
    display: flex;
    gap: 0.5rem;
}

.tab {
    padding: 0.75rem 1.25rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-family: 'Rubik', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: transparent;
}

.tab-icon {
    animation: pulse-icon 2s ease-in-out infinite;
}

@keyframes pulse-icon {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
    table-layout: fixed;
}

.results-table thead {
    background: var(--table-header);
}

.results-table th {
    padding: 0.875rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.results-table th:hover {
    background: var(--bg-secondary);
}

.results-table th.sortable::after {
    content: ' ⇅';
    opacity: 0.3;
    margin-left: 0.25rem;
}

.results-table th.sort-asc::after {
    content: ' ↑';
    opacity: 1;
    margin-left: 0.25rem;
}

.results-table th.sort-desc::after {
    content: ' ↓';
    opacity: 1;
    margin-left: 0.25rem;
}

.results-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    vertical-align: top;
}

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

.results-table tbody tr:hover {
    background: var(--bg-secondary);
}

.results-table tbody tr.hidden {
    display: none;
}

.record-cell {
    max-width: 0;
    width: 35%;
}

.record-value-wrapper {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.record-value-wrapper::-webkit-scrollbar {
    height: 6px;
}

.record-value-wrapper::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.record-value-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.record-value-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.results-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    vertical-align: top;
}

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

.results-table tbody tr:hover {
    background: var(--bg-secondary);
}

.results-table tbody tr.hidden {
    display: none;
}

.provider-cell {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.provider-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.provider-name {
    font-weight: 500;
    color: var(--text-primary);
}

.provider-location {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.flag-icon {
    width: 24px;
    height: 18px;
    object-fit: cover;
    border-radius: 2px;
    vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.status-loading {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
}

.loading-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 0.8s linear infinite;
}

.record-value {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.record-line {
    display: block;
}

.copy-icon {
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s ease;
    font-size: 1rem;
    position: relative;
}

.copy-icon:hover {
    color: var(--accent-primary);
}

.copy-icon:hover::after {
    content: 'Copy to clipboard';
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-family: 'Rubik', sans-serif;
}

/* Footer */
footer {
    width: 100%;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    position: relative;
    z-index: 2;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Rubik', sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

footer a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

.footer-link {
    cursor: pointer;
    color: var(--accent-primary);
}

.footer-link:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background-color: var(--bg-primary);
    margin: 0 auto;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 800px;
    height: 600px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
}

.modal-content.large {
    width: 800px;
    height: 600px;
}

.modal-content.filter {
    width: 600px;
    height: auto;
    max-height: 400px;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.filter-type-selector {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.filter-type-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.filter-type-option input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.filter-type-option label {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.filter-modal-input {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: 'Rubik', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.filter-modal-input:focus {
    outline: none;
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-help {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0;
}

.filter-help p {
    margin-bottom: 0.5rem;
}

.keyboard-shortcut {
    display: inline-block;
    padding: 0.15rem 0.35rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.7rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 2px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.close {
    color: var(--text-secondary);
    font-size: 2rem;
    font-weight: 300;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.close:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.modal-body {
    color: var(--text-primary);
    line-height: 1.8;
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

.modal-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 1rem;
}

.modal-body ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

.modal-body a {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.modal-body a:hover {
    color: #3b82f6;
    text-decoration: underline;
}

.error-icon {
    color: var(--danger);
    font-size: 3rem;
    text-align: center;
    margin-bottom: 1rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { 
        opacity: 0; 
        top: 45%;
    }
    to { 
        opacity: 1; 
        top: 50%;
    }
}

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

@media (max-width: 1024px) {
    .container {
        padding: 1rem;
    }

    .input-group {
        flex-direction: column;
        align-items: stretch;
    }

    .input-group > *:first-child,
    .input-group > .select-wrapper {
        flex: 1;
        width: 100%;
    }

    .footer-content {
        padding: 1.5rem 1rem;
    }

    .modal-content {
        width: 90%;
        height: 80vh;
    }

    .modal-content.large {
        width: 90%;
        height: 80vh;
    }

    .modal-content.filter {
        width: 90%;
    }
}

@media (max-width: 768px) {
    .results-table th,
    .results-table td {
        padding: 0.65rem;
        font-size: 0.8rem;
    }

    .logo-text {
        font-size: 1.25rem;
    }

    .footer-content {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        font-size: 14px;
    }

    .footer-left {
        flex-direction: column;
        gap: 0.5rem;
    }

    .tabs {
        flex-direction: column;
    }

    .tabs-left, .tabs-right {
        flex-direction: column;
    }
}