/* Fuentes auto-alojadas (sin peticiones a terceros) */
@font-face { font-family: "Archivo"; src: url("/fonts/archivo.woff2") format("woff2"); font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/plex-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/plex-sans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/plex-sans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/plex-sans-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/plex-mono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/plex-mono-500.woff2") format("woff2"); font-weight: 500 600; font-display: swap; }

/* Layout: taller de máquinas — barra lateral fija + lienzo central con un "eje" vertical que une los pasos.
   Color: verde máquina (el engranaje del logo, #2E5B4C) + ámbar (la cola del logo, #E39A1D) como acento.
   --accent es el ámbar exacto del logo (fondos de botones, marcas); --brass es su tono oscuro para texto e iconos
   sobre claro (contraste 5,7:1). Sobre el ámbar el texto va en verde casi negro (--on-accent): en blanco no se leería. */
:root {
  --bg: #ECEFEA;
  --surface: #FFFFFF;
  --surface-2: #F5F7F3;
  --ink: #161A17;
  --muted: #5B645E;
  --faint: #8A938C;
  --line: #D3D9D1;
  --line-strong: #B9C2B8;
  --machine: #2E5B4C;
  --machine-hover: #24493D;
  --on-machine: #FFFFFF;
  --machine-soft: #DCE8E1;
  --accent: #E39A1D;
  --accent-hover: #C98819;
  --on-accent: #12261E;
  --accent-soft: #F9EBD2;
  --accent-mark: #E39A1D;
  --band: #2E5B4C;      /* franja final de la web: verde de marca también en modo oscuro (con el botón ámbar encima) */
  --on-band: #FFFFFF;
  --brass: #8B5E11;
  --brass-soft: #F9EBD2;
  --on-brass: #FFFFFF;
  --ok: #2B7A4B;
  --ok-soft: #DDF0E3;
  --warn: #9A6A12;
  --warn-soft: #F6EBD2;
  --err: #B0291F;
  --err-soft: #F7DEDB;
  --shadow: 0 1px 2px rgb(22 26 23 / 0.06), 0 6px 20px rgb(22 26 23 / 0.06);
  --font-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
  --radius-sm: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1311; --surface: #161B18; --surface-2: #1C221E; --ink: #E5EBE6; --muted: #9DA8A0; --faint: #6F7A72;
    --line: #29312C; --line-strong: #3A443D; --machine: #79B89B; --machine-hover: #8FC9AE; --on-machine: #0C1712; --machine-soft: #1F3329;
    --accent: #E39A1D; --accent-hover: #E7A83D; --on-accent: #12261E; --accent-soft: #3A2E18; --accent-mark: #E39A1D; --mark-top: 86%; --mark-bottom: 97%;
    --brass: #D9A64C; --brass-soft: #3A2E18; --on-brass: #1C1508; --ok: #6CC793; --ok-soft: #173326; --warn: #E0B357; --warn-soft: #3A2E14;
    --err: #F08A80; --err-soft: #3D1C19; --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
  /* El logo tiene zonas transparentes y verde oscuro: sobre fondo oscuro va en una placa clara para que se vea igual. */
  :root:not([data-theme="light"]) .brand-mark { background: #F5F7F3; border-radius: 8px; padding: 2px 3px; }
}
:root[data-theme="dark"] {
  --bg: #0F1311; --surface: #161B18; --surface-2: #1C221E; --ink: #E5EBE6; --muted: #9DA8A0; --faint: #6F7A72;
  --line: #29312C; --line-strong: #3A443D; --machine: #79B89B; --machine-hover: #8FC9AE; --on-machine: #0C1712; --machine-soft: #1F3329;
  --accent: #E39A1D; --accent-hover: #E7A83D; --on-accent: #12261E; --accent-soft: #3A2E18; --accent-mark: #E39A1D; --mark-top: 86%; --mark-bottom: 97%;
  --brass: #D9A64C; --brass-soft: #3A2E18; --on-brass: #1C1508; --ok: #6CC793; --ok-soft: #173326; --warn: #E0B357; --warn-soft: #3A2E14;
  --err: #F08A80; --err-soft: #3D1C19; --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}
:root[data-theme="dark"] .brand-mark { background: #F5F7F3; border-radius: 8px; padding: 2px 3px; }

html, body { min-height: 100%; }
body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--machine); }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; height: 100vh;
  padding-block: 20px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: 16px;
  border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 20px; background: var(--surface-2);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark { height: 34px; width: auto; flex: 0 0 auto; display: block; }
.brand-name { font-family: var(--font-display); font-stretch: 125%; font-weight: 800; font-size: 21px; letter-spacing: -0.01em; }
.brand-tag { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.nav { display: grid; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; text-align: left; color: var(--muted); font-weight: 500;
}
.nav button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav button:hover { background: var(--surface); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--machine-soft); color: var(--machine); font-weight: 600; }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.saving-card { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px; }
.saving-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.saving-card .big { font-family: var(--font-display); font-stretch: 112%; font-weight: 750; font-size: 24px; }
.saving-card small { color: var(--muted); font-size: 12px; }

.main { min-width: 0; padding-block: 24px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.main-inner { max-width: 1180px; margin: 0 auto; display: grid; gap: 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.eyebrow { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-size: clamp(26px, 3.2vw, 36px); font-stretch: 118%; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }
h2 { font-size: 19px; font-stretch: 110%; font-weight: 750; letter-spacing: -0.01em; }
h3 { font-size: 16px; font-stretch: 105%; font-weight: 700; }
.lede { color: var(--muted); max-width: 62ch; margin: 6px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--machine); border-color: var(--machine); color: var(--on-machine); }
.btn-primary:hover { background: var(--machine-hover); border-color: var(--machine-hover); }
.btn-brass { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-brass:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-danger { color: var(--err); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.icon-btn svg { width: 17px; height: 17px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.err { color: var(--err); background: var(--err-soft); border-color: transparent; }
.chip.brass { color: var(--brass); background: var(--brass-soft); border-color: transparent; }
.chip.example { font-family: var(--font-mono); font-weight: 500; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

.app-tile { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; flex: 0 0 auto; background: var(--machine-soft); color: var(--machine); }
.app-tile svg { width: 17px; height: 17px; }
.app-tile.t-ai { background: var(--brass-soft); color: var(--brass); }
.app-tile.t-logic { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.app-stack { display: inline-flex; }
.app-stack .app-tile { width: 26px; height: 26px; border: 2px solid var(--surface); margin-left: -6px; }
.app-stack .app-tile:first-child { margin-left: 0; }
.app-stack .app-tile svg { width: 14px; height: 14px; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .2s; flex: 0 0 auto; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgb(0 0 0 / .25); }
.switch input:checked + .track { background: var(--machine); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ---------- Panel / dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .value { font-family: var(--font-display); font-stretch: 112%; font-weight: 750; font-size: 30px; line-height: 1.1; margin-top: 4px; }
.kpi .value small { font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .foot { font-size: 12px; color: var(--faint); margin-top: 4px; }

.ai-box { display: grid; gap: 12px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background:
  linear-gradient(var(--surface), var(--surface)) padding-box,
  repeating-linear-gradient(135deg, var(--line) 0 1px, transparent 1px 9px) border-box; }
.ai-box textarea { width: 100%; min-height: 84px; resize: vertical; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-2); }
.ai-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ai-suggest { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-suggest button { border: 1px dashed var(--line-strong); background: transparent; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--muted); }
.ai-suggest button:hover { color: var(--ink); border-color: var(--ink); }
.ai-status { font-size: 13px; color: var(--muted); }

.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.flow-list { display: grid; }
.flow-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.flow-row:last-child { border-bottom: 0; }
.flow-row .name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flow-row .name button { border: 0; background: none; padding: 0; font-weight: 600; text-align: left; }
.flow-row .name button:hover { color: var(--machine); text-decoration: underline; text-underline-offset: 3px; }
.flow-row .meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin-top: 4px; flex-wrap: wrap; }
.flow-row .actions { display: flex; align-items: center; gap: 6px; }

.empty { padding: 28px 18px; text-align: center; color: var(--muted); display: grid; gap: 10px; justify-items: center; }

/* ---------- Templates (almacén) ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--muted); }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.tpl { display: grid; grid-template-rows: auto auto 1fr auto auto; gap: 10px; padding: 16px; }
.tpl .cat { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.tpl p { margin: 0; color: var(--muted); font-size: 14px; }
.tpl .facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.tpl .facts div { display: grid; gap: 2px; }
.tpl .facts span { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.tpl .facts strong { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tpl .steps-mini { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tpl .steps-mini .arrow { color: var(--faint); font-size: 12px; }
.tpl-actions { display: flex; gap: 8px; }

/* ---------- Editor ---------- */
.editor-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.name-input { flex: 1 1 260px; min-width: 0; border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm);
  font-family: var(--font-display); font-stretch: 112%; font-weight: 780; font-size: clamp(20px, 2.4vw, 26px); padding: 4px 8px; margin-left: -8px; }
.name-input:hover { border-color: var(--line); }
.name-input:focus { border-color: var(--line-strong); background: var(--surface); outline: none; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 18px; align-items: start; }
.rail-wrap { position: relative; padding: 8px 0 20px; }
.rail { position: relative; display: grid; gap: 0; max-width: 560px; margin: 0 auto; }
.rail::before { content: ""; position: absolute; left: 34px; top: 30px; bottom: 30px; width: 2px;
  background: repeating-linear-gradient(to bottom, var(--line-strong) 0 6px, transparent 6px 10px); }
.node {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; width: 100%;
  transition: border-color .15s, transform .15s;
}
.node:hover { border-color: var(--line-strong); }
.node[aria-pressed="true"] { border-color: var(--machine); box-shadow: 0 0 0 3px var(--machine-soft), var(--shadow); }
.node .app-tile { width: 42px; height: 42px; border-radius: 10px; }
.node .app-tile svg { width: 21px; height: 21px; }
.node .kind, .node .title, .node .summary { display: block; }
.node .kind { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.node .title { font-weight: 650; font-size: 15px; line-height: 1.25; }
.node .summary { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .state { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.node .state.ok { background: var(--ok-soft); color: var(--ok); }
.node .state.skip { background: var(--surface-2); color: var(--faint); border: 1px dashed var(--line-strong); }
.node .state.err { background: var(--err-soft); color: var(--err); }
.node .state.run { background: var(--brass-soft); color: var(--brass); }
.node.is-skipped { opacity: .55; }
.joint { position: relative; height: 44px; display: flex; align-items: center; }
.joint .gear { position: absolute; left: 25px; width: 20px; height: 20px; color: var(--line-strong); background: var(--bg); border-radius: 50%; }
.joint .add { position: absolute; left: 60px; height: 26px; padding: 0 10px; border-radius: 999px; border: 1px dashed var(--line-strong); background: var(--bg); color: var(--muted); font-size: 12.5px; opacity: 0; transition: opacity .15s; display: inline-flex; align-items: center; gap: 4px; }
.joint:hover .add, .joint .add:focus-visible, .rail.touch .joint .add { opacity: 1; }
.joint .add:hover { color: var(--machine); border-color: var(--machine); }
.joint .add svg { width: 13px; height: 13px; }
.end-cap { display: flex; align-items: center; gap: 10px; padding-left: 16px; color: var(--faint); font-size: 13px; }
.end-cap .dot { width: 38px; height: 38px; border-radius: 50%; border: 2px dashed var(--line-strong); display: grid; place-items: center; background: var(--bg); }
.end-cap .dot svg { width: 16px; height: 16px; }
.add-last { margin: 8px 0 0 0; }
.token-runner { position: absolute; left: 22px; width: 26px; height: 26px; color: var(--brass); z-index: 3; pointer-events: none; transition: top .38s cubic-bezier(.5,0,.3,1); display: none; }
.token-runner.on { display: block; }
.token-runner svg { width: 26px; height: 26px; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .token-runner svg { animation: none; } .token-runner { transition: none; } }

.inspector { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); max-height: calc(100vh - 32px); overflow: auto; }
.insp-head { display: flex; gap: 12px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.insp-head .app-tile { width: 40px; height: 40px; }
.insp-body { padding: 16px 18px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > label, .field .flabel { font-size: 13px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 10px; background: var(--surface); min-width: 0;
}
.field textarea { min-height: 92px; resize: vertical; font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }
.field input.mono-in { font-family: var(--font-mono); font-size: 13px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--machine); outline: 2px solid var(--machine-soft); outline-offset: 0; }
.preview { font-size: 12.5px; background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 8px 10px; white-space: pre-wrap; word-break: break-word; color: var(--muted); }
.preview b { color: var(--ink); font-weight: 600; }
.test-log .preview, .field .preview { max-height: 260px; overflow: auto; }
.preview .miss { color: var(--err); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vars { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.vars-title { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.var-group { display: grid; gap: 4px; }
.var-group .g { font-size: 11px; font-family: var(--font-mono); color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.var-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.var-chips button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 5px; padding: 2px 7px; font-size: 12px; }
.var-chips button:hover { border-color: var(--machine); color: var(--machine); }
.insp-foot { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.test-log { display: grid; gap: 8px; }
.log-item { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.log-item summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 10px; font-size: 13px; }
.log-item summary::-webkit-details-marker { display: none; }
.log-item pre { margin: 0; padding: 10px; background: var(--surface-2); border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; }
.msg-card { margin: 0; padding: 10px 12px; background: var(--surface-2); border-top: 1px solid var(--line); font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.msg-card .to { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); margin-bottom: 6px; display: block; }
.notice { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
.notice svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; color: var(--brass); }

/* ---------- History ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }

/* ---------- ROI calculator ---------- */
.calc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.calc-form { display: grid; gap: 14px; }
.result-big { font-family: var(--font-display); font-stretch: 118%; font-weight: 800; font-size: clamp(34px, 5vw, 52px); line-height: 1; letter-spacing: -0.02em; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.result-grid div { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.result-grid span { display: block; font-size: 12px; color: var(--muted); }
.result-grid strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.bars { display: grid; gap: 10px; margin-top: 6px; }
.bar { display: grid; grid-template-columns: 120px minmax(0, 1fr) 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { height: 14px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar .fill { height: 100%; background: var(--line-strong); border-radius: 3px; }
.bar .fill.good { background: var(--machine); }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Pricing ---------- */
.plans { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: stretch; }
.plan { padding: 20px; display: grid; gap: 14px; grid-template-rows: auto auto 1fr auto; }
.plan.featured { border: 2px solid var(--machine); position: relative; }
.plan.featured .ribbon { position: absolute; top: -11px; left: 18px; background: var(--machine); color: var(--on-machine); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; letter-spacing: .04em; text-transform: uppercase; }
.price { font-family: var(--font-display); font-stretch: 115%; font-weight: 800; font-size: 38px; line-height: 1; }
.price small { font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--muted); }
.plan ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; font-size: 14px; }
.plan li { display: flex; gap: 8px; align-items: flex-start; }
.plan li svg { width: 16px; height: 16px; color: var(--machine); flex: 0 0 auto; margin-top: 3px; }
.service { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 20px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ---------- Modal & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgb(10 14 12 / .5); display: grid; place-items: center; z-index: 50;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.modal { width: min(760px, 100%); max-height: 100%; overflow: auto; background: var(--surface); border-radius: 14px; border: 1px solid var(--line); box-shadow: 0 30px 80px rgb(0 0 0 / .3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 16px 18px; display: grid; gap: 14px; }
.pick-search { width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.pick-group { display: grid; gap: 8px; }
.pick-group h3 { font-size: 13px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 500; font-stretch: 100%; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.pick { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; text-align: left; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.pick:hover { border-color: var(--machine); }
.pick strong { display: block; font-size: 14px; }
.pick span { display: block; font-size: 12px; color: var(--muted); }
.field textarea.code-box, .code-box { width: 100%; min-height: 280px; font-family: var(--font-mono); font-size: 12px; line-height: 1.45; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-2); resize: vertical; white-space: pre; overflow: auto; }
.steps-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.confirm-inline { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }

/* ---------- Mobile nav ---------- */
.bottom-nav { display: none; }
@media (max-width: 1020px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; max-height: none; }
  .two-col, .calc { grid-template-columns: minmax(0, 1fr); }
  .plans { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding-block: 16px calc(84px + env(safe-area-inset-bottom, 0px)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .bottom-nav button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; color: var(--muted); border-radius: 8px; }
  .bottom-nav button svg { width: 20px; height: 20px; }
  .bottom-nav button[aria-current="page"] { color: var(--machine); font-weight: 600; background: var(--machine-soft); }
  .mobile-brand { display: flex !important; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .row-2, .result-grid { grid-template-columns: minmax(0, 1fr); }
  .service { grid-template-columns: minmax(0, 1fr); }
  .bar { grid-template-columns: 90px minmax(0, 1fr) 76px; }
  .rail::before { left: 30px; }
  .joint .gear { left: 21px; }
  .joint .add { left: 52px; opacity: 1; }
  .token-runner { left: 18px; }
  .flow-row { grid-template-columns: minmax(0, 1fr); }
}
.mobile-brand { display: none; align-items: center; gap: 8px; }
.mobile-brand .brand-mark { height: 28px; width: auto; }
.mobile-brand .brand-name { font-size: 18px; }

[hidden] { display: none !important; }
a.btn { text-decoration: none; }
