:root {
  --bg-dark: #0a0a0c;
  --bg-card: rgba(22, 22, 28, 0.75);
  --bg-card-solid: #16161c;
  --bg-input: #121218;
  --bg-hover: #22222d;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.18);
  
  --primary: #E50914;
  --primary-hover: #b80710;
  --primary-glow: rgba(229, 9, 20, 0.25);
  
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-purple: #8b5cf6;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --font-ui: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

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

/* App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(15, 15, 19, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-badge {
  background: rgba(229, 9, 20, 0.1);
  border: 1px solid rgba(229, 9, 20, 0.3);
  padding: 8px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.badge-wasm {
  background: linear-gradient(135deg, #E50914, #ff525d);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.mode-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.status-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-indicator.loading {
  background: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse 1.5s infinite;
}

.status-indicator.ready {
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
}

.status-indicator.error {
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

.status-text {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.status-detail {
  font-size: 0.7rem;
  color: var(--text-muted);
}

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

/* Workspace Grid */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

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

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-tabs .tab-btn {
  flex: 1;
  padding: 0.75rem 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.sidebar-tabs .tab-btn.active {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  background: rgba(229, 9, 20, 0.05);
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar-panel.active {
  display: flex;
}

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

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

.db-size-badge {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 12px;
  color: var(--text-muted);
}

/* Schema Tree */
.schema-tree {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.table-node {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.table-header {
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  gap: 0.5rem;
}

.table-header:hover {
  background: var(--bg-hover);
}

.table-header-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.table-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.table-expand-icon {
  color: var(--text-muted);
  transition: transform 0.2s ease, color 0.15s ease;
  flex-shrink: 0;
}

.table-header:hover .table-expand-icon {
  color: #fff;
}

.table-expand-icon.expanded {
  transform: rotate(90deg);
  color: var(--accent-red);
}

.table-name-text {
  font-weight: 600;
  font-size: 0.85rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-rows-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 6px;
  border-radius: 8px;
}

.btn-select-table {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid rgba(229, 9, 20, 0.3);
  background: rgba(229, 9, 20, 0.1);
  color: #ff4d4d;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-select-table:hover {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
  box-shadow: 0 0 8px rgba(229, 9, 20, 0.4);
}

.column-list {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.8rem;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border-color);
  gap: 0.3rem;
}

.column-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 2px 0;
}

.column-name {
  color: #d1d5db;
}

.column-type {
  color: var(--accent-purple);
  font-size: 0.7rem;
}

/* Sample Presets */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.preset-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-card:hover {
  border-color: var(--primary);
  background: rgba(229, 9, 20, 0.08);
  transform: translateY(-1px);
}

.preset-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  color: #fff;

}

.preset-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.preset-sql-preview {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent-blue);
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  overflow: hidden;
}

/* Editor Section */
.editor-section {
  display: flex;
  flex-direction: column;
  background: var(--bg-card-solid);
  border-bottom: 1px solid var(--border-color);
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.15);
}

.editor-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sql-chips {
  display: flex;
  gap: 0.25rem;
  margin-right: 0.5rem;
}

.chip-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.editor-wrapper {
  position: relative;
  height: 140px;
}

#sqlEditor {
  width: 100%;
  height: 100%;
  background: var(--bg-input);
  color: #e5e7eb;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  border: none;
  resize: none;
  outline: none;
}

#sqlEditor:focus {
  background: #0e0e13;
}

.editor-footer {
  padding: 0.25rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: flex-end;
}

.keyboard-shortcut {
  font-size: 0.7rem;
  color: var(--text-dim);
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 12px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 16px rgba(229, 9, 20, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--border-color-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.05);
}

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

.btn-file input[type="file"] {
  display: none;
}

/* Results Section */
.results-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-dark);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-card-solid);
  border-bottom: 1px solid var(--border-color);
}

.results-tabs {
  display: flex;
  gap: 0.5rem;
}

.results-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s;
}

.results-tab-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.count-pill {
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 10px;
}

.execution-metrics {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.execution-metrics strong {
  color: var(--accent-green);
}

.export-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-search {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  outline: none;
  width: 160px;
}

.table-search:focus {
  border-color: var(--accent-blue);
}

/* Results Body */
.results-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.results-panel {
  display: none;
  height: 100%;
  width: 100%;
  overflow: auto;
  flex-direction: column;
}

.results-panel.active {
  display: flex;
}

/* Empty & Error States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.empty-state h4 {
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.25rem;
}

.error-banner {
  margin: 1rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  padding: 1rem;
  color: #fca5a5;
}

.error-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #ef4444;
}

.error-message {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

/* Data Table Grid */
.table-container {
  flex: 1;
  overflow: auto;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: left;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #181820;
  color: #d1d5db;
  font-weight: 600;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
  z-index: 10;
}

.sortable-th {
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sortable-th:hover {
  background: #22222e;
  color: #fff;
}

.sortable-th.sorted-col {
  color: var(--primary);
  background: rgba(229, 9, 20, 0.1);
}

.sort-arrow {
  font-size: 0.7rem;
  margin-left: 4px;
  color: var(--text-muted);
}

.sortable-th.sorted-col .sort-arrow {
  color: var(--primary);
}

.data-table td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #e5e7eb;
  white-space: nowrap;
  max-width: 350px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.date-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: help;
}

.date-badge:hover {
  background: rgba(59, 130, 246, 0.25);
  color: #bfdbfe;
}

.runtime-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: help;
}

.runtime-badge:hover {
  background: rgba(16, 185, 129, 0.25);
  color: #a7f3d0;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-card-solid);
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Chart Panel */
.chart-controls-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card-solid);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  outline: none;
}

.chart-wrapper {
  flex: 1;
  padding: 1.5rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Explain Plan */
.explain-container {
  padding: 1.5rem;
}

.explain-header h4 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.explain-header p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .sidebar {
    width: 240px;
  }
}

/* HTTPVFS Loading Overlay */
.vfs-loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  background: rgba(18, 18, 24, 0.95);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  border: 1px solid rgba(59, 130, 246, 0.3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  margin: 2rem auto;
  max-width: 540px;
  text-align: center;
  animation: fadeIn 0.25s ease-out;
}

.vfs-spinner-graphic {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.vfs-spinner-graphic .pulse-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #3b82f6;
  border-right-color: #10b981;
  animation: vfsSpin 1s linear infinite;
}

.vfs-spinner-graphic .pulse-icon {
  font-size: 1.75rem;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes vfsSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.vfs-loading-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #f3f4f6;
  margin-bottom: 0.5rem;
}

.vfs-loading-desc {
  font-size: 0.85rem;
  color: #9ca3af;
  margin-bottom: 1.25rem;
  max-width: 440px;
  line-height: 1.4;
}

.vfs-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1rem;
  position: relative;
}

.vfs-progress-fill {
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981, #3b82f6);
  border-radius: 3px;
  position: absolute;
  animation: vfsShimmer 1.5s infinite linear;
}

@keyframes vfsShimmer {
  0% { left: -40%; }
  100% { left: 100%; }
}

.vfs-stats-pill {
  display: flex;
  gap: 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.vfs-stats-pill strong {
  color: #60a5fa;
}

.btn-loading {
  opacity: 0.85;
  cursor: wait !important;
  pointer-events: none;
}

.btn-loading .spinner-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: vfsSpin 0.8s linear infinite;
  margin-right: 6px;
}

