/* SrgArt Pine Creator — Mini App (REVISION 2 Phase 1).
   Tokens: dark-first palette with high contrast for mobile, with opt-in
   overrides that mirror Telegram's --tg-theme-* CSS variables. Layout:
   mobile-first 320-430px, fluid up to 480px, capped at 720px. Motion: only
   transform/opacity, prefers-reduced-motion disables ambient.
   60 FPS budget: no expensive filters or shadow blurs (per AC-11/16).
   Animated properties: transform, opacity, color, background, border-color.

   REVISION 2 §43 AC-43.5: --tg-theme-* variables are pulled from
   Telegram.WebApp.themeParams at runtime by app.js#applyTelegramTheme and
   applied as inline custom-properties on document.documentElement. The
   override blocks below re-bind our brand tokens to those values when
   present, so any Telegram-themed client (light or dark) blends
   seamlessly with the Mini App chrome. */

:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c222b;
  --fg: #f0f6fc;
  --fg-mute: #8b949e;
  --fg-dim: #6e7681;
  --accent: #58a6ff;
  --accent-soft: #1f6feb;
  --ok: #3fb950;
  --warn: #d29922;
  --error: #f85149;
  --border: #30363d;
  --border-soft: #21262d;
  --code-bg: #0a0d12;
  --code-fg: #c9d1d9;

  /* Pine Editor palette — derived from the TradingView Pine Editor
     screenshots at
        /Users/sergejgres/Desktop/Screenshot 2026-09-15 at 12.15.29.png
        /Users/sergejgres/Desktop/Screenshot 2026-09-18 at 16.30.01.png
     function / named-arg blue, enum / constant members pink, strings
     green, numbers orange, control flow + type declarations teal,
     comments muted gray (NOT italic), identifiers and assignment LHS
     inherit --code-fg (no separate identifier hue). */
  --code-comment: #7a8590;
  --code-keyword: #61BEAE;
  --code-string:  #4F9249;
  --code-number:  #ED8F30;
  --code-fn:      #6EA2F4;
  --code-namespace:#F08E89;
  --code-operator:#b5bcc4;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  /* 60 FPS budget: only animate transform / opacity. No filter blur. */
  --easing: cubic-bezier(0.22, 0.61, 0.36, 1);
  /* REVISION 2 §43 AC-43.5: Telegram theme tokens. app.js copies these from
     window.Telegram.WebApp.themeParams at boot. They are undefined until
     that copy happens; the var() fallbacks below use our brand palette. */
  --tg-bg:           var(--tg-theme-bg-color,           var(--bg));
  --tg-bg-elev:      var(--tg-theme-secondary-bg-color, var(--bg-elev));
  --tg-fg:           var(--tg-theme-text-color,         var(--fg));
  --tg-hint:         var(--tg-theme-hint-color,         var(--fg-mute));
  --tg-link:         var(--tg-theme-link-color,         var(--accent));
  --tg-button:       var(--tg-theme-button-color,       var(--accent));
  --tg-button-text:  var(--tg-theme-button-text-color,  #ffffff);
  --tg-header-bg:    var(--tg-theme-header-bg-color,    var(--bg-elev));
}

/* REVISION 2 §43: when Telegram exposes its theme variables, the Mini App
   blends with the user's Telegram theme. Both light and dark schemes are
   honored because Telegram supplies different palettes for each. */
:root[data-tg-scheme="light"] {
  --bg:       #ffffff;
  --bg-elev:  #f4f4f5;
  --bg-elev-2:#eaeaec;
  --fg:       #0f1419;
  --fg-mute:  #5c6770;
  --fg-dim:   #8a8f96;
  --border:   #d4d4d8;
  --border-soft:#e4e4e7;
  --code-bg:  #f6f8fa;
  --code-fg:  #1f2328;

  /* Light-theme palette (a reasonable complement of the dark above; not
     screenshot-derived). Identifiers and assignment LHS still inherit
     --code-fg, so they look neutral in light too. */
  --code-comment: #6a737d;
  --code-keyword: #008080;
  --code-string:  #228b22;
  --code-number:  #c75c00;
  --code-fn:      #2256a8;
  --code-namespace:#c0656a;
  --code-operator:#4f5862;
  --shadow:   0 6px 24px rgba(15, 20, 25, 0.12);
}

:root[data-tg-scheme="dark"] {
  /* Same as default :root — kept here so a future Telegram-side theme
     override can target :root[data-tg-scheme="dark"] without us re-listing
     every brand token. */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--tg-bg);
  color: var(--tg-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

/* REVISION 3 AC-REV3-1: глобальный override для [hidden].
   Без этого CSS display:flex на .list-view / .new-view / .detail-view / .landing
   перебивает HTML hidden и секции остаются видимыми («простыня»). */
[hidden] {
  display: none !important;
}

/* REVISION 3 AC-REV3-15: production hides the developer-only landing hooks
   (демо-ссылки + dev-fallback). The server (apps/srgart-agent/mini-app/
   server.mjs) tags <body> with `.is-dev` when IS_DEVELOPMENT=true so the
   elements with `[data-app-env="development"]` remain visible in dev-build.
   In production build the class is absent, the rule kicks in and the
   elements are visually removed. JS-side gates in boot() are the second
   line of defence (see app.js:isDevelopment + demo-block + allowDevFallback). */
body:not(.is-dev) [data-app-env="development"] {
  display: none !important;
}
body.is-dev [data-app-env="development"] {
  display: revert;
}

.layout {
  display: block;
  padding: 14px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
}

/* REVISION 3 AC-REV3-2: generationView — внутренний grid для header/core/stage-rail/activity/code/final/error.
   Сам generationView НЕ [hidden] когда активен; .layout остаётся блочным контейнером для всех view. */
.generation-view {
  display: grid;
  /* rows: header / core / stage-rail / activity / code-panel / final|error-state */
  grid-template-rows: auto auto auto auto 1fr auto;
  gap: 12px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
}

.header__left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.header__right { display: flex; gap: 6px; align-items: center; }

.title {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--tg-bg-elev);
  color: var(--fg-mute);
  font-size: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status[data-state="done"]   { color: var(--ok);   border-color: var(--ok); }
.status[data-state="error"]  { color: var(--error);border-color: var(--error); }
.status[data-state="ready"], .status[data-state="connected"], .status[data-state="connecting"] {
  color: var(--accent); border-color: var(--accent-soft);
}

/* REVISION 2 §16: header has status + MM:SS elapsed in a single row. */
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header__elapsed {
  font-size: 12px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
  /* Hide until the first elapsed tick (job has started). */
  opacity: 0;
  transition: opacity 200ms var(--easing);
}
.header__elapsed.is-running { opacity: 1; }

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-mute);
  background: var(--code-bg);
  white-space: nowrap;
}
.badge--muted { color: var(--fg-dim); }
.badge--ok    { color: var(--ok); border-color: var(--ok); }

/* REVISION 2 §42: debug bar (visible only with ?debug=1). */
.debug-bar {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--fg-mute);
}
.debug-bar__row {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}
.debug-bar__k {
  flex: 0 0 auto;
  color: var(--accent);
}
.debug-bar__v {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}

/* ---------- Indicator Core ---------- */
.core {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 8px 8px;
}

.indicator-core {
  /* REVISION 2 §16: Core 160-180px (we pick 180). Mobile-first 320-430px,
     180px is ~56% of 320 (320→180 fits) and ~42% of 430. */
  width: 180px;
  height: 180px;
  max-width: 60vw;
  color: var(--accent);
  transition: color 320ms var(--easing), transform 320ms var(--easing);
  will-change: transform;
}

/* State-driven colors (one composition that evolves) */
.layout[data-state="idle"]       .indicator-core { color: var(--fg-dim); }
.layout[data-state="preparing"]  .indicator-core { color: var(--accent); }
.layout[data-state="generating"] .indicator-core { color: var(--accent); }
.layout[data-state="verifying"]  .indicator-core { color: var(--warn); }
.layout[data-state="repairing"]  .indicator-core { color: var(--warn); }
.layout[data-state="success"]    .indicator-core { color: var(--ok); }
.layout[data-state="error"]      .indicator-core { color: var(--error); }

/* Ambient ring rotation: only when state is preparing/generating/verifying/repairing.
   Transform-only — 60 FPS friendly. */
.core-ring { transform-origin: 100px 100px; }

.layout[data-state="preparing"]  .core-ring--outer,
.layout[data-state="generating"] .core-ring--outer { animation: spin 4s linear infinite; }
.layout[data-state="verifying"]  .core-ring--outer,
.layout[data-state="repairing"]  .core-ring--outer { animation: spin 3s linear infinite reverse; }
.layout[data-state="preparing"]  .core-ring--middle,
.layout[data-state="generating"] .core-ring--middle { animation: spin 7s linear infinite reverse; }
.layout[data-state="verifying"]  .core-ring--middle,
.layout[data-state="repairing"]  .core-ring--middle { animation: spin 5s linear infinite; }

/* Ambient dots — pulse + translate. Visible only in active states. */
.core-glow { opacity: 0; transition: opacity 320ms var(--easing); }
.layout[data-state="preparing"]  .core-glow,
.layout[data-state="generating"] .core-glow,
.layout[data-state="verifying"]  .core-glow,
.layout[data-state="repairing"]  .core-glow { opacity: 1; }

.core-dot { fill: currentColor; opacity: 0.0; transition: opacity 320ms var(--easing); transform-origin: 100px 100px; }
.layout[data-state="preparing"]  .core-dot,
.layout[data-state="generating"] .core-dot,
.layout[data-state="verifying"]  .core-dot,
.layout[data-state="repairing"]  .core-dot { opacity: 0.85; }
.layout[data-state="generating"] .core-dot,
.layout[data-state="verifying"]  .core-dot { animation: dotPulse 1.6s ease-in-out infinite; }
.core-dot:nth-child(odd)  { animation-delay: 0.2s !important; }
.core-dot:nth-child(3n)   { animation-delay: 0.4s !important; }

/* Success: show check, hide dots/cross, slow celebratory pulse. */
.core-check { stroke-dasharray: 64; stroke-dashoffset: 64; opacity: 0; transition: opacity 320ms var(--easing), stroke-dashoffset 600ms var(--easing); }
.core-cross { opacity: 0; transition: opacity 240ms var(--easing); }
.layout[data-state="success"] .core-check { opacity: 1; stroke-dashoffset: 0; }
.layout[data-state="success"] .core-glow  { opacity: 1; }
.layout[data-state="success"] .core-node circle:first-child { animation: successPulse 2.4s ease-in-out infinite; }

/* Error: show cross, dim everything else. */
.layout[data-state="error"] .core-cross { opacity: 1; }

/* Subtle scale on state transition */
.layout[data-state="generating"] .indicator-core,
.layout[data-state="verifying"]  .indicator-core,
.layout[data-state="repairing"]  .indicator-core { transform: scale(1.04); }
.layout[data-state="success"]    .indicator-core { transform: scale(1.0); }
.layout[data-state="error"]      .indicator-core { transform: scale(0.98); }

.core__label {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  text-align: center;
  transition: color 240ms var(--easing);
}
.core__meta {
  font-size: 12px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50%      { transform: scale(1.5); opacity: 1; }
}
@keyframes successPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

/* ---------- Stage rail ---------- */
/* REVISION 2 §16: compact stepper. 4 dots in a thin row + "Этап N/4" count.
   Labels are hidden on mobile (they'd compete with the activity copy). */
.stage-rail {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tg-bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
.stage {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-mute);
  border: 1px solid transparent;
  transition: background 240ms var(--easing), color 240ms var(--easing), border-color 240ms var(--easing);
}
.stage__dot {
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--border);
  flex: 0 0 10px;
  transition: background 240ms var(--easing), box-shadow 240ms var(--easing), transform 240ms var(--easing);
}
.stage__label {
  /* Hidden on mobile — the activity row already says what stage is current. */
  display: none;
}
.stage-rail__count {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}
.stage.is-active .stage__dot {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(88, 166, 255, 0.55);
  transform: scale(1.18);
  animation: pulse 2.4s ease-in-out infinite;
}
.stage.is-done .stage__dot { background: var(--ok); }

/* ---------- Activity panel ---------- */
.activity {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.activity__row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}
.activity__spinner {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent);
  flex: 0 0 12px;
  opacity: 0;
  transition: opacity 200ms var(--easing);
}
.layout[data-state="preparing"]  .activity__spinner,
.layout[data-state="generating"] .activity__spinner,
.layout[data-state="verifying"]  .activity__spinner,
.layout[data-state="repairing"]  .activity__spinner { opacity: 1; animation: dotPulse 1.4s ease-in-out infinite; }
.layout[data-state="success"]    .activity__spinner { background: var(--ok);   opacity: 1; animation: none; }
.layout[data-state="error"]      .activity__spinner { background: var(--error); opacity: 1; animation: none; }

.activity__copy {
  flex: 1 1 auto;
  font-size: 14px;
  color: var(--fg);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity__hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-mute);
}

/* ---------- Code panel ---------- */
.code-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 220px;
  max-height: 50vh;
  transition: max-height 200ms var(--easing);
}
/* REVISION 2 §19: empty state — the panel is absent (display:none) until the
   first code_delta arrives. We toggle .code-panel--empty from app.js. */
.code-panel--empty {
  display: none;
}
.code-panel--collapsed {
  max-height: 140px;
}
.code-panel--collapsed .code-copy-overlay {
  /* Hide copy overlay when collapsed — the user can still copy via the final-scene button. */
  display: none;
}
.code-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 11px;
  color: var(--fg-mute);
}
.code-meta__label { font-weight: 600; color: var(--fg); letter-spacing: 0.04em; text-transform: uppercase; font-size: 10px; }
.code-meta__stats { flex: 1 1 auto; font-variant-numeric: tabular-nums; }
.code-meta__btn {
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--fg);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  min-height: 28px;
}

.code {
  position: relative;
  flex: 1 1 auto;
  margin: 0;
  padding: 10px 10px 10px 56px; /* leave room for line numbers */
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  overflow: auto;
  white-space: pre;
  scroll-behavior: smooth;
  counter-reset: line;
}
.code__lines {
  position: absolute;
  left: 0;
  top: 0;
  padding: 10px 8px;
  width: 44px;
  text-align: right;
  color: var(--fg-dim);
  background: var(--code-bg);
  border-right: 1px solid var(--border-soft);
  font-variant-numeric: tabular-nums;
  user-select: none;
  pointer-events: none;
  white-space: pre;
}
.code__content { display: block; }

/* ---------- Pine syntax highlighting (lightweight, no library) ----------
   Tokens emitted by tokenizePine() in app.js. Code spans are created with
   document.createElement('span') and assigned className only — never via the
   HTML-parsing API surface. */
/* Pine syntax highlighting classes emitted by tokenizePineToSpans()
   in pine-tokenizer.js. Spans are created via element.className (the
   safe textContent API path), never via innerHTML. Palette: function /
   named-arg blue, enum / constant members pink, strings green, numbers
   orange, control flow + types teal, comments muted gray (NOT italic),
   operators light gray. tk-ident / tk-param inherit --code-fg so they
   render as ordinary body text. */
.tk-comment   { color: var(--code-comment); }
.tk-keyword   { color: var(--code-keyword); }
.tk-string    { color: var(--code-string); }
.tk-number    { color: var(--code-number); }
.tk-fn        { color: var(--code-fn); }
.tk-namespace { color: var(--code-namespace); }
.tk-operator  { color: var(--code-operator); }
/* tk-builtin was retired when the palette was realigned to TradingView's
   Pine Editor — every `x.y` is now either tk-fn (callable) or
   tk-namespace (enum/constant member). */
.tk-ident     { color: inherit; }
.tk-param     { color: inherit; }

/* ---------- Final actions (morph slot) ---------- */
/* REVISION 2 §22: morph from Core, NOT a new card. The slot lives inside the
   activity panel area; visible only when state=success. The action buttons
   (Copy / Download / Open) replace the live "current activity" copy. */
.final-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--ok);
  /* Reveal animation matches the Core success pulse (transform/opacity only). */
  animation: finalActionsIn 360ms var(--easing);
}
@keyframes finalActionsIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1.00); }
}
.final-actions__subtext {
  color: var(--ok);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
}
.final-actions__row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
/* REVISION 3 AC-REV3-8: ".final-actions__tertiary" (the "Открыть код" button
   styling) has been removed. The two remaining primary / secondary buttons
   inherit from the base .btn rule above. */
.final-actions .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Error state ---------- */
/* REVISION 2 §41: error-state shown ONLY after retries are exhausted
   (attempt >= maxAttempts). App.js toggles .error-state--hidden when the
   pipeline still has retries left; we animate the reveal. */
.error-state {
  background: var(--bg-elev);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: var(--error);
}
.error-state--hidden {
  display: none;
}
.error-state__icon { color: var(--error); }
.error-state__icon img { display: block; width: 96px; height: 96px; object-fit: contain; }
.error-state__title { font-weight: 600; font-size: 18px; color: var(--fg); }
.error-state__message {
  color: var(--fg-mute); font-size: 13px;
  max-width: 100%;
  word-break: break-word;
}
.error-state__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 10px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms var(--easing), background 160ms var(--easing), border-color 160ms var(--easing);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.85; cursor: default; }
.btn--primary { background: var(--tg-button); color: var(--tg-button-text); border-color: var(--tg-button); }
.btn--secondary { background: var(--bg-elev-2); color: var(--fg); border-color: var(--accent-soft); }
.btn--copied { background: var(--ok) !important; color: white !important; border-color: var(--ok) !important; }

/* Code-panel collapse chevron (top-right of code-meta) */
.code-meta__chevron {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 160ms var(--easing), border-color 160ms var(--easing);
}
.code-meta__chevron:active { transform: scale(0.95); }

/* Floating copy button on code panel (small overlay, top-right of code area) */
.code-copy-overlay {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  min-height: 28px;
  opacity: 0.78;
  transition: opacity 160ms var(--easing), background 160ms var(--easing);
}
.code-copy-overlay:hover { opacity: 1; }

/* Reconnecting ribbon — thin pulse indicator shown when SSE stalls >500ms. */

/* Reconnecting ribbon — thin pulse indicator shown when SSE stalls >500ms. */
.layout--reconnecting {
  position: relative;
}
.layout--reconnecting::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: var(--accent);
  z-index: 50;
  animation: ribbonPulse 2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes ribbonPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Activity elapsed format: "В работе · MM:SS" */
.activity__elapsed {
  font-size: 12px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Paused ambient animation: kill all running keyframes when document.hidden.
   This saves battery when the user backgrounds the Mini App. */
.layout--paused .core-ring,
.layout--paused .core-dot,
.layout--paused .core-node circle:first-child,
.layout--paused .activity__spinner,
.layout--paused .stage.is-active {
  animation-play-state: paused !important;
}

/* ---------- Landing / footer ---------- */
.landing {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.footer { min-height: 24px; display: flex; align-items: center; justify-content: center; }
.footer__error { color: var(--error); font-size: 12px; text-align: center; }

/* ---------- Mobile breakpoints ---------- */
@media (max-width: 380px) {
  .layout { padding: 10px; gap: 10px; }
  .indicator-core { width: 180px; height: 180px; }
  .stage { font-size: 11px; padding: 6px 6px; }
  .code { font-size: 11px; padding-left: 48px; }
  .code__lines { width: 38px; padding: 10px 6px; }
  .activity__copy { font-size: 13px; }
  /* Tight final-scene buttons so they fit a 320px viewport. */
  .final__actions .btn { padding: 0 10px; font-size: 13px; }
  .code-meta__chevron { width: 26px; height: 26px; }
}
@media (min-width: 480px) {
  .indicator-core { width: 240px; height: 240px; }
  .code { font-size: 13px; }
}

/* ---------- prefers-reduced-motion ----------
   Per AC-011 / AC-016: disable ambient animation when the user has set the
   OS-level reduce-motion preference. Transients still happen — just instantly. */
@media (prefers-reduced-motion: reduce) {
  .core-ring,
  .core-dot,
  .core-node circle:first-child,
  .activity__spinner,
  .stage.is-active {
    animation: none !important;
  }
  * { transition-duration: 1ms !important; }
  .code { scroll-behavior: auto !important; }
  .indicator-core { transform: none !important; }
  .core-glow { opacity: 0; }
  .layout[data-state="preparing"]  .core-glow,
  .layout[data-state="generating"] .core-glow,
  .layout[data-state="verifying"]  .core-glow,
  .layout[data-state="repairing"]  .core-glow,
  .layout[data-state="success"]    .core-glow { opacity: 0.6; } /* keep some visual cue, no animation */
}

/* ---------- REVISION 2 AC-UX.35: ambient idle wait ----------
   When the backend has been silent for >15s while we're still in an active
   state (preparing / generating / verifying / repairing), we slow the Core
   rings down to a calm ambient pulse. This signals "the system is still
   working" without changing the business stage — the activity copy stays
   what the server last told us, only the visual cadence drops. Frontend
   never invents progress % or stage names.
   The class is toggled by app.js#markIdleWait / clearIdleWait. */
.layout--idle-wait .core-ring--outer  { animation-duration: 12s !important; }
.layout--idle-wait .core-ring--middle { animation-duration: 18s !important; }
.layout--idle-wait .core-ring--inner  { animation-duration:  9s !important; }
.layout--idle-wait .core-dot          { animation-duration: 3.2s !important; }
.layout--idle-wait .core-glow         { opacity: 0.55; }

/* REVISION 2 §44 / §45 / §46: Indicators Library views.
   Mobile-first, single column. Uses the same brand tokens as the rest of the
   UI so the new views look native. */
.list-view, .new-view, .detail-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.list-view__head, .detail-view__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.list-view__title, .new-view__title, .detail-view__title {
  font-size: 17px;
  font-weight: 600;
}
.list-view__hint {
  font-size: 13px;
  color: var(--error);
  padding: 6px 10px;
  background: rgba(248, 81, 73, 0.08);
  border-radius: var(--radius-sm);
}
.list-view__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-view__empty {
  padding: 150px 14px 22px;
  text-align: center;
  color: var(--fg-mute);
  font-size: 14px;
  background: url('./assets/icons/empty-library.webp') center 18px / 124px 124px no-repeat;
}
.list-view__item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 4px;
  padding: 12px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--tap);
  transition: transform 120ms var(--easing), border-color 120ms;
}
.list-view__item--without-icon { grid-template-columns: minmax(0, 1fr); }
.list-view__item-icon {
  grid-row: 1 / span 3;
  width: 48px;
  height: 48px;
  align-self: center;
  object-fit: contain;
}
.list-view__item-header,
.list-view__item-meta,
.list-view__assign-btn { grid-column: 2; }
.list-view__item--without-icon .list-view__item-header,
.list-view__item--without-icon .list-view__item-meta,
.list-view__item--without-icon .list-view__assign-btn { grid-column: 1; }
.list-view__item:hover, .list-view__item:focus {
  border-color: var(--accent);
  outline: none;
}
.list-view__item:active { transform: scale(0.99); }
.list-view__item-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-view__item-meta {
  font-size: 12px;
  color: var(--fg-mute);
}

/* REVISION 3.2 AC-REV3.2-4b (TYPE-10..14): each list item carries a
   type chip next to the title. The chip is a small pill so the user
   can see the indicator's type at a glance without opening the
   detail view. Legacy (no-profile) indicators get a different chip
   style + a "Выбрать" button to assign a profile. */
.list-view__item-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.list-view__item-header .list-view__item-title {
  flex: 1 1 auto;
  min-width: 0;
}
.list-view__chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--fg-mute);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex: 0 1 auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-view__chip--legacy {
  color: var(--warn);
  border-color: rgba(210, 153, 34, 0.4);
  background: rgba(210, 153, 34, 0.08);
}
.list-view__assign-btn {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  min-height: 32px;
  align-self: flex-start;
}

/* REVISION 3.2 AC-REV3.2-4b (TYPE-18): error-state banner shows the
   same type/mode chip as the failed job, so the user sees «Повторить»
   with the same context. */
.error-state__banner {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 4px 0;
}
.error-state__chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--fg-mute);
  border: 1px solid var(--border);
}
.error-state__mode {
  font-size: 12px;
  color: var(--fg-mute);
}

/* REVISION 3.2 AC-REV3.2-4b (TYPE-13/14, TYPE-22 Mini App): the detail
   header carries a slightly larger type chip + a separate mode label
   for strategy_constructor. Legacy indicators also get a "Указать
   тип" button next to the chip. */
.detail-view__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.detail-view__type-icon {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-right: 4px;
}
.detail-view__chip-row {
  display: inline-flex;
  gap: 4px;
}
.detail-view__chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--fg-mute);
  border: 1px solid var(--border);
}
.detail-view__chip--legacy {
  color: var(--warn);
  border-color: rgba(210, 153, 34, 0.4);
  background: rgba(210, 153, 34, 0.08);
}
.detail-view__mode {
  font-size: 12px;
  color: var(--fg-mute);
}
.detail-view__legacy-hint {
  font-size: 13px;
  color: var(--warn);
  margin: 0 0 8px 0;
}

/* REVISION 3.2 AC-REV3.2-4b (TYPE-22 Mini App): legacy edit gate
   modal — a small bottom-sheet-style overlay that shows the
   "Перед правкой выберите тип" message with Continue/Cancel buttons. */
.legacy-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.legacy-gate[hidden] {
  display: none !important;
}
.legacy-gate__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.legacy-gate__panel {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.legacy-gate__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.legacy-gate__hint {
  margin: 0;
  font-size: 13px;
  color: var(--fg-mute);
}
.legacy-gate__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field__label {
  font-size: 12px;
  color: var(--fg-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field__input {
  font-family: inherit;
  font-size: 15px;
  color: var(--tg-fg);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--tap);
  resize: vertical;
}
.field__input--area { min-height: 140px; font-family: inherit; }
.field__input:focus { border-color: var(--accent); outline: none; }
.edit-images { display: grid; gap: 9px; }
.edit-images__picker { justify-self: start; cursor: pointer; }
.edit-images__hint { color: var(--fg-mute); font-size: 12px; }
.edit-images__preview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.edit-images__item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev-2); }
.edit-images__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit-images__remove { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; border-radius: 50%; background: rgba(13, 17, 23, 0.82); color: #fff; font-size: 18px; line-height: 1; }
.form-error { margin: 0; color: var(--error); font-size: 13px; line-height: 1.4; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.new-view__actions, .detail-view__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-view__download-status {
  padding: 9px 11px;
  border: 1px solid rgba(63, 185, 80, 0.45);
  border-radius: var(--radius-sm);
  background: rgba(63, 185, 80, 0.08);
  color: var(--ok);
  font-size: 12px;
  line-height: 1.4;
}
.detail-view__download-status--error {
  border-color: rgba(248, 81, 73, 0.45);
  background: rgba(248, 81, 73, 0.08);
  color: var(--error);
}
.detail-view__danger { color: var(--error); border-color: rgba(248,81,73,0.4); }
.detail-view__convert { flex: 1 0 100%; }
.detail-view__code {
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  max-height: 360px;
  overflow: auto;
  white-space: pre;
  margin: 0;
}
.new-view__sub {
  font-size: 13px;
  color: var(--fg-mute);
}

/* ---------- REVISION 3.2 AC-REV3.2-4a: new-indicator picker ---------- */
.new-catalog-error {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: rgba(248, 81, 73, 0.08);
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--error);
}
.new-catalog-error__icon { width: 72px; height: 72px; object-fit: contain; }
.new-catalog-error__content { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
.new-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.new-step__hint {
  font-size: 12px;
  color: var(--fg-mute);
}
.new-type-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.new-type-list__item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 20px;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 4px;
  padding: 8px 12px 8px 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--tap);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  transition: border-color 120ms, background-color 120ms, transform 120ms var(--easing);
}
.new-type-list__item-icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 64px;
  height: 64px;
  object-fit: contain;
}
.new-type-list__item:hover,
.new-type-list__item:focus {
  border-color: var(--accent);
  outline: none;
}
.new-type-list__item:active { transform: scale(0.99); }
.new-type-list__item--selected {
  border-color: var(--accent);
  background: rgba(46, 140, 240, 0.10);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.new-type-list__item-title {
  grid-column: 2;
  grid-row: 1;
  font-weight: 600;
  font-size: 15px;
}
.new-type-list__item-sub {
  grid-column: 2;
  grid-row: 2;
  font-size: 12px;
  color: var(--fg-mute);
  line-height: 1.4;
}
.new-type-list__item-check {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: transparent;
  font-size: 11px;
}
.new-type-list__item--selected .new-type-list__item-check {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}
.new-type-banner {
  min-height: 38px;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg);
}
.new-type-banner:empty {
  padding: 0;
  border-color: transparent;
  min-height: 0;
}
.new-mode-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.new-mode-selector__title {
  font-size: 12px;
  color: var(--fg-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.new-mode-selector__hint {
  margin: 0;
  font-size: 12px;
  color: var(--fg-mute);
}
.new-mode-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.new-mode-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--tap);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  transition: border-color 120ms, background-color 120ms;
}
.new-mode-option:hover,
.new-mode-option:focus {
  border-color: var(--accent);
  outline: none;
}
.new-mode-option--selected {
  border-color: var(--accent);
  background: rgba(46, 140, 240, 0.10);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.new-mode-option__title {
  font-weight: 600;
}
.new-mode-option__sub {
  font-size: 12px;
  color: var(--fg-mute);
}
.new-format-disclosure {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.new-format-disclosure__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--tap);
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
}
.new-format-disclosure__toggle:hover,
.new-format-disclosure__toggle:focus {
  border-color: var(--accent);
  outline: none;
}
.new-format-disclosure__caret {
  font-size: 10px;
  display: inline-block;
  transition: transform 120ms;
}
.new-format-disclosure__toggle[aria-expanded="true"] .new-format-disclosure__caret {
  transform: rotate(90deg);
}
.new-format-disclosure__panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.new-format-disclosure__hint {
  margin: 0;
  font-size: 12px;
  color: var(--fg-mute);
}
.new-status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--fg-mute);
}
.new-status-line__prefix { color: var(--fg-mute); }
.new-status-line__text { color: var(--fg); font-weight: 600; }
.new-status-line__sep { color: var(--fg-mute); }

/* REVISION 3.2 AC-REV3.2-4a attempt 2: dedicated step-2 inline error slot.
   Lives inside #newStepForm so it is always visible when the user is on
   step 2. We intentionally use the same visual language as the catalog
   error fallback so the user recognises "this is a server-side problem
   I should fix before submitting again". */
.new-form-error {
  padding: 10px 12px;
  background: rgba(248, 81, 73, 0.08);
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--error);
}
.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--fg);
}
.btn--ghost:hover { border-color: var(--accent); }
/* touch target minimum for the inline "Изменить тип" */
#newChangeTypeBtn { margin-left: auto; padding: 4px 10px; min-height: 32px; }


/* ---------- REVISION 2 §32 / §33: Safe areas + mobile-first 320-430 ---------- */
:root {
  /* Telegram WebView exposes --tg-viewport-stable-height / safe-area inset
     variables; we use CSS env() which falls back gracefully on Android. */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}
.layout {
  /* REVISION 2 §32: bottom actions (sticky to .final-actions / .error-state)
     don't crash into the system gesture area. */
  padding-bottom: max(12px, var(--safe-bottom));
  padding-top:    max(4px, var(--safe-top));
  padding-left:   max(8px, var(--safe-left));
  padding-right:  max(8px, var(--safe-right));
}
/* REVISION 2 §33: Mobile-first — no horizontal scroll on 320px, 340px, 360px,
   390px, 430px. We avoid min-width: 100vw and tight grid columns. */
.layout {
  /* Long words (paths, hashes) should not push us wider than the viewport. */
  overflow-x: hidden;
  word-break: break-word;
}
@media (max-width: 360px) {
  /* Narrowest viewport — drop Core to 150px so it fits with margin. */
  .indicator-core { width: 150px; height: 150px; }
  .stage-rail { padding: 8px; gap: 8px; }
  .stages { gap: 6px; }
  .stage__dot { width: 8px; height: 8px; flex-basis: 8px; }
}
@media (max-width: 340px) {
  /* Squeeze further: stage labels stay hidden, stage dots keep their slot. */
  .indicator-core { width: 140px; height: 140px; }
  .title { font-size: 15px; }
  .activity__copy { font-size: 13px; }
}
@media (max-width: 320px) {
  .indicator-core { width: 130px; height: 130px; }
  .stage-rail { padding: 6px; }
}

/* REVISION 3 AC-REV3-13: bottom-sheet modal for delete confirmation. */
.bottom-sheet { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.bottom-sheet[hidden] { display: none !important; }
.bottom-sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.bottom-sheet__panel {
  position: relative; width: 100%; max-width: 480px;
  background: var(--tg-theme-bg-color, #0d1117);
  color: var(--tg-theme-text-color, #f0f6fc);
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  padding: 20px 16px 28px; box-shadow: 0 -8px 32px rgba(0,0,0,0.45);
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.bottom-sheet__title { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.bottom-sheet__icon { display: block; width: 88px; height: 88px; object-fit: contain; margin: -6px auto 4px; }
.bottom-sheet__body { font-size: 14px; opacity: 0.85; margin-bottom: 20px; line-height: 1.45; }
.bottom-sheet__actions { display: flex; gap: 8px; }
.bottom-sheet__actions .btn { flex: 1; }
.bottom-sheet__actions--stack { flex-direction: column; }
.bottom-sheet__actions--stack .btn { width: 100%; }
.btn--danger { background: #b62324; color: #fff; border: none; }
.btn--danger:hover { background: #a01d1e; }
.btn--danger:active { background: #8a1819; }
/* Release notice stays in flow: no overlay over the editor or mobile keyboard. */
.release-banner {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 101;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--tg-bg-elev);
  color: var(--tg-fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.release-banner[hidden] { display: none; }
.release-banner__copy { display: grid; gap: 3px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.release-banner__copy strong { font-weight: 600; }
.release-banner__copy span { font-size: 12px; line-height: 1.35; }
.release-banner .btn { flex: 0 0 auto; min-height: 44px; padding: 8px 12px; }
@media (max-width: 360px) {
  .release-banner { gap: 8px; padding: 8px; flex-wrap: wrap; }
  .release-banner__copy { flex-basis: 180px; }
}

/* ===== Blueprint structure view (M6-L2, read-only) ===== */
.bp-structure__head { margin: 0 0 6px; }
.bp-structure__title { margin: 0; font-size: 17px; }
.bp-structure__meta { margin: 2px 0 8px; font-size: 12px; opacity: .75; }
.bp-structure__badges { display: flex; gap: 6px; margin: 0 0 10px; }
.bp-badge { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.bp-badge--research { background: rgba(88, 166, 255, .16); color: #58a6ff; }
.bp-badge--nolive { background: rgba(248, 81, 73, .14); color: #f85149; }
.bp-structure__nodes { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bp-node { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; padding: 8px 10px; border: 1px solid rgba(255,255,255,.09); border-radius: 10px; }
.bp-node__dot { width: 8px; height: 8px; border-radius: 50%; align-self: center; background: #8b949e; }
.bp-node__dot--context { background: #58a6ff; }
.bp-node__dot--gate { background: #d29922; }
.bp-node__dot--presentation { background: #3fb950; }
.bp-node__dot--composer, .bp-node__dot--source { background: #bc8cff; }
.bp-node__name { font-weight: 600; }
.bp-node__def { font-size: 11px; opacity: .7; word-break: break-all; }
.bp-node__params { list-style: none; margin: 2px 0 0; padding: 0 0 0 14px; font-size: 11px; opacity: .8; width: 100%; }
.bp-structure__edges { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 12px; opacity: .85; }
.bp-edge { font-family: var(--font-mono, monospace); }
.bp-view { padding: 12px 14px 24px; }
.bp-view__back { margin-bottom: 10px; background: none; border: none; color: var(--accent, #58a6ff); font-size: 13px; cursor: pointer; padding: 4px 0; }
.bp-structure { display: block; }
.list-view__blueprints { margin-top: 18px; }
.list-view__blueprints-hint { font-size: 11px; opacity: .6; margin: -2px 0 8px; }
.list-view__subhead { font-size: 13px; opacity: .8; margin: 0 0 8px; }

/* ===== Blueprint Interactive Diagram (M6-L2 v2) ===== */
.bp-diagram-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.bp-diagram { display: block; touch-action: pan-x pan-y; }
.bp-diagram__node { transition: opacity 0.2s; }
.bp-diagram__node--selected rect { stroke-width: 3; filter: brightness(1.3); }
.bp-diagram__node--dimmed { opacity: 0.3; }
.bp-diagram__edge { transition: opacity 0.2s, stroke-width 0.2s; opacity: 0.7; }
.bp-diagram__edge--highlight { stroke-width: 3.5 !important; opacity: 1 !important; filter: brightness(1.4); }
.bp-diagram__edge--dimmed { opacity: 0.08 !important; }

/* ===== M9: графический редактор схемы (чертёж = промпт) ===== */
.bp-edit { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.bp-edit__hint { flex: 1; min-width: 140px; font-size: 11px; opacity: .65; }
.bp-sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.bp-sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.bp-sheet__panel {
  position: relative; width: 100%; padding: 16px 14px calc(14px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0; background: var(--tg-theme-secondary-bg-color, #232e3c);
  display: flex; flex-direction: column; gap: 10px;
}
.bp-sheet__title { margin: 0; font-size: 16px; }
.bp-sheet__meta { margin: 0; font-size: 12px; opacity: .7; }
.bp-sheet__desc { margin: 0; font-size: 13px; line-height: 1.5; color: var(--tg-theme-text-color, #e6edf3); opacity: .92; }
.bp-sheet__row { display: flex; gap: 8px; flex-wrap: wrap; }
.bp-sheet__row .btn { flex: 1; min-width: 100px; }
.bp-sheet__danger { color: #f85149; }
.bp-sheet__field textarea { width: 100%; box-sizing: border-box; }
.bp-sheet__kinds { display: flex; gap: 6px; flex-wrap: wrap; }
.bp-kind-chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--tg-theme-hint-color, #708499);
  background: transparent; color: inherit; font-size: 12px; cursor: pointer;
}
.bp-kind-chip.is-active { border-width: 2px; border-color: #58a6ff; background: rgba(88,166,255,.12); }
