/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:        oklch(0.145 0 0);
  --bg-soft:   oklch(0.175 0 0);
  --bg-hover:  oklch(0.205 0 0);
  --line:      oklch(0.25  0 0);
  --line-soft: oklch(0.22  0 0);
  --text:      oklch(0.97  0 0);
  --text-2:    oklch(0.75  0 0);
  --text-3:    oklch(0.55  0 0);
  --text-4:    oklch(0.40  0 0);
  --fg-invert: oklch(0.145 0 0);
  --ok:        oklch(0.78 0.15 150);
  --warn:      oklch(0.80 0.13 70);
  --err:       oklch(0.70 0.17 25);

  --edge-color:        color-mix(in oklch, var(--text) 34%, var(--line));
  --edge-width:        1.35;
  --card-bg:           oklch(0.195 0 0);
  --card-bg-root:      oklch(0.225 0 0);
  --panel-shadow:      0 8px 20px -12px rgba(0,0,0,.56);
  --panel-shadow-soft: 0 1px 0 color-mix(in oklch, var(--text) 6%, transparent) inset;
  --grid-line:         rgba(255,255,255,.03);
  --grid-core:         rgba(255,255,255,.03);
}
html[data-theme="light"] {
  --bg:        oklch(0.995 0 0);
  --bg-soft:   oklch(0.975 0 0);
  --bg-hover:  oklch(0.955 0 0);
  --line:      oklch(0.89  0 0);
  --line-soft: oklch(0.93  0 0);
  --text:      oklch(0.18  0 0);
  --text-2:    oklch(0.40  0 0);
  --text-3:    oklch(0.55  0 0);
  --text-4:    oklch(0.70  0 0);
  --fg-invert: oklch(0.995 0 0);
  --ok:        oklch(0.52 0.14 150);
  --warn:      oklch(0.58 0.14 60);
  --err:       oklch(0.55 0.18 25);

  --edge-color:        color-mix(in oklch, var(--text) 48%, var(--line));
  --edge-width:        1.5;
  --card-bg:           var(--bg);
  --card-bg-root:      var(--bg-soft);
  --panel-shadow:      0 4px 12px -8px rgba(0,0,0,.18);
  --panel-shadow-soft: 0 1px 0 #fff inset;
  --grid-line:         rgba(0,0,0,.04);
  --grid-core:         rgba(0,0,0,.035);
}

/* ── Reset / Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  font-feature-settings: "ss01","cv11";
  -webkit-font-smoothing: antialiased;
}
body { margin: 0; }

/* ── App shell layout ───────────────────────────────────────────────────── */
#app    { display: flex; flex-direction: column; height: 100vh; }
#main   { display: flex; flex: 1; min-height: 0; }
main    { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
section { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

#workspace-state { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#tab-chat        { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#tab-migration   { flex: 1; overflow-y: auto; }
#tab-docs        { flex: 1; overflow-y: auto; }

/* ── Status bar ─────────────────────────────────────────────────────────── */
#status-bar {
  height: 28px; border-top: 1px solid var(--line-soft);
  flex-shrink: 0; display: flex; align-items: center;
  padding: 0 1rem; gap: 1.25rem;
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  color: var(--text-3); background: var(--bg);
}
.status-ready  { display: flex; align-items: center; gap: .375rem; }
.status-spacer { flex: 1; }
.status-file   { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-cmdk   { background: none; border: none; cursor: pointer; font-family: inherit; font-size: 11px; color: var(--text-3); padding: 0; }
.status-cmdk:hover { color: var(--text-2); }

/* ── Typography utilities ───────────────────────────────────────────────── */
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.cap  {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-3);
}

/* ── Hairlines ──────────────────────────────────────────────────────────── */
.hb { border-bottom: 1px solid var(--line-soft); }
.ht { border-top:    1px solid var(--line-soft); }
.hr { border-right:  1px solid var(--line-soft); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; border-radius: 4px;
  font-size: 12.5px; font-weight: 500; line-height: 1;
  color: var(--text-2); background: transparent;
  border: 1px solid var(--line-soft);
  transition: all .12s ease; cursor: pointer;
  white-space: nowrap; font-family: inherit;
}
.btn:hover    { color: var(--text); background: var(--bg-soft); border-color: var(--line); }
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn-primary  { color: var(--fg-invert); background: var(--text); border-color: var(--text); }
.btn-primary:hover { background: var(--text); filter: brightness(.9); color: var(--fg-invert); }
html[data-theme="light"] .btn-primary:hover { filter: brightness(1.12); }
.btn-ghost       { border-color: transparent; }
.btn-ghost:hover { border-color: transparent; background: var(--bg-soft); }
.btn-sm { padding: .35rem .55rem; font-size: 11.5px; gap: .35rem; }
.btn-cta { padding: .55rem 1rem; }

/* ── Kbd badge ──────────────────────────────────────────────────────────── */
.kbd {
  display: inline-flex; align-items: center;
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  padding: 2px 4px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--text-3); background: var(--bg-soft); line-height: 1;
}

/* ── Inputs ─────────────────────────────────────────────────────────────── */
.input {
  width: 100%; background: transparent; border: 1px solid var(--line);
  color: var(--text); padding: .6rem .75rem; border-radius: 4px;
  font-size: 13.5px; transition: border-color .15s; font-family: inherit;
}
.input:focus { outline: none; border-color: var(--text-3); }
.input::placeholder { color: var(--text-4); }
.label {
  display: block; font-size: 10.5px; color: var(--text-3);
  letter-spacing: .09em; text-transform: uppercase;
  font-weight: 500; margin-bottom: .4rem;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Status dot ─────────────────────────────────────────────────────────── */
.dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--ok); display: inline-block; flex-shrink: 0;
}

/* ── Toggle switch ──────────────────────────────────────────────────────── */
.toggle {
  position: relative; width: 28px; height: 16px;
  border-radius: 999px; background: var(--line); cursor: pointer;
  transition: background .15s; flex-shrink: 0;
}
.toggle.on { background: var(--text); }
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 999px;
  background: var(--bg); transition: transform .15s;
}
.toggle.on::after { transform: translateX(12px); background: var(--fg-invert); }

/* ── Drop zone ──────────────────────────────────────────────────────────── */
.drop {
  position: relative; border: 1px dashed var(--line);
  border-radius: 6px; background: transparent;
  transition: background .15s, border-color .15s; cursor: pointer;
}
.drop:hover    { border-color: var(--text-3); background: var(--bg-soft); }
.drop.drag-over { border-color: var(--text); background: var(--bg-soft); }

/* ── Sidebar rail ───────────────────────────────────────────────────────── */
#sidebar {
  width: 52px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: var(--bg); overflow: hidden;
  transition: width .15s ease;
  position: relative; z-index: 10;
}
#sidebar.expanded { width: 220px; }

.rail-label { opacity: 0; transition: opacity .12s ease; white-space: nowrap; overflow: hidden; }
#sidebar.expanded .rail-label { opacity: 1; }

.rail-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 4px; color: var(--text-3);
  font-size: 12.5px; width: 100%; text-align: left;
  background: transparent; border: none; cursor: pointer;
  transition: color .12s, background .12s; font-family: inherit;
}
.rail-item:hover  { color: var(--text); background: var(--bg-soft); }
.rail-item.active { color: var(--text); background: var(--bg-soft); }
.rail-item .ico   { width: 16px; flex-shrink: 0; display: inline-flex; justify-content: center; }

/* Sidebar components */
.sidebar-logo       { height: 48px; padding: 0 .75rem; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sidebar-logo-icon  { width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 3px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg-soft); }
.sidebar-logo-text  { line-height: 1.3; overflow: hidden; }
.sidebar-logo-name  { font-size: 12.5px; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; }
.sidebar-logo-sub   { font-size: 9.5px; }
.sidebar-section    { padding: .5rem; }
.sidebar-section-nav { padding: 0 .5rem; }
.sidebar-recent-wrap { padding: .75rem .5rem 0; flex-shrink: 0; }
.sidebar-recent-label { padding: .25rem .625rem; font-size: 9.5px; margin-bottom: .25rem; }
.sidebar-spacer     { flex: 1; }
.sidebar-footer-wrap { padding: .5rem; flex-shrink: 0; display: flex; flex-direction: column; justify-content: flex-end; }
.nav-label-row      { flex: 1; display: flex; align-items: center; justify-content: space-between; }

/* User bar */
.user-info-row { padding: .375rem .625rem; display: flex; align-items: center; gap: 10px; }
.user-avatar   { width: 24px; height: 24px; border-radius: 3px; border: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: center; font-size: 10px; font-family: monospace; flex-shrink: 0; background: var(--bg-soft); }
.user-meta     { min-width: 0; flex: 1; }
.user-name     { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-tokens   { font-size: 10px; color: var(--text-3); font-family: monospace; }
.sidebar-action-btns { display: flex; gap: .25rem; margin-top: .75rem; }
.sidebar-action-btn  { flex: 1; justify-content: center; padding: 6px; }

/* Collapsed sidebar overrides */
#sidebar:not(.expanded) .sidebar-only-expanded { display: none; }
#sidebar:not(.expanded) #sidebar-btns { justify-content: flex-start; padding-left: 6px; }
#sidebar:not(.expanded) #theme-btn    { flex: none; width: 32px; padding: 7px; }

/* Sidebar recent items */
.rail-item-recent { font-size: 11.5px; color: var(--text-3); }
.rail-item-recent .rail-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item-recent .ico { color: var(--text-4); }

/* ── Grid background ────────────────────────────────────────────────────── */
.grid-bg {
  background-image:
    radial-gradient(ellipse 70% 60% at center, transparent 0%, var(--bg) 100%),
    linear-gradient(to right,  var(--line-soft) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-soft) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
}

/* ── Upload page ────────────────────────────────────────────────────────── */
.upload-state  { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.upload-grid   { position: absolute; inset: 0; opacity: .5; pointer-events: none; }
.upload-center { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem; overflow: hidden; }
.upload-tagline { margin-bottom: .75rem; }
.upload-title  { font-size: 32px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; margin: 0 0 .75rem; }
.upload-desc   { font-size: 14.5px; color: var(--text-2); line-height: 1.6; margin: 0 0 2.5rem; max-width: 480px; }
.drop-body     { display: flex; align-items: center; gap: 1.25rem; }
.drop-icon     { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 4px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg-soft); }
.drop-text     { flex: 1; }
.drop-title    { font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.drop-sub      { font-size: 13px; color: var(--text-2); }
.upload-error  { font-size: 12px; color: var(--err); margin: .5rem 0 0; }
.upload-steps  { display: grid; grid-template-columns: repeat(3,1fr); gap: .5rem; margin-top: 1.5rem; }
.upload-step   { padding: .75rem; border: 1px solid var(--line-soft); border-radius: 4px; }
.upload-step-num  { margin-bottom: .5rem; }
.upload-step-name { font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.upload-step-sub  { font-size: 11.5px; color: var(--text-3); }

/* ── Upload hero (two-column: form | animation) ─────────────────────────── */
.upload-hero {
  width: 100%; max-width: 1000px;
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 48px;
  align-items: center;
}
@media (max-width: 860px) {
  .upload-hero { grid-template-columns: 1fr; }
  .bpt-preview-stage { display: none; }
}

/* ── Workspace / File header ────────────────────────────────────────────── */
.file-header-top       { padding: 1rem 1.5rem .75rem; display: flex; align-items: flex-start; gap: 1rem; }
.file-header-meta      { flex: 1; min-width: 0; }
.file-header-label-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.file-header-name      { font-size: 14.5px; margin: 0; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-header-actions   { display: flex; align-items: center; gap: .375rem; padding-top: .25rem; position: relative; }
.file-header-tabs      { padding: 0 1.5rem; display: flex; gap: 1.5rem; }

/* ── Workspace tabs ─────────────────────────────────────────────────────── */
.ws-tab {
  position: relative; padding: .65rem .15rem; font-size: 13px;
  color: var(--text-3); border: none; background: transparent;
  cursor: pointer; font-weight: 400; font-family: inherit;
  transition: color .12s;
}
.ws-tab:hover { color: var(--text-2); }
.ws-tab.active { color: var(--text); font-weight: 500; }
.ws-tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--text);
}

/* ── Chat panel ─────────────────────────────────────────────────────────── */
.chat-scroll        { flex: 1; overflow-y: auto; }
.chat-scroll-inner  { max-width: 720px; margin: 0 auto; padding: 2.5rem 2rem; }
.chat-footer        { padding: 1rem 1.5rem; background: var(--bg); flex-shrink: 0; }
.chat-footer-inner  { max-width: 720px; margin: 0 auto; }
.chat-input-box     { border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: flex-end; gap: .5rem; padding: .5rem .75rem; background: var(--bg-soft); transition: border-color .15s; }
.chat-input         { flex: 1; background: transparent; border: none; outline: none; resize: none; font-size: 14px; line-height: 1.5; padding: .375rem 0; min-height: 24px; max-height: 160px; color: var(--text); font-family: inherit; }
.chat-hints         { margin-top: .5rem; display: flex; justify-content: space-between; }

/* ── Panel (Migration / Docs) ───────────────────────────────────────────── */
.panel-inner   { max-width: 720px; margin: 0 auto; padding: 2.5rem 2rem; }
.panel-tagline { margin-bottom: .75rem; }
.panel-title   { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; margin: 0 0 .75rem; }
.panel-desc    { font-size: 14.5px; color: var(--text-2); line-height: 1.6; margin: 0 0 1.75rem; max-width: 460px; }

.feature-table         { border: 1px solid var(--line-soft); border-radius: 4px; overflow: hidden; margin-bottom: 1.5rem; }
.feature-table-header  { padding: .625rem 1rem; background: var(--bg-soft); border-bottom: 1px solid var(--line-soft); }
.feature-table-grid    { display: grid; grid-template-columns: 1fr 1fr; }
.feature-row           { padding: .625rem 1rem; font-size: 13px; border-bottom: 1px solid var(--line-soft); display: flex; gap: .75rem; }
.feature-row--right    { border-left: 1px solid var(--line-soft); }
.feature-row--last     { border-bottom: none; }
.feature-row-num       { min-width: 18px; }
.panel-cta             { display: flex; align-items: center; gap: .75rem; }
.content-header        { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.content-status        { display: flex; align-items: center; gap: .5rem; }
.content-actions       { gap: .375rem; }

/* ── History view ───────────────────────────────────────────────────────── */
.history-scroll-inner { max-width: 820px; margin: 0 auto; padding: 2.5rem 2rem; }
.history-head      { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.75rem; }
.history-tagline   { margin-bottom: .5rem; }
.history-title     { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; margin: 0 0 .25rem; }
.history-sub       { font-size: 13px; margin: 0; }
.history-search-wrap { position: relative; margin-bottom: 1rem; }
.search-icon       { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text-4); pointer-events: none; display: flex; }
.input-search      { padding-left: 2.25rem; }
.history-empty     { padding: 3rem; text-align: center; color: var(--text-3); font-size: 13px; }

/* History rows */
.history-row          { padding: .625rem 1rem; transition: background .1s; cursor: pointer; }
.history-row:hover    { background: var(--bg-hover); }
.history-row-file     { display: flex; align-items: center; gap: .5rem; min-width: 0; margin-bottom: .3rem; }
.history-row-bottom   { display: flex; align-items: center; gap: .5rem; padding-left: 1.5rem; }
.history-row-filename { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.history-row-meta     { font-size: 11px; color: var(--text-3); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-row-actions  { display: flex; gap: .25rem; flex-shrink: 0; align-items: center; }
.shrink-0             { flex-shrink: 0; }

/* ── Chat as document ───────────────────────────────────────────────────── */
.doc-msg { margin-bottom: 2rem; }
.doc-msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.doc-label {
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-3);
  margin-bottom: .6rem; display: flex; align-items: center; gap: .75rem;
}
.doc-msg.user .doc-text {
  font-size: 14.5px; color: var(--text); line-height: 1.6;
  max-width: 85%; text-align: right; white-space: pre-wrap;
}
.msg-label-inner { display: inline-flex; align-items: center; gap: 6px; }
.error-label     { color: var(--err); }
.error-text      { font-size: 13.5px; color: var(--err); }

/* Thinking dots */
.thinking-dots { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.thinking-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
  animation: thinking .9s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes thinking {
  0%,60%,100% { opacity: .2; transform: translateY(0); }
  30%          { opacity: 1;  transform: translateY(-3px); }
}

/* Streaming cursor */
.cursor-blink::after {
  content: "▊"; margin-left: 2px; color: var(--text-2);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Suggested questions ────────────────────────────────────────────────── */
.suggest-item {
  display: flex; align-items: center; gap: .75rem;
  width: 100%; padding: .625rem .75rem; margin: 0 -.75rem;
  border-radius: 4px; background: transparent; border: none;
  cursor: pointer; font-size: 14px; color: var(--text-2);
  text-align: left; font-family: inherit; transition: all .12s;
}
.suggest-item:hover { color: var(--text); background: var(--bg-soft); }
.suggest-item .ico     { flex-shrink: 0; color: var(--text-3); display: flex; }
.suggest-item .ico-end { margin-left: auto; opacity: 0; transition: opacity .12s; color: var(--text-4); display: flex; }
.suggest-item:hover .ico-end { opacity: 1; }

/* ── Markdown document ──────────────────────────────────────────────────── */
.doc { color: var(--text); line-height: 1.65; }
.doc h1,.doc h2,.doc h3 { font-weight: 600; letter-spacing: -.015em; color: var(--text); }
.doc h1 { font-size: 26px; margin: 1.4em 0 .5em; line-height: 1.2; }
.doc h2 { font-size: 19px; margin: 1.4em 0 .4em; line-height: 1.25; }
.doc h3 { font-size: 13px; margin: 1.4em 0 .35em; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; font-weight: 500; }
.doc p  { font-size: 14.5px; margin: .5em 0; }
.doc ul,.doc ol { margin: .5em 0 .5em 1.4em; }
.doc li { font-size: 14.5px; line-height: 1.6; margin: .2em 0; }
.doc ul li { list-style: none; position: relative; padding-left: 14px; }
.doc ul li::before { content: ""; position: absolute; left: 0; top: .7em; width: 6px; height: 1px; background: var(--text-4); }
.doc code { font-family: 'JetBrains Mono', monospace; font-size: .86em; background: var(--bg-soft); padding: 1px 5px; border-radius: 3px; color: var(--text); border: 1px solid var(--line-soft); }
.doc pre  { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 4px; padding: .8rem 1rem; overflow-x: auto; font-size: 12.5px; margin: .9em 0; }
.doc pre code { background: transparent; border: none; padding: 0; }
.doc table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 13px; }
.doc th,.doc td { text-align: left; padding: .55rem .85rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.doc thead th { color: var(--text-3); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; border-bottom-color: var(--line); }
.doc strong { color: var(--text); font-weight: 600; }
.doc em     { font-style: italic; color: var(--text-2); }
.doc blockquote { border-left: 2px solid var(--line); padding-left: 1rem; color: var(--text-2); margin: .8em 0; }
.doc hr     { border: none; border-top: 1px solid var(--line-soft); margin: 1.6em 0; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
.scroll-thin::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; border: 2px solid var(--bg); background-clip: padding-box; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--text-4); border: 2px solid var(--bg); background-clip: padding-box; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }

/* ── Export dropdown ────────────────────────────────────────────────────── */
#export-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 4px; z-index: 50; min-width: 140px;
  overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.export-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: .5rem .75rem;
  font-size: 12.5px; color: var(--text-2); text-align: left;
  background: transparent; border: none; cursor: pointer;
  transition: all .1s; font-family: inherit;
}
.export-item:hover { background: var(--bg-hover); color: var(--text); }

/* ── Command palette ────────────────────────────────────────────────────── */
#cmdk-overlay {
  position: fixed; inset: 0;
  background: color-mix(in oklch, var(--bg) 80%, transparent);
  backdrop-filter: blur(4px); z-index: 50;
}
#cmdk {
  position: fixed; top: 15vh; left: 50%; transform: translateX(-50%);
  width: min(560px, 90vw); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; z-index: 51;
  overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.cmdk-search      { display: flex; align-items: center; gap: .75rem; padding: 0 1rem; height: 48px; }
.cmdk-search-icon { color: var(--text-3); flex-shrink: 0; display: flex; }
.cmdk-input       { flex: 1; background: transparent; border: none; outline: none; font-size: 14px; color: var(--text); font-family: inherit; }
.cmdk-footer      { height: 32px; display: flex; align-items: center; justify-content: space-between; padding: 0 1rem; }
.cmdk-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: .625rem 1rem; text-align: left;
  background: transparent; border: none; cursor: pointer;
  font-size: 13.5px; color: var(--text); font-family: inherit;
  transition: background .08s;
}
.cmdk-item:hover, .cmdk-item.selected { background: var(--bg-soft); }
.cmdk-item .ico { color: var(--text-3); flex-shrink: 0; display: flex; }
.cmdk-item .sub { margin-left: auto; font-size: 11.5px; color: var(--text-3); font-family: 'JetBrains Mono', monospace; }

/* ── Auth layout ────────────────────────────────────────────────────────── */
.auth-wrap { width: 100%; max-width: 380px; }

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp .25s ease both; }

/* ── API notice ─────────────────────────────────────────────────────────── */
.api-notice { font-style: italic; font-size: 0.85em; opacity: 0.7; color: var(--text-2); }

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.t2 { color: var(--text-2); }
.t3 { color: var(--text-3); }
.t4 { color: var(--text-4); }
::selection { background: var(--text); color: var(--fg-invert); }

/* ── BPT Preview Stage ──────────────────────────────────────────────────── */
.bpt-preview-stage { position: relative; min-height: 540px; overflow: hidden; }
.canvas-host {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.canvas { position: relative; }
.canvas svg { position: absolute; inset: 0; overflow: visible; }

/* ── BPT cells ──────────────────────────────────────────────────────────── */
.bpt-cell {
  position: absolute;
  transform: translate(-50%, 0);
  width: 156px; height: 50px; padding: 8px 10px;
  background: var(--card-bg);
  border: 1px solid var(--line); border-radius: 5px;
  box-shadow: var(--panel-shadow-soft), var(--panel-shadow);
  transition: border-color .15s, transform .2s, box-shadow .2s;
  opacity: 0; visibility: hidden; transform-origin: 50% 0%;
  user-select: none;
}
.bpt-cell.visible {
  visibility: visible;
  animation: bptCellIn .78s cubic-bezier(.18,.9,.22,1) both;
  animation-delay: var(--delay, 0ms);
}
.bpt-cell:hover { border-color: var(--text-3); transform: translate(-50%, -1px); }
.bpt-cell.root  { background: var(--card-bg-root); }
.bpt-row  { display: flex; align-items: center; gap: 8px; height: 100%; }
.bpt-icon {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; width: 14px; height: 14px; color: var(--text-2);
  opacity: 0; transform: translateY(4px) scale(.92);
}
.bpt-cell.root .bpt-icon { color: var(--text); }
.bpt-title { font-size: 12px; font-weight: 500; line-height: 1.25; opacity: 0; transform: translateY(5px); }
.bpt-meta  {
  margin-top: 2px; color: var(--text-3); font-size: 9.5px;
  letter-spacing: .02em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translateY(6px);
}
.bpt-cell.visible .bpt-icon  { animation: bptIconLift .52s cubic-bezier(.2,.9,.22,1) both; animation-delay: calc(var(--delay, 0ms) + 120ms); }
.bpt-cell.visible .bpt-title { animation: bptTextLift .46s cubic-bezier(.2,.9,.22,1) both; animation-delay: calc(var(--delay, 0ms) + 160ms); }
.bpt-cell.visible .bpt-meta  { animation: bptTextLift .46s cubic-bezier(.2,.9,.22,1) both; animation-delay: calc(var(--delay, 0ms) + 220ms); }

/* ── BPT edges & branches ───────────────────────────────────────────────── */
.bpt-edge {
  fill: none; stroke: var(--edge-color); stroke-width: var(--edge-width);
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: var(--len); stroke-dashoffset: var(--len); opacity: 0;
}
.bpt-edge.visible {
  opacity: .96;
  animation:
    bptEdgeReveal .16s linear forwards,
    bptEdgeDraw var(--dur, 420ms) cubic-bezier(.22,1,.36,1) forwards;
  animation-delay: var(--delay, 0ms);
}
.bpt-branch {
  width: 52px; height: 18px; display: grid; place-items: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--line-soft); border-radius: 3px;
  background: var(--bg); color: var(--text-3); opacity: 0;
}
.bpt-branch.visible {
  animation: bptBranchIn .48s cubic-bezier(.2,.9,.22,1) both;
  animation-delay: var(--delay, 0ms);
}

/* ── BPT canvas keyframes ───────────────────────────────────────────────── */
@keyframes bptCellIn {
  0%   { opacity: 0; transform: translate(-50%,-18px) scale(.88) rotateX(10deg); filter: blur(6px); }
  45%  { opacity: 1; transform: translate(-50%,  3px) scale(1.02) rotateX(0);   filter: blur(0);   }
  72%  { opacity: 1; transform: translate(-50%, -1px) scale(.995);               filter: blur(0);   }
  100% { opacity: 1; transform: translate(-50%,  0)   scale(1);                  filter: blur(0);   }
}
@keyframes bptIconLift {
  0%   { opacity: 0; transform: translateY(4px) scale(.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes bptTextLift {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes bptEdgeDraw {
  from { stroke-dashoffset: var(--len); }
  to   { stroke-dashoffset: 0; }
}
@keyframes bptEdgeReveal {
  from { opacity: 0; }
  to   { opacity: .96; }
}
@keyframes bptBranchIn {
  from { opacity: 0; transform: translateY(-6px) scale(.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Billing view ────────────────────────────────────────────────────────── */
.billing-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}
.billing-head { margin-bottom: 2rem; }
.billing-tagline { color: var(--text-3); margin-bottom: .4rem; }
.billing-title { font-size: 24px; font-weight: 700; margin-bottom: .35rem; }
.billing-sub { color: var(--text-3); }

.balance-hero {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.balance-label { color: var(--text-3); margin-bottom: .5rem; }
.balance-amount {
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: .35rem;
  font-variant-numeric: tabular-nums;
}
.balance-tok-unit { font-size: 16px; font-weight: 400; color: var(--text-3); }
.balance-hint { color: var(--text-3); }

.billing-section-label { color: var(--text-3); margin-bottom: .75rem; }

.pkg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 2rem;
}
.pkg-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  transition: border-color .15s, background .15s;
}
.pkg-card:hover { border-color: var(--text-4); background: var(--bg-hover); }
.pkg-card.popular { border-color: var(--text-2); }
.pkg-badge {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--fg-invert);
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 9px;
  white-space: nowrap;
}
.pkg-name { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.pkg-tokens { font-size: 20px; font-weight: 700; margin: .4rem 0 .1rem; font-variant-numeric: tabular-nums; }
.pkg-tok-unit { font-size: 12px; font-weight: 400; color: var(--text-3); }
.pkg-price { font-size: 15px; font-weight: 600; }
.pkg-per-tok { font-size: 10.5px; color: var(--text-3); margin-top: .2rem; }

.billing-ref {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.billing-ref-head { color: var(--text-3); margin-bottom: .65rem; }
.billing-ref-rows { display: flex; flex-direction: column; gap: .4rem; }
.billing-ref-row { display: flex; align-items: baseline; gap: .75rem; font-size: 13px; }
.billing-ref-cost { font-size: 12px; color: var(--text); min-width: 44px; flex-shrink: 0; }
.billing-ref-desc { color: var(--text-3); }

.billing-contact {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem;
}
.billing-contact-head { font-size: 14px; font-weight: 600; margin-bottom: .5rem; }
.billing-contact-links { display: flex; flex-direction: column; gap: .4rem; margin-top: .75rem; }
.billing-contact-link {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  padding: .4rem .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: fit-content;
  transition: border-color .15s, color .15s;
}
.billing-contact-link:hover { color: var(--text); border-color: var(--text-4); }
