* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* VS Code Dark Theme Colors */
:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --bg-hover: #3e3e42;
    --border-color: #464647;
    --text-primary: #d4d4d4;
    --text-secondary: #858585;
    --accent-primary: #007acc;
    --accent-secondary: #0e639c;
    --success: #4ec9b0;
    --error: #f48771;
    --warning: #dcdcaa;
}

body {
    font-family: 'Fira Code', 'Menlo', 'Monaco', 'Courier New', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 0;
    overflow-x: hidden;
}

.container {
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: var(--bg-secondary);
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.section-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.section-header:hover {
    background: rgba(37, 37, 38, 0.8);
}

h1 {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.5px;
}

.header-subtitle {
    color: var(--text-secondary);
    font-size: 12px;
    margin: 0;
    font-weight: normal;
}

.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
    margin: 0;
    min-height: 300px;
    max-height: 50vh;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, margin 0.3s ease;
    opacity: 1;
}

.main-grid.collapsed {
    max-height: 0;
    min-height: 0;
    opacity: 0;
    margin: 0;
    border-bottom: none;
}

.panel {
    background: var(--bg-primary);
    padding: 8px 12px;
    border: none;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, padding 0.3s ease;
    max-height: 100vh;
    opacity: 1;
}

.panel:last-child {
    border-right: none;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease;
    opacity: 1;
}

.panel-content.collapsed {
    display: none !important;
    opacity: 0;
}

.panel.collapsed {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}

.collapse-btn {
    background: transparent;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.collapse-btn:hover {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
}

.toggle-text-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--accent-primary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 11px;
    height: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 3px;
}

.toggle-text-btn:hover {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-text-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.panel h2 {
    font-size: 12px;
    color: var(--accent-primary);
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-icon {
    font-size: 14px;
}

.input-section {
    display: grid;
    gap: 8px;
}

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.tabs[style*="border: none"] {
    border-bottom: none !important;
}

.tab-button {
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-button:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab-button.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: transparent;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: auto;
}

.tab-content.active {
    display: block;
}

textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 12px;
    resize: none;
    flex: 1;
    transition: border-color 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

textarea::placeholder {
    color: var(--text-secondary);
}

.file-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.file-input-wrapper input[type="file"] {
    display: none;
}

.file-input-label {
    display: block;
    padding: 8px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--accent-primary);
    font-weight: 500;
    font-size: 12px;
}

.file-input-label:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.button-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 0 0 6px 0;
    align-items: center;
}

button {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

button:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.btn-primary:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: #d16969;
    color: #fff;
    border-color: #d16969;
}

.btn-danger:hover {
    background: #f48771;
    border-color: #f48771;
}

.query-mode-btn {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.query-mode-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.query-mode-btn.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.query-mode-section {
    display: block;
}

.query-mode-section.hide {
    display: none;
}

.search-filter-container {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.search-box {
    position: relative;
    flex: 1;
}

.search-box input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    transition: border-color 0.2s ease;
    height: 32px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.table-wrapper {
    overflow: auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

thead {
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--accent-primary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    border-right: 1px solid var(--border-color);
}

th:last-child {
    border-right: none;
}

th:hover {
    background: var(--bg-hover);
}

.sort-indicator {
    margin-left: 4px;
    font-size: 10px;
}

td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    word-break: break-word;
    max-width: 400px;
    border-right: 1px solid var(--border-color);
}

td:last-child {
    border-right: none;
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

.column-selector {
    background: var(--bg-tertiary);
    padding: 6px;
    margin: 0;
    border: 1px solid var(--border-color);
}

.column-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    margin: 0;
    padding: 0;
}

.column-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: move;
    transition: all 0.2s ease;
    user-select: none;
}

.column-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.column-item.dragging {
    opacity: 0.5;
    background: var(--accent-secondary);
}

.column-item.drag-over {
    border-top: 2px solid var(--accent-primary);
    padding-top: 2px;
}

.column-item .drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    font-size: 10px;
    padding: 0 4px;
    flex-shrink: 0;
}

.column-item .drag-handle:active {
    cursor: grabbing;
}

.column-item input[type="checkbox"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: var(--accent-primary);
    flex-shrink: 0;
}

.column-item label {
    cursor: pointer;
    flex: 1;
    color: var(--text-primary);
    margin: 0;
}

.filter-controls {
    background: var(--bg-tertiary);
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    max-height: 150px;
    overflow-y: auto;
}

.filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.filter-row select,
.filter-row input {
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 11px;
    transition: border-color 0.2s ease;
}

.filter-row select:focus,
.filter-row input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.status-message {
    padding: 8px 12px;
    margin-bottom: 8px;
    font-size: 12px;
    display: none;
    border-left: 3px solid;
}

.status-message.show {
    display: block;
}

.status-message.success {
    background: rgba(78, 201, 176, 0.1);
    color: var(--success);
    border-left-color: var(--success);
}

.status-message.error {
    background: rgba(244, 135, 113, 0.1);
    color: var(--error);
    border-left-color: var(--error);
}

.status-message.info {
    background: rgba(0, 122, 204, 0.1);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
}

.pglite-section {
    background: var(--bg-tertiary);
    padding: 8px;
    border: 1px solid var(--border-color);
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pglite-section h3 {
    margin-bottom: 8px;
    color: var(--accent-primary);
    font-size: 12px;
    text-transform: uppercase;
}

.query-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    margin-bottom: 6px;
    resize: none;
    min-height: 32px;
    max-height: 200px;
    overflow-y: auto;
    transition: min-height 0.2s ease;
}

.query-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.query-result {
    background: var(--bg-primary);
    padding: 8px;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    flex: 1;
    overflow-y: auto;
    font-size: 12px;
    min-height: 0;
    font-family: 'Fira Code', 'Monaco', monospace;
}

.query-result table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.query-result th {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    text-align: left;
    color: var(--accent-primary);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.query-result td {
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    color: var(--text-primary);
}

.query-result tbody tr:hover {
    background: var(--bg-tertiary);
}

.query-result tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.json-preview {
    background: var(--bg-tertiary);
    padding: 8px;
    border: 1px solid var(--border-color);
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 11px;
    max-height: 100px;
    overflow-y: auto;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 8px 0;
}

.stat-card {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    padding: 8px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.stat-value {
    font-size: 16px;
    font-weight: bold;
}

.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.no-data {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.json-structure-info {
    background: rgba(0, 122, 204, 0.1);
    border-left: 3px solid var(--accent-primary);
    padding: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--accent-primary);
}

.copy-btn {
    padding: 4px 8px;
    font-size: 11px;
}

.hide {
    display: none !important;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 16px;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
}

.footer-message {
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
}

.footer-message strong {
    color: var(--accent-primary);
}

.footer-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.footer-buttons a img {
    height: 40px !important;
    width: 150px !important;
    transition: transform 0.2s ease;
}

.footer-buttons a img:hover {
    transform: scale(1.05);
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
        max-height: 45vh;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .search-filter-container {
        flex-direction: column;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 12px;
    }

    .header {
        flex-wrap: wrap;
        gap: 4px;
    }

    .header > div {
        gap: 4px;
    }

    /* Logo in header */
    h1 img {
        width: 18px !important;
        height: 18px !important;
        margin-right: 6px !important;
    }

    /* Output section height control */
    #outputPanel:not(.collapsed) {
        max-height: 35vh;
        min-height: 120px;
    }

    #outputPanel:not(.collapsed) .panel-content {
        max-height: 35vh;
    }

    /* Query section visibility and height control */
    #queryPanel:not(.collapsed) {
        max-height: 30vh;
        min-height: 100px;
    }

    #queryPanel:not(.collapsed) .panel-content {
        max-height: 30vh;
        overflow-y: auto;
    }

    /* Ensure collapsed state works on mobile */
    #outputPanel.collapsed,
    #queryPanel.collapsed {
        max-height: 0 !important;
        min-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }

    .footer {
        padding: 12px;
        gap: 8px;
    }

    .footer-message {
        font-size: 12px;
    }

    .footer-buttons a img {
        height: 32px !important;
        width: 120px !important;
    }
}

@media (max-width: 480px) {
    .main-grid {
        grid-template-columns: 1fr;
        max-height: 40vh;
    }

    .header {
        padding: 4px 8px;
    }

    h1 {
        font-size: 11px;
    }

    button, .collapse-btn {
        padding: 4px 8px;
        font-size: 11px;
        height: 28px;
    }

    /* Logo in header */
    h1 img {
        width: 16px !important;
        height: 16px !important;
        margin-right: 6px !important;
    }

    /* Output section height control */
    #outputPanel:not(.collapsed) {
        max-height: 30vh;
        min-height: 100px;
    }

    #outputPanel:not(.collapsed) .panel-content {
        max-height: 30vh;
    }

    /* Query section visibility and height control */
    #queryPanel:not(.collapsed) {
        max-height: 25vh;
        min-height: 80px;
        overflow: visible;
    }

    #queryPanel:not(.collapsed) .panel-content {
        max-height: 25vh;
        overflow-y: auto;
    }

    /* Ensure collapsed state works on mobile */
    #outputPanel.collapsed,
    #queryPanel.collapsed {
        max-height: 0 !important;
        min-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }

    .query-result {
        max-height: 150px;
        overflow-y: auto;
    }

    table {
        font-size: 11px;
    }

    th, td {
        padding: 4px 6px;
    }

    .footer {
        padding: 8px;
        gap: 6px;
    }

    .footer-message {
        font-size: 11px;
    }

    .footer-buttons {
        flex-direction: column;
    }

    .footer-buttons a img {
        height: 28px !important;
        width: 100px !important;
    }
}

/* Header Links */
.header-links {
    display: flex;
    gap: 16px;
    align-items: center;
}

.header-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
}

.header-link:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 2% auto;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideDown 0.3s ease-out;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: var(--accent-primary);
    font-size: 20px;
    margin: 0;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
}

.modal-close {
    color: var(--text-secondary);
    position: absolute;
    right: 20px;
    top: 12px;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.modal-close:hover,
.modal-close:focus {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body h3 {
    color: var(--success);
    font-size: 16px;
    margin-top: 20px;
    margin-bottom: 12px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    line-height: 1.6;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.modal-body ul,
.modal-body ol {
    margin-left: 20px;
    margin-bottom: 16px;
    line-height: 1.8;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-body strong {
    color: var(--warning);
}

.modal-body code {
    background-color: var(--bg-tertiary);
    color: var(--success);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Fira Code', monospace;
    font-size: 12px;
}

.modal-body a {
    color: var(--accent-primary);
    text-decoration: none;
}

.modal-body a:hover {
    text-decoration: underline;
}

.faq-item {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.faq-item:last-child {
    border-bottom: none;
}

.faq-item h3 {
    color: var(--accent-primary);
    font-size: 15px;
    margin-bottom: 8px;
}

/* Mobile responsiveness for modals */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 5% auto;
        max-height: 85vh;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-content h2 {
        font-size: 18px;
        padding: 12px 16px;
    }

    .header-links {
        gap: 12px;
    }

    .header-link {
        font-size: 12px;
        padding: 3px 6px;
    }
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(3px);
}

.loading-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.loading-spinner {
    font-size: 64px;
    color: var(--accent-primary);
    animation: rotate 2s linear infinite;
    margin-bottom: 16px;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 18px;
    color: var(--text-primary);
    font-weight: 500;
    letter-spacing: 1px;
}

/* Mobile responsiveness for loading overlay */
@media (max-width: 768px) {
    .loading-spinner {
        font-size: 48px;
    }

    .loading-text {
        font-size: 16px;
    }
}
