:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --danger: #f87171;
  --success: #4ade80;
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --border: #cbd5e1;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-dim: #0ea5e9;
  --danger: #dc2626;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.top-menu {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: auto;
}

.menu {
  position: relative;
}

.menu > summary,
.menu-trigger {
  list-style: none;
  cursor: pointer;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.menu-trigger {
  background: transparent;
  border: none;
  font-family: inherit;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu > summary:hover,
.menu-trigger:hover,
.menu.open > summary,
.menu.open .menu-trigger {
  background: var(--surface-2);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 11rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.35rem;
  box-shadow: 0 12px 32px color-mix(in srgb, var(--bg) 55%, transparent);
  z-index: 50;
  display: none;
  flex-direction: column;
  gap: 0.15rem;
}

.menu.open .menu-dropdown {
  display: flex;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-weight: 500;
  font-size: 0.85rem;
}

.menu-item:hover:not(:disabled) {
  background: var(--surface-2);
}

.menu-item.danger-text {
  color: var(--danger);
}

.menu-item:disabled {
  opacity: 0.45;
}

.url-form {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 280px;
  max-width: 560px;
}

input[type="text"],
input[type="url"],
input[type="search"],
input[type="number"],
input[type="date"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}

button,
.btn {
  background: var(--accent-dim);
  color: #041016;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.file-badge {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface-2);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.main {
  display: grid;
  flex: 1;
  min-height: 0;
  position: relative;
}

.main.workspace {
  --sidebar-rail: 2rem;
  --sidebar-explorer: 260px;
  --sidebar-history: 220px;
  grid-template-columns: var(--sidebar-explorer) 1fr var(--sidebar-history);
  min-height: calc(100vh - 72px);
}

.main.workspace.explorer-collapsed {
  grid-template-columns: var(--sidebar-rail) 1fr var(--sidebar-history);
}

.main.workspace.history-collapsed {
  grid-template-columns: var(--sidebar-explorer) 1fr var(--sidebar-rail);
}

.main.workspace.explorer-collapsed.history-collapsed {
  grid-template-columns: var(--sidebar-rail) 1fr var(--sidebar-rail);
}

.explorer-column,
.history-column {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.explorer-column .sidebar,
.history-column .sidebar {
  height: 100%;
}

.main.explorer-collapsed .explorer-column .sidebar,
.main.history-collapsed .history-column .sidebar {
  visibility: hidden;
  pointer-events: none;
}

.sidebar-toggle {
  position: absolute;
  top: 1rem;
  z-index: 3;
  padding: 0.25rem 0.4rem;
  font-size: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}

.sidebar-toggle.explorer {
  right: 0.35rem;
}

.main.explorer-collapsed .sidebar-toggle.explorer {
  right: auto;
  left: 50%;
  transform: translateX(-50%);
}

.sidebar-toggle.history {
  left: 0.35rem;
}

.main.history-collapsed .sidebar-toggle.history {
  left: 50%;
  transform: translateX(-50%);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
  overflow: auto;
}

.right-sidebar,
.explorer-panel {
  border-right: 1px solid var(--border);
}

.right-sidebar {
  border-right: none;
  border-left: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sidebar-header h3 {
  margin: 0;
}

.main:not(.explorer-collapsed) .explorer-panel .sidebar-header {
  padding-right: 2rem;
}

.main:not(.history-collapsed) .query-history-panel .sidebar-header {
  padding-left: 2rem;
}

.icon-btn {
  padding: 0.35rem 0.55rem;
  min-width: 2rem;
}

.sidebar h3 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.schema-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.schema-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  background: var(--bg);
}

.schema-list .type {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
}

.content {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.workspace-content {
  min-width: 0;
}

.sql-panel {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1rem;
}

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

.sql-panel-header h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.sql-editor-host {
  min-height: 120px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.sql-editor-host .cm-editor {
  min-height: 120px;
}

.sql-editor-host .cm-scroller {
  min-height: 120px;
}

.sql-hints {
  flex: 1;
}

.sql-hints .meta {
  font-size: 0.75rem;
}

.view-tabs {
  display: flex;
  gap: 0.35rem;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}

.tab.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.tab:disabled {
  opacity: 0.45;
}

.tree-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  background: var(--bg);
}

.tree-item:hover {
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}

.tree-item.active {
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

.tree-icon {
  color: var(--accent);
  font-size: 0.75rem;
}

.tree-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-empty {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.tree-node {
  list-style: none;
}

.tree-children {
  list-style: none;
  padding: 0 0 0 1rem;
  margin: 0.15rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.tree-schema {
  font-weight: 600;
}

.tree-table .tree-expand {
  cursor: pointer;
}

.tree-column {
  font-size: 0.8rem;
  padding-left: 0.35rem !important;
}

.tree-column .type {
  margin-left: auto;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
}

.tree-delete {
  margin-left: auto;
  opacity: 0;
  padding: 0.1rem 0.35rem !important;
  font-size: 0.85rem !important;
  line-height: 1;
}

.tree-table:hover .tree-delete {
  opacity: 1;
}

.danger-btn {
  color: var(--danger) !important;
  border-color: color-mix(in srgb, var(--danger) 35%, transparent) !important;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-item {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.history-sql {
  flex: 1;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-actions {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.query-history-panel {
  border-left: 1px solid var(--border);
}

.query-stats {
  display: flex;
  gap: 1rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(420px, 100%);
  box-shadow: 0 12px 40px color-mix(in srgb, var(--bg) 60%, transparent);
}

.modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.modal-subtitle {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  word-break: break-all;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
}

.form-field input,
.form-field select {
  width: 100%;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.table-badge {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}

.toolbar .search {
  flex: 1;
}

.dropzone {
  display: block;
  position: relative;
  border: 2px dashed color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 20px;
  padding: 0;
  text-align: center;
  background: color-mix(in srgb, var(--surface) 90%, var(--accent) 3%);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
  cursor: pointer;
  overflow: hidden;
}

.dropzone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 80% 60% at 50% 0%,
    color-mix(in srgb, var(--accent) 12%, transparent),
    transparent 70%
  );
  pointer-events: none;
  opacity: 0.6;
}

.dropzone:hover:not(.loading) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent),
    0 16px 48px color-mix(in srgb, var(--accent) 12%, transparent);
  transform: translateY(-1px);
}

.dropzone.drag-over {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.dropzone.loading {
  pointer-events: none;
  opacity: 0.85;
}

.dropzone-inner {
  position: relative;
  padding: 2.75rem 2rem 2.5rem;
}

.dropzone-icon {
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1.25rem;
  color: var(--accent);
  opacity: 0.9;
}

.dropzone-icon svg {
  width: 100%;
  height: 100%;
}

.dropzone-title {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.dropzone-sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

.dropzone-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.5rem;
  background: var(--accent-dim);
  color: #041016;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s, transform 0.15s;
}

.dropzone:hover:not(.loading) .dropzone-cta {
  background: var(--accent);
}

.dropzone-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1.25rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
}

.dropzone-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Landing page */
.landing {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.5rem 3rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.landing-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent),
    radial-gradient(ellipse 40% 30% at 90% 80%, color-mix(in srgb, var(--accent) 6%, transparent), transparent),
    var(--bg);
}

.landing-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(color-mix(in srgb, var(--border) 40%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--border) 40%, transparent) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 30%, black, transparent);
  opacity: 0.35;
}

.landing-hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.landing-hero-badge {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  margin-bottom: 1.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: 999px;
}

.landing-title {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.landing-title-accent {
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 60%, #a78bfa) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.landing-subtitle {
  margin: 0 auto;
  max-width: 36rem;
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--muted);
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  width: 100%;
  margin-bottom: 2rem;
}

.landing-feature {
  padding: 1.25rem 1.15rem;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.landing-feature:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--bg) 60%, transparent);
}

.landing-feature-icon {
  width: 2.25rem;
  height: 2.25rem;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.landing-feature-icon svg {
  width: 100%;
  height: 100%;
}

.landing-feature h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.landing-feature p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

.header-landing {
  justify-content: space-between;
}

.landing-upload {
  width: 100%;
}

.landing-load-panel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.landing-or {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
}

.landing-or span {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.landing-url {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.5rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 100%;
}

.landing-url-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.landing-url-desc {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.landing-url-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.landing-url-input {
  width: 100%;
}

.landing-samples {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.landing-samples-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.landing-sample-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.landing-sample-link {
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.landing-sample-link:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.landing-sample-link:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.landing-formats {
  margin-top: 1.25rem;
  text-align: center;
}

.landing-formats-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.landing-footer {
  margin-top: 2rem;
  padding: 1rem 0 0.5rem;
  text-align: center;
}

.landing-footer-link {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}

.landing-footer-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.format-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
}

.format-chip {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.format-chip.muted {
  color: var(--muted);
  border-style: dashed;
}

@media (max-width: 768px) {
  .landing-load-panel {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .landing-or {
    padding: 0.25rem 0;
  }
}

@media (max-width: 640px) {
  .landing {
    padding: 1.5rem 1rem 2rem;
  }

  .landing-features {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .landing-feature {
    padding: 1rem;
  }

  .landing-feature p {
    display: none;
  }

  .dropzone-inner {
    padding: 2rem 1.25rem 1.75rem;
  }
}

@media (max-width: 420px) {
  .landing-features {
    grid-template-columns: 1fr;
  }

  .landing-feature p {
    display: block;
  }
}

.table-wrap {
  overflow: auto;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 0;
  z-index: 1;
}

.th-inner {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
}

.th-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.th-label .sort {
  color: var(--accent);
  font-size: 0.75rem;
}

.filter-input {
  width: 100%;
  padding: 0.35rem 0.5rem !important;
  font-size: 0.8rem !important;
}

tbody td {
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  padding: 0.45rem 0.65rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.footer .meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-right: auto;
}

.pager {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.error-banner {
  margin: 0.75rem 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: #fecaca;
  font-size: 0.9rem;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--accent);
}

.table-panel {
  position: relative;
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

.hidden-input {
  display: none;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #cbd5e1;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-dim: #0ea5e9;
  --danger: #dc2626;
  --success: #16a34a;
}

.sql-editor-host {
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.sql-editor-host .cm-editor {
  min-height: 120px;
}

.sql-hints .meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.query-stats {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tree-node {
  list-style: none;
}

.tree-children {
  list-style: none;
  padding: 0 0 0 1rem;
  margin: 0.15rem 0;
}

.tree-schema .tree-label {
  font-weight: 600;
}

.tree-table {
  padding-left: 0.25rem;
}

.tree-column {
  font-size: 0.8rem;
  opacity: 0.9;
}

.tree-column .type {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--muted);
}

.tree-delete {
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.15s;
}

.tree-table:hover .tree-delete {
  opacity: 1;
}

.danger-btn {
  background: color-mix(in srgb, var(--danger) 20%, var(--surface-2));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(420px, 100%);
  box-shadow: 0 16px 48px color-mix(in srgb, var(--bg) 60%, transparent);
}

.modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.modal-subtitle {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  word-break: break-all;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
}

.form-field span {
  color: var(--muted);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.history-sql {
  flex: 1;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-actions {
  display: flex;
  gap: 0.2rem;
}

.query-history-panel {
  border-left: 1px solid var(--border);
}

@media (max-width: 1100px) {
  .main.workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .explorer-column,
  .history-column {
    max-height: 200px;
  }

  .sidebar-toggle {
    display: none;
  }
}

/* "+ Add data" button in the header */
.add-data-btn {
  background: var(--surface-2);
  color: var(--accent);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

.add-data-btn:hover:not(:disabled) {
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
}

/* Type editor modal */
.type-editor-modal {
  width: min(720px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.type-editor-rows {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.25rem 0 0.5rem;
  padding-right: 0.25rem;
}

.type-editor-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) minmax(160px, 1.4fr) minmax(140px, 1.4fr);
  gap: 0.6rem;
  align-items: start;
  padding: 0.5rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.type-editor-col {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.type-editor-name {
  font-weight: 600;
  font-size: 0.85rem;
  word-break: break-word;
}

.type-editor-col .type {
  font-size: 0.72rem;
  color: var(--muted);
}

.type-editor-controls {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.type-editor-controls select,
.type-editor-format-input {
  width: 100%;
  font-size: 0.82rem;
}

.type-editor-format {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.type-editor-preview {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.74rem;
  min-width: 0;
}

.type-editor-preview-pair {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
}

.type-editor-preview-pair .raw {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-editor-preview-pair .arrow {
  color: var(--accent);
  flex: 0 0 auto;
}

.type-editor-preview-pair .conv {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-editor-preview-empty {
  color: var(--muted);
  font-style: italic;
}
/* ── Mode tabs (Workspace / Notebook) ───────────────────────── */
.mode-tabs {
  display: flex;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

/* ── Notebook ───────────────────────────────────────────────── */
.notebook {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.notebook-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.notebook-intro.meta {
  margin: 0;
  flex: 1;
  min-width: 12rem;
}

.nb-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.nb-cell-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nb-cell-label {
  font-weight: 600;
  color: var(--muted);
  margin-right: auto;
}

.nb-sql {
  width: 100%;
  min-height: 5rem;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
}

.nb-cell-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.pinned-toast {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nb-chart-controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.nb-mode-tabs {
  display: flex;
  gap: 0.35rem;
}

.nb-spec-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.nb-spec {
  width: 100%;
  min-height: 9rem;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
}

.nb-chart {
  width: 100%;
  height: 320px;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}

.nb-chart:empty {
  height: 0;
  min-height: 0;
  margin-top: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
}

/* ── Explore tab (Superset-style: config left, viz right) ─────── */
.explore {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explore-header .meta {
  margin: 0;
}

.explore-chart {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explore-chart-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.explore-chart-label {
  font-weight: 600;
  color: var(--muted);
  margin-right: auto;
}

.explore-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.explore-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.35rem;
  border-right: 1px solid var(--border);
}

.explore-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.explore-sidebar-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.explore-sidebar-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.explore-source {
  gap: 0.65rem;
}

.explore-field,
.explore-sql-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.explore-field > span,
.explore-sql-field > span:first-child {
  font-weight: 600;
}

.explore-field select,
.explore-field input {
  width: 100%;
  font-size: 0.85rem;
}

.explore-sql-field {
  width: 100%;
}

.explore-viz {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  min-width: 0;
}

.explore-sql-panel {
  flex-shrink: 0;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.explore-sql {
  width: 100%;
  min-height: 7.5rem;
  max-height: 14rem;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.explore-sql-hint {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.explore-panels-section {
  gap: 0.5rem;
}

.explore-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

.explore-panel {
  padding: 0.25rem 0 0;
}

.explore-filter-panel,
.explore-format-rules {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.explore-filter-header,
.explore-format-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.explore-filter-row,
.explore-rule-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.55rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.explore-filter-row select,
.explore-filter-row input,
.explore-rule-row select,
.explore-rule-row input {
  width: 100%;
  font-size: 0.85rem;
}

.explore-filter-where summary,
.explore-where-pre {
  font-size: 0.8rem;
}

.explore-where-pre {
  margin: 0.35rem 0 0;
  padding: 0.5rem;
  background: var(--surface);
  border-radius: 6px;
  overflow-x: auto;
  font-family: "IBM Plex Mono", monospace;
}

.explore-builder-section {
  gap: 0.65rem;
}

.explore-sidebar .chart-builder {
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.explore-sidebar .cb-field {
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.explore-sidebar .cb-field select,
.explore-sidebar .cb-field input {
  width: 100%;
}

.explore-sidebar .cb-type {
  max-width: none;
}

.explore-sidebar .cb-title input {
  min-width: 0;
  width: 100%;
}

.explore-spec-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.explore-spec-text {
  min-height: 8rem;
}

.explore-spec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.explore-chart-area {
  flex: 1;
  min-height: 360px;
  width: 100%;
  padding: 0.75rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}

.explore-chart-area:empty {
  min-height: 360px;
}

@media (max-width: 960px) {
  .explore-layout {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .explore-sidebar {
    max-height: none;
    border-right: none;
    overflow: visible;
  }

  .explore-viz {
    min-height: 420px;
  }
}

.add-cell-btn {
  align-self: flex-start;
}

/* ── Chart builder form ─────────────────────────────────────── */
.chart-builder {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.9rem;
  align-items: flex-end;
}

.cb-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.cb-field > span {
  font-weight: 600;
}

.cb-field select,
.cb-field input {
  font-size: 0.85rem;
}

.cb-field {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
}

.cb-type {
  max-width: 9rem;
}

.cb-title input {
  min-width: 12rem;
}

/* ── Notebook pin picker ────────────────────────────────────── */
.nb-pin-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.nb-pin-picker select {
  min-width: 10rem;
}

/* ── Dashboard ──────────────────────────────────────────────── */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.dash-select {
  min-width: 12rem;
  font-size: 0.9rem;
}

.dash-rename-input {
  min-width: 10rem;
  font-size: 0.9rem;
}

.dash-tile-count {
  margin-left: auto;
}

.dashboard-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.dashboard-empty p {
  margin: 0.25rem 0;
}

.dashboard-canvas.grid-stack {
  background: var(--surface-2);
  min-height: 480px;
  border-radius: var(--radius);
}

.grid-stack-item-content {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.dash-tile {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.dash-tile-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  flex-shrink: 0;
}

.dash-tile-header:active {
  cursor: grabbing;
}

.dash-tile-title {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-tile-actions {
  display: flex;
  gap: 0.25rem;
}

.dash-tile-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1;
}

.dash-tile-btn:hover {
  background: var(--surface-1);
}

.dash-tile-chart {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0.5rem;
  background: #ffffff;
}

/* ----- Pivot tab ----- */
.pivot {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pivot-builder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pivot-intro.meta {
  margin: 0;
}

.pivot-axis {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pivot-axis-label {
  font-weight: 600;
  color: var(--muted);
  width: 5rem;
  flex-shrink: 0;
}

.pivot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pivot-dropzone {
  flex: 1;
  min-width: 12rem;
  min-height: 2.4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 40%, transparent);
  transition: border-color 0.12s ease, background 0.12s ease;
}

.pivot-dropzone.drag-over {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.pivot-palette {
  background: var(--bg);
}

.pivot-field {
  cursor: grab;
  user-select: none;
}

.pivot-field:active {
  cursor: grabbing;
}

.pivot-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.2rem 0.15rem 0.5rem;
  font-size: 0.85rem;
}

.pivot-chip-empty {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.pivot-chip-x {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.2rem;
  font-size: 0.75rem;
  line-height: 1;
}

.pivot-chip-x:hover {
  color: var(--danger);
}

.pivot-add {
  min-width: 9rem;
}

.pivot-measures {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pivot-measure {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.3rem;
}

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

.pivot-sql {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.pivot-result th.pivot-rowhead-col,
.pivot-result td.pivot-rowhead {
  position: sticky;
  left: 0;
  background: var(--surface-2);
  font-weight: 600;
  z-index: 1;
}

/* Pivot table pinned as a dashboard tile: fill and scroll within the tile. */
.dash-tile-chart .table-wrap {
  height: 100%;
  max-height: 100%;
  overflow: auto;
}
