:root {
  --bg: #0a0a0a;
  --card-bg: #1a1a2e;
  --surface: #16162a;
  --border: #2a2a4a;
  --text: #f5f5f5;
  --text-muted: #a0a0b0;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
  --success: #22c55e;
  --info: #3b82f6;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Login Page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin-bottom: 1.5rem;
  object-fit: cover;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  text-decoration: none;
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  width: 100%;
  margin-top: 0.5rem;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 1rem;
  display: none;
}

/* Nav Bar */
.navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.navbar-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.navbar-brand {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.navbar-links {
  display: flex;
  gap: 0.25rem;
  margin-left: 1rem;
}

.navbar-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
}

.navbar-links a:hover,
.navbar-links a.active {
  color: var(--text);
  background: var(--surface);
}

.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.navbar-user {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.navbar-brand-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.navbar-dropdown {
  position: relative;
}

.navbar-dropdown-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.navbar-dropdown-btn:hover {
  color: var(--text);
  background: var(--surface);
}

.navbar-dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem;
  min-width: 160px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.navbar-dropdown:hover .navbar-dropdown-content {
  display: block;
}

.navbar-dropdown-content a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.85rem;
}

.navbar-dropdown-content a:hover {
  color: var(--text);
  background: var(--surface);
}

/* Dashboard */
.dashboard {
  padding: 2rem;
  max-width: 1000px;
  margin: 0 auto;
}

.dashboard h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 600;
}

/* Terminal Page */
.term-tabs {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 0.5rem;
  height: 36px;
  overflow-x: auto;
}

.term-tab-list {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.term-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
  border-bottom: none;
}

.term-tab:hover { background: var(--surface); color: var(--text); }

.term-tab.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.term-tab-name { user-select: none; }

.term-tab-close {
  font-size: 1rem;
  line-height: 1;
  opacity: 0.4;
  cursor: pointer;
  padding: 0 0.1rem;
}

.term-tab-close:hover { opacity: 1; color: var(--danger); }

.term-tab-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.term-tab-add {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.5rem;
  line-height: 1;
}

.term-tab-add:hover { color: var(--accent); }

.term-tab-preset {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.term-tab-preset:hover { background: var(--surface); }

.term-panels {
  height: calc(100vh - 57px - 36px);
  background: #0a0a0a;
}

.term-panel {
  height: 100%;
  padding: 4px;
}

.term-panel .xterm {
  height: 100%;
}

/* File Browser */
.fb-layout {
  display: flex;
  height: calc(100vh - 57px);
  overflow: hidden;
}

.fb-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 300px;
}

.fb-table-wrap {
  flex: 1;
  overflow: auto;
}

.fb-bulk {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: rgba(124, 58, 237, 0.1);
  border-bottom: 1px solid var(--accent);
  font-size: 0.85rem;
}

.fb-bulk span {
  color: var(--accent);
  font-weight: 500;
}

.fb-table input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.fb-table .fb-check-cell {
  width: 30px;
  text-align: center;
}

/* Editor panel */
.fb-editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  min-width: 400px;
}

.fb-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem;
  height: 36px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.fb-editor-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
}

.fb-editor-tab {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.fb-editor-tab:hover { background: var(--surface); color: var(--text); }
.fb-editor-tab.active { background: var(--bg); color: var(--text); }

.fb-editor-tab-close {
  font-size: 0.9rem;
  opacity: 0.4;
  cursor: pointer;
}

.fb-editor-tab-close:hover { opacity: 1; color: var(--danger); }

.fb-editor-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.fb-validation-msg {
  font-size: 0.75rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filebrowser {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.fb-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.fb-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

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

.fb-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.fb-breadcrumb a:hover { text-decoration: underline; }

.fb-actions {
  display: flex;
  gap: 0.5rem;
}

.fb-table {
  width: 100%;
  border-collapse: collapse;
}

.fb-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.fb-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.fb-table tr:hover td {
  background: var(--surface);
}

.fb-table .fb-name {
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.fb-table .fb-name:hover {
  color: var(--accent);
}

.fb-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.fb-dir .fb-icon { color: var(--accent); }
.fb-file .fb-icon { color: var(--text-muted); }

.fb-size, .fb-modified, .fb-perms {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Upload dropzone */
.fb-dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1rem;
  transition: border-color 0.2s, background 0.2s;
  display: none;
}

.fb-dropzone.active {
  display: block;
}

.fb-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.05);
}

/* File preview modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 800px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 500;
}

.modal-body {
  padding: 1.25rem;
  overflow: auto;
  flex: 1;
}

.modal-body pre {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

/* Database Manager */
.db-layout {
  display: flex;
  height: calc(100vh - 57px);
}

.db-sidebar {
  width: 280px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.db-sidebar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.db-sidebar-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.db-tree {
  overflow-y: auto;
  flex: 1;
  padding: 0.25rem 0;
  font-size: 0.82rem;
}

.db-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 1rem 0.5rem;
  text-align: center;
}

.db-tree-empty {
  padding: 0.3rem 0 0.3rem 1.25rem;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.75rem;
}

.db-layout.sidebar-collapsed .db-sidebar {
  width: 60px;
}

.db-layout.sidebar-collapsed .db-sidebar-header {
  justify-content: center;
  padding: 0.75rem 0.5rem;
}

.db-layout.sidebar-collapsed .db-sidebar-header h3,
.db-layout.sidebar-collapsed #discoverBtn,
.db-layout.sidebar-collapsed .db-tree {
  display: none;
}

/* Database node */
.db-tree-db-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}

.db-tree-db-row:hover { background: var(--surface); }
.db-tree-db.active > .db-tree-db-row { background: rgba(124, 58, 237, 0.1); }

.db-tree-arrow {
  font-size: 0.6rem;
  width: 1rem;
  text-align: center;
  color: var(--text-muted);
  flex-shrink: 0;
  cursor: pointer;
}

.db-tree-db-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.db-tree-db-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.db-tree-children {
  padding-left: 1.25rem;
}

/* Table node */
.db-tree-table-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}

.db-tree-table-row:hover { background: var(--surface); }

.db-tree-table-icon {
  width: 1.1rem;
  height: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  background: var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
}

.db-tree-table-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.db-tree-table-name:hover { color: var(--accent); }

.db-tree-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.6;
}

/* Column node */
.db-tree-col {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem 0.15rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.db-tree-col-icon {
  font-size: 0.7rem;
  width: 0.9rem;
  text-align: center;
  flex-shrink: 0;
}

.db-tree-col-name {
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-tree-col-type {
  font-size: 0.65rem;
  opacity: 0.5;
  flex-shrink: 0;
  text-transform: lowercase;
}

.db-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-editor {
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.db-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.db-editor-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.db-history-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  max-width: 170px;
}

.db-editor-shell {
  position: relative;
  min-height: 190px;
  background: var(--bg);
}

.db-sql-editor {
  height: 190px;
}

.db-editor-fallback {
  width: 100%;
  min-height: 190px;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: none;
  color: var(--text);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
}

.db-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-results-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.db-results-summary {
  min-width: 220px;
}

.db-results-info {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 500;
}

.db-results-subinfo {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.db-results-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.db-control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.db-control input,
.db-control select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  min-height: 32px;
  outline: none;
}

.db-control input:focus,
.db-control select:focus {
  border-color: var(--accent);
}

.db-filter-control input {
  min-width: 210px;
}

.db-query-modal {
  max-width: 860px;
}

.db-query-browser {
  max-width: 980px;
}

.db-query-save-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.db-query-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.db-query-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.db-query-save-submit {
  width: auto;
  margin-top: 0;
}

.db-query-browser-toolbar {
  margin-bottom: 1rem;
}

.db-query-search {
  width: 100%;
  padding: 0.7rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.db-query-search:focus {
  border-color: var(--accent);
}

.db-saved-query-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.db-saved-query-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.015);
  padding: 0.9rem 1rem;
}

.db-saved-query-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.db-saved-query-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.db-saved-query-meta {
  margin-top: 0.2rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.db-saved-query-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.db-saved-query-notes {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.db-saved-query-sql {
  margin-top: 0.75rem;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

.db-saved-query-empty {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 1.4rem;
  text-align: center;
  color: var(--text-muted);
}

.db-toggle-btn.active {
  background: rgba(124, 58, 237, 0.16);
  border-color: rgba(124, 58, 237, 0.6);
  color: var(--text);
}

.db-toggle-btn.active:hover {
  background: rgba(124, 58, 237, 0.24);
}

.db-cell-preview {
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.db-cell-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.db-cell-preview-value {
  padding: 0 1rem 0.85rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

.db-results-table-wrap {
  flex: 1;
  overflow: auto;
}

.db-results-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

.db-results-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card-bg);
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  min-width: 96px;
  user-select: none;
}

.db-results-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: top;
  cursor: pointer;
}

.db-results-table tr:hover td {
  background: var(--surface);
}

.db-results-table th:last-child,
.db-results-table td:last-child {
  border-right: none;
}

.db-results-table.is-wrap td {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
}

.db-results-table.is-compact th {
  padding: 0.35rem 0.55rem;
  font-size: 0.68rem;
}

.db-results-table.is-compact td {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}

.db-rownum-head,
.db-rownum {
  position: sticky;
  left: 0;
  width: 58px;
  min-width: 58px;
  max-width: 58px;
  text-align: right;
}

.db-rownum-head {
  z-index: 4;
}

.db-rownum {
  z-index: 1;
  color: var(--text-muted);
  background: var(--bg);
}

.db-results-table tr:hover .db-rownum {
  background: var(--surface);
}

.db-col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

.db-col-resizer::after {
  content: '';
  position: absolute;
  top: 18%;
  bottom: 18%;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: rgba(160, 160, 176, 0.25);
}

.db-results-table th:hover .db-col-resizer::after {
  background: rgba(124, 58, 237, 0.8);
}

.db-results-table td.is-selected {
  outline: 1px solid rgba(124, 58, 237, 0.8);
  outline-offset: -1px;
  background: rgba(124, 58, 237, 0.08);
}

.db-blob,
.db-json {
  color: var(--text-muted);
}

.db-empty-string {
  color: var(--text-muted);
  opacity: 0.8;
}

.db-empty-row td {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
}

.db-resizing,
.db-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.db-null {
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.5;
}

.db-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* System Monitor */
.sys-page {
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.sys-section { margin-bottom: 2rem; }

.sys-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sys-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.sys-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sys-auto-label { opacity: 0.6; }

.sys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.sys-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.sys-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sys-card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sys-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.sys-card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Bar components */
.sys-bar-group { display: flex; flex-direction: column; gap: 0.3rem; }

.sys-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sys-bar-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 1.5rem;
  text-align: right;
  flex-shrink: 0;
}

.sys-bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.sys-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.5s ease;
}

.sys-bar-pct {
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 2.5rem;
  text-align: right;
  flex-shrink: 0;
}

/* Memory stacked bar */
.sys-bar-stack { margin-bottom: 0.25rem; }

.sys-bar-stack .sys-bar-track { height: 12px; }

.sys-bar-used { background: var(--accent); position: absolute; left: 0; top: 0; }
.sys-bar-cached { background: rgba(124, 58, 237, 0.3); position: absolute; top: 0; }

.sys-mem-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sys-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.3rem;
}

.sys-dot-used { background: var(--accent); }
.sys-dot-cached { background: rgba(124, 58, 237, 0.3); }
.sys-dot-free { background: var(--surface); border: 1px solid var(--border); }

/* Disk items */
.sys-disk-item { margin-bottom: 0.75rem; }
.sys-disk-item:last-child { margin-bottom: 0; }

.sys-disk-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
}

.sys-disk-detail {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Network */
.sys-net-item {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sys-net-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.sys-net-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.sys-net-addr {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.sys-net-rates {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.sys-net-rx { color: var(--success); }
.sys-net-tx { color: var(--info); }

.sys-net-total {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Process manager */
.sys-proc-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.sys-filter {
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  width: 160px;
}

.sys-filter:focus { border-color: var(--accent); }

.sys-proc-wrap {
  overflow: auto;
  max-height: 500px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sys-proc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.sys-proc-table th {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sys-proc-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sys-proc-table tr:hover td { background: var(--surface); }

.sys-proc-pid {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sys-proc-cmd {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
}

.sys-val-high { color: var(--danger); font-weight: 600; }
.sys-val-med { color: #eab308; }

.sys-stat-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: var(--surface);
  border-radius: 4px;
  font-family: monospace;
}

.sys-proc-controls .btn-ghost.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Utility */
.hidden { display: none !important; }

@media (max-width: 640px) {
  .login-card { padding: 2rem 1.5rem; }
  .navbar { padding: 0.5rem 1rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .db-layout { flex-direction: column; }
  .db-sidebar { width: 100%; height: 200px; }
  .db-layout.sidebar-collapsed .db-sidebar { width: 100%; height: 58px; }
  .db-sql-editor,
  .db-editor-shell,
  .db-editor-fallback { min-height: 220px; height: 220px; }
  .db-results-toolbar { padding: 0.75rem; }
  .db-results-controls { width: 100%; }
  .db-filter-control { width: 100%; }
  .db-filter-control input { min-width: 0; width: 100%; }
  .db-cell-preview-header { align-items: flex-start; flex-direction: column; }
  .db-saved-query-head { flex-direction: column; }
  .db-saved-query-actions { width: 100%; }
  .sys-grid { grid-template-columns: 1fr; }
}
