:root {
    --sidebar-bg: #161b27;
    --sidebar-section-bg: #1e2433;
    --sidebar-text: #8b949e;
    --sidebar-text-active: #e6edf3;
    --sidebar-hover: #252d3d;
    --sidebar-border: #2d3748;
    --accent: #0078d4;
    --accent-hover: #106ebe;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #d0d7de;
    --text: #1f2328;
    --text-muted: #656d76;
    --error-bg: #fff0f0;
    --error-border: #f85149;
    --error-text: #82071e;
    --success-bg: #dafbe1;
    --success-border: #2da44e;
    --warn-bg: #fff8c5;
    --warn-border: #d4a72c;
    --header-h: 48px;
    --sidebar-w: 280px;
    --editor-bg: #1e1e1e;
    --editor-text: #d4d4d4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; color: var(--text); background: var(--bg); }

/* ── Connection Page ── */
.connect-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f1623 0%, #1a2540 100%);
}

.connect-card {
    background: var(--surface);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
    padding: 40px 48px;
    width: 420px;
    max-width: 95vw;
}

.connect-header {
    text-align: center;
    margin-bottom: 32px;
}

.connect-logo {
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
}

.connect-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.connect-header p {
    font-size: 13px;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,120,212,0.12);
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 6px;
    color: var(--error-text);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.5;
}

.btn-connect {
    width: 100%;
    padding: 11px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 4px;
}

.btn-connect:hover { background: var(--accent-hover); }
.btn-connect:active { transform: scale(0.99); }

/* ── App Shell ── */
.app-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    height: var(--header-h);
    background: #1a2540;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 0 14px;
    flex-shrink: 0;
    border-bottom: 1px solid #2d3748;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo { width: 26px; height: 26px; }

.app-title {
    color: #e6edf3;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.connection-badge {
    color: #8b949e;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.conn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #3fb950;
    flex-shrink: 0;
}

.connection-badge strong { color: #c9d1d9; }

.btn-disconnect {
    padding: 5px 12px;
    background: transparent;
    color: #8b949e;
    border: 1px solid #3d4554;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}

.btn-disconnect:hover {
    background: #f85149;
    border-color: #f85149;
    color: white;
}

/* ── App Layout ── */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--sidebar-border);
    overflow: hidden;
}

.sidebar-db-section {
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #4a5568;
    margin-bottom: 6px;
}

.db-select {
    width: 100%;
    padding: 6px 8px;
    background: var(--sidebar-section-bg);
    color: var(--sidebar-text-active);
    border: 1px solid var(--sidebar-border);
    border-radius: 5px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

.db-select:focus { border-color: var(--accent); }

.sidebar-tables-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #4a5568;
}

.table-count-badge {
    background: #2d3748;
    color: #8b949e;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 600;
}

.sidebar-search-wrap {
    padding: 0 8px 8px;
}

.table-search {
    width: 100%;
    padding: 5px 9px;
    background: var(--sidebar-section-bg);
    color: var(--sidebar-text-active);
    border: 1px solid var(--sidebar-border);
    border-radius: 5px;
    font-size: 12px;
    outline: none;
}

.table-search::placeholder { color: #4a5568; }
.table-search:focus { border-color: #3d5a80; }

.table-list {
    flex: 1;
    overflow-y: auto;
    padding: 2px 0;
}

.table-list::-webkit-scrollbar { width: 5px; }
.table-list::-webkit-scrollbar-track { background: transparent; }
.table-list::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 3px; }

.sidebar-placeholder, .sidebar-loading {
    padding: 20px 14px;
    color: #4a5568;
    font-size: 12px;
    text-align: center;
}

.table-item { user-select: none; }

.table-row {
    display: flex;
    align-items: center;
    padding: 4px 6px 4px 8px;
    cursor: pointer;
    gap: 4px;
    min-width: 0;
}

.table-row:hover { background: var(--sidebar-hover); }

.expand-btn {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4a5568;
    font-size: 9px;
    flex-shrink: 0;
    transition: transform 0.15s;
    border-radius: 3px;
}

.expand-btn:hover { color: #8b949e; background: #2d3748; }
.expand-btn.open { transform: rotate(90deg); }

.table-type-icon {
    font-size: 11px;
    flex-shrink: 0;
    opacity: 0.7;
}

.table-name-text {
    color: var(--sidebar-text-active);
    font-size: 12px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-name-text:hover { color: #60a5fa; }

.table-schema-badge {
    color: #4a5568;
    font-size: 10px;
    flex-shrink: 0;
    margin-left: 2px;
}

.columns-list {
    padding: 0 0 4px 26px;
    border-left: 1px solid var(--sidebar-border);
    margin-left: 20px;
}

.col-item {
    display: flex;
    align-items: center;
    padding: 3px 6px;
    gap: 6px;
}

.col-name {
    color: #8b949e;
    font-size: 11px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-type-badge {
    color: #4a5568;
    font-size: 10px;
    background: #1e2433;
    border: 1px solid #2d3748;
    border-radius: 3px;
    padding: 0 4px;
    flex-shrink: 0;
}

.col-notnull {
    color: #f85149;
    font-size: 9px;
    opacity: 0.7;
    flex-shrink: 0;
}

.col-loading {
    color: #4a5568;
    font-size: 11px;
    padding: 6px 8px;
    font-style: italic;
}

/* ── Main Content ── */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.editor-section {
    background: var(--editor-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-bottom: 2px solid #333;
}

.query-editor {
    width: 100%;
    height: 180px;
    min-height: 80px;
    max-height: 60vh;
    resize: vertical;
    background: var(--editor-bg);
    color: var(--editor-text);
    border: none;
    outline: none;
    padding: 14px 16px;
    font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    tab-size: 4;
}

.query-editor::placeholder { color: #3c3c3c; }

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: #252526;
    border-top: 1px solid #333;
}

.btn-execute {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-execute:hover { background: var(--accent-hover); }
.btn-execute:active { transform: scale(0.98); }
.btn-execute kbd {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 10px;
    font-family: inherit;
}

.btn-clear {
    padding: 6px 12px;
    background: transparent;
    color: #8b949e;
    border: 1px solid #3c3c3c;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-clear:hover { background: #3c3c3c; color: #e6edf3; }

.exec-status {
    font-size: 12px;
    margin-left: 4px;
}

.exec-status.running { color: #d4a72c; }
.exec-status.success { color: #3fb950; }
.exec-status.error { color: #f85149; }
.exec-status.warn { color: #d4a72c; }

/* ── Results ── */
.results-section {
    flex: 1;
    overflow: auto;
    background: var(--surface);
}

.results-inner {
    min-height: 100%;
    padding: 0;
}

.results-placeholder {
    padding: 40px 24px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

.results-loading {
    padding: 24px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Error panel */
.error-panel {
    margin: 12px;
    border: 1px solid var(--error-border);
    border-radius: 6px;
    background: var(--error-bg);
    overflow: hidden;
}

.error-panel-header {
    background: var(--error-border);
    color: white;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.error-panel-body {
    padding: 12px 14px;
    color: var(--error-text);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.error-panel-footer {
    padding: 6px 14px;
    color: #a5202a;
    font-size: 11px;
    border-top: 1px solid #fca5a5;
}

/* Success panel */
.success-panel {
    margin: 12px;
    padding: 14px 18px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 6px;
    color: #116329;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.success-icon { font-size: 16px; }
.exec-time-label { color: #57ab5a; font-size: 12px; margin-left: 4px; }

/* Results table */
.results-table-wrap {
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.results-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f6f8fa;
}

.results-table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    background: #f6f8fa;
}

.results-table td {
    padding: 6px 12px;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text);
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
}

.results-table tr:hover td { background: #f6fbff; }

.null-val {
    color: #9a9a9a;
    font-style: italic;
    font-size: 11px;
}

/* Pagination */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    background: #fafbfc;
    position: sticky;
    bottom: 0;
    flex-wrap: wrap;
    gap: 8px;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 12px;
}

.pagination-cap-warn {
    color: #b45309;
    font-size: 11px;
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    border-radius: 4px;
    padding: 2px 8px;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-controls select {
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
    margin-right: 4px;
}

.pagination-controls select:focus { outline: none; border-color: var(--accent); }

.page-btn {
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
    transition: all 0.1s;
}

.page-btn:hover:not(:disabled) { background: var(--accent); color: white; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.page-indicator {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 4px;
    white-space: nowrap;
}

/* Scrollbars (results) */
.results-section::-webkit-scrollbar { width: 7px; height: 7px; }
.results-section::-webkit-scrollbar-track { background: #f6f8fa; }
.results-section::-webkit-scrollbar-thumb { background: #d0d7de; border-radius: 4px; }
.results-section::-webkit-scrollbar-thumb:hover { background: #b0b8c2; }
