/*! StiffStruct, (c) 2026 Mohammad Asad. All rights reserved. Proprietary: copying, mirroring or reusing this code is not permitted without written permission (see terms.html#intellectual-property). build 20261018-2109 */
/* Code export view (js/ui/code-view.js). Colours come from the design-system variables, so dark mode works. */

.cv {
  --cv-line: 20px;
  --cv-font: 12.5px;
  width: 100%; max-width: 1240px; margin: 0 auto; padding: 20px 20px 48px;
  display: flex; flex-direction: column; gap: 14px;
}
.cv [hidden] { display: none !important; }

.cv-title { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.cv-lead { margin: 4px 0 0; max-width: 70ch; }
.cv-btn-icon { display: inline-flex; align-items: center; flex: none; }

/* tabs */
.cv-tabs { margin-top: 2px; }

/* panel: options + actions bar above the code */
.cv-panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-1); overflow: hidden; min-width: 0;
}
.cv-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.cv-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.cv-spacer { flex: 1 1 0; min-width: 0; }
.cv-meta { font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cv-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* code area: line-number gutter + highlighted code, one scroll container */
.cv-code {
  display: flex; align-items: stretch;
  height: clamp(300px, 58vh, 780px); overflow: auto; overscroll-behavior: contain;
  background: var(--bg-elev); color: var(--fg);
  font-family: var(--font-mono); font-size: var(--cv-font); line-height: var(--cv-line);
}
.cv-code:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.cv-code.is-message { display: block; }
.cv-gutter, .cv-pre {
  margin: 0; padding: 10px 0; font-family: var(--font-mono); font-size: var(--cv-font); line-height: var(--cv-line);
  tab-size: 4; background: transparent; border: 0;
}
.cv-gutter {
  position: sticky; left: 0; z-index: 1; flex: none;
  min-width: calc(var(--cv-digits, 3) * 1ch + 24px); padding: 10px 10px 10px 8px; box-sizing: border-box;
  text-align: right; user-select: none; -webkit-user-select: none;
  color: var(--fg-subtle); background: var(--bg-sunken); border-right: 1px solid var(--border);
}
.cv-pre { flex: 1 0 auto; min-width: 0; padding: 10px 18px 10px 14px; white-space: pre; }
.cv-pre code { font: inherit; background: none; padding: 0; color: inherit; }

/* syntax tokens */
.tk-c { color: var(--fg-subtle); font-style: italic; }
.tk-s { color: var(--success); }
.tk-n { color: var(--warning); }
.tk-k { color: var(--accent-text); font-weight: 600; }
.tk-k2 { color: var(--info); }
.tk-f { color: var(--diag-V); }

/* loading / error placeholders inside the code box */
.cv-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px; height: 100%; min-height: 160px;
  color: var(--fg-muted); font-family: var(--font-ui); font-size: 13px;
}
.cv-error {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 18px;
  padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  border-radius: var(--radius); background: var(--danger-soft); color: var(--fg); font-family: var(--font-ui); font-size: 13px;
}
.cv-error p { margin: 0; }

/* run in browser */
.cv-run { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cv-run:empty { display: none; }
.cv-status {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--fg-muted);
}
.cv-status.is-ok { color: var(--success); background: var(--success-soft); border-color: transparent; }
.cv-status.is-warn { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
.cv-status.is-error { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.cv-console {
  margin: 0; padding: 12px 14px; max-height: 380px; overflow: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-sunken); color: var(--fg);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre; tab-size: 4;
}
.cv-console:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cv-err { color: var(--danger); }
.cv-figs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.cv-fig {
  margin: 0; overflow: hidden; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.cv-fig img { display: block; width: 100%; height: auto; background: #fff; }
.cv-fig figcaption { padding: 6px 10px; font-size: 12px; border-top: 1px solid var(--border); }
.cv-dl { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-text); text-decoration: none; }
.cv-dl:hover { text-decoration: underline; }
.cv-files { padding: 10px 14px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }
.cv-files-title { margin: 0 0 4px; font-size: 13px; font-weight: 650; }
.cv-files ul { margin: 0; padding-left: 18px; }

/* local instructions */
.cv-help { padding: 10px 16px; font-size: 13px; color: var(--fg-muted); }
.cv-help summary { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--fg); font-weight: 600; padding: 2px 0; }
.cv-help[open] summary { margin-bottom: 6px; }
.cv-help ol, .cv-help ul { margin: 4px 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 3px; }
.cv-help p { margin: 6px 0 2px; }
.cv-help code { padding: 1px 5px; border-radius: 4px; background: var(--bg-sunken); color: var(--fg); font-size: 12px; }

@media (max-width: 640px) {
  .cv { padding: 14px 12px 36px; }
  .cv-meta { order: 3; flex-basis: 100%; }
  .cv-code { height: clamp(260px, 52vh, 600px); }
}
