@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --bg-hover: #1f1f1f;
  --border: #2a2a2a;
  --border-focus: #3a3a3a;
  --text-primary: #ffffff;
  --text-secondary: #888888;
  --text-muted: #555555;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.08);
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-width: 280px;
  --radius: 8px;
  --radius-sm: 6px;
  --transition: 150ms ease;
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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

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

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo svg {
  flex-shrink: 0;
  color: var(--accent);
}

.sidebar-logo h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

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

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

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

/* ── Schema ── */
.table-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.table-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.row-badge {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--font-mono);
}

.schema-search {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 8px;
}

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

.schema-search::placeholder {
  color: var(--text-muted);
}

.column-list {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
}

.column-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  gap: 8px;
}

.column-item:hover {
  background: var(--bg-hover);
}

.column-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-type {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ── Preset queries ── */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--transition);
  border: 1px solid transparent;
}

.preset-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

/* ── History ── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all var(--transition);
}

.history-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Main area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Editor ── */
.editor-section {
  padding: 20px 24px 0;
  flex-shrink: 0;
}

.editor-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.editor-wrapper {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}

.editor-wrapper:focus-within {
  border-color: var(--border-focus);
}

.editor-container {
  position: relative;
  min-height: 120px;
  max-height: 240px;
}

.editor-highlight,
.editor-textarea {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
}

.editor-highlight {
  pointer-events: none;
  color: var(--text-primary);
  z-index: 1;
}

.editor-textarea {
  background: transparent;
  color: transparent;
  caret-color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  z-index: 2;
  -webkit-text-fill-color: transparent;
}

.editor-textarea::placeholder {
  -webkit-text-fill-color: var(--text-muted);
}

.sql-keyword {
  color: var(--accent);
  font-weight: 500;
}

.sql-string {
  color: var(--success);
}

.sql-number {
  color: #f59e0b;
}

.sql-function {
  color: #a78bfa;
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.editor-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.editor-hint kbd {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.run-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}

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

.run-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.run-btn.running {
  animation: pulse 1.2s ease-in-out infinite;
}

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

/* ── Error bar ── */
.error-bar {
  margin: 10px 24px 0;
  padding: 10px 14px;
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 13px;
  font-family: var(--font-mono);
  display: none;
}

.error-bar.visible {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* ── Results ── */
.results-section {
  flex: 1;
  padding: 16px 24px 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.results-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.results-empty svg {
  opacity: 0.3;
}

.results-empty p {
  font-size: 14px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.results-stats {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-toggle button {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-secondary);
  padding: 5px 14px;
  font-size: 12px;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.view-toggle button + button {
  border-left: 1px solid var(--border);
}

.view-toggle button.active {
  background: var(--accent);
  color: white;
}

.view-toggle button:hover:not(.active) {
  background: var(--bg-hover);
}

/* ── Table ── */
.results-table-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.results-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.results-table th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

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

.results-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.015);
}

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

.results-table td.numeric {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── Chart ── */
.chart-container {
  flex: 1;
  min-height: 0;
  position: relative;
  display: none;
}

.chart-container.visible {
  display: block;
}

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

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.25s ease;
}
