:root {
    --bg-app: #1e1e1e;
    --bg-sidebar: #252526;
    --bg-panel: #1e1e1e;
    --bg-input: #2d2d2d;
    --bg-header: #333333;

    --border-color: #3e3e42;
    --border-light: rgba(255, 255, 255, 0.1);

    --text-primary: #cccccc;
    --text-muted: #858585;
    --text-highlight: #4facfe;

    --accent: #0e639c;
    --accent-hover: #1177bb;
    --danger: #d16969;

    --table-header-bg: #2d2d2d;
    --table-row-even: #1e1e1e;
    --table-row-odd: #252526;
    --table-row-hover: #2a2d2e;

    --font-ui: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
}

/* Loading Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-app);
    z-index: 1000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.overlay.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    height: 48px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: #fff;
}

.logo .icon {
    color: var(--text-highlight);
}

/* DB Controls (Drag & Drop) */
.db-controls {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    padding: 1.5rem 1rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
    cursor: pointer;
}

.drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(14, 99, 156, 0.1);
}

.drop-zone p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.5rem 0;
}

.db-status {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.db-name {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: #fff;
    word-break: break-all;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

.hidden {
    display: none !important;
}

/* UI Elements */
.icon {
    vertical-align: middle;
}

.text-muted {
    color: var(--text-muted);
}

.small {
    font-size: 0.8rem;
}

.btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.1s;
}

.btn:hover:not(:disabled) {
    background: var(--border-color);
    color: #fff;
}

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

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
}

/* Schema Explorer Tree */
.schema-explorer {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.schema-explorer h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.schema-tree {
    font-size: 0.85rem;
}

.tree-table-item {
    margin-bottom: 0.5rem;
}

.tree-table-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    color: #dcdcaa;
    /* VS Code variable color */
}

.tree-table-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tree-table-header.active {
    background: rgba(255, 255, 255, 0.1);
}

.col-list {
    margin-left: 1.5rem;
    margin-top: 0.2rem;
    display: none;
}

.col-list.open {
    display: block;
}

.col-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0.5rem;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.col-type {
    color: #569cd6;
    /* VS Code type color */
    font-size: 0.75rem;
}

/* Main Panel */
.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    min-width: 0;
}

/* Editor Section */
.editor-section {
    height: 40%;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-color);
}

.section-header {
    height: 40px;
    padding: 0 1rem;
    background: var(--bg-sidebar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
}

.section-header h2 {
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.exec-time,
.row-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.editor-container {
    flex: 1;
    position: relative;
    padding: 0.5rem;
}

#sql-editor {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: #ce9178;
    /* VS Code string color, but used for raw text here */
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 0.5rem;
    resize: none;
    outline: none;
}

#sql-editor:focus {
    /* Optional mild focus indicator */
}

/* Results Section */
.results-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Important for flex child scrolling */
}

.table-container {
    flex: 1;
    overflow: auto;
    position: relative;
    background: var(--bg-app);
}

.error-msg {
    padding: 1rem;
    color: #f48771;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: rgba(209, 105, 105, 0.1);
    border-bottom: 1px solid rgba(209, 105, 105, 0.3);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: left;
    white-space: nowrap;
}

.data-table th,
.data-table td {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table th {
    background: var(--table-header-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: 600;
    color: var(--text-highlight);
    box-shadow: 0 1px 0 var(--border-color);
    /* for sticky border */
}

.data-table tbody tr:nth-child(even) {
    background: var(--table-row-even);
}

.data-table tbody tr:nth-child(odd) {
    background: var(--table-row-odd);
}

.data-table tbody tr:hover {
    background: var(--table-row-hover);
}

/* Tooltip for truncated content (naive implementation via title attr) */
.data-table td[title] {
    cursor: help;
}