:root {
  --ink: #1d2520;
  --muted: #77817a;
  --line: #e3e8e2;
  --paper: #f8faf7;
  --surface: #ffffff;
  --mint: #d9f0df;
  --mint-strong: #8ac9a0;
  --forest: #285a42;
  --coral: #e9785b;
  --shadow: 0 18px 55px rgba(45, 72, 52, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: #edf3ed;
  font-family: "DM Sans", sans-serif;
  min-height: 100vh;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  background: linear-gradient(130deg, #f4f8f3 0%, #fbfcfa 48%, #edf4ef 100%);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding: 28px 20px 20px;
  background: rgba(239, 246, 239, 0.84);
  border-right: 1px solid var(--line);
}

.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #173d2a;
  background: var(--mint-strong);
  border-radius: 12px 12px 12px 4px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  box-shadow: 5px 5px 0 #c0e2c9;
}
.brand-name, h1, h2 { font-family: "Space Grotesk", sans-serif; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: 0; }
.brand-caption { color: var(--muted); font-size: 11px; margin-top: 2px; }

.new-chat-button, .settings-button {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  transition: transform 160ms ease, background 160ms ease;
}
.new-chat-button {
  justify-content: center;
  padding: 13px 15px;
  color: #fff;
  background: var(--forest);
  box-shadow: 0 7px 16px rgba(40, 90, 66, 0.2);
}
.new-chat-button:hover { transform: translateY(-1px); background: #1f4a35; }
.button-icon { font-size: 20px; font-weight: 400; line-height: 12px; }

.sidebar-section { flex: 1; min-height: 0; }
.section-label, .eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.section-label { padding: 0 9px 12px; }
.history-list { display: grid; gap: 3px; }
.history-empty { color: #9da8a0; font-size: 12px; line-height: 1.5; padding: 4px 9px; }
.history-item {
  overflow: hidden;
  padding: 10px 9px;
  color: #526057;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item:hover { background: #e5efe6; color: var(--forest); }

.sidebar-footer { display: grid; gap: 12px; }
.connection-chip { display: flex; align-items: center; gap: 8px; color: #637067; font-size: 11px; }
.connection-dot, .live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--mint-strong); }
.connection-dot.offline { background: var(--coral); }
.settings-button { justify-content: flex-start; padding: 9px; color: #68756c; background: transparent; font-size: 12px; }
.settings-button:hover { background: #e5efe6; color: var(--forest); }

.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px clamp(24px, 5vw, 72px) 22px;
  border-bottom: 1px solid rgba(227, 232, 226, 0.8);
}
.topbar h1 { margin: 7px 0 0; font-size: clamp(20px, 2.5vw, 28px); font-weight: 600; }
.topbar-badge { display: flex; align-items: center; gap: 8px; color: var(--forest); font-size: 12px; font-weight: 600; }

.conversation { flex: 1; width: min(920px, 100%); margin: 0 auto; padding: 38px clamp(20px, 5vw, 72px) 24px; }
.welcome-state { animation: rise 500ms ease both; }
.welcome-orbit {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 25px;
  color: #1c4d35;
  background: radial-gradient(circle at 30% 25%, #fff 0 8%, transparent 9%), #c9e8d1;
  border: 1px solid #b1dbbc;
  border-radius: 18px 18px 18px 5px;
  box-shadow: 12px 12px 0 #e2f1e4;
  font-family: "Space Grotesk", sans-serif;
  font-size: 16px;
  font-weight: 700;
}
.welcome-kicker { margin: 0 0 10px; color: var(--coral); font-size: 13px; font-weight: 700; }
.welcome-state h2 { max-width: 550px; margin: 0; font-size: clamp(32px, 5vw, 58px); line-height: 1.05; letter-spacing: 0; }
.welcome-copy { max-width: 500px; margin: 18px 0 32px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.suggestion-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.suggestion-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 128px;
  padding: 16px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.74);
  text-align: left;
  line-height: 1.4;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.suggestion-card:hover { border-color: var(--mint-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.suggestion-tag { color: var(--forest); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.suggestion-arrow { position: absolute; right: 15px; bottom: 13px; color: var(--coral); font-size: 18px; }

.message-list { display: grid; gap: 27px; }
.message { display: flex; min-width: 0; gap: 12px; animation: rise 280ms ease both; }
.message-avatar { flex: 0 0 30px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; font-size: 11px; font-weight: 700; }
.message.user .message-avatar { color: #7f3c2d; background: #f7d2c7; }
.message.assistant .message-avatar { color: #1c4d35; background: var(--mint); }
.message-content { min-width: 0; padding-top: 4px; line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-label { margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.message-body { color: #35423a; font-size: 15px; }
.sql-panel { margin-top: 10px; white-space: normal; font-size: 13px; }
.sql-panel summary { cursor: pointer; color: var(--forest); font-weight: 700; }
.sql-tree { margin-top: 10px; white-space: normal; font-size: 13px; }
.sql-tree > summary { cursor: pointer; color: var(--forest); font-weight: 700; }
.sql-tree-branches { position: relative; margin: 6px 0 0 7px; padding-left: 18px; border-left: 1px solid var(--line); }
.sql-tree-branches > .sql-panel { position: relative; margin-top: 8px; }
.sql-tree-branches > .sql-panel:first-child { margin-top: 0; }
.sql-tree-branches > .sql-panel::before { content: ""; position: absolute; left: -18px; top: 10px; width: 14px; border-top: 1px solid var(--line); }
.sql-editor { display: block; width: 100%; margin: 8px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #f5f9f5; color: var(--ink); font-family: Consolas, monospace; font-size: 12.5px; resize: vertical; }
.sql-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sql-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 14px; border: 1px solid var(--forest); border-radius: 8px; background: var(--forest); color: #fff; font-size: 12.5px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: background 140ms ease, border-color 140ms ease; }
.sql-btn.secondary { border-color: var(--line); background: var(--surface); color: var(--forest); }
.sql-btn.secondary:hover:not(:disabled) { border-color: var(--mint-strong); background: #f5f9f5; }
.sql-btn:not(.secondary):hover:not(:disabled) { background: #1f4a35; }
.sql-btn:disabled { opacity: 0.6; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; transition: color 140ms ease, border-color 140ms ease, background 140ms ease; }
.icon-btn:hover { border-color: var(--mint-strong); background: #f5f9f5; color: var(--forest); }
.icon-btn:focus-visible { outline: 2px solid var(--mint-strong); outline-offset: 1px; }
.sql-clear { width: 26px; height: 26px; margin-left: auto; border-radius: 50%; }
.sql-clear[hidden] { display: none; }
.result-toolbar { display: flex; justify-content: flex-end; margin-top: 10px; }
.result-toolbar + .result-grid { margin-top: 6px; }
.result-note { margin-top: -6px; color: var(--muted); font-size: 12px; }
.message-actions { display: flex; gap: 6px; margin-top: 10px; white-space: normal; }
.message-actions .icon-btn { width: 28px; height: 28px; border-color: transparent; background: transparent; }
.message-actions .icon-btn:hover { border-color: var(--line); background: #f5f9f5; }
.sql-editor[readonly] { background: #f5f9f5; }
.sql-editor:not([readonly]) { background: #fff; border-color: var(--mint-strong); outline: none; }
.sql-output { margin-top: 8px; overflow-x: auto; color: var(--muted); }
.sql-output:empty { display: none; }
.sql-plan { max-height: 320px; overflow: auto; white-space: pre; font-size: 12px; }
.message.user .message-body { color: var(--ink); }
.message-body strong { color: #234e38; font-weight: 700; }
.message-body em { color: #526057; }
.message-body code { padding: 2px 5px; color: #315640; border-radius: 4px; background: #edf5ee; font-family: Consolas, monospace; font-size: 0.92em; }
.markdown-table { display: block; width: 100%; max-width: 100%; margin: 12px 0; overflow-x: auto; border-collapse: collapse; font-size: 13px; }
.markdown-table th, .markdown-table td { padding: 9px 11px; border: 1px solid var(--line); text-align: left; white-space: nowrap; overflow-wrap: normal; }
.result-grid { max-width: 100%; max-height: 60vh; margin: 12px 0; overflow: auto; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-x pan-y; }
.result-grid .markdown-table { display: table; width: max-content; min-width: 100%; margin: 0; overflow: visible; }
.result-grid .markdown-table th { position: sticky; top: 0; z-index: 1; }
.markdown-table th { color: var(--forest); background: #f5f9f5; font-weight: 700; }
.markdown-heading { margin: 16px 0 7px; color: var(--ink); font-family: "Space Grotesk", sans-serif; font-size: 1.08em; }
.markdown-list { margin: 8px 0; padding-left: 22px; }
.markdown-list li { margin: 4px 0; }
.markdown-code { overflow-x: auto; margin: 12px 0; padding: 13px 15px; color: #e9f5eb; border-radius: 8px; background: #21372b; font: 12px/1.55 Consolas, monospace; white-space: pre-wrap; }
.markdown-mermaid { overflow-x: auto; margin: 16px 0; padding: 20px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 18px; background: radial-gradient(ellipse at 12% 0%, rgba(56, 214, 196, 0.1), transparent 42%), radial-gradient(ellipse at 100% 100%, rgba(124, 140, 255, 0.11), transparent 45%), #0f1722; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 30px rgba(0, 0, 0, 0.22); text-align: center; }
.markdown-mermaid svg { max-width: 100%; height: auto; overflow: visible; }
.markdown-mermaid svg .node rect { rx: 12px; ry: 12px; }
.markdown-mermaid svg .cluster rect { rx: 14px; ry: 14px; }
.markdown-mermaid svg .edgePath .path, .markdown-mermaid svg .flowchart-link { stroke-linecap: round; stroke-linejoin: round; }
.plan-view { margin-top: 6px; white-space: normal; }
.plan-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.plan-tab { padding: 6px 14px; color: var(--muted); font-size: 12px; font-weight: 600; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); transition: all 200ms var(--ease); }
.plan-tab:hover { color: var(--mint-strong); border-color: rgba(56, 214, 196, 0.5); }
.plan-tab.active { color: #fff; border-color: transparent; background: linear-gradient(135deg, #1fa89a, #4d63e8); }
.plan-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-left: auto; color: var(--muted); font-size: 11px; }
.plan-legend-item::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 50%; background: var(--dot); vertical-align: -1px; }
.plan-stmt { margin-bottom: 14px; padding: 14px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 18px; background: radial-gradient(ellipse at 12% 0%, rgba(56, 214, 196, 0.1), transparent 42%), radial-gradient(ellipse at 100% 100%, rgba(124, 140, 255, 0.11), transparent 45%), #0f1722; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 30px rgba(0, 0, 0, 0.22); }
.plan-stmt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.plan-stmt-title { color: #e9f4f4; font-family: "Space Grotesk", sans-serif; font-size: 15px; font-weight: 600; }
.plan-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-chip { padding: 3px 10px; color: #c9d4e1; font-size: 11px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.04); }
.plan-sql { margin-top: 8px; padding: 8px 12px; color: #8be9dd; font: 11.5px/1.5 Consolas, monospace; border-radius: 10px; background: rgba(0, 0, 0, 0.28); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-scroll { margin-top: 12px; overflow: auto; border-radius: 14px; background: rgba(0, 0, 0, 0.18); overscroll-behavior: contain; }
.plan-canvas { position: relative; }
.plan-edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.plan-edges .plan-edge { fill: none; stroke: #7c8cff; stroke-opacity: 0.45; stroke-linecap: round; pointer-events: stroke; transition: stroke-opacity 200ms; }
.plan-edges .plan-edge:hover { stroke-opacity: 0.85; stroke: #38d6c4; }
.plan-edge-label { fill: #a9b6c7; font-size: 10px; text-anchor: middle; paint-order: stroke; stroke: #0f1722; stroke-width: 3px; stroke-linejoin: round; }
.plan-node { position: absolute; display: flex; flex-direction: column; justify-content: space-between; gap: 3px; padding: 10px 12px 9px; color: #e9f4f4; text-align: left; border: 1px solid var(--line); border-left: 4px solid var(--kind); border-radius: 14px; background: linear-gradient(160deg, #1a2a3d, #131c29); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); transition: transform 200ms var(--ease), box-shadow 200ms var(--ease), border-color 200ms var(--ease); }
.plan-node:hover { transform: translateY(-2px); border-color: var(--kind); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5); }
.plan-node.selected { border-color: var(--kind); box-shadow: 0 0 0 2px rgba(56, 214, 196, 0.35), 0 10px 26px rgba(0, 0, 0, 0.5); }
.plan-node-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.plan-badge { flex: 0 0 auto; padding: 2px 7px; color: #0b0f14; font-size: 9.5px; font-weight: 800; letter-spacing: 0.06em; border-radius: 999px; }
.plan-title { overflow: hidden; font-size: 12.5px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.plan-object { overflow: hidden; color: #8be9dd; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.plan-node-meta { display: flex; justify-content: space-between; color: #a9b6c7; font-size: 11px; }
.plan-node-meta b { color: #e9f4f4; }
.plan-bar { height: 6px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, 0.08); }
.plan-bar span { display: block; height: 100%; border-radius: 999px; }
.plan-details { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(18, 25, 35, 0.8); animation: rise 220ms var(--ease) both; }
.plan-details[hidden] { display: none; }
.plan-details-title { margin-bottom: 8px; color: var(--mint-strong); font-family: "Space Grotesk", sans-serif; font-size: 14px; font-weight: 600; }
.plan-details-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 12px; }
.plan-details-list dt { color: var(--muted); }
.plan-details-list dd { margin: 0; color: #dbe8f3; overflow-wrap: anywhere; }
.plan-missing { margin-top: 10px; padding: 9px 12px; color: #ffd9a8; font-size: 12px; border: 1px solid rgba(254, 150, 102, 0.4); border-radius: 12px; background: rgba(254, 150, 102, 0.08); }
.chart-source { display: none; }
.message.assistant .message-content { flex: 1 1 0; }
.chart-card .chart-report { position: absolute; top: 10px; right: 10px; z-index: 2; }
.chart-card { position: relative; margin: 16px 0; padding: 14px 12px 10px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 18px; background: radial-gradient(ellipse at 12% 0%, rgba(56, 214, 196, 0.1), transparent 42%), radial-gradient(ellipse at 100% 100%, rgba(124, 140, 255, 0.11), transparent 45%), #0f1722; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 30px rgba(0, 0, 0, 0.22); white-space: normal; animation: rise 360ms var(--ease) both; }
.chart-canvas { width: 100%; min-height: 280px; }
.typing-dots { display: flex; gap: 4px; padding: 10px 0; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--mint-strong); animation: pulse 900ms infinite; }
.typing-dots span:nth-child(2) { animation-delay: 150ms; }
.typing-dots span:nth-child(3) { animation-delay: 300ms; }

.composer { width: min(920px, 100%); margin: 0 auto; padding: 0 clamp(20px, 5vw, 72px) 25px; }
.composer-inner { display: flex; align-items: flex-end; gap: 10px; padding: 9px 9px 9px 17px; border: 1px solid #cbd8cd; border-radius: 13px; background: var(--surface); box-shadow: 0 8px 25px rgba(50, 79, 57, 0.08); }
textarea { width: 100%; max-height: 130px; resize: none; padding: 8px 0; color: var(--ink); border: 0; outline: 0; background: transparent; line-height: 1.5; }
textarea::placeholder { color: #9ba69e; }
.send-button { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; color: #fff; border: 0; border-radius: 9px; background: var(--forest); font-size: 21px; transition: background 160ms ease, transform 160ms ease; }
.send-button:hover { background: #1f4a35; transform: translateY(-1px); }
.send-button:disabled { cursor: wait; opacity: 0.45; }
.composer-meta { display: flex; justify-content: space-between; gap: 16px; padding: 9px 3px 0; color: #9aa59c; font-size: 10px; }

.settings-dialog { width: min(440px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 14px; box-shadow: 0 30px 90px rgba(25, 44, 31, 0.25); }
.settings-dialog::backdrop { background: rgba(25, 42, 30, 0.35); backdrop-filter: blur(3px); }
.settings-card { display: grid; gap: 9px; padding: 26px; background: var(--surface); }
.dialog-heading { display: flex; justify-content: space-between; margin-bottom: 9px; }
.dialog-heading h2 { margin: 8px 0 0; font-size: 24px; }
.close-button { align-self: start; border: 0; background: transparent; color: var(--muted); font-size: 24px; }
.settings-card label { margin-top: 7px; color: #536057; font-size: 12px; font-weight: 700; }
.settings-card input { padding: 11px 12px; border: 1px solid #ccd8ce; border-radius: 8px; outline: 0; }
.settings-card input:focus { border-color: var(--mint-strong); box-shadow: 0 0 0 3px #e4f3e7; }
.dialog-note { margin: 5px 0 8px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 7px; }
.primary-button, .secondary-button { padding: 10px 14px; border-radius: 8px; font-size: 12px; font-weight: 700; }
.primary-button { color: #fff; border: 1px solid var(--forest); background: var(--forest); }
.secondary-button { color: #526057; border: 1px solid var(--line); background: #f7faf7; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 0.35; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 780px) {
  .app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
  .sidebar { display: flex; flex-direction: row; align-items: center; gap: 14px; padding: 14px 18px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand-caption, .sidebar-section, .connection-chip { display: none; }
  .brand-lockup { flex: 1; }
  .new-chat-button { padding: 10px 12px; font-size: 12px; }
  .sidebar-footer { display: flex; align-items: center; }
  .sidebar-footer .settings-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; font-size: 0; }
  .sidebar-footer .settings-button span { font-size: 18px; }
  .chat-panel { flex: 1; min-height: 0; }
  .topbar { flex: 0 0 auto; padding: 22px 20px 17px; }
  .conversation { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .composer { flex: 0 0 auto; }
  .topbar-badge { font-size: 0; }
  .topbar-badge .live-dot { width: 8px; height: 8px; }
  .conversation { padding-top: 28px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .suggestion-card { min-height: 86px; }
  .composer-meta { display: none; }
  .sql-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .sql-btn { min-height: 38px; padding: 0 8px; }
  .sql-clear { grid-column: 3; justify-self: end; width: 32px; height: 32px; margin-left: 0; }
  .icon-btn { width: 36px; height: 36px; }
  .message-actions .icon-btn { width: 34px; height: 34px; }
}

@media (max-width: 360px) {
  .new-chat-button { justify-content: center; width: 38px; height: 38px; padding: 0; font-size: 0; }
  .button-icon { font-size: 20px; }
}

/* ===== BizQL dark theme ===== */
:root {
  color-scheme: dark;
  --ink: #e6edf5;
  --muted: #8b98a9;
  --line: #243041;
  --paper: #0b0f14;
  --surface: #121923;
  --mint: #12303a;
  --mint-strong: #38d6c4;
  --forest: #1fa89a;
  --coral: #ff8a6b;
  --raised: #182231;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
html { background: #0b0f14; -webkit-text-size-adjust: 100%; }
body { background: #0b0f14; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(56, 214, 196, 0.3); }
.app-shell { background: radial-gradient(900px 500px at 85% -10%, rgba(124, 140, 255, 0.12), transparent 60%), radial-gradient(700px 500px at 0% 100%, rgba(56, 214, 196, 0.08), transparent 60%), #0b0f14; }
.sidebar { background: rgba(14, 20, 29, 0.72); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-color: var(--line); }
.brand-mark { width: 40px; height: 40px; padding: 8px; color: #06201d; background: linear-gradient(135deg, #38d6c4, #7c8cff); border-radius: 13px; box-shadow: 0 6px 22px rgba(56, 214, 196, 0.35); }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { background: linear-gradient(90deg, #e6edf5, #9fb0ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.new-chat-button, .send-button, .primary-button, .sql-btn:not(.secondary) { background: linear-gradient(135deg, #1fa89a, #4d63e8); color: #fff; border-color: transparent; box-shadow: 0 8px 22px rgba(56, 214, 196, 0.18); }
.new-chat-button:hover, .send-button:hover, .sql-btn:not(.secondary):hover:not(:disabled) { background: linear-gradient(135deg, #25bfae, #5b70f5); box-shadow: 0 10px 28px rgba(77, 99, 232, 0.35); }
.new-chat-button, .settings-button, .send-button, .suggestion-card, .history-item, .icon-btn, .sql-btn { transition: transform 220ms var(--ease), background 220ms var(--ease), border-color 220ms var(--ease), box-shadow 220ms var(--ease), color 220ms var(--ease); }
.new-chat-button:active, .send-button:active, .suggestion-card:active, .sql-btn:active { transform: scale(0.97); }
.history-item { color: #a9b6c7; }
.history-item:hover, .settings-button:hover { background: var(--raised); color: var(--mint-strong); }
.history-empty, .settings-button, .connection-chip { color: var(--muted); }
.connection-dot, .live-dot { background: var(--mint-strong); box-shadow: 0 0 10px var(--mint-strong); animation: glow 2.4s ease-in-out infinite; }
.connection-dot.offline { background: var(--coral); box-shadow: 0 0 10px var(--coral); }
.topbar { border-color: var(--line); background: rgba(11, 15, 20, 0.6); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.topbar-badge { color: var(--mint-strong); }
.welcome-orbit { width: 64px; height: 64px; padding: 15px; color: var(--mint-strong); background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.14), transparent 55%), var(--surface); border: 1px solid rgba(56, 214, 196, 0.35); border-radius: 20px; box-shadow: 0 0 0 6px rgba(56, 214, 196, 0.06), 0 12px 40px rgba(56, 214, 196, 0.2); animation: float 5s ease-in-out infinite; }
.welcome-orbit span, .welcome-orbit svg { display: block; width: 100%; height: 100%; }
.welcome-kicker { color: var(--coral); }
.welcome-state h2 { background: linear-gradient(120deg, #fff 30%, #9fb0ff 70%, #38d6c4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.suggestion-card { background: rgba(18, 25, 35, 0.7); border-color: var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.suggestion-card:hover { border-color: rgba(56, 214, 196, 0.55); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(56, 214, 196, 0.15); background: var(--raised); }
.suggestion-tag { color: var(--mint-strong); }
.message-avatar { overflow: hidden; }
.message.user .message-avatar { color: #ffd3c6; background: #3a2420; }
.message.assistant .message-avatar { padding: 5px; color: var(--mint-strong); background: var(--mint); box-shadow: 0 0 14px rgba(56, 214, 196, 0.25); }
.message-body { color: #c9d4e1; }
.message.user .message-body { color: var(--ink); }
.message-body strong { color: #fff; }
.message-body em { color: #a9b6c7; }
.message-body code { color: #8be9dd; background: #17212e; }
.sql-panel summary, .sql-tree > summary { color: var(--mint-strong); }
.sql-editor, .sql-editor[readonly] { background: #0e1520; color: var(--ink); border-color: var(--line); }
.sql-editor:not([readonly]) { background: #101a27; border-color: var(--mint-strong); box-shadow: 0 0 0 3px rgba(56, 214, 196, 0.12); }
.sql-btn.secondary { background: var(--surface); color: var(--mint-strong); border-color: var(--line); box-shadow: none; }
.sql-btn.secondary:hover:not(:disabled) { background: var(--raised); border-color: var(--mint-strong); }
.icon-btn { background: var(--surface); border-color: var(--line); color: var(--muted); }
.icon-btn:hover, .message-actions .icon-btn:hover { background: var(--raised); border-color: var(--mint-strong); color: var(--mint-strong); }
.message-actions .icon-btn { background: transparent; border-color: transparent; }
.markdown-table th { color: var(--mint-strong); background: #0f1722; }
.markdown-table td { color: #c9d4e1; }
.markdown-table tbody tr { transition: background 160ms ease; }
.markdown-table tbody tr:hover { background: rgba(56, 214, 196, 0.06); }
.result-grid { border-color: var(--line); background: rgba(14, 20, 29, 0.6); }
.markdown-code { background: #0a1018; color: #d7e4f0; border: 1px solid var(--line); }
.markdown-mermaid { border-color: rgba(56, 214, 196, 0.28); }
.composer { padding-bottom: calc(25px + env(safe-area-inset-bottom)); }
.composer-inner { background: rgba(18, 25, 35, 0.9); border-color: var(--line); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); transition: border-color 220ms var(--ease), box-shadow 220ms var(--ease); }
.composer-inner:focus-within { border-color: rgba(56, 214, 196, 0.6); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(56, 214, 196, 0.12); }
textarea::placeholder, .settings-card input::placeholder { color: #5f6d7f; }
.composer-meta { color: #5f6d7f; }
.settings-dialog { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7); }
.settings-dialog[open] { animation: rise 260ms var(--ease) both; }
.settings-dialog::backdrop { background: rgba(4, 7, 11, 0.7); backdrop-filter: blur(6px); }
.settings-card { background: var(--surface); }
.settings-card label { color: #a9b6c7; }
.settings-card input { color: var(--ink); background: #0e1520; border-color: var(--line); transition: border-color 200ms ease, box-shadow 200ms ease; }
.settings-card input:focus { border-color: var(--mint-strong); box-shadow: 0 0 0 3px rgba(56, 214, 196, 0.15); }
.dialog-note code { color: #8be9dd; }
.secondary-button { color: #a9b6c7; background: var(--raised); border-color: var(--line); }
.close-button:hover { color: var(--ink); }
* { scrollbar-width: thin; scrollbar-color: #2a384c transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a384c; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--mint-strong); outline-offset: 2px; }

@keyframes glow { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

@media (max-width: 780px) {
  .sidebar { padding-top: calc(14px + env(safe-area-inset-top)); }
  textarea, .settings-card input { font-size: 16px; }
  .composer-inner { border-radius: 16px; }
}

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

/* ===== History tree & top-right controls ===== */
.history-toggle { display: none; }
.sidebar-section { overflow-y: auto; }
.history-list { gap: 2px; }
.history-node { border-radius: 9px; }
.history-node > summary { display: flex; align-items: center; gap: 8px; padding: 9px; list-style: none; color: #c9d4e1; font-size: 13px; font-weight: 600; border-radius: 9px; cursor: pointer; user-select: none; transition: background 220ms var(--ease), color 220ms var(--ease); }
.history-node > summary::-webkit-details-marker { display: none; }
.history-node > summary:hover { background: var(--raised); }
.history-node.active > summary { color: var(--mint-strong); background: rgba(56, 214, 196, 0.08); }
.tree-caret { flex: 0 0 8px; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 220ms var(--ease); opacity: 0.8; }
.history-node[open] > summary .tree-caret { transform: rotate(45deg); }
.history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-branches { position: relative; margin: 2px 0 6px 12px; padding-left: 12px; border-left: 1px solid var(--line); display: grid; gap: 1px; animation: rise 240ms var(--ease) both; }
.history-branches .history-item { position: relative; width: 100%; padding: 7px 8px; font-size: 12px; }
.history-branches .history-item::before { content: ""; position: absolute; left: -12px; top: 50%; width: 9px; border-top: 1px solid var(--line); }

.topbar-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; padding-left: 16px; }
.topbar-actions .connection-chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(18, 25, 35, 0.7); font-size: 12px; white-space: nowrap; }
.topbar-actions .settings-button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(18, 25, 35, 0.7); font-size: 12px; white-space: nowrap; }
.topbar-actions .settings-button:hover { border-color: rgba(56, 214, 196, 0.55); }

@media (max-width: 780px) {
  .sidebar { position: relative; z-index: 20; }
  .brand-lockup { min-width: 0; }
  .brand-caption { display: block; font-size: 10px; white-space: nowrap; }
  .history-toggle { display: grid; place-items: center; width: 38px; height: 38px; color: var(--muted); font-size: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); transition: color 220ms var(--ease), border-color 220ms var(--ease); }
  .sidebar-open .history-toggle { color: var(--mint-strong); border-color: var(--mint-strong); }
  .sidebar-section { display: none; position: absolute; top: 100%; left: 0; right: 0; max-height: 60vh; padding: 14px 14px 18px; background: rgba(14, 20, 29, 0.97); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); box-shadow: 0 24px 40px rgba(0, 0, 0, 0.55); }
  .sidebar-open .sidebar-section { display: block; animation: rise 220ms var(--ease) both; }
  .button-text { display: none; }
  .new-chat-button { justify-content: center; width: 38px; height: 38px; padding: 0; }
  .topbar { flex-wrap: nowrap; align-items: center; gap: 8px; padding: 16px 16px 14px; }
  .topbar h1 { font-size: 17px; line-height: 1.25; }
  .topbar-actions { gap: 8px; padding-left: 0; flex: 0 0 auto; }
  .topbar-actions .connection-chip { display: flex; padding: 6px 10px; font-size: 11px; }
  .topbar-actions .settings-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; }
  .settings-text { display: none; }
}

@media (max-width: 420px) {
  .eyebrow { display: none; }
  .topbar-actions .connection-chip #connectionLabel { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ===== Object Explorer & sidebar layout ===== */
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; gap: 18px; overflow: hidden; }
.sidebar-drawer { display: flex; flex: 1; flex-direction: column; gap: 14px; min-height: 0; }
.explorer { display: flex; flex: 1 1 56%; flex-direction: column; gap: 8px; min-height: 0; }
.explorer-head { display: flex; align-items: center; justify-content: space-between; }
.explorer-head .section-label { padding: 0 9px; }
.explorer-refresh { width: 26px; height: 26px; color: var(--muted); font-size: 15px; line-height: 1; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.explorer-refresh:hover:not(:disabled) { color: var(--mint-strong); background: var(--raised); }
.explorer-refresh:disabled { opacity: 0.5; cursor: default; }
#explorerEmbeddings { margin-left: auto; }
.embed-status { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.embed-filter { margin-bottom: 10px; font-size: 14px; }
.embed-list { display: grid; gap: 8px; }
.embed-card { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(18, 25, 35, 0.4); }
.embed-card summary { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 28px; }
.embed-name { flex: 1; min-width: 0; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.embed-badge { padding: 1px 8px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; border-radius: 999px; background: rgba(255, 255, 255, 0.06); color: var(--muted); }
.embed-badge.ok { color: #5fd6a4; }
.embed-badge.stale, .embed-badge.inactive { color: #e7b955; }
.embed-badge.invalid { color: #f08080; }
.embed-meta { margin-top: 6px; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.embed-preview { display: block; margin: 6px 0; max-height: 220px; overflow: auto; font-size: 11.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 780px) { .embed-filter { font-size: 16px; } .explorer-refresh { width: 36px; height: 36px; } }
.explorer-filter { width: 100%; padding: 8px 10px; color: var(--ink); font: inherit; font-size: 12px; border: 1px solid var(--line); border-radius: 9px; background: rgba(18, 25, 35, 0.6); outline: none; }
.explorer-filter:focus { border-color: var(--mint-strong); }
.explorer-tree { flex: 1; min-height: 0; padding-right: 2px; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 2px; }
.explorer-count { margin-left: auto; padding: 1px 7px; color: var(--muted); font-size: 10px; font-weight: 600; border-radius: 999px; background: rgba(255, 255, 255, 0.05); }
.explorer-items { margin-right: 0; }
.explorer-item { position: relative; display: flex; align-items: center; border-radius: 8px; }
.explorer-item::before { content: ""; position: absolute; left: -12px; top: 50%; width: 9px; border-top: 1px solid var(--line); }
.explorer-item:hover { background: var(--raised); }
.explorer-item .explorer-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 7px 8px; font-size: 12px; background: transparent; cursor: pointer; }
.explorer-item .explorer-name::before { display: none; }
.explorer-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explorer-badge { flex: 0 0 18px; display: grid; place-items: center; width: 18px; height: 18px; color: #0b0f14; font-size: 10px; font-weight: 700; border-radius: 5px; background: var(--mint-strong); }
.explorer-badge.kind-v { background: #8c9cff; }
.explorer-badge.kind-p { background: #ffb86b; }
.explorer-badge.kind-fn { background: #ff8a6b; }
.explorer-more { flex: 0 0 28px; width: 28px; height: 28px; color: var(--muted); font-size: 16px; border: 0; border-radius: 7px; background: transparent; opacity: 0; cursor: pointer; }
.explorer-item:hover .explorer-more, .explorer-more:focus-visible { opacity: 1; }
.explorer-more:hover { color: var(--mint-strong); }
.sidebar-drawer .new-chat-button { flex: 0 0 auto; }
.sidebar-drawer .sidebar-section { flex: 1 1 34%; min-height: 80px; }
.sidebar-backdrop { display: none; }

.context-menu { position: fixed; z-index: 1000; min-width: 190px; padding: 5px; border: 1px solid var(--line); border-radius: 11px; background: var(--raised); box-shadow: 0 18px 45px rgba(0, 0, 0, 0.5); animation: rise 140ms var(--ease) both; }
.context-menu[hidden] { display: none; }
.context-item { display: block; width: 100%; padding: 9px 12px; color: #d4deea; font: inherit; font-size: 13px; text-align: left; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.context-item:hover, .context-item:focus-visible { color: var(--mint-strong); background: rgba(56, 214, 196, 0.1); outline: none; }

.object-dialog { width: min(920px, calc(100% - 32px)); }
.object-dialog .settings-card { max-height: calc(100dvh - 48px); grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; }
.object-toolbar { display: flex; align-items: center; gap: 10px; min-height: 0; }
.object-toolbar:empty { display: none; }
.object-toolbar .result-note { margin: 0; }
.object-body { min-height: 0; overflow: auto; color: var(--muted); font-size: 13px; }
.object-body .result-grid { max-height: none; margin: 0; }
.script-view { margin: 0; padding: 14px; color: #d4deea; font: 12.5px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: rgba(0, 0, 0, 0.3); }

@media (hover: none) { .explorer-more { opacity: 1; } }

@media (max-width: 780px) {
  .sidebar { position: relative; height: auto; overflow: visible; }
  .history-toggle { margin-left: auto; }
  .sidebar-drawer { display: none; position: absolute; top: 100%; left: 0; right: 0; max-height: calc(100dvh - 72px - env(safe-area-inset-top)); padding: 14px 14px 18px; overflow-y: auto; background: rgba(14, 20, 29, 0.98); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); box-shadow: 0 24px 40px rgba(0, 0, 0, 0.55); }
  .sidebar-open .sidebar-drawer { display: flex; animation: rise 220ms var(--ease) both; }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.45); }
  .explorer { flex: 0 0 auto; }
  .explorer-tree { flex: none; max-height: 38vh; }
  .sidebar-drawer .sidebar-section { display: block; position: static; flex: 0 0 auto; max-height: none; padding: 0; background: none; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; overflow: visible; animation: none; }
  .sidebar-drawer .new-chat-button { width: 100%; height: auto; padding: 12px 15px; font-size: 14px; }
  .sidebar-drawer .button-text { display: inline; }
  .explorer-filter { font-size: 16px; }
  .context-item { padding: 12px 14px; font-size: 15px; }
  .object-dialog { width: calc(100% - 16px); }
  .object-dialog .settings-card { padding: 18px; }
}

.explorer-controls { display: grid; gap: 6px; }
.explorer-schema { width: 100%; padding: 8px 10px; color: var(--ink); font: inherit; font-size: 12px; border: 1px solid var(--line); border-radius: 9px; background: rgba(18, 25, 35, 0.6); outline: none; cursor: pointer; }
.explorer-schema:focus { border-color: var(--mint-strong); }
.explorer-schema option { color: #e6edf5; background: #121923; }
@media (max-width: 780px) { .explorer-schema { font-size: 16px; } }

/* ELK diagrams */
.diagram-source { display: none; }
.dg-card { max-width: 100%; margin: 14px 0; border: 1px solid rgba(120, 150, 190, 0.22); border-radius: 16px; background: linear-gradient(160deg, #141c28, #0e141d); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35); overflow: hidden; }
.dg-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid rgba(120, 150, 190, 0.16); }
.dg-card-title { flex: 1; min-width: 0; color: #e6edf5; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dg-chip { padding: 2px 9px; color: #38d6c4; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; border: 1px solid rgba(56, 214, 196, 0.4); border-radius: 999px; }
.dg-tools { display: flex; align-items: center; gap: 4px; }
.dg-tool { min-width: 30px; height: 28px; padding: 0 8px; color: #c8d3e0; font: inherit; font-size: 13px; border: 1px solid rgba(120, 150, 190, 0.25); border-radius: 8px; background: rgba(255, 255, 255, 0.04); cursor: pointer; }
.dg-tool:hover { color: #38d6c4; border-color: #38d6c4; }
.dg-zoom { min-width: 40px; color: #8fa0b5; font-size: 11px; text-align: center; }
.dg-viewport { position: relative; height: 380px; overflow: hidden; cursor: grab; touch-action: pan-x pan-y; user-select: none; background-image: radial-gradient(rgba(120, 150, 190, 0.16) 1px, transparent 1px); background-size: 20px 20px; }
.dg-viewport.panning { cursor: grabbing; }
.dg-stage { position: absolute; top: 0; left: 0; }
.dg-scene { position: relative; transform-origin: 0 0; }
.dg-edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.dg-edge-line { fill: none; stroke: #5c7aa6; stroke-width: 1.6; stroke-linejoin: round; transition: stroke 160ms ease, opacity 160ms ease; }
.dg-edge { color: #5c7aa6; }
.dg-edge.dashed .dg-edge-line { stroke-dasharray: 6 5; }
.dg-edge.hot .dg-edge-line { stroke: #38d6c4; stroke-width: 2.4; }
.dg-edge.hot { color: #38d6c4; }
.dg-edge path[fill] { fill: currentColor; }
.dg-edge-label { fill: #c8d3e0; font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.dg-edge-label-bg { fill: #0e141d; stroke: rgba(120, 150, 190, 0.3); }
.dg-node { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; padding: 8px 12px; color: #e6edf5; border: 1px solid color-mix(in srgb, var(--accent, #38d6c4) 55%, transparent); border-left: 4px solid var(--accent, #38d6c4); border-radius: 12px; background: linear-gradient(160deg, color-mix(in srgb, var(--accent, #38d6c4) 16%, #172130), #141c28); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); cursor: pointer; transition: opacity 160ms ease, box-shadow 160ms ease; }
.dg-node:hover, .dg-node.focus { box-shadow: 0 0 0 2px var(--accent, #38d6c4), 0 6px 20px rgba(0, 0, 0, 0.45); }
.dg-node.dim, .dg-edge.dim { opacity: 0.3; }
.dg-node-head { display: flex; align-items: center; gap: 8px; }
.dg-pill { flex: none; padding: 1px 7px; color: #0b1118; font-size: 9px; font-weight: 800; letter-spacing: 0.06em; border-radius: 999px; background: var(--accent, #38d6c4); }
.dg-title { min-width: 0; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.dg-subtitle { margin-top: 2px; color: #8fa0b5; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dg-node.dg-decision { border-radius: 999px; text-align: center; }
.dg-node.dg-decision .dg-node-head { justify-content: center; }
.dg-node.dg-entity { padding: 0; justify-content: flex-start; overflow: hidden; }
.dg-entity .dg-node-head { padding: 8px 12px; background: color-mix(in srgb, var(--accent, #38d6c4) 25%, transparent); }
.dg-fields { padding: 4px 0; }
.dg-field { display: flex; align-items: center; gap: 8px; height: 22px; padding: 0 12px; font-size: 11px; }
.dg-field:hover { background: rgba(255, 255, 255, 0.05); }
.dg-key { width: 22px; flex: none; font-size: 9px; font-weight: 800; text-align: center; border-radius: 4px; }
.dg-key.k-pk { color: #0b1118; background: #f5b83d; }
.dg-key.k-fk { color: #0b1118; background: #6fa8ff; }
.dg-field-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dg-field-type { color: #8fa0b5; }
.dg-card.dg-full { position: fixed; inset: 0; z-index: 1000; margin: 0; border-radius: 0; display: flex; flex-direction: column; }
.dg-card.dg-full .dg-viewport { flex: 1; height: auto; }
body.dg-lock { overflow: hidden; }
@media (max-width: 780px) { .dg-viewport { height: 320px; } }

/* Tabulator data grids */
.grid-card { width: fit-content; min-width: min(100%, 220px); max-width: 100%; margin: 12px 0; border: 1px solid rgba(120, 150, 190, 0.22); border-radius: 14px; background: #0e141d; overflow: hidden; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3); }
.grid-holder.tabulator { max-width: 100%; }
.grid-card .result-grid { margin: 0; border: 0; border-radius: 0; }
.grid-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid rgba(120, 150, 190, 0.16); }
.grid-toolbar .grid-report { margin-left: 0; }
.pin-canvas.pin-table { min-height: 0; max-height: 420px; overflow: auto; border: 1px solid rgba(120, 150, 190, 0.16); border-radius: 12px; }
.viewer-stage.viewer-table { height: auto; max-height: 75vh; overflow: auto; }
.sql-failed > summary, .sql-failed > .sql-editor { text-decoration: line-through; opacity: 0.6; }
.sql-failed .sql-failed-badge { text-decoration: none; display: inline-block; color: #ff7b7b; font-size: 0.85em; }
.grid-count { margin-left: auto; padding: 2px 10px; color: #38d6c4; font-size: 11px; font-weight: 700; border: 1px solid rgba(56, 214, 196, 0.35); border-radius: 999px; }
.grid-search { flex: 1; min-width: 0; max-width: 260px; padding: 6px 12px; color: #e6edf5; font: inherit; font-size: 12px; border: 1px solid rgba(120, 150, 190, 0.25); border-radius: 999px; background: rgba(255, 255, 255, 0.04); outline: none; }
.grid-search:focus { border-color: #38d6c4; }
@media (max-width: 780px) { .grid-search { font-size: 16px; } }
.grid-holder.tabulator { border: 0; background: transparent; color: #dbe4ef; font-size: 12.5px; }
.grid-holder .tabulator-header { border-bottom: 1px solid rgba(56, 214, 196, 0.4); background: linear-gradient(180deg, #1c2a3d, #162131); color: #e6edf5; }
.grid-holder .tabulator-header .tabulator-col { border-right: 1px solid rgba(120, 150, 190, 0.14); background: transparent; }
.grid-holder .tabulator-col .tabulator-col-content { padding: 9px 12px; }
.grid-holder .tabulator-col .tabulator-col-title { font-weight: 700; letter-spacing: 0.02em; }
.grid-holder .tabulator-col.tabulator-sortable:hover,
.grid-holder .tabulator-col.tabulator-sortable.tabulator-col-sorter-element:hover { background: #7ee8da; color: #0b1118; }
.grid-holder .tabulator-col.tabulator-sortable:hover .tabulator-col-title { color: #0b1118; }
.grid-holder .tabulator-col.tabulator-sortable:hover .tabulator-arrow { border-bottom-color: #0b1118; }
.grid-holder .tabulator-col.tabulator-sortable:hover[aria-sort="descending"] .tabulator-arrow { border-top-color: #0b1118; }
.grid-holder .tabulator-col .tabulator-arrow { border-bottom-color: #38d6c4; }
.grid-holder .tabulator-col[aria-sort="descending"] .tabulator-arrow { border-top-color: #38d6c4; }
.grid-holder .tabulator-tableholder { background: transparent; -webkit-overflow-scrolling: touch; }
.grid-holder .tabulator-row { min-height: 32px; border-bottom: 1px solid rgba(120, 150, 190, 0.1); background: #0e141d; color: #dbe4ef; }
.grid-holder .tabulator-row.tabulator-row-even { background: #121a26; }
.grid-holder .tabulator-row:hover,
.grid-holder .tabulator-row.tabulator-selectable:hover,
.grid-holder .tabulator-row.tabulator-row-even:hover,
.grid-holder .tabulator-row.tabulator-row-odd:hover { background: #7ee8da; color: #0b1118; }
.grid-holder .tabulator-row:hover .tabulator-cell { color: #0b1118; font-weight: 600; }
.grid-holder .tabulator-row .tabulator-cell { padding: 7px 12px; border-right: 1px solid rgba(120, 150, 190, 0.08); }
.tabulator-tooltip, .tabulator-popup-container .tabulator-tooltip { color: #000 !important; }
.grid-holder .tabulator-placeholder span { color: #8fa0b5; font-weight: 600; }

.message-body [hidden] { display: none !important; }

/* ===== Workspace tabs: Explore / Code / Pin Board ===== */
.tab-panel[hidden] { display: none !important; }
.tab-explore { display: contents; }
.chart-card .chart-pin { position: absolute; top: 10px; right: 56px; z-index: 2; }

.tab-bar { position: sticky; top: 0; z-index: 6; display: flex; gap: 4px; padding: 0 clamp(24px, 5vw, 72px); border-bottom: 1px solid var(--line); background: rgba(11, 15, 20, 0.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); overflow-x: auto; scrollbar-width: none; }
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; border: 0; background: transparent; transition: color 200ms var(--ease); }
.tab-btn::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, #38d6c4, #7c8cff); opacity: 0; transform: scaleX(0.4); transition: opacity 200ms var(--ease), transform 200ms var(--ease); }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--mint-strong); }
.tab-btn.active::after { opacity: 1; transform: scaleX(1); }

.code-panel, .pins-panel { flex: 1; width: 100%; max-width: 1560px; margin: 0 auto; padding: 22px clamp(16px, 4vw, 56px) 40px; }
.code-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 16px; align-items: start; }
.code-main { display: grid; gap: 16px; min-width: 0; }

.ws-card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(18, 25, 35, 0.75); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); }
.ws-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ws-card-title { color: var(--ink); font-size: 13px; font-weight: 700; letter-spacing: 0.02em; }
.ws-card-tools { display: flex; gap: 6px; }
.ws-badge { padding: 2px 10px; color: var(--mint-strong); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; border: 1px solid rgba(56, 214, 196, 0.4); border-radius: 999px; }

.code-editor { display: block; width: 100%; min-height: 170px; padding: 12px 14px; color: var(--ink); font: 13px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace; tab-size: 2; border: 1px solid var(--line); border-radius: 10px; background: #0e1520; outline: none; resize: vertical; }
.code-editor:focus { border-color: var(--mint-strong); box-shadow: 0 0 0 3px rgba(56, 214, 196, 0.12); }
.code-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.code-actions .sql-btn { min-width: 96px; min-height: 36px; }

.ws-tabs { display: flex; gap: 6px; }
.ws-tab { padding: 6px 14px; color: var(--muted); font-size: 12px; font-weight: 600; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); transition: all 200ms var(--ease); }
.ws-tab:hover { color: var(--mint-strong); border-color: rgba(56, 214, 196, 0.5); }
.ws-tab.active { color: #fff; border-color: transparent; background: linear-gradient(135deg, #1fa89a, #4d63e8); }
.ws-card-head .sql-btn[hidden] { display: none; }
.code-view { min-width: 0; overflow-x: auto; }
.code-view[hidden] { display: none; }
.code-view .grid-card { margin: 0; }
.ws-note { padding: 6px 2px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.ws-error { color: #ff9b8a; }

.chart-form { display: grid; gap: 8px; }
.chart-form label, .chart-field-label { margin-top: 4px; color: #a9b6c7; font-size: 12px; font-weight: 700; }
.chart-form select, .chart-form input[type="text"] { width: 100%; min-height: 38px; padding: 8px 10px; color: var(--ink); font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 9px; background: #0e1520; outline: none; }
.chart-form select:focus, .chart-form input[type="text"]:focus { border-color: var(--mint-strong); box-shadow: 0 0 0 3px rgba(56, 214, 196, 0.12); }
.chart-form select option { color: #e6edf5; background: #121923; }
.chart-form select:disabled, .chart-form input:disabled { opacity: 0.5; }
.chart-y { display: flex; flex-wrap: wrap; gap: 6px; }
.chart-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin: 0; padding: 6px 10px; color: #c9d4e1; font-size: 12px; font-weight: 600; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; }
.chart-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-chip:has(input:checked) { color: var(--mint-strong); border-color: rgba(56, 214, 196, 0.6); background: rgba(56, 214, 196, 0.08); }
.chart-chip input { margin: 0; accent-color: #38d6c4; }
.chart-hint, .chart-empty, .chart-note { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.chart-empty { margin-top: 12px; padding: 18px 12px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.chart-note { margin-top: 10px; }
.chart-note[hidden], .chart-empty[hidden], .chart-stage[hidden] { display: none; }
.chart-form .sql-btn { width: 100%; min-height: 38px; margin-top: 6px; }
.chart-stage { position: relative; width: 100%; margin-top: 14px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 14px; background: #0f1722; overflow: hidden; }

.pins-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.pins-bar select { flex: 1 1 220px; min-width: 0; max-width: 360px; min-height: 38px; padding: 8px 10px; color: var(--ink); font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 9px; background: #0e1520; outline: none; }
.pins-bar select:focus { border-color: var(--mint-strong); }
.pins-bar select option { color: #e6edf5; background: #121923; }
.pins-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pins-actions .sql-btn { min-height: 38px; }
.pins-actions .sql-btn:disabled { opacity: 0.45; }
.pins-stage-head { display: none; }
.pins-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.pins-empty { padding: 36px 16px; color: var(--muted); font-size: 14px; line-height: 1.6; text-align: center; border: 1px dashed var(--line); border-radius: 14px; }
.pins-empty[hidden] { display: none; }
.pin-card { min-width: 0; padding: 12px 12px 10px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 16px; background: radial-gradient(ellipse at 12% 0%, rgba(56, 214, 196, 0.1), transparent 42%), radial-gradient(ellipse at 100% 100%, rgba(124, 140, 255, 0.11), transparent 45%), #0f1722; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22); animation: rise 320ms var(--ease) both; }
.pin-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.pin-title { flex: 1; min-width: 0; margin: 0; color: #e9f4f4; font-family: "Space Grotesk", sans-serif; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-tools { display: flex; gap: 6px; }
.pin-canvas { width: 100%; min-height: 240px; }
.pin-meta { margin-top: 4px; color: #5f6d7f; font-size: 11px; }
.pins-stage.presenting { position: fixed; inset: 0; z-index: 900; padding: 20px clamp(16px, 4vw, 48px) 32px; overflow-y: auto; background: #0b0f14; overscroll-behavior: contain; }
.pins-stage.presenting .pins-stage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.pins-stage.presenting .pins-stage-head h2 { margin: 0; min-width: 0; font-size: clamp(20px, 3vw, 34px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pins-stage.presenting .pins-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); }
.pins-stage.presenting .pin-canvas { min-height: 320px; }
body.presenting-lock { overflow: hidden; }

.viewer-dialog { width: min(1100px, calc(100% - 32px)); max-width: none; }
.viewer-dialog .settings-card { grid-template-rows: auto minmax(0, 1fr); max-height: calc(100dvh - 48px); }
.viewer-stage { width: 100%; height: min(70vh, 640px); min-height: 280px; border: 1px solid rgba(56, 214, 196, 0.28); border-radius: 14px; background: #0f1722; overflow: hidden; }
.settings-card select { padding: 11px 12px; color: var(--ink); font: inherit; border: 1px solid var(--line); border-radius: 8px; background: #0e1520; outline: 0; }
.settings-card select option { color: #e6edf5; background: #121923; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 2000; display: flex; align-items: center; gap: 14px; max-width: min(92vw, 460px); padding: 11px 16px; color: var(--ink); font-size: 13px; border: 1px solid rgba(56, 214, 196, 0.45); border-radius: 12px; background: var(--raised); box-shadow: 0 18px 45px rgba(0, 0, 0, 0.55); transform: translateX(-50%); animation: rise 200ms var(--ease) both; }
.toast[hidden] { display: none; }
.toast-action { padding: 4px 8px; color: var(--mint-strong); font-size: 12px; font-weight: 700; white-space: nowrap; border: 0; background: transparent; }

/* ---------- Design mode ---------- */
.code-modes { display: inline-flex; gap: 4px; margin-bottom: 12px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.03); }
.mode-btn { min-height: 34px; padding: 0 16px; color: var(--muted); font-size: 13px; font-weight: 700; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.mode-btn.active { color: var(--ink); background: rgba(56,214,196,.16); }
.dz-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.dz-layout { display: grid; grid-template-columns: 176px minmax(0, 1fr); gap: 10px; }
.dz-layout.no-palette { grid-template-columns: minmax(0, 1fr); }
.dz-palette { min-width: 0; max-height: 420px; padding: 8px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.02); }
.dz-palette[hidden], .dz-sqlbox[hidden], .dz-hint[hidden], .dz-edge-x[hidden] { display: none; }
.dz-search, .dz-input { width: 100%; min-height: 34px; padding: 0 8px; color: var(--ink); font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised, #121a2b); }
.dz-pal-title { margin: 10px 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.dz-pal-list { display: grid; gap: 4px; }
.dz-pal-item { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 8px; color: var(--ink); font-size: 13px; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: grab; }
.dz-pal-item:hover { border-color: var(--mint-strong); }
.dz-pal-glyph { flex: 0 0 auto; width: 18px; text-align: center; color: var(--mint-strong); }
.dz-pal-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-viewport { position: relative; height: 420px; min-width: 0; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background-color: rgba(0,0,0,.2); background-image: radial-gradient(rgba(255,255,255,.1) 1px, transparent 1px); background-size: 20px 20px; overscroll-behavior: contain; }
.dz-world { position: relative; }
.dz-edges { position: absolute; top: 0; left: 0; z-index: 0; pointer-events: none; overflow: visible; }
.dz-edge { fill: none; stroke: var(--mint-strong); stroke-width: 2; }
.dz-edge.selected { stroke: #7c8cff; stroke-width: 3; }
.dz-temp { fill: none; stroke: #7c8cff; stroke-width: 2; stroke-dasharray: 5 4; }
.dz-edge-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.dz-edge-x { position: absolute; z-index: 3; width: 24px; height: 24px; padding: 0; color: #fff; border: 0; border-radius: 50%; background: #e5484d; transform: translate(-50%, -50%); cursor: pointer; }
.dz-node { position: absolute; top: 0; left: 0; z-index: 1; width: 184px; height: 88px; border: 1px solid var(--line); border-top: 3px solid var(--mint-strong); border-radius: 10px; background: #141c2e; box-shadow: 0 4px 14px rgba(0,0,0,.35); user-select: none; }
.dz-node.dz-output { border-top-color: #7c8cff; }
.dz-node.dz-source { border-top-color: #38d6c4; }
.dz-node.dz-filter, .dz-node.dz-aggregate, .dz-node.dz-sort { border-top-color: #f5b84b; }
.dz-node.dz-lookup, .dz-node.dz-mergejoin { border-top-color: #e88bd0; }
.dz-node.selected { border-color: #7c8cff; box-shadow: 0 0 0 2px rgba(124,140,255,.5); }
.dz-node.dragging { opacity: .85; z-index: 2; }
.dz-node.dz-idle { opacity: .5; }
.dz-node.dz-warn { border-color: #e5484d; }
.dz-head { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; cursor: grab; touch-action: none; }
.dz-glyph { color: var(--mint-strong); }
.dz-title { flex: 1 1 auto; min-width: 0; overflow: hidden; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.dz-step { flex: 0 0 auto; padding: 0 6px; color: #0b1220; font-size: 11px; font-weight: 800; border-radius: 8px; background: var(--mint-strong); }
.dz-tools { display: none; gap: 2px; }
.dz-node.selected .dz-tools { display: flex; }
.dz-tools button { width: 24px; height: 24px; padding: 0; color: var(--ink); border: 0; border-radius: 6px; background: rgba(255,255,255,.08); cursor: pointer; }
.dz-text { padding: 2px 14px 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dz-two .dz-text { padding-left: 46px; }
.dz-plabel { position: absolute; left: 14px; color: var(--muted); font-size: 9px; transform: translateY(-50%); pointer-events: none; }
.dz-port { position: absolute; z-index: 2; width: 14px; height: 14px; padding: 0; border: 2px solid var(--mint-strong); border-radius: 50%; background: #0b1220; transform: translate(-50%, -50%); cursor: crosshair; touch-action: none; }
.dz-port::after { content: ""; position: absolute; inset: -10px; }
.dz-in { left: 0; }
.dz-out { left: 100%; top: 50%; }
.dz-port.armed, .dz-port.hot, .dz-connecting .dz-in { background: #7c8cff; border-color: #7c8cff; }
.dz-hint { position: absolute; top: 50%; left: 50%; z-index: 0; max-width: 80%; color: var(--muted); font-size: 13px; text-align: center; transform: translate(-50%, -50%); pointer-events: none; }
.dz-status { margin-top: 8px; font-size: 13px; color: var(--muted); }
.dz-status.ok { color: var(--mint-strong); }
.dz-status.bad { color: #ff8a8f; }
.dz-sqlbox { margin-top: 10px; }
.dz-sql { max-height: 260px; margin: 0 0 8px; padding: 10px; overflow: auto; font: 12px/1.5 Consolas, monospace; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.25); }
.design-dialog { width: min(640px, calc(100% - 24px)); }
.design-dialog .settings-card { max-height: 88vh; overflow-y: auto; }
.dz-form { display: grid; gap: 14px; margin: 12px 0; }
.dz-field { display: grid; gap: 6px; }
.dz-label { font-size: 12px; font-weight: 700; }
.dz-note { color: var(--muted); font-size: 12px; }
.dz-rows, .dz-row-list { display: grid; gap: 8px; }
.dz-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dz-row .dz-input { flex: 1 1 110px; width: auto; }
.dz-eq, .dz-order { color: var(--muted); font-size: 13px; }
.dz-grow { flex: 1 1 auto; }
.dz-mini, .dz-add { min-height: 32px; padding: 0 10px; color: var(--ink); font-size: 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; }
.dz-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 180px; overflow-y: auto; }
.dz-check-wrap { display: grid; gap: 6px; }
.dz-check-tools { display: flex; gap: 6px; }

/* Data Engineering */
.domain-toggle { margin-right: 8px; }
.de-files { display: grid; gap: 8px; }
.de-file { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.02); }
.de-file.expired { border-color: rgba(255,200,87,.5); }
.de-file-info { min-width: 0; flex: 1 1 200px; }
.de-file-name { font: 700 13px Consolas, monospace; }
.de-file-meta { margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.de-file-warn { margin-top: 4px; color: #ffc857; font-size: 12px; }
.de-file-actions { display: flex; gap: 6px; }
.file-dialog { width: min(620px, calc(100% - 24px)); }
.file-dialog .settings-card { max-height: 90vh; overflow-y: auto; }
.file-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 10px 0 6px; font-size: 13px; }
.check-row input { width: auto; }
.file-error { margin: 8px 0; padding: 8px 10px; color: #ff8a8f; font-size: 13px; border: 1px solid rgba(255,138,143,.4); border-radius: 8px; }
.file-error[hidden], .file-preview[hidden], .file-dialog [hidden], #deDomain[hidden], #sqlDomain[hidden] { display: none; }
.file-table-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.file-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.file-table th, .file-table td { padding: 5px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
.file-table th { position: sticky; top: 0; background: #11202b; }

@media (max-width: 1100px) {
  .code-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 780px) {
  .tab-bar { flex: 0 0 auto; padding: 0 8px; overflow-x: visible; }
  .tab-btn { flex: 1 1 0; gap: 6px; min-height: 48px; padding: 0 6px; font-size: 13px; }
  .tab-btn svg { width: 17px; height: 17px; }
  .code-panel, .pins-panel { min-height: 0; padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  .ws-card { padding: 12px; border-radius: 12px; }
  .code-editor { min-height: 140px; font-size: 16px; }
  .code-actions { display: grid; grid-template-columns: repeat(3, 1fr); }
  .code-actions .sql-btn { min-width: 0; min-height: 42px; padding: 0 8px; }
  .chart-form select, .chart-form input[type="text"], .pins-bar select { font-size: 16px; min-height: 44px; }
  .chart-chip { padding: 8px 12px; font-size: 13px; }
  .chart-form .sql-btn { min-height: 44px; }
  .ws-card-head .sql-btn { min-height: 36px; }
  .pins-bar select { flex: 1 1 100%; max-width: none; }
  .pins-actions { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
  .pins-actions .sql-btn { min-height: 44px; }
  .pins-grid { grid-template-columns: minmax(0, 1fr); }
  .pin-canvas { min-height: 260px; }
  .pins-stage.presenting { padding: calc(12px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom)); }
  .viewer-dialog { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .viewer-dialog .settings-card { height: 100%; max-height: none; padding: 16px; border-radius: 0; }
  .viewer-stage { height: 100%; min-height: 0; }
  .settings-card select, .settings-card input { font-size: 16px; }
  .toast { bottom: calc(18px + env(safe-area-inset-bottom)); }
  .code-modes { display: flex; }
  .mode-btn { flex: 1 1 0; min-height: 40px; }
  .dz-toolbar { display: grid; grid-template-columns: repeat(3, 1fr); }
  .dz-toolbar .sql-btn { min-width: 0; min-height: 42px; padding: 0 8px; }
  .dz-layout { grid-template-columns: minmax(0, 1fr); }
  .dz-palette { max-height: 220px; }
  .dz-viewport { height: 380px; }
  .dz-input, .dz-search { min-height: 44px; font-size: 16px; }
  .dz-mini, .dz-add { min-height: 40px; }
  .design-dialog { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .design-dialog .settings-card { height: 100%; max-height: none; border-radius: 0; }
  .file-dialog { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .file-dialog .settings-card { height: 100%; max-height: none; border-radius: 0; }
  .file-grid { grid-template-columns: minmax(0, 1fr); }
  .de-file-actions { width: 100%; }
  .de-file-actions .sql-btn { flex: 1; min-height: 40px; }
  .domain-toggle { margin-right: 0; }
}
