@font-face {
  font-family: 'Virgil';
  src: url('https://cdn.jsdelivr.net/npm/@excalidraw/excalidraw/dist/excalidraw-assets/Virgil.woff2') format('woff2');
  font-display: swap;
}

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */
:root {
  /* Surface colors — warm palette */
  --bg: #FAFAF7;
  --bg-card: #FEFEFA;
  --bg-header: #0f0f0f;

  /* Text colors */
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-dark: #f1f5f9;

  /* Border & shadow */
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.12);

  /* Shape */
  --radius: 6px;
  --radius-lg: 12px;

  /* Typography */
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Source Code Pro', 'SF Mono', Consolas, monospace;

  /* Accent */
  --accent: #3b82f6;
  --accent-light: #dbeafe;
  --accent-hover: #2563eb;
  --green: #10b981;

  /* Animation */
  --duration: 200ms;

  /* Category colors -- match card header backgrounds */
  --cat-admin: #2d8cf0;
  --cat-billing: #ff6b6b;
  --cat-measurements: #66d9a0;
  --cat-medications: #a78bfa;
  --cat-icu: #fbbf24;
  --cat-notes: #f472b6;
  --cat-clinical: #2d8cf0;
  --cat-derived: #ff6b6b;
  --cat-health: #66d9a0;
  --cat-vocab: #a78bfa;
  --cat-metadata: #94a3b8;

  /* Card surface colors */
  --card-border: #e2ddd5;
  --card-hover-bg: #fdfcf9;
  --card-col-border: #f5f3ef;
  --card-col-hover: #faf8f5;

  /* Detail panel */
  --detail-bg: #FEFDFB;
  --faq-bg: #f5f0e8;
  --bridge-bg: #eef4ff;

  /* Layout */
  --header-height: 52px;

  /* SQL dark theme — warm tint */
  --sql-bg: #12121a;
  --sql-bg-raised: #1a1a28;
  --sql-bg-input: #252535;
  --sql-border: #30363d;
  --sql-text: #c9d1d9;
  --sql-text-bright: #e6edf3;
  --sql-text-muted: #8b949e;
  --sql-text-dim: #6e7681;
  --sql-accent: #58a6ff;
  --sql-error: #f85149;
  --sql-success: #238636;
  --sql-success-hover: #2ea043;
  --sql-row-hover: #1f2937;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@supports not (height: 100dvh) {
  body { height: 100vh; }
}

/* ==========================================================================
   Accessibility: Skip Link & Focus Styles
   ========================================================================== */
.skip-link {
  position: absolute;
  left: -9999px;
  top: -9999px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border-radius: 4px;
  text-decoration: none;
}

.skip-link:focus {
  left: 10px;
  top: 10px;
}

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

:focus:not(:focus-visible) { outline: none; }

.sql-panel :focus-visible { outline-color: var(--sql-accent); }

.search-box:focus-visible {
  border-color: rgba(255, 255, 255, 0.6);
  outline-color: rgba(255, 255, 255, 0.4);
}

/* ==========================================================================
   Header
   ========================================================================== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-header);
  color: var(--text-on-dark);
  flex-shrink: 0;
  z-index: 100;
  gap: 16px;
}

header h1 {
  font-family: 'Virgil', cursive;
  font-size: 21px;
  font-weight: 400;
  letter-spacing: 0;
  white-space: nowrap;
  flex: 1;
}

.header-subtitle {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  opacity: 0.5;
  margin-left: 10px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

/* Tab group for format switching */
.tab-group {
  display: flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}

.tab {
  padding: 6px 20px;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 18px;
  font-family: var(--font);
  transition: color var(--duration), background-color var(--duration);
}

.tab.active {
  background: rgba(255, 255, 255, 0.85);
  color: var(--bg-header);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.tab:hover:not(.active) {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
}

/* Search input */
.search-box {
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  font-family: var(--font);
  width: 200px;
  outline: none;
}

.search-box::placeholder { color: rgba(255, 255, 255, 0.4); }
.search-box:focus { border-color: rgba(255, 255, 255, 0.4); }

/* Header right section */
#db-status {
  font-size: 13px;
  color: var(--green);
  font-family: var(--font-mono);
}

.start-here-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 400;
  font-family: 'Shantell Sans', cursive;
  cursor: pointer;
  transition: background-color var(--duration);
  white-space: nowrap;
}

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

/* ==========================================================================
   Welcome Modal
   ========================================================================== */
.welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-modal {
  background: #fff;
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 90%;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  position: relative;
}

.welcome-modal h2 {
  font-family: 'Shantell Sans', cursive;
  font-size: 22px;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.welcome-modal p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 12px;
}

.welcome-modal .tip {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
}

.welcome-modal .tip-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.welcome-modal .tip-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.welcome-modal .tip-text strong { color: var(--text-primary); }

.welcome-badge-pk { color: #b45309; font-family: var(--font-mono); font-size: 11px; }
.welcome-badge-fk { color: #7c3aed; font-family: var(--font-mono); font-size: 11px; }

.welcome-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.welcome-link-btn {
  padding: 8px 24px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  font-family: 'Shantell Sans', cursive;
  text-decoration: none;
}

.welcome-link-btn:hover { background: rgba(59, 130, 246, 0.08); }

.welcome-close {
  padding: 8px 24px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  font-family: 'Shantell Sans', cursive;
}

.welcome-close:hover { background: var(--accent-hover); }

/* ==========================================================================
   Main Layout
   ========================================================================== */
.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.canvas-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

.canvas-wrap.hidden { display: none; }

.canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  padding: 20px;
}

.canvas svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.3s ease;
}

.canvas svg.active-lines { z-index: 15; }

/* ==========================================================================
   Category Group Boxes
   ========================================================================== */
.group-box {
  position: absolute;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}

.group-label {
  position: absolute;
  top: -10px;
  left: 12px;
  background: var(--bg);
  padding: 0 8px;
  font-family: 'Shantell Sans', cursive;
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
  color: var(--text-secondary);
  border-radius: 999px;
}

/* ==========================================================================
   Table Cards
   ========================================================================== */
.table-card {
  position: absolute;
  width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 10px rgba(15, 23, 42, 0.04);
  z-index: 10;
  cursor: pointer;
  transition: transform 0.25s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease;
  overflow: hidden;
  font-family: var(--font-mono);
  contain: layout style;
}

.table-card:hover {
  box-shadow: var(--shadow-hover);
  border-color: #9ca3af;
  background: var(--card-hover-bg);
}

.table-card.highlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light), 0 2px 8px rgba(0, 0, 0, 0.15);
}

.table-card.dimmed { opacity: 0.2; }

/* Card header */
.card-header {
  padding: 5px 10px;
  background: #4a5568;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: 'Shantell Sans', cursive;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 13px 13px 0 0;
}

.card-header .rows {
  font-weight: 400;
  font-size: 10px;
  opacity: 0.5;
}

.card-subtitle {
  padding: 3px 10px 2px;
  font-size: 11px;
  font-family: 'Shantell Sans', cursive;
  color: var(--text-secondary);
  opacity: 0.7;
  font-style: normal;
  border-bottom: 1px solid var(--card-col-border);
}

/* Card columns list */
.card-cols {
  padding: 2px 0;
  font-size: 12px;
}

.card-col {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  gap: 0;
  border-bottom: 1px solid var(--card-col-border);
}

.card-col:last-child { border-bottom: none; }
.card-col:hover { background: var(--card-col-hover); }
.card-col.col-highlight { background: #dbeafe; }
.card-col.col-hidden { display: none; }

.card-col-expander {
  padding: 4px 10px;
  font-size: 11px;
  font-family: 'Shantell Sans', cursive;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
  border-bottom: none;
}
.card-col-expander:hover { background: var(--card-col-hover); }

.card-col .col-name {
  flex: 1;
  color: var(--text-primary);
  font-family: 'Literata', Georgia, serif;
  font-size: 12px;
  font-weight: 500;
}

/* PK/FK badges */
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 0;
  letter-spacing: 0.5px;
  font-family: var(--font-mono);
  margin-left: auto;
}

.badge-pk { background: transparent; color: #b45309; }
.badge-fk { background: transparent; color: #7c3aed; }

/* Category-specific card header colors */
.cat-admin .card-header { background: var(--cat-admin); }
.cat-billing .card-header { background: var(--cat-billing); }
.cat-measurements .card-header { background: var(--cat-measurements); color: var(--text-primary); }
.cat-medications .card-header { background: var(--cat-medications); }
.cat-icu .card-header { background: var(--cat-icu); color: var(--text-primary); }
.cat-notes .card-header { background: var(--cat-notes); }
.cat-clinical .card-header { background: var(--cat-clinical); }
.cat-derived .card-header { background: var(--cat-derived); }
.cat-health .card-header { background: var(--cat-health); color: var(--text-primary); }
.cat-vocab .card-header { background: var(--cat-vocab); }
.cat-metadata .card-header { background: var(--cat-metadata); }

/* Focus animation states */
.table-card.focused {
  z-index: 20;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 4px 20px rgba(59, 130, 246, 0.25);
  transform: scale(1.03);
}

.table-card.connected {
  z-index: 15;
  border-color: #93c5fd;
  box-shadow: var(--shadow-hover);
}

.table-card.dismissed {
  opacity: 0;
  pointer-events: none;
}

.group-box.hidden {
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

/* ==========================================================================
   Detail Panel (right side drawer)
   ========================================================================== */
.detail-panel {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  width: 340px;
  background: var(--detail-bg);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.06);
  z-index: 80;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.detail-panel.open { transform: translateX(0); }

.detail-header {
  position: sticky;
  top: 0;
  background: var(--detail-bg);
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 1;
}

.detail-title {
  font-size: 17px;
  font-weight: 600;
  font-family: 'Shantell Sans', cursive;
  color: var(--text-primary);
}

.detail-rows {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Shantell Sans', cursive;
  margin-top: 2px;
}

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

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

.detail-desc {
  padding: 12px 20px;
  font-size: 13px;
  font-family: 'Shantell Sans', cursive;
  color: var(--text-secondary);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
}

.detail-section {
  padding: 10px 20px 4px;
  font-size: 13px;
  font-weight: 400;
  font-family: 'Shantell Sans', cursive;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.detail-col {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  padding: 5px 20px;
  gap: 2px 8px;
  font-size: 14px;
  border-bottom: 1px solid var(--card-col-border);
}

.detail-col:hover { background: var(--card-col-hover); }

.detail-col-name {
  font-family: 'Literata', Georgia, serif;
  color: var(--text-primary);
  flex: 1;
}

.detail-col-ref {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: 4px;
  opacity: 0.7;
}

.detail-col-def {
  width: 100%;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Shantell Sans', cursive;
  line-height: 1.4;
  padding-left: 0;
}

.detail-doc-link {
  display: inline-block;
  padding: 6px 20px;
  font-size: 12px;
  font-family: 'Shantell Sans', cursive;
  color: var(--accent);
  text-decoration: none;
}

.detail-doc-link:hover { text-decoration: underline; }

.detail-col-desc {
  font-size: 14px;
  color: var(--text-muted);
  flex: 1;
}

.detail-clinical {
  padding: 12px 20px 8px;
  font-family: 'Shantell Sans', cursive;
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
}

.detail-clinical-label {
  font-family: 'Shantell Sans', cursive;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-clinical p {
  margin: 0 0 8px;
}

.detail-clinical p:last-child { margin-bottom: 0; }

.detail-faq {
  padding: 12px 20px;
  margin: 0;
  font-family: 'Shantell Sans', cursive;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  background: var(--faq-bg);
  border-bottom: none;
  font-style: normal;
  border-radius: 0;
  margin-bottom: 0;
}

.detail-bridge {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bridge-bg);
}

.bridge-label {
  font-size: 13px;
  font-weight: 400;
  font-family: 'Shantell Sans', cursive;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
}

.bridge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: 'Shantell Sans', cursive;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--duration);
}

.bridge-pill:hover {
  background: var(--accent-hover);
}

.bridge-arrow {
  font-size: 10px;
  opacity: 0.6;
}

/* ==========================================================================
   Tooltip
   ========================================================================== */
.tooltip {
  position: fixed;
  background: var(--bg-header);
  color: var(--text-on-dark);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 300px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tooltip.visible { opacity: 1; }
.tooltip-name { font-weight: 600; }
.tooltip-rows { font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.tooltip-desc { font-size: 12px; color: rgba(255, 255, 255, 0.7); margin-top: 4px; }

/* ==========================================================================
   Legend
   ========================================================================== */
.legend {
  position: absolute;
  top: 8px;
  right: 16px;
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ==========================================================================
   SQL Panel (bottom dock, dark terminal theme)
   ========================================================================== */
.sql-panel {
  flex-shrink: 0;
  height: 200px;
  display: flex;
  flex-direction: column;
  background: var(--sql-bg);
  border-top: 1px solid var(--sql-border);
  z-index: 90;
  transition: height 0.3s ease;
  contain: layout style;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.sql-panel.minimized {
  height: 42px;
  overflow: hidden;
  flex-shrink: 0;
}

.sql-panel.maximized {
  flex: 1;
  height: auto;
}

/* SQL drag handle */
.sql-drag-handle {
  height: 4px;
  cursor: ns-resize;
  flex-shrink: 0;
}
.sql-drag-handle:hover { background: #94a3b8; }

/* SQL header bar */
.sql-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--sql-border);
  flex-shrink: 0;
  min-height: 34px;
  background: #0f0f0f;
}

.sql-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.sql-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: flex-end;
}

/* Format dropdown in SQL header */
#format-select {
  padding: 3px 8px;
  border: 1px solid var(--sql-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--sql-bg);
  color: var(--sql-text);
}

#format-select option {
  background: var(--sql-bg);
  color: var(--sql-text);
}

/* Toggle buttons in SQL header */
.toggle-btn {
  border: none;
  background: none;
  color: var(--sql-text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  padding: 4px 10px;
}

.toggle-btn:hover { color: var(--sql-accent); }

#toggle-samples {
  border: 1px solid var(--sql-border);
  border-radius: 4px;
  padding: 3px 10px;
}
#toggle-samples:hover {
  color: var(--sql-text-bright);
  border-color: var(--sql-text-muted);
}

#exploration-progress a {
  color: #fbbf24;
  text-shadow: 0 0 6px rgba(251, 191, 36, 0.3);
  text-decoration: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
}
#exploration-progress a:hover {
  color: #f59e0b;
}

#minimize-sql {
  color: #fff;
  font-weight: 700;
  background: #dc2626;
  border-radius: 4px;
  padding: 4px 12px;
}

#minimize-sql:hover {
  background: #b91c1c;
  color: #fff;
}

/* SQL body layout */
.sql-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sql-editor-wrap {
  width: 45%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sql-border);
}

.sql-results-wrap {
  flex: 1;
  overflow: auto;
  background: var(--sql-bg);
}

/* SQL textarea */
#sql-editor {
  flex: 1;
  border: none;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--sql-text-bright);
  background: var(--sql-bg);
  resize: none;
  outline: none;
  line-height: 1.7;
  caret-color: var(--sql-accent);
}

#sql-editor::placeholder { color: var(--sql-text-dim); }

/* SQL action bar */
.sql-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-top: 1px solid var(--sql-border);
  background: var(--sql-bg-raised);
}

/* Generic button style for SQL panel */
.btn {
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  border: 1px solid var(--sql-border);
  background: var(--sql-bg-input);
  color: var(--sql-text);
  transition: border-color var(--duration), color var(--duration), background-color var(--duration);
}

.btn:hover:not(:disabled) {
  border-color: var(--sql-text-muted);
  color: #fff;
}

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

.btn-run {
  background: var(--sql-success);
  border-color: var(--sql-success);
  color: #fff;
}

.btn-run:hover:not(:disabled) {
  background: var(--sql-success-hover);
  border-color: var(--sql-success-hover);
}

#query-time {
  font-size: 11px;
  color: var(--sql-text-muted);
  font-family: var(--font-mono);
  margin-left: auto;
}

/* Results table */
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}

.results-table th {
  position: sticky;
  top: 0;
  background: var(--sql-bg-raised);
  color: var(--sql-accent);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--sql-border);
  white-space: nowrap;
}

.results-table td {
  padding: 4px 10px;
  color: var(--sql-text);
  border-bottom: 1px solid var(--sql-bg-input);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results-table tr:nth-child(even) td { background: var(--sql-bg-raised); }
.results-table tr:hover td { background: var(--sql-row-hover); }

.null-value {
  color: var(--sql-text-dim);
  font-style: italic;
}

.query-empty,
.query-error,
.query-truncated {
  padding: 14px;
  font-size: 13px;
  color: var(--sql-text-muted);
}

.query-error { color: var(--sql-error); }

/* Progress bar */
.sql-progress {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--sql-border);
  background: var(--sql-bg-raised);
}

.progress-track {
  flex: 1;
  height: 3px;
  background: var(--sql-border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--sql-accent);
  width: 0%;
}

.progress-bar.indeterminate {
  width: 100%;
  animation: indeterminate-slide 1.5s infinite;
}

@keyframes indeterminate-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

#progress-text {
  font-size: 13px;
  color: var(--sql-text-muted);
  font-family: var(--font-mono);
}

/* ==========================================================================
   Sample Queries Panel (inside SQL editor wrap, above textarea)
   ========================================================================== */
.samples-panel {
  display: none;
  border-bottom: 1px solid var(--sql-border);
  max-height: 160px;
  overflow-y: auto;
  background: var(--sql-bg-raised);
  flex-shrink: 0;
}

.samples-panel.visible { display: block; }

/* Reset button defaults for sample items */
button.sample-item {
  font: inherit;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sample-item {
  display: flex;
  align-items: flex-start;
  padding: 6px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--sql-bg-input);
  gap: 10px;
  transition: background 0.15s;
}

.sample-item:hover { background: var(--sql-row-hover); }

.sample-label {
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--sql-text);
  white-space: nowrap;
}

.sample-tag {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 0;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.sample-tag-basic  { background: #dbeafe; color: #1e40af; }
.sample-tag-join   { background: #fef3c7; color: #92400e; }
.sample-tag-agg    { background: #d1fae5; color: #065f46; }
.sample-tag-window { background: #ede9fe; color: #5b21b6; }
.sample-tag-cte    { background: #fce7f3; color: #9d174d; }
.sample-tag-tsql   { background: #fee2e2; color: #991b1b; }

.sample-sql {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--sql-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1024px) {
  .sql-body { flex-direction: column; }

  .sql-editor-wrap {
    width: 100%;
    flex: 0 0 50%;
    border-right: none;
    border-bottom: 1px solid var(--sql-border);
  }

  .table-card { width: 140px; }
}

@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  header h1 { font-size: 16px; }
  header h1 span { display: none; }

  .header-center {
    width: 100%;
    order: 3;
  }

  .search-box { width: 100%; }
  .sql-panel { height: 160px; }
  .table-card { width: 120px; }
  #sql-editor { font-size: 16px; }

  .detail-panel {
    width: 100%;
    top: 0;
    height: 100%;
    border-left: none;
    border-top: 2px solid var(--border);
    border-radius: 12px 12px 0 0;
  }

  .detail-close {
    font-size: 28px;
    padding: 8px 12px;
    min-width: 44px;
    min-height: 44px;
  }

  .sample-item { padding: 12px 16px; }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
