/* ─── Theme Variables ─── */
[data-theme="dark"] {
  --bg: #121214;
  --surface: #1a1a1e;
  --surface-raised: #222226;
  --surface-hover: #2a2a2e;
  --border: #333338;
  --border-subtle: #2a2a2e;
  --text: #e8e8ec;
  --text-secondary: #9a9aa0;
  --text-muted: #6a6a70;
  --accent: #f0a050;
  --accent-hover: #f5b870;
  --accent-bg: rgba(240, 160, 80, 0.1);
  --accent-border: rgba(240, 160, 80, 0.25);
  --error: #f06060;
  --success: #60c080;
  --null-color: #6a6a70;
  --null-bg: rgba(106, 106, 112, 0.1);
  --sidebar-bg: #161618;
  --editor-bg: #1a1a1e;
  --results-bg: #161618;
  --topbar-bg: #1a1a1e;
  --modal-bg: #1e1e22;
  --modal-overlay: rgba(0, 0, 0, 0.6);
  --scrollbar-thumb: #3a3a40;
  --scrollbar-track: transparent;
  --badge-bg: rgba(240, 160, 80, 0.15);
  --badge-text: #f0a050;
  --row-hover: rgba(240, 160, 80, 0.05);
  --row-stripe: rgba(255, 255, 255, 0.02);
  --cm-theme: monokai;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #f0f0f2;
  --surface-hover: #e8e8ea;
  --border: #d8d8dc;
  --border-subtle: #e8e8ea;
  --text: #1a1a1e;
  --text-secondary: #5a5a60;
  --text-muted: #8a8a90;
  --accent: #c07020;
  --accent-hover: #a06018;
  --accent-bg: rgba(192, 112, 32, 0.08);
  --accent-border: rgba(192, 112, 32, 0.2);
  --error: #d04040;
  --success: #308050;
  --null-color: #a0a0a8;
  --null-bg: rgba(160, 160, 168, 0.1);
  --sidebar-bg: #f0f0f2;
  --editor-bg: #ffffff;
  --results-bg: #fafafa;
  --topbar-bg: #ffffff;
  --modal-bg: #ffffff;
  --modal-overlay: rgba(0, 0, 0, 0.3);
  --scrollbar-thumb: #c0c0c4;
  --scrollbar-track: transparent;
  --badge-bg: rgba(192, 112, 32, 0.12);
  --badge-text: #c07020;
  --row-hover: rgba(192, 112, 32, 0.06);
  --row-stripe: rgba(0, 0, 0, 0.02);
  --cm-theme: default;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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

/* ─── Top Bar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo {
  font-size: 20px;
  color: var(--accent);
  line-height: 1;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #1a1a1e;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--accent-border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

/* ─── Theme Toggle Icons ─── */
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ─── Main Layout (IDE grid) ─── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  width: 240px;
  min-width: 180px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-family: 'JetBrains Mono', monospace;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.sidebar-empty {
  padding: 20px 14px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

/* Schema table items */
.schema-table {
  user-select: none;
}

.schema-table-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
  transition: background 0.1s;
}

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

.schema-table-header .arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.schema-table-header .arrow.expanded {
  transform: rotate(90deg);
}

.schema-table-header .table-icon {
  color: var(--accent);
  font-size: 11px;
  flex-shrink: 0;
}

.schema-table-header .table-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schema-table-header .row-count {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.schema-columns {
  display: none;
  padding: 2px 0 4px 0;
}

.schema-columns.expanded {
  display: block;
}

.schema-column {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 14px 3px 34px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

.schema-column .col-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schema-column .col-type {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: lowercase;
}

/* ─── Workspace ─── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ─── Panel Toolbar ─── */
.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shortcut-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ─── Editor Panel ─── */
.editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 50%;
  min-height: 120px;
  background: var(--editor-bg);
}

.editor-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* CodeMirror overrides */
.editor-wrap .CodeMirror {
  height: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  padding: 4px 0;
}

.editor-wrap .CodeMirror-gutters {
  border-right: 1px solid var(--border-subtle);
}

/* Light theme CodeMirror overrides */
[data-theme="light"] .editor-wrap .CodeMirror {
  background: var(--editor-bg);
  color: var(--text);
}

[data-theme="light"] .editor-wrap .CodeMirror-gutters {
  background: var(--surface-raised);
  border-right-color: var(--border);
}

[data-theme="light"] .editor-wrap .CodeMirror-linenumber {
  color: var(--text-muted);
}

[data-theme="light"] .editor-wrap .CodeMirror-activeline-background {
  background: var(--accent-bg);
}

[data-theme="light"] .editor-wrap .CodeMirror-cursor {
  border-left-color: var(--text);
}

[data-theme="light"] .editor-wrap .CodeMirror-selected {
  background: rgba(192, 112, 32, 0.15);
}

/* ─── Resize Handle ─── */
.resize-handle {
  height: 6px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--accent);
}

.resize-grip {
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0.5;
}

.resize-handle:hover .resize-grip,
.resize-handle.active .resize-grip {
  background: #1a1a1e;
  opacity: 0.8;
}

/* ─── Results Panel ─── */
.results-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 50%;
  min-height: 120px;
  background: var(--results-bg);
  overflow: hidden;
}

/* Results tabs */
.results-tabs {
  display: flex;
  gap: 2px;
}

.tab {
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}

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

.tab.active {
  color: var(--accent);
  background: var(--accent-bg);
}

/* Results content */
.results-content,
.messages-content {
  flex: 1;
  overflow: auto;
}

.results-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

.result-info {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ─── Results Table ─── */
.results-table-wrap {
  overflow: auto;
  height: 100%;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.results-table th {
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  padding: 6px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}

.results-table td {
  padding: 5px 12px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table tr:nth-child(even) td {
  background: var(--row-stripe);
}

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

.results-table td.null-cell {
  color: var(--null-color);
  background: var(--null-bg);
  font-style: italic;
}

/* ─── Pagination ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
  flex-shrink: 0;
}

.page-info {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ─── Messages ─── */
.messages-list {
  padding: 8px 12px;
}

.message-item {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.message-item:last-child {
  border-bottom: none;
}

.message-time {
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  flex-shrink: 0;
  padding-top: 1px;
}

.message-text {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  word-break: break-word;
}

.message-text.error {
  color: var(--error);
}

.message-text.success {
  color: var(--success);
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 560px;
  max-width: 90vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

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

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
}

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

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

/* History items */
.history-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
  font-size: 13px;
}

.history-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border-subtle);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--surface-hover);
}

.history-query {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

.history-meta {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  pointer-events: none;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ─── CodeMirror Hint Overrides ─── */
.CodeMirror-hints {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 50;
}

.CodeMirror-hint {
  padding: 4px 8px;
  color: var(--text);
}

.CodeMirror-hint-active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* ─── Feature Tour Modal ─── */
.tour-modal {
  width: 480px;
  max-width: 92vw;
  max-height: none;
  overflow: hidden;
  border-radius: 16px;
}

.tour-slides {
  position: relative;
  overflow: hidden;
}

.tour-slide {
  display: none;
  padding: 36px 32px 24px;
  text-align: center;
  animation: tourFadeIn 0.3s ease;
}

.tour-slide.active {
  display: block;
}

@keyframes tourFadeIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

.tour-icon {
  margin-bottom: 16px;
  color: var(--accent);
}
.tour-icon svg {
  width: 44px;
  height: 44px;
}

.tour-heading {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.tour-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
  max-width: 380px;
  margin: 0 auto 16px;
}

.tour-hint {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 auto;
  max-width: 400px;
}

.tour-hint code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--accent);
  word-break: break-word;
}

.tour-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border-subtle);
}

.tour-dots {
  display: flex;
  gap: 6px;
}

.tour-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.2s;
  cursor: pointer;
}

.tour-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}

.tour-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tour-skip {
  color: var(--text-muted) !important;
  font-size: 11px !important;
}

.tour-text kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar {
    width: 180px;
    min-width: 140px;
  }

  .app-subtitle {
    display: none;
  }

  .shortcut-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  .sidebar {
    display: none;
  }
}
