/* ============================================================
   SQL Generator — Premium Dark UI
   Inspired by: Linear, Vercel, Warp, Raycast
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300..800;1,14..32,300..800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap");

/* ── TOKENS ── */
:root {
  --ink-0: #ffffff;
  --ink-1: #f4f4f5;
  --ink-2: #a1a1aa;
  --ink-3: #71717a;
  --ink-4: #3f3f46;
  --ink-5: #27272a;
  --ink-6: #18181b;
  --ink-7: #0f0f10;
  --ink-8: #09090b;

  --surface-0: rgba(255,255,255,0.025);
  --surface-1: rgba(255,255,255,0.05);
  --surface-2: rgba(255,255,255,0.08);
  --surface-3: rgba(255,255,255,0.12);

  --border-0: rgba(255,255,255,0.05);
  --border-1: rgba(255,255,255,0.09);
  --border-2: rgba(255,255,255,0.15);

  --bg: #09090b;
  --bg-panel: #0f0f10;
  --text: #f4f4f5;
  --text-soft: #a1a1aa;
  --text-muted: #71717a;

  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-dim: rgba(37,99,235,0.15);
  --accent-glow: rgba(37,99,235,0.25);

  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Fira Code", monospace;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 18px;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semi: 600;
  --weight-bold: 700;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-2xl: 24px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.6);
  --shadow-xl: 0 32px 80px rgba(0,0,0,0.7), 0 12px 32px rgba(0,0,0,0.5);

  --ease: cubic-bezier(0.22,1,0.36,1);
  --ease-spring: cubic-bezier(0.34,1.56,0.64,1);
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;

  --header-h: 58px;
}

[data-theme="light"] {
  --ink-0: #111827; --ink-1: #1f2937; --ink-2: #374151; --ink-3: #6b7280;
  --ink-4: #9ca3af; --ink-5: #d1d5db; --ink-6: #e5e7eb; --ink-7: #f3f4f6; --ink-8: #ffffff;
  --surface-0: rgba(0,0,0,.02); --surface-1: rgba(0,0,0,.04);
  --surface-2: rgba(0,0,0,.06); --surface-3: rgba(0,0,0,.09);
  --border-0: rgba(0,0,0,.05); --border-1: rgba(0,0,0,.09); --border-2: rgba(0,0,0,.14);
  --bg: #ffffff; --bg-panel: #f9fafb; --text: #111827; --text-soft: #374151; --text-muted: #6b7280;
  --accent-dim: rgba(37,99,235,0.08);
}

/* ── RESET ── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}
button,input,select,textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(37,99,235,0.3); color: var(--ink-0); }

/* ────────────────────────────────────────────────────────────
   AMBIENT BACKGROUND
   ──────────────────────────────────────────────────────────── */
.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 20%, black 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 20%, black 30%, transparent 100%);
}

.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  will-change: transform;
}
.bg-blob-1 {
  width: 700px; height: 700px;
  top: -300px; right: -150px;
  background: radial-gradient(circle, rgba(37,99,235,0.07) 0%, transparent 70%);
  animation: blob-drift 22s ease-in-out infinite;
}
.bg-blob-2 {
  width: 550px; height: 550px;
  bottom: -200px; left: -100px;
  background: radial-gradient(circle, rgba(139,92,246,0.05) 0%, transparent 70%);
  animation: blob-drift 28s ease-in-out infinite reverse;
}
.bg-blob-3 {
  width: 400px; height: 400px;
  top: 40%; left: 40%;
  background: radial-gradient(circle, rgba(6,182,212,0.04) 0%, transparent 70%);
  animation: blob-drift 18s ease-in-out infinite 6s;
}

@keyframes blob-drift {
  0%,100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(40px,-30px) scale(1.05); }
  66% { transform: translate(-20px,20px) scale(0.97); }
}

#particleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
}

/* Mouse glow */
.mouse-glow {
  position: fixed;
  width: 400px;
  height: 400px;
  pointer-events: none;
  z-index: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37,99,235,0.08) 0%, transparent 70%);
  transform: translate(-50%, -50%);
  transition: opacity var(--dur-slow) ease;
  opacity: 0;
}

/* ────────────────────────────────────────────────────────────
   HEADER
   ──────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 20px;
  background: rgba(9,9,11,0.75);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border-0);
  animation: fadeInDown var(--dur-slow) var(--ease) both;
}

[data-theme="light"] .app-header {
  background: rgba(255,255,255,0.85);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(37,99,235,0.4);
  animation: brand-pulse 3s ease-in-out infinite;
}

@keyframes brand-pulse {
  0%,100% { box-shadow: 0 0 20px rgba(37,99,235,0.4); }
  50% { box-shadow: 0 0 32px rgba(37,99,235,0.65); }
}

.brand-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--ink-0);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: var(--weight-normal);
}

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

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.header-btn svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.header-btn:hover {
  background: var(--surface-1);
  border-color: var(--border-2);
  color: var(--text);
  transform: translateY(-1px);
}
.header-btn:active { transform: translateY(1px) scale(0.97); }
.header-btn.icon-only { padding: 0; width: 34px; justify-content: center; }

.kbd-hint {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  cursor: pointer;
}

/* ────────────────────────────────────────────────────────────
   KBD
   ──────────────────────────────────────────────────────────── */
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-1);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-1);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 10px;
  font-weight: var(--weight-semi);
  line-height: 1;
}

/* ────────────────────────────────────────────────────────────
   WORKSPACE
   ──────────────────────────────────────────────────────────── */
.workspace {
  position: relative;
  z-index: 2;
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.panel-left {
  width: 420px;
  min-width: 300px;
  max-width: 600px;
  border-right: 1px solid var(--border-0);
  background: rgba(9,9,11,0.4);
  flex-shrink: 0;
}
[data-theme="light"] .panel-left { background: rgba(255,255,255,0.5); }

.panel-right {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-1) transparent;
}
.panel-right::-webkit-scrollbar { width: 4px; }
.panel-right::-webkit-scrollbar-thumb { background: var(--border-1); border-radius: 10px; }

/* Resize handle */
.resize-handle {
  width: 4px;
  background: var(--border-0);
  cursor: col-resize;
  transition: background var(--dur-fast) var(--ease);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.resize-handle:hover,
.resize-handle.dragging { background: var(--accent); }
.resize-handle::after {
  content: '';
  position: absolute;
  inset: 0 -4px;
}

/* ────────────────────────────────────────────────────────────
   TABS
   ──────────────────────────────────────────────────────────── */
.panel-header {
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border-0);
  flex-shrink: 0;
}

.panel-tabs {
  display: flex;
  gap: 2px;
  position: relative;
  padding-bottom: 0;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  position: relative;
}
.tab-btn svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.tab-btn:hover { color: var(--text-soft); }
.tab-btn.active { color: var(--ink-0); }

.tab-indicator {
  position: absolute;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  transition: left var(--dur-base) var(--ease), width var(--dur-base) var(--ease);
  box-shadow: 0 0 12px rgba(37,99,235,0.6);
}

.tab-pane { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-pane.active { display: flex; }

/* ────────────────────────────────────────────────────────────
   AI PROMPT TAB
   ──────────────────────────────────────────────────────────── */
.ai-prompt-area {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  overflow: hidden;
}

.prompt-chips {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-0);
  flex-shrink: 0;
}

.chips-label {
  display: block;
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-pill);
  background: var(--surface-0);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.chip:hover {
  background: var(--accent-dim);
  border-color: rgba(37,99,235,0.4);
  color: var(--accent-light);
  transform: translateY(-1px);
}
.chip:active { transform: scale(0.96); }

.prompt-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  overflow: hidden;
}

.prompt-textarea {
  flex: 1;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.7;
  resize: none;
  outline: none;
  transition:
    border-color var(--dur-base) var(--ease),
    background var(--dur-base) var(--ease),
    box-shadow var(--dur-base) var(--ease);
  min-height: 120px;
}
.prompt-textarea::placeholder { color: var(--text-muted); }
.prompt-textarea:focus {
  border-color: var(--accent);
  background: rgba(37,99,235,0.04);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.prompt-hint {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-muted);
}

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

/* ────────────────────────────────────────────────────────────
   BUTTONS
   ──────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid rgba(37,99,235,0.6);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  cursor: pointer;
  transition:
    transform var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
  box-shadow: 0 0 20px rgba(37,99,235,0.3), 0 1px 0 rgba(255,255,255,0.1) inset;
  position: relative;
  overflow: hidden;
}
.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 200%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  transition: left 0.4s ease;
}
.btn-primary:hover::before { left: 100%; }
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 32px rgba(37,99,235,0.5), 0 4px 16px rgba(0,0,0,0.3);
}
.btn-primary:active { transform: translateY(1px) scale(0.97); }
.btn-primary svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-ghost-sm {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
.btn-ghost-sm:hover {
  background: var(--surface-1);
  border-color: var(--border-2);
  color: var(--text-soft);
}

/* ────────────────────────────────────────────────────────────
   VISUAL BUILDER TAB
   ──────────────────────────────────────────────────────────── */
.builder-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-1) transparent;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.builder-scroll::-webkit-scrollbar { width: 3px; }
.builder-scroll::-webkit-scrollbar-thumb { background: var(--border-1); border-radius: 10px; }

.builder-section {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-0);
}
.builder-section:last-of-type { border-bottom: none; }

.builder-row.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.form-label .required { color: var(--error); }

.form-input, .form-select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--text);
  font-size: var(--text-sm);
  outline: none;
  transition:
    border-color var(--dur-base) var(--ease),
    background var(--dur-base) var(--ease),
    box-shadow var(--dur-base) var(--ease);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  background: rgba(37,99,235,0.04);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-select {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.select-wrap { position: relative; }
.select-chevron {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  stroke: var(--text-muted); fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  pointer-events: none;
}

.section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-label {
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.section-hint {
  font-size: 10px;
  color: var(--ink-4);
}

.column-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.column-input-row .form-input { flex: 1; }

.btn-add {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.btn-add svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.btn-add:hover {
  background: var(--accent-dim);
  border-color: rgba(37,99,235,0.4);
  color: var(--accent-light);
  transform: scale(1.05);
}

/* Pills */
.pills-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  min-height: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: var(--weight-medium);
  animation: pill-in var(--dur-base) var(--ease-spring) both;
}
@keyframes pill-in {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.pill-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.pill-remove:hover { background: rgba(239,68,68,0.2); color: var(--error); }

/* Collapsible sections */
.collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}
.collapse-toggle > span:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}
.collapse-toggle svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0.6;
}
.collapse-toggle:hover { color: var(--text); }
.collapse-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: var(--weight-semi);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.badge.has-items {
  background: var(--accent-dim);
  color: var(--accent-light);
}
.chevron {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform var(--dur-base) var(--ease);
}
.collapse-body { overflow: hidden; }
.collapsible[aria-expanded="false"] .collapse-body { display: none; }
.collapsible[aria-expanded="true"] .chevron { transform: rotate(180deg); }

/* Condition rows */
.conditions-list, .joins-list, .sort-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.condition-row, .join-row, .sort-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border-0);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  position: relative;
  animation: slide-in var(--dur-base) var(--ease-spring) both;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.condition-row-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: end;
}

.condition-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.logical-select-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}
.logical-select-wrap label { font-size: 10px; color: var(--text-muted); }
.logical-select-wrap select {
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-soft);
  font-size: 11px;
  outline: none;
  cursor: pointer;
}

.btn-remove-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn-remove-row:hover {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: var(--error);
}

/* Join row layout */
.join-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

/* Sort row */
.sort-row-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: end;
}
.sort-direction-group {
  display: flex;
  gap: 4px;
}
.dir-btn {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: var(--weight-semi);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.dir-btn.active {
  background: var(--accent-dim);
  border-color: rgba(37,99,235,0.4);
  color: var(--accent-light);
}
.dir-btn:hover:not(.active) {
  background: var(--surface-1);
  border-color: var(--border-2);
  color: var(--text-soft);
}

.btn-add-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px dashed var(--border-1);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
.btn-add-row svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.btn-add-row:hover {
  background: var(--surface-0);
  border-color: var(--accent);
  color: var(--accent-light);
  border-style: solid;
}

.builder-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  padding-bottom: 4px;
  border-top: 1px solid var(--border-0);
  margin-top: 4px;
  flex-shrink: 0;
}

/* ────────────────────────────────────────────────────────────
   RIGHT PANEL — EMPTY STATE
   ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  gap: 12px;
  padding: 40px;
  text-align: center;
}

.empty-illustration {
  animation: float 4s ease-in-out infinite;
  opacity: 0.7;
}

@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.empty-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semi);
  color: var(--text-soft);
}
.empty-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 300px;
}

.empty-arrow {
  color: var(--text-muted);
  animation: bounce 1.8s ease-in-out infinite;
  opacity: 0.4;
}
.empty-arrow svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

/* ────────────────────────────────────────────────────────────
   LOADING STATE
   ──────────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  gap: 20px;
  padding: 40px;
}

.thinking-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.thinking-orb {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thinking-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
  animation: ring-spin linear infinite;
}
.ring-1 {
  border-top-color: var(--accent);
  animation-duration: 1.2s;
  inset: 0;
}
.ring-2 {
  border-right-color: var(--purple);
  animation-duration: 1.8s;
  animation-direction: reverse;
  inset: 8px;
}
.ring-3 {
  border-bottom-color: var(--cyan);
  animation-duration: 2.4s;
  inset: 16px;
}

@keyframes ring-spin { to { transform: rotate(360deg); } }

.thinking-icon {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
  stroke: var(--accent-light);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: icon-pulse 1.5s ease-in-out infinite;
}
@keyframes icon-pulse {
  0%,100% { opacity: 0.6; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.05); }
}

.thinking-dots {
  display: flex;
  gap: 5px;
}
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; background: var(--purple); }
.dot:nth-child(3) { animation-delay: 0.4s; background: var(--cyan); }
@keyframes dot-bounce {
  0%,100% { transform: scale(0.7); opacity: 0.4; }
  50% { transform: scale(1); opacity: 1; }
}

.thinking-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-style: italic;
}

.thinking-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 400px;
}
.sk-line {
  height: 10px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.sk-w-80 { width: 80%; } .sk-w-60 { width: 60%; } .sk-w-90 { width: 90%; }
.sk-w-50 { width: 50%; } .sk-w-75 { width: 75%; }
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ────────────────────────────────────────────────────────────
   SQL OUTPUT
   ──────────────────────────────────────────────────────────── */
.sql-output {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeInUp var(--dur-slow) var(--ease) both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* SQL Code Panel */
.sql-code-panel {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: rgba(0,0,0,0.4);
  box-shadow: var(--shadow-md);
}
[data-theme="light"] .sql-code-panel { background: #0d1117; }

.sql-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-0);
  background: rgba(255,255,255,0.02);
}

.sql-code-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}
.code-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}
.dot-red { background: #ef4444; }
.dot-yellow { background: #f59e0b; }
.dot-green { background: #22c55e; }

.code-lang {
  margin-left: 8px;
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sql-code-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.toolbar-btn svg {
  width: 12px; height: 12px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.toolbar-btn:hover {
  background: var(--surface-1);
  border-color: var(--border-2);
  color: var(--text-soft);
  transform: translateY(-1px);
}
.toolbar-btn:active { transform: scale(0.95); }
.toolbar-btn.success-flash {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.3);
  color: var(--success);
}

/* SQL Code block - syntax highlighting */
.sql-code {
  margin: 0;
  padding: 20px 22px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.8;
  color: #e2e8f0;
  white-space: pre;
  tab-size: 2;
  max-height: 360px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-1) transparent;
}
.sql-code::-webkit-scrollbar { height: 4px; }
.sql-code::-webkit-scrollbar-thumb { background: var(--border-1); border-radius: 10px; }

/* Syntax tokens */
.tok-kw  { color: #c792ea; font-weight: 500; }  /* keywords */
.tok-fn  { color: #82aaff; }                      /* functions */
.tok-str { color: #c3e88d; }                      /* strings */
.tok-num { color: #f78c6c; }                      /* numbers */
.tok-cmt { color: #546e7a; font-style: italic; }  /* comments */
.tok-op  { color: #89ddff; }                      /* operators */
.tok-id  { color: #ffcb6b; }                      /* identifiers/columns */
.tok-tbl { color: #80cbc4; }                      /* table names */
.tok-pun { color: #89ddff; }                      /* punctuation */

/* Analysis Grid */
.analysis-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.analysis-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px;
  border: 1px solid var(--border-0);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  transition:
    background var(--dur-base) var(--ease),
    border-color var(--dur-base) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
  animation: card-in var(--dur-slow) var(--ease) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
#cardQueryType { animation-delay: 60ms; }
#cardTables { animation-delay: 120ms; }
#cardComplexity { animation-delay: 180ms; }
#cardCost { animation-delay: 240ms; }

.analysis-card:hover {
  background: var(--surface-1);
  border-color: var(--border-1);
  transform: translateY(-2px);
}

.analysis-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.analysis-icon svg {
  width: 14px; height: 14px;
  stroke: var(--text-soft); fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

.analysis-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.analysis-label {
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.analysis-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  color: var(--ink-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* complexity / cost color coding */
.complexity-simple, .cost-low { color: var(--success) !important; }
.complexity-moderate, .cost-medium { color: var(--warning) !important; }
.complexity-complex, .cost-high { color: #f97316 !important; }
.complexity-very-complex, .cost-very-high { color: var(--error) !important; }

.analysis-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.analysis-tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text-soft);
  font-size: 10px;
  font-weight: var(--weight-medium);
}

/* Explanation & Warnings */
.explanation-block, .warnings-block {
  padding: 14px 16px;
  border: 1px solid var(--border-0);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  animation: fadeInUp var(--dur-slow) var(--ease) both;
}

.explanation-label, .warnings-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.explanation-label svg, .warnings-label svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.warnings-label { color: var(--warning); }
.explanation-block p {
  font-size: var(--text-sm);
  color: var(--text-soft);
  line-height: 1.7;
}
.warnings-block ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.warnings-block li {
  font-size: var(--text-sm);
  color: var(--text-soft);
  padding-left: 14px;
  position: relative;
}
.warnings-block li::before {
  content: '⚠';
  position: absolute;
  left: 0;
  font-size: 10px;
  color: var(--warning);
}
/* ── WHY THIS TOOL ──────────────────────────────────── */
.sql-why {
  max-width: 1100px;
  margin: 0 auto 48px;
  padding: 0 clamp(16px, 3vw, 40px);
}

.sql-why__heading {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-0, #fff);
  margin-bottom: 8px;
}

.sql-why__subheading {
  font-size: 0.9rem;
  color: var(--text-muted, rgba(255,255,255,0.5));
  margin-bottom: 24px;
}

.sql-why__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.sql-why__card {
  padding: 22px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.sql-why__card:hover {
  border-color: rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  transform: translateY(-2px);
}

.sql-why__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.5);
  margin-bottom: 18px;
}

.sql-why__icon svg {
  width: 16px;
  height: 16px;
}

.sql-why__label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  margin-bottom: 12px;
}

.sql-why__desc {
  font-size: 0.85rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.7);
}

.sql-why__desc code {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.8rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
}

@media (max-width: 900px) {
  .sql-why__grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .sql-why__grid { grid-template-columns: 1fr; }
}
/* ────────────────────────────────────────────────────────────
   COMMAND PALETTE
   ──────────────────────────────────────────────────────────── */
.cmd-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14vh 16px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: fadeIn var(--dur-fast) var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.cmd-box {
  width: min(580px, 100%);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  background: rgba(12,12,14,0.97);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: scale-in var(--dur-base) var(--ease-spring);
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.cmd-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-0);
}
.cmd-search-row svg {
  width: 15px; height: 15px;
  stroke: var(--text-muted); fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
#cmdInput {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: var(--text-base);
}
#cmdInput::placeholder { color: var(--text-muted); }
.cmd-esc { font-size: 10px; }

.cmd-results {
  max-height: 360px;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-1) transparent;
}

.cmd-group-label {
  padding: 8px 10px 4px;
  font-size: 10px;
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.6;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.cmd-item svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
  opacity: 0.7;
}
.cmd-item kbd { margin-left: auto; }
.cmd-item:hover { background: var(--surface-1); color: var(--text); }
.cmd-item.focused { background: var(--surface-1); color: var(--text); }

/* ────────────────────────────────────────────────────────────
   MODALS
   ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fadeIn var(--dur-base) var(--ease);
}

.modal-box {
  width: min(480px, 100%);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  background: rgba(12,12,14,0.98);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: scale-in var(--dur-base) var(--ease-spring);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-0);
}
.modal-head h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-semi);
  color: var(--ink-1);
}
.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.modal-close svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.modal-close:hover {
  background: var(--surface-1);
  color: var(--text);
  transform: rotate(90deg);
}

.modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-0);
  font-size: var(--text-sm);
  color: var(--text-soft);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row div { display: flex; align-items: center; gap: 3px; }

/* Fullscreen */
.fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,0.94);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn var(--dur-base) var(--ease);
}

.fullscreen-box {
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  background: rgba(4,4,6,0.98);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: scale-in var(--dur-base) var(--ease-spring);
}

.fullscreen-code {
  flex: 1;
  max-height: none;
  overflow-y: auto;
}

/* ────────────────────────────────────────────────────────────
   TOAST
   ──────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 380px;
  padding: 12px 16px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  background: rgba(15,15,16,0.97);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-xl);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
  pointer-events: all;
  animation: toast-in 0.28s var(--ease-spring) both;
  position: relative;
  overflow: hidden;
}
.toast::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 100%;
  background: var(--accent);
  animation: toast-progress linear forwards;
  transform-origin: left;
}
.toast.toast-success::after { background: var(--success); }
.toast.toast-error::after { background: var(--error); }
.toast.toast-warning::after { background: var(--warning); }
.toast.toast-info::after { background: var(--accent); }

@keyframes toast-progress {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(10px) scale(0.95); }
}
.toast.removing { animation: toast-out 0.2s var(--ease) both; }

.toast-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toast.toast-success .toast-icon { color: var(--success); }
.toast.toast-error .toast-icon { color: var(--error); }
.toast.toast-warning .toast-icon { color: var(--warning); }
.toast.toast-info .toast-icon { color: var(--accent-light); }

.toast-close {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--surface-1);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  flex-shrink: 0;
}
.toast-close:hover { background: var(--surface-2); color: var(--text); }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ────────────────────────────────────────────────────────────
   RESPONSIVE
   ──────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .analysis-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-left { width: 360px; }
}

@media (max-width: 768px) {
  .workspace { flex-direction: column; height: auto; min-height: calc(100vh - var(--header-h)); }
  .panel-left { width: 100%; min-width: unset; max-width: unset; border-right: none; border-bottom: 1px solid var(--border-0); max-height: 70vh; overflow-y: auto; }
  .panel-right { min-height: 50vh; overflow-y: visible; }
  .resize-handle { display: none; }
  .analysis-grid { grid-template-columns: 1fr 1fr; }
  .brand-sub { display: none; }
  .condition-row-inner { grid-template-columns: 1fr; }
  .join-row-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .analysis-grid { grid-template-columns: 1fr; }
  .header-btn:not(.icon-only) span { display: none; }
  .chip:nth-child(n+5) { display: none; }
  .panel-right { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── BOOKMARK BUTTON ── */
#bookmarkBtn.sql-bookmarked {
    background: var(--surface-1);
    border-color: var(--border-2);
    color: var(--text-soft);
}

#bookmarkBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}