/* --- Global Styles & Color Variables --- */
:root {
    --font-main: 'Inter', sans-serif;
    --color-primary: #007bff;
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-text: #212529;
    --color-text-muted: #6c757d;
    --color-border: #dee2e6;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.07);
    --border-radius: 8px;
}

body.dark-mode {
    --color-bg: #1a1a1a;
    --color-surface: #252525;
    --color-text: #e0e0e0;
    --color-text-muted: #888;
    --color-border: #444;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

body {
    font-family: var(--font-main);
    margin: 0;
    padding: 20px;
    background-color: var(--color-bg);
    color: var(--color-text);
    transition: background-color 0.3s, color 0.3s;
}

.container {
    background-color: var(--color-surface);
    padding: 20px 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 95%;
    max-width: 1400px;
    margin: auto;
    border: 1px solid var(--color-border);
    transition: background-color 0.3s;
}

/* --- Header & Controls --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 15px;
}
header h1 {
    color: var(--color-primary);
    margin: 0;
    font-size: 1.8em;
}
header h1 i { margin-right: 10px; }
.header-controls { display: flex; gap: 15px; align-items: center; }

input[type="file"] { display: none; }
.custom-file-upload, #theme-toggle, .execute-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 15px;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    font-weight: 500;
    transition: background-color 0.2s;
    color: white;
}
.custom-file-upload { background-color: var(--color-primary); }
.custom-file-upload:hover { background-color: #0056b3; }

#theme-toggle { background-color: #6c757d; }
#theme-toggle:hover { background-color: #5a6268; }

.execute-btn { background-color: var(--color-success); }
.execute-btn:hover { background-color: #218838; }
.execute-btn:disabled { background-color: #6c757d; cursor: not-allowed; }

.message { text-align: center; font-weight: 500; margin-bottom: 15px; padding: 10px; border-radius: 5px; }

/* --- Main Layout & Sidebar --- */
#db-viewer-container { display: flex; gap: 20px; margin-top: 20px; }
#sidebar {
    flex: 1;
    max-width: 280px;
    background-color: var(--color-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    transition: background-color 0.3s;
}
.sidebar-header h2 {
    color: var(--color-primary);
    margin: 0 0 10px 0;
    font-size: 1.2em;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}
#table-list { list-style: none; padding: 0; margin: 0; max-height: 70vh; overflow-y: auto; }
#table-list li { padding: 10px; cursor: pointer; border-bottom: 1px solid var(--color-border); transition: background-color 0.2s; font-weight: 500; display: flex; align-items: center; gap: 8px; }
#table-list li:last-child { border-bottom: none; }
#table-list li:hover, #table-list li.active { background-color: rgba(0, 123, 255, 0.1); color: var(--color-primary); }
#table-list li.no-data { cursor: default; color: var(--color-text-muted); }
#table-list li.no-data:hover { background-color: transparent; }

/* --- Main Content Area --- */
#main-content { flex: 3; display: flex; flex-direction: column; gap: 20px; min-width: 0; /* Prevents flexbox overflow */ }
#query-section, #results-container {
    background-color: var(--color-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    transition: background-color 0.3s;
}
.query-header, #results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.query-header h2, #results-header h3 { color: var(--color-primary); margin: 0; }

/* --- CodeMirror Editor --- */
.CodeMirror { border: 1px solid var(--color-border); height: 150px; font-family: 'Courier New', Courier, monospace; font-size: 14px; border-radius: 5px; }
.cm-s-material-darker.CodeMirror { background: #2a2a2a; color: #d4d4d4; }
.CodeMirror-readonly .CodeMirror-cursor { display: none; }

/* --- Results Table --- */
#results { margin-top: 10px; max-height: 450px; overflow: auto; border: 1px solid var(--color-border); border-radius: 5px; }
#results table { width: 100%; border-collapse: separate; border-spacing: 0; }
#results th, #results td { border-bottom: 1px solid var(--color-border); padding: 12px 15px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
#results th { background-color: var(--color-primary); color: white; position: sticky; top: 0; z-index: 1; }
#results tr:hover td { background-color: rgba(0, 123, 255, 0.05); }

.no-data { color: var(--color-text-muted); font-style: italic; text-align: center; padding: 40px; }
#query-status { font-size: 0.9em; color: var(--color-text-muted); }

/* --- Responsive Design for Mobile --- */
@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 15px; }
    #db-viewer-container { flex-direction: column; }
    #sidebar { max-width: 100%; }
    header { flex-direction: column; align-items: flex-start; }
}
