/* Superchart - hand-drawn whiteboard theme.
 *
 * The vibe is the rest of gustavskuze.com (typewriter type, sticky-note yellow,
 * hard offset shadows, slightly crooked edges) carried onto a cool whiteboard
 * field, with the home page's "connective points" line network drifting behind
 * the UI - drawn as ink, not pencil on paper.
 *
 * Whiteboard is the only page theme: light background, dark ink, high contrast.
 */

@font-face {
  font-family: 'PencilNote';
  src: url('note-font.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #e9edf2;
  --panel: rgba(255, 255, 255, .88);
  --panel-2: rgba(233, 238, 244, .9);
  --line: #b9c3ce;
  --line-soft: #d6dde5;
  --ink: #16191e;
  --ink-soft: #4e5a68;
  --ink-faint: #5f6975;
  --accent: #f2dc3c;          /* sticky-note yellow */
  --accent-ink: #16191e;
  --accent-soft: rgba(242, 220, 60, .28);
  --blue: #2f6fb5;
  --amber: #8a5a12;
  --red: #b23b32;
  --user: rgba(242, 220, 60, .22);
  --user-line: rgba(180, 160, 20, .55);
  --code-bg: #10151c;
  --code-ink: #cfd8e2;
  --net-node: #4f6f9c;
  --net-line: #7f96b6;
  --radius: 13px 12px 14px 11px;
  --radius-sm: 9px 8px 10px 7px;
  --shadow: 2px 3px 0 rgba(30, 40, 55, .22);
  --display: 'PencilNote', 'Special Elite', 'Courier New', ui-monospace, monospace;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: .01em;
  line-height: 1.25;
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; z-index: 100;
  font-family: var(--display);
}
.skip:focus { left: 8px; top: 8px; }

/* ---- connective-points background ---- */
#constellation {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none; display: block;
}

/* ---- buttons ---- */
button {
  font-family: var(--display);
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  cursor: pointer;
  transition: transform .08s, box-shadow .08s, background .15s, border-color .15s, color .15s;
}
button:hover { border-color: var(--ink-faint); box-shadow: var(--shadow); transform: translate(-1px, -1px); }
button:active { transform: translate(1px, 1px); box-shadow: none; }
button[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
button.primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent-ink); font-weight: 400;
  box-shadow: var(--shadow);
}
button.primary:hover { transform: translate(-1px, -1px); box-shadow: 3px 4px 0 rgba(0,0,0,.5); }
button.ghost { background: transparent; }
button.mini { padding: 5px 10px; font-size: .82rem; }
button.icon { padding: 6px 11px; font-size: 1.05rem; }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }

/* ---- app shell ---- */
#app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- sidebar ---- */
#sidebar {
  flex: 0 0 290px;
  display: flex; flex-direction: column; min-width: 0;
  background: var(--panel);
  border-right: 1.5px solid var(--line);
}
.sb-head { padding: 16px 15px 9px; display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand .logo { display: flex; }
.brand .logo svg { transform: rotate(-6deg); filter: drop-shadow(2px 2px 0 rgba(0,0,0,.45)); }
.brand-txt { display: flex; flex-direction: column; line-height: 1.05; }
.brand-txt strong { font-family: var(--display); font-weight: 400; font-size: 1.22rem; letter-spacing: .02em; }
.brand-txt small { color: var(--ink-faint); font-size: .7rem; font-family: var(--display); letter-spacing: .03em; }
.sb-search { display: block; padding: 0 15px 10px; }
.sb-search input {
  width: 100%; padding: 8px 11px;
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
.sb-search input::placeholder { color: var(--ink-faint); }
.chat-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 12px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin: 3px 0; border-radius: var(--radius-sm);
  border: 1.5px solid transparent; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); border-color: var(--line); box-shadow: inset 3px 0 0 var(--accent); }
.chat-item .ci-main { min-width: 0; flex: 1 1 auto; }
.chat-item .ci-title { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-sub { font-size: .68rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--display); }
.chat-item .ci-del {
  opacity: 0; padding: 3px 8px; font-size: .9rem; background: transparent; border-color: transparent; box-shadow: none;
}
.chat-item:hover .ci-del, .chat-item.active .ci-del { opacity: 1; }
.chat-item .ci-del:hover { color: var(--red); border-color: var(--red); transform: none; box-shadow: none; }
.empty-list { color: var(--ink-faint); font-size: .82rem; padding: 14px 10px; font-family: var(--display); }
.sb-foot { position: relative; border-top: 1.5px solid var(--line-soft); padding: 11px 15px; display: flex; flex-direction: column; gap: 9px; }

.status { display: flex; align-items: center; gap: 8px; font-size: .74rem; color: var(--ink-soft); font-family: var(--display); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.status.ok .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(245, 224, 78, .2));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.status.warn .dot { background: var(--amber); }
.status.bad .dot { background: var(--red); }
.sb-actions { display: flex; gap: 6px; }

/* ---- main ---- */
#main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; border-bottom: 1.5px solid var(--line);
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}
#menu { display: none; }
.title-wrap { min-width: 0; flex: 1 1 auto; }
#view-title { margin: 0; font-size: 1.16rem; cursor: text; }
#view-title:hover { text-decoration: underline dotted; text-underline-offset: 4px; }
#title-input.title-input {
  display: block; width: 100%; max-width: 46ch; margin: 0;
  font-family: var(--display); font-size: 1.16rem;
  background: var(--panel-2); color: var(--ink);
  border: 1.5px solid var(--accent); border-radius: var(--radius-sm);
  padding: 1px 8px;
}
#chat-title {
  font-family: var(--display); font-size: 1.16rem; margin: 0; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text;
}
#chat-meta { font-size: .72rem; color: var(--ink-faint); font-family: var(--display); }
.top-actions { display: flex; gap: 6px; }
.syncid-slot { display: inline-flex; align-items: center; }
.syncid-slot .syncid-chip-link { max-width: 124px; font-size: 10px; padding: 5px 8px; }
body .syncid-pop, body .syncid-dialog {
  --syncid-btn-radius: var(--radius-sm);
  --syncid-btn-size: 15px;
  --syncid-btn-weight: 400;
  --syncid-btn-font: 'PencilNote', 'Special Elite', 'Courier New', ui-monospace, monospace;
  --syncid-accent: var(--accent);
  --syncid-accent-ink: var(--accent-ink);
}

/* ---- messages ---- */
.messages { flex: 1 1 auto; overflow-y: auto; padding: 22px 16px 8px; scroll-behavior: smooth; }
.thread { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 12px; }
.msg .avatar {
  flex: none; width: 30px; height: 30px; border-radius: 9px 7px 10px 8px;
  display: grid; place-items: center; font-size: .8rem; font-weight: 400;
  font-family: var(--display);
  background: var(--panel-2); border: 1.5px solid var(--line); color: var(--ink-soft);
  transform: rotate(-3deg);
}
.msg.user .avatar { background: var(--accent); border-color: var(--accent-ink); color: var(--accent-ink); transform: rotate(3deg); }
.msg-body { min-width: 0; flex: 1 1 auto; }
.bubble {
  border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 11px 14px; background: var(--panel);
  box-shadow: var(--shadow);
}
.msg.user .bubble { background: var(--user); border-color: var(--user-line); }
.msg .who { font-size: .72rem; color: var(--ink-faint); margin-bottom: 4px; font-family: var(--display); }
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .4em 0 .7em; padding-left: 1.3em; }
.bubble li { margin: .15em 0; }
.bubble a { color: var(--blue); }
.bubble code.inline {
  font-family: var(--mono); font-size: .86em;
  background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 5px; padding: 1px 5px;
}
.bubble strong { color: var(--ink); }
.msg.error .bubble { border-color: var(--red); background: var(--panel); background: color-mix(in srgb, var(--red) 12%, var(--panel)); }
.msg.warn .bubble { border-color: var(--amber); background: var(--panel); background: color-mix(in srgb, var(--amber) 12%, var(--panel)); }
.warn-note { margin-top: 8px; font-size: 12.5px; line-height: 1.35; color: var(--amber); }
.thinking .bubble { color: var(--ink-soft); font-style: italic; }
.dots i { animation: blink 1.2s infinite; font-style: normal; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---- code + chart cards ---- */
.card {
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); margin: 10px 0; overflow: hidden; box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; background: var(--panel-2); border-bottom: 1.5px solid var(--line);
  font-size: .78rem; color: var(--ink-soft); font-family: var(--display);
}
.card-head .lang { font-family: var(--display); text-transform: uppercase; letter-spacing: .12em; font-size: .66rem; color: var(--ink-faint); }
.card-head .spacer { margin-left: auto; }
.card pre {
  margin: 0; padding: 13px 15px; overflow-x: auto;
  font-family: var(--mono); font-size: .82rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-ink);
}
.card pre code { white-space: pre; }
.chart-wrap { padding: 12px; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 14px 12px; font-size: .78rem; color: var(--ink-soft); font-family: var(--display); }
.chart-legend .k { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .sw { width: 12px; height: 12px; border-radius: 3px 2px 3px 2px; border: 1px solid rgba(0,0,0,.4); }
.card-note { padding: 8px 14px; font-size: .76rem; color: var(--ink-faint); border-top: 1.5px solid var(--line-soft); font-family: var(--display); }

/* ---- empty state ---- */
.welcome { max-width: 720px; margin: 4vh auto 0; text-align: center; }
.welcome h2 { font-size: 1.7rem; margin: 0 0 6px; }
.welcome p { color: var(--ink-soft); margin: 0 auto 18px; max-width: 46ch; }
.welcome .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; text-align: left; }
.welcome .cards button { text-align: left; padding: 12px 14px; background: var(--panel); border-radius: var(--radius); }
.welcome .cards button strong { display: block; font-size: .95rem; margin-bottom: 3px; font-family: var(--display); font-weight: 400; }
.welcome .cards button span { color: var(--ink-soft); font-size: .8rem; }
.welcome .demo-note { margin-top: 16px; font-size: .78rem; color: var(--ink-faint); }

/* ---- composer ---- */
.composer-wrap { border-top: 1.5px solid var(--line); background: var(--panel); background: color-mix(in srgb, var(--panel) 80%, transparent); padding: 10px 16px 14px; }
.suggestions { max-width: 820px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.suggestions:empty { display: none; }
.suggest-bar { max-width: 820px; margin: 0 auto 6px; display: flex; justify-content: flex-end; }
.suggest-toggle { color: var(--ink-faint); padding: 3px 9px; font-size: .72rem; }
.suggest-toggle:hover { color: var(--ink); }
.suggest-toggle .chev { display: inline-block; min-width: .7em; text-align: center; }
.suggest {
  font-family: var(--display); font-size: .8rem; padding: 6px 12px; background: transparent;
  border: 1.5px dashed var(--line); border-radius: 999px; color: var(--ink-soft); box-shadow: none;
}
.suggest:hover { color: var(--ink); border-style: solid; border-color: var(--ink-faint); transform: none; box-shadow: none; }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 9px; align-items: flex-end; }
.composer textarea {
  flex: 1 1 auto; min-width: 0; resize: none; max-height: 220px;
  padding: 11px 13px; background: var(--panel-2);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--ink-faint); }
.composer .send { padding: 11px 20px; border-radius: var(--radius); }
.hint { max-width: 820px; margin: 7px auto 0; font-size: .72rem; color: var(--ink-faint); font-family: var(--display); }

#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }

/* ---- sidebar sections (presets + your charts) ---- */
.sb-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 12px; }
.sb-section {
  display: flex; align-items: center; gap: 6px;
  padding: 13px 8px 6px; font-family: var(--display); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .14em; color: var(--ink-faint);
  border-bottom: 1.5px dashed var(--line-soft); margin: 0 2px 6px;
}
.sb-section .count { color: var(--ink-faint); }
.chat-list { padding: 0; }
.preset-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 9px; margin: 3px 0;
  border-radius: var(--radius-sm); border: 1.5px solid transparent; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.preset-item:hover { background: var(--panel-2); border-color: var(--line); }
.preset-item .pi-thumb {
  flex: none; width: 42px; height: 30px; border: 1.5px solid var(--line);
  border-radius: 6px 5px 7px 5px; overflow: hidden; background: var(--panel-2);
}
.preset-item .pi-thumb svg { width: 100%; height: 100%; display: block; }
.preset-item .pi-txt { min-width: 0; }
.preset-item .pi-name { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset-item .pi-cat { font-size: .66rem; color: var(--ink-faint); font-family: var(--display); letter-spacing: .03em; }

/* ---- gallery (home) ---- */
.gallery {
  max-width: 1040px; margin: 0 auto; padding: 26px 20px 44px;
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.gallery .gallery-intro { grid-column: 1 / -1; }
.gallery .gallery-intro h2 { margin: 0 0 5px; font-size: 1.9rem; }
.gallery .gallery-intro p { margin: 0; color: var(--ink-soft); max-width: 68ch; }
.preset-card {
  border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel); display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.preset-card:nth-child(3n) { transform: rotate(-.35deg); }
.preset-card:nth-child(3n+1) { transform: rotate(.4deg); }
.preset-card:hover { border-color: var(--accent); transform: translate(-2px, -2px) rotate(0deg); box-shadow: 4px 5px 0 rgba(0,0,0,.55); }
.preset-card .pc-thumb { background: var(--panel-2); border-bottom: 1.5px solid var(--line); padding: 9px; }
.preset-card .pc-thumb svg { width: 100%; height: auto; display: block; }
.preset-card .pc-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }
.preset-card .pc-name { font-family: var(--display); font-size: 1.05rem; }
.preset-card .pc-blurb { color: var(--ink-soft); font-size: .82rem; }
.preset-card .pc-foot { display: flex; gap: 8px; padding: 0 14px 14px; align-items: center; }
.preset-card .pc-cat {
  font-family: var(--display); font-size: .66rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); margin-right: auto;
}

/* ---- workspace ---- */
.stage { flex: 1 1 auto; overflow-y: auto; }
.workspace { max-width: 900px; margin: 0 auto; padding: 20px 16px 32px; }
.canvas { border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; margin-bottom: 18px; box-shadow: var(--shadow); }
.canvas-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel-2); border-bottom: 1.5px solid var(--line); }
.canvas-head .spacer { margin-left: auto; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; padding: 2px; gap: 2px; }
.seg-btn {
  border: 0; background: transparent; padding: 5px 15px; font-size: .84rem;
  border-radius: 999px; color: var(--ink-soft); box-shadow: none;
}
.seg-btn:hover { transform: none; box-shadow: none; color: var(--ink); }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); }
.chart-view { padding: 12px; overflow-x: auto; }
.chart-view svg { display: block; width: 100%; height: auto; }
/* ---- take the chart elsewhere (clipboard / PNG / SVG) ---- */
.export-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 12px 12px; }
.export-bar .spacer { margin-left: auto; }
.export-hint { font-family: var(--display); font-size: .66rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-faint); }
.code-view pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--mono); font-size: .82rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-ink);
}
.code-view code { white-space: pre; }

/* ---- editable Python script ---- */
.code-bar, .config-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 12px 8px; }
.code-bar .spacer, .config-bar .spacer { margin-left: auto; }
.code-hint, .config-hint { font-size: .76rem; color: var(--ink-soft); max-width: 66ch; }
.code-hint b, .config-hint b { color: var(--ink); }
.code-hint code {
  font-family: var(--mono); font-size: .86em; background: var(--panel-2);
  border: 1px solid var(--line-soft); border-radius: 4px; padding: 0 4px;
}
.code-input, .config-input {
  display: block; width: 100%; min-height: 430px; resize: vertical;
  font-family: var(--mono); font-size: .82rem; line-height: 1.5;
  padding: 12px 16px; white-space: pre; overflow: auto; tab-size: 4;
  background: var(--code-bg); color: var(--code-ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
.config-input { min-height: 470px; }
.code-view .data-msg, .config-view .data-msg { margin: 6px 12px 10px; }
.canvas .empty-canvas { padding: 44px 20px; text-align: center; color: var(--ink-faint); font-family: var(--display); }
.workspace .messages { overflow: visible; padding: 0; }
.workspace .thread { max-width: none; }

/* ---- workspace: canvas column + AI panel column ---- */
.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px; align-items: start;
  max-width: 1300px; margin: 0 auto; padding: 20px 16px 32px;
}
.col-main { min-width: 0; }
.col-ai {
  position: sticky; top: 8px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 132px);
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.ai-head {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--panel-2); border-bottom: 1.5px solid var(--line);
}
.ai-head strong { font-family: var(--display); font-weight: 400; font-size: 1.06rem; }
.ai-head .ai-sub { font-size: .7rem; color: var(--ink-faint); font-family: var(--display); }
.ai-head .ai-clear { margin-left: auto; }
.thread-empty {
  color: var(--ink-faint); font-size: .82rem; font-family: var(--display);
  line-height: 1.5; padding: 10px 2px;
}
.col-ai .messages { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px; min-height: 140px; max-height: none; }
.col-ai .thread { max-width: none; }
.col-ai .composer-wrap { border-top: 1.5px solid var(--line-soft); background: transparent; padding: 10px 12px 12px; }
.col-ai .suggestions { max-width: none; margin-bottom: 8px; }
.col-ai .suggest-bar { max-width: none; }
.col-ai .composer { max-width: none; }
.col-ai .hint { display: none; }

/* ---- data tab ---- */
.data-view { padding: 12px; }
.data-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.data-bar .spacer { margin-left: auto; }
.data-hint { font-size: .76rem; color: var(--ink-soft); max-width: 62ch; }
.data-hint b { color: var(--ink); }
#data-input {
  width: 100%; min-height: 200px; resize: vertical;
  font-family: var(--mono); font-size: .82rem; line-height: 1.5;
  padding: 10px 12px; white-space: pre; overflow: auto;
  background: var(--code-bg); color: var(--code-ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
#data-input[hidden] { display: none; }

/* ---- data tab: spreadsheet grid ---- */
.data-grid-wrap {
  overflow: auto; max-height: min(58vh, 560px);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel);
}
.data-grid { border-collapse: separate; border-spacing: 0; width: 100%; }
.data-grid th, .data-grid td { padding: 0; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.data-grid thead th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); }
.data-grid .dg-gutter, .data-grid .dg-rowhead {
  position: sticky; left: 0; z-index: 1; background: var(--panel-2);
  width: 1px; white-space: nowrap; padding: 0;
}
.data-grid thead .dg-gutter { z-index: 3; }
/* Keep flex off the <th> itself: a flex <th> leaves the table's cell layout and
   every header collapses onto column 0. The flex row lives in an inner wrapper. */
.data-grid .dg-headwrap, .data-grid .dg-rowhead-wrap { display: flex; align-items: center; }
.data-grid .dg-headwrap { min-width: 100%; }
.data-grid .dg-rowhead-wrap { gap: 4px; padding: 0 6px; width: max-content; }
.data-grid .dg-rownum { font-size: .68rem; color: var(--ink-faint); min-width: 1.2em; text-align: right; font-family: var(--mono); }
.data-grid input {
  border: 0; outline: 0; background: transparent; color: var(--ink);
  font-family: var(--mono); font-size: .8rem; line-height: 1.4;
  padding: 6px 8px; width: 100%; min-width: 64px;
}
.data-grid thead input.dg-head { font-weight: 700; color: var(--ink); min-width: 80px; }
.data-grid input.dg-cell.num { text-align: right; }
.data-grid input:focus { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 2px; }
.data-grid tr:hover td, .data-grid tr:hover .dg-rowhead { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.data-grid .dg-delrow, .data-grid .dg-delcol {
  border: 0; background: transparent; color: var(--ink-faint); cursor: pointer;
  font-size: .9rem; line-height: 1; padding: 2px 5px; border-radius: 4px; opacity: 0;
}
.data-grid tr:hover .dg-delrow, .data-grid .dg-colhead:hover .dg-delcol { opacity: 1; }
.data-grid .dg-delrow:hover, .data-grid .dg-delcol:hover { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.data-grid-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.data-grid-foot .spacer { margin-left: auto; }
.data-dims { font-size: .72rem; color: var(--ink-faint); font-family: var(--display); }
@media (pointer: coarse) {
  .data-grid .dg-delrow, .data-grid .dg-delcol { opacity: 1; }
}
.data-msg { font-size: .78rem; color: var(--ink-soft); min-height: 1.2em; margin-top: 6px; font-family: var(--display); }
.data-msg.bad { color: var(--red); }
.data-msg.good { color: var(--accent); }

/* ---- style tab (colour schemes + textures) ---- */
.style-view { padding: 14px; }
.style-group { margin-bottom: 16px; }
.style-label {
  font-family: var(--display); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .14em; color: var(--ink-faint); margin-bottom: 9px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 11px; background: var(--panel-2);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  color: var(--ink-soft); font-family: var(--display); font-size: .8rem;
}
.chip .chip-name { white-space: nowrap; }
.chip.active { border-color: var(--accent); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }
.chip-note { align-self: center; font-size: 11.5px; opacity: 0.65; font-style: italic; }
.scheme-chip .dots-row { display: inline-flex; overflow: hidden; border-radius: 5px; }
.scheme-chip .dots-row i { display: block; width: 12px; height: 18px; }
.texture-chip svg { display: block; border-radius: 3px; background: var(--panel); }
.style-hint { margin: 6px 2px 0; font-size: .76rem; color: var(--ink-faint); max-width: 62ch; }

/* bar-colour rule targeting: which data drives the colour, and what it paints.
   Rendered as chips (never a dropdown) so it matches the rest of the Style tab. */
.rule-opts { flex-basis: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.rule-opt { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .78rem; color: var(--ink-soft); }
.rule-opt-label { color: var(--ink-faint); text-transform: uppercase; letter-spacing: .1em; font-size: .66rem; }
.rule-chip { padding: 3px 9px; font-size: .76rem; }

/* ---- responsive ---- */
@media (max-width: 1000px) {
  .workspace { grid-template-columns: 1fr; padding: 12px 10px 24px; }
  .col-ai { position: static; max-height: none; }
  .col-ai .messages { max-height: 340px; }
}
@media (max-width: 780px) {
  #sidebar {
    position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.sb-open #sidebar { transform: none; }
  #menu { display: inline-block; }
  .messages { padding: 16px 10px 8px; }
  .composer-wrap { padding: 10px 10px 12px; }
  .gallery { grid-template-columns: 1fr; padding: 16px 10px 32px; }
  .preset-card, .preset-card:nth-child(3n), .preset-card:nth-child(3n+1) { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto; }
}

/* ---- projects: a spreadsheet plus the charts the AI builds from it ---- */
.project-view { max-width: 1000px; margin: 0 auto; padding: 20px 16px 40px; }
.pv-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.pv-head-txt { min-width: 0; flex: 1 1 auto; }
#pv-name { margin: 0; font-size: 1.7rem; cursor: text; }
#pv-name:hover { text-decoration: underline dotted; text-underline-offset: 4px; }
.pv-sub { margin: 4px 0 0; color: var(--ink-faint); font-size: .74rem; font-family: var(--display); }
.pv-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pv-intake {
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 16px; box-shadow: var(--shadow);
}
.pv-intake h3 { margin: 0 0 6px; font-family: var(--display); font-weight: 400; font-size: 1.15rem; }
.pv-lede { margin: 0 0 12px; color: var(--ink-soft); font-size: .85rem; max-width: 72ch; }
.pv-lede b { color: var(--ink); }
textarea.pv-paste {
  width: 100%; min-height: 210px; resize: vertical;
  font-family: var(--mono); font-size: .82rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; white-space: pre; overflow-wrap: normal; overflow-x: auto;
}
textarea.pv-paste::placeholder { color: var(--ink-faint); }
.pv-intake-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pv-intake-row .spacer { margin-left: auto; }
.pv-file {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--display); font-size: .8rem; color: var(--ink-soft);
  padding: 7px 12px; background: var(--panel-2);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
.pv-file:hover { color: var(--ink); border-color: var(--ink-faint); }
.pv-file input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

.pv-body { display: flex; flex-direction: column; gap: 16px; }
.pv-panel {
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel);
  box-shadow: var(--shadow); overflow: hidden;
}
.pv-panel-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; background: var(--panel-2); border-bottom: 1.5px solid var(--line);
}
.pv-panel-head strong { font-family: var(--display); font-weight: 400; }
.pv-panel-head .spacer { margin-left: auto; }

.pv-cols { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 2px; }
.pv-cols:empty { display: none; }
.pv-col {
  display: inline-flex; align-items: baseline; gap: 6px; max-width: 34ch;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 4px 8px; font-size: .72rem; color: var(--ink-soft); background: var(--panel-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pv-col b { color: var(--ink); font-family: var(--display); font-weight: 400; }
.pv-col i { font-style: normal; text-transform: uppercase; letter-spacing: .08em; font-size: .58rem; color: var(--ink-faint); }
.pv-col.k-number { border-color: color-mix(in srgb, var(--blue) 50%, var(--line)); }
.pv-col.k-bool { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); }
.pv-col.k-text { border-color: color-mix(in srgb, var(--line) 100%, transparent); }

.pv-grid-wrap { padding: 0 12px 12px; max-height: 430px; overflow: auto; }

.pv-analysis { padding: 12px 16px 14px; }
.pv-analysis p { margin: 0 0 .7em; }
.pv-analysis p:last-child { margin-bottom: 0; }
.pv-analysis ul, .pv-analysis ol { margin: .4em 0 .8em; padding-left: 1.4em; }
.pv-analysis li { margin: .2em 0; }
.pv-analysis strong { color: var(--ink); }
.pv-analysis code.inline {
  font-family: var(--mono); font-size: .82em; background: var(--code-bg);
  color: var(--code-ink); padding: 1px 5px; border-radius: 5px;
}

.pv-charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 12px; }
.pv-chart {
  display: flex; flex-direction: column; overflow: hidden;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.pv-chart:hover { border-color: var(--accent); }
.pv-chart-thumb { padding: 8px; background: var(--panel); border-bottom: 1.5px solid var(--line); }
.pv-chart-thumb svg { width: 100%; height: auto; display: block; }
.pv-chart-body { padding: 9px 11px; flex: 1 1 auto; }
.pv-chart-name { font-family: var(--display); font-size: .95rem; }
.pv-chart-blurb { color: var(--ink-soft); font-size: .76rem; margin-top: 2px; }
.pv-chart-foot { display: flex; gap: 8px; padding: 0 11px 11px; }

.pv-ask .pv-panel-head { border-bottom: 1.5px solid var(--line-soft); }
.pv-log {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 220px; overflow-y: auto; padding: 10px 12px 0;
}
.pv-log-user { font-size: .82rem; color: var(--ink); }
.pv-log-ai { font-size: .72rem; color: var(--ink-faint); font-family: var(--display); }
.pv-log-ai.bad { color: var(--red); }
.pv-log-hint { font-size: .75rem; color: var(--ink-faint); font-family: var(--display); }
.pv-ask .composer { max-width: none; margin: 0; padding: 12px; }
.pv-ask .composer textarea { min-height: 44px; }
.pv-ask .data-msg { padding: 0 12px 12px; }
.gallery-intro button { margin-top: 10px; }

/* ---- take it elsewhere: the "..." menu (feature a chart) ---- */
.export-more { position: relative; display: inline-flex; }
.menu-pop {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 25;
  min-width: 15rem; display: flex; flex-direction: column; gap: 2px; padding: 5px;
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.menu-pop[hidden] { display: none; }
.menu-item {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  padding: 8px 10px; border-radius: 6px; font-size: .82rem; color: var(--ink);
  cursor: pointer; box-shadow: none; transform: none; white-space: nowrap;
}
.menu-item:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: none; transform: none; }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--red) 16%, transparent); }
.menu-item[hidden] { display: none; }

/* ---- showcase: featured charts ("beyond the spreadsheet") ---- */
.showcase { max-width: 1100px; margin: 0 auto; padding: 26px 20px 48px; }
.sc-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.sc-head-txt { min-width: 0; flex: 1 1 auto; }
.showcase .sc-head h2 { margin: 0 0 6px; font-size: 1.9rem; }
.sc-lede { margin: 0; color: var(--ink-soft); max-width: 74ch; }
.sc-lede b { color: var(--ink); }
.sc-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.sc-card {
  margin: 0; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.sc-card:hover { border-color: var(--accent); transform: translate(-2px, -2px); box-shadow: 4px 5px 0 rgba(0,0,0,.55); }
.sc-chart { padding: 14px; background: var(--panel-2); border-bottom: 1.5px solid var(--line); }
.sc-chart svg { display: block; width: 100%; height: auto; }
.sc-chart .empty-canvas { padding: 30px 16px; text-align: center; color: var(--ink-faint); font-family: var(--display); }
.sc-cap { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; }
.sc-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.1rem; }
.sc-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.sc-tag {
  font-family: var(--display); font-size: .62rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--accent-ink); background: var(--accent); padding: 2px 8px; border-radius: 999px;
}
.sc-note { font-size: .74rem; color: var(--ink-faint); }
.sc-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.sc-foot .spacer { margin-left: auto; }
.sc-empty {
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 34px 22px; text-align: center; color: var(--ink-soft); max-width: 62ch; margin: 0 auto;
}
.sc-empty p { margin: 0 0 10px; }
.sc-empty b { color: var(--ink); }
.sc-empty button { margin-top: 8px; }
.gallery-intro button + button { margin-left: 8px; }
@media (max-width: 780px) {
  .sc-grid { grid-template-columns: 1fr; }
  .showcase { padding: 16px 10px 32px; }
}
