/* WIT Relay · consola. Solo composición: los componentes y tokens vienen de wit-ui.css. */

html, body { background: var(--ds-canvas); }
a { text-underline-offset: 2px; }
a.btn { text-decoration: none; }
code { font-size: .92em; }

.boot { min-height: 100vh; display: grid; place-items: center; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--ds-surface); border-right: 1px solid var(--ds-border-subtle);
  padding: 14px 12px 20px; display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; padding: 2px 6px; color: var(--ds-text); text-decoration: none; }
.brand-logo { height: 20px; width: auto; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group > .t-micro { padding: 0 8px 6px; color: var(--ds-text-muted); }
a.nav-link { text-decoration: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 6px; }
.side-foot .seg { align-self: flex-start; }
.who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.who .t-micro { color: var(--ds-text-muted); }
.who-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logout { align-self: flex-start; }

.main { padding-block: 22px 72px; padding-inline: 28px; min-width: 0; outline: none; }
.view { max-width: 1280px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .crumbs { display: none; }
.page-head p { color: var(--ds-text-secondary); margin-top: 4px; max-width: 72ch; font-size: 13.5px; }
.page-head h1 { text-wrap: balance; }
.title-id { font-size: 19px; font-weight: 500; }
.page-actions { justify-content: flex-end; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.login .brand { padding: 0; }
.login h1 { margin-bottom: 4px; }
.login .btn-lg { width: 100%; }
.login-sep { display: flex; align-items: center; gap: 10px; color: var(--ds-text-muted); font-size: 12px; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; height: 1px; background: var(--ds-border-subtle); }
.login details summary { cursor: pointer; color: var(--ds-text-secondary); }
.login pre.code { white-space: pre-wrap; word-break: break-all; }

/* ---------- piezas comunes ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpis > .empty { grid-column: 1 / -1; }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .t-micro { color: var(--ds-text-muted); letter-spacing: .05em; }
.kpi .v { font: 600 24px/1.15 var(--ds-font-display); font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--ds-text-muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px var(--ds-card-p); border-bottom: 1px solid var(--ds-border-subtle); }
.toolbar .input-group { flex: 1 1 220px; max-width: 340px; }
.toolbar .chips { gap: 6px; }
.toolbar-2 { padding-top: 0; border-bottom: 1px solid var(--ds-border-subtle); }
.toolbar + .toolbar-2 { padding-top: 0; }
.toolbar:has(+ .toolbar-2) { border-bottom: 0; }
.sel-auto { width: auto; min-width: 150px; max-width: 240px; }
.card .empty { border: 0; background: transparent; }
.empty-text { max-width: 58ch; margin-top: 4px; }

table.ds td .sub { display: block; font-size: 11.5px; color: var(--ds-text-muted); }
table.ds td b { font-weight: 500; }
table.ds tbody tr.link { cursor: pointer; }
table.ds td a { text-decoration: none; }
table.ds td a:hover { text-decoration: underline; }
table.ds td.wrap { white-space: normal; max-width: 420px; }
table.ds td .actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: nowrap; }
td.nowrap, th.nowrap, table.ds td.num { white-space: nowrap; }
.mono { font-family: var(--ds-font-data); font-size: 12px; }
.prov { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; white-space: nowrap; }
.prov i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.prov.an i { background: #C9785A; } .prov.oa i { background: var(--ds-text-secondary); } .prov.ge i { background: #4C8DF6; } .prov.fk i { background: var(--ds-border-strong); }
.fmt { font: 500 11px var(--ds-font-data); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--ds-border); color: var(--ds-text-secondary); background: var(--ds-surface-2); white-space: nowrap; }
.chain { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12px; color: var(--ds-text-muted); }
.chain b { font-weight: 500; color: var(--ds-text-secondary); }
.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert a { color: inherit; font-weight: 500; }
.alert-spin::before {
  content: ""; width: 14px; height: 14px; flex: none; margin-top: 2px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: ds-spin .7s linear infinite;
}

/* ---------- editor + vista previa ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 20px; align-items: start; }
.preview { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 32px); overflow-y: auto; padding-bottom: 2px; }
.form-card .card-p { display: flex; flex-direction: column; gap: 14px; }
.f2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.f3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 14px; }
.hint-map { font: 11.5px/1.5 var(--ds-font-data); color: var(--ds-text-muted); }
.hint-map b { color: var(--ds-info-text); font-weight: 500; }
.hint-warn { color: var(--ds-warn-text); }
.hint-danger, table.ds td .sub.hint-danger { color: var(--ds-danger-text); }
.field > .seg, .card-p > .seg { align-self: flex-start; max-width: 100%; }
.seg-wrap { flex-wrap: wrap; align-self: flex-start; max-width: 100%; }
.tool-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--ds-border-subtle); }
.tool-row:first-child { border-top: 0; padding-top: 0; }
.tool-row b { font-size: 13px; font-weight: 500; display: block; }
.tool-row span { font-size: 12px; color: var(--ds-text-muted); }
.fb-list { display: flex; flex-direction: column; gap: 6px; }
.fb-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-r-control); background: var(--ds-surface-2); }
.fb-row .ord, .ord { font: 600 12px var(--ds-font-data); color: var(--ds-text-muted); text-align: center; }
.fb-row .m { font-size: 13px; min-width: 0; }
.fb-row .sub { display: block; font-size: 11.5px; color: var(--ds-text-muted); margin-top: 2px; }
.fb-fields { display: grid; grid-template-columns: 130px minmax(0, 1fr) 170px; gap: 8px; min-width: 0; }
.fb-fields .sub { grid-column: 1 / -1; }
.fb-actions { display: flex; gap: 2px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check input:disabled + span, .check:has(input:disabled) { color: var(--ds-text-muted); cursor: not-allowed; }
.textarea.code, textarea.code { font-family: var(--ds-font-data); font-size: 12.5px; line-height: 1.55; min-height: 120px; tab-size: 2; }
.select-sm { height: var(--ds-h-sm); font-size: 12px; width: auto; max-width: 260px; }
.input.file { padding: 4px 6px; height: auto; min-height: var(--ds-h-md); }

.frows { display: flex; flex-direction: column; gap: 6px; }
.frow { display: grid; grid-template-columns: minmax(110px, 1.1fr) 116px 92px minmax(110px, 1fr) 32px; gap: 8px; align-items: center; }
.frow.fhead { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ds-text-muted); }
.frow .check { justify-content: center; }
.frow-err { margin-top: -2px; }

pre.code {
  margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--ds-code-bg);
  border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-r-control);
  font: 12px/1.6 var(--ds-font-data); color: var(--ds-text); tab-size: 2;
}
pre.code.wrap { white-space: pre-wrap; word-break: break-word; }
pre.code.tall { max-height: 460px; overflow: auto; }
pre.code.mid { max-height: 300px; overflow: auto; }
pre.code .k { color: var(--ds-info-text); }
pre.code .s { color: var(--ds-accent-text); }
pre.code .c { color: var(--ds-text-muted); font-style: italic; }
pre.code .h { color: var(--ds-warn-text); }
pre.code .n { color: var(--ds-info-text); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.code-head .t-label { color: var(--ds-text-secondary); }
details > summary { cursor: pointer; }
details.plain > summary { color: var(--ds-text-secondary); font-size: 12px; font-weight: 500; padding: 2px 0; }
details.plain[open] > summary { margin-bottom: 8px; }

.chain-step { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-top: 1px solid var(--ds-border-subtle); }
.chain-step:first-child { border-top: 0; padding-top: 0; }
.chain-step:last-child { padding-bottom: 0; }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 8px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--ds-text-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.line-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.line-item .secondary { min-width: 0; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-r-control); background: var(--ds-surface-2); font-size: 13px; }
.file-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-row .name .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.markers { display: flex; flex-wrap: wrap; gap: 6px; }
.marker { font: 11.5px var(--ds-font-data); padding: 2px 7px; border-radius: 4px; background: var(--ds-surface-3); color: var(--ds-text-secondary); }
.marker em { font-style: normal; color: var(--ds-text-muted); }

/* ---------- timeline de una ejecución ---------- */
.tl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl li { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 12px; padding-bottom: 16px; position: relative; }
.tl li::before { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 1.5px; background: var(--ds-border); }
.tl li:last-child { padding-bottom: 0; }
.tl li:last-child::before { display: none; }
.tl .dot { width: 12px; height: 12px; margin-top: 3px; border-radius: 50%; border: 2px solid var(--ds-border-strong); background: var(--ds-surface); position: relative; z-index: 1; }
.tl .dot.ok { background: var(--ds-ok); border-color: var(--ds-ok); }
.tl .dot.warn { background: transparent; border-color: var(--ds-warn); }
.tl .dot.danger { background: var(--ds-danger); border-color: var(--ds-danger); }
.tl .dot.live { border-color: var(--ds-info); border-right-color: transparent; animation: ds-spin .8s linear infinite; }
.tl .tl-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 500; }
.tl .tl-sub { display: block; font-size: 12px; color: var(--ds-text-muted); margin-top: 2px; }
.tl .tl-detail { display: block; font-size: 12px; color: var(--ds-text-secondary); margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tl time, .tl .tl-right { font: 11.5px var(--ds-font-data); color: var(--ds-text-muted); white-space: nowrap; text-align: right; }

/* ---------- pipeline ---------- */
.pipe-wrap { overflow-x: auto; }
.pipe { display: grid; grid-template-columns: minmax(170px, .9fr) 48px minmax(200px, 1fr) minmax(0, 1.6fr); align-items: center; min-width: 780px; }
.pipe .step { padding: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pipe .step a { text-decoration: none; }
.pipe .step a:hover { text-decoration: underline; }
.pipe .step .t-micro { color: var(--ds-text-muted); letter-spacing: .05em; }
.pipe .conn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--ds-border-strong); }
.pipe .conn svg { width: 40px; height: 14px; }
.pipe .conn span { font-size: 10.5px; font-weight: 600; text-align: center; line-height: 1.25; }
.pipe .conn.ok { color: var(--ds-ok); } .pipe .conn.ok span { color: var(--ds-ok-text); }
.pipe .conn.bad { color: var(--ds-danger); } .pipe .conn.bad span { color: var(--ds-danger-text); }
.pipe-fns { display: flex; flex-direction: column; gap: 10px; }
/* Pipeline de varios pasos: una fila de tarjetas en orden, con scroll horizontal si no entra */
.pipe.pipe-multi { display: flex; align-items: stretch; min-width: 0; }
.pipe.pipe-multi > .step { flex: 0 0 230px; }
.pipe.pipe-multi > .conn { flex: 0 0 44px; }
.pipe.pipe-multi pre.code { font-size: 11.5px; margin: 0; }
.pipe-fn { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; }

/* ---------- barras de costo ---------- */
.cost-bars { display: flex; flex-direction: column; gap: 10px; }
.cb-row { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 96px; gap: 12px; align-items: center; font-size: 13px; }
.cb-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-track { height: 14px; background: var(--ds-surface-2); border-radius: 3px; overflow: hidden; }
.cb-track i { display: block; height: 100%; background: var(--ds-accent-solid); border-radius: 3px; min-width: 2px; }
.cb-row .num { font-family: var(--ds-font-data); font-size: 12.5px; text-align: right; }

/* ---------- toasts y diálogos ---------- */
.toast { flex-wrap: nowrap; }
.toast-title { font-weight: 600; }
.toast-text { color: var(--ds-text-secondary); margin-top: 2px; overflow-wrap: anywhere; }
.toast-fix { color: var(--ds-text-muted); margin-top: 4px; font-size: 12px; overflow-wrap: anywhere; }
dialog.ds-modal.wide { width: min(560px, calc(100vw - 32px)); }
dialog.ds-modal .modal-body { display: flex; flex-direction: column; gap: 12px; }
dialog.ds-modal .modal-body .field-label { color: var(--ds-text-secondary); }
.secret { display: flex; gap: 8px; align-items: stretch; }
.secret pre.code { flex: 1; white-space: pre-wrap; word-break: break-all; user-select: all; }

.tabs-sm .tab { padding: 5px 10px; font-size: 12px; }

/* ---------- editor de microservicios ---------- */
.view.view-wide { max-width: none; }
.ide { display: grid; grid-template-columns: 230px minmax(0, 1fr) minmax(0, 380px); gap: 16px; align-items: start; }
.ide-files { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.ide-file {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 7px 12px; border: 0; border-left: 2px solid transparent;
  background: none; text-align: left; font-size: 12.5px; color: var(--ds-text-secondary); cursor: pointer;
}
.ide-file:hover { background: var(--ds-surface-2); color: var(--ds-text); }
.ide-file[aria-current="true"] { background: var(--ds-accent-soft); color: var(--ds-text); border-left-color: var(--ds-accent-solid); }
.ide-file:focus-visible { outline: 2px solid var(--ds-accent-solid); outline-offset: -2px; }
.ide-file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ide-file .role { flex: none; font: 10.5px var(--ds-font-ui); color: var(--ds-text-muted); text-transform: lowercase; }
.ide-file .dirty { flex: none; color: var(--ds-warn-text); font-size: 10px; }
.ide-main { min-width: 0; }
.ide-main .card-head { flex-wrap: wrap; }
.ide-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.ide-test { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.ide-textarea { width: 100%; min-height: 520px; border: 0; border-radius: 0; resize: vertical; }
.ide-img { max-width: 100%; max-height: 420px; object-fit: contain; border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-r-control); background: var(--ds-surface-2); }
.ide-markers { border-top: 1px solid var(--ds-border-subtle); }
.plain-list { margin: 4px 0 0; padding-left: 18px; }
.plain-list li + li { margin-top: 2px; }

/* CodeMirror con los tokens de wit-ui (claro y oscuro salen de las mismas variables) */
.ide-main .CodeMirror {
  height: calc(100vh - 290px); min-height: 460px; font: 12.5px/1.55 var(--ds-font-data);
  background: var(--ds-code-bg); color: var(--ds-text); border-radius: 0 0 var(--ds-r-card) var(--ds-r-card);
}
.cm-s-relay .CodeMirror-gutters { background: var(--ds-surface-2); border-right: 1px solid var(--ds-border-subtle); }
.cm-s-relay .CodeMirror-linenumber { color: var(--ds-text-muted); }
.cm-s-relay .CodeMirror-cursor { border-left-color: var(--ds-text); }
.cm-s-relay .CodeMirror-activeline-background { background: var(--ds-surface-2); }
.cm-s-relay .CodeMirror-selected, .cm-s-relay.CodeMirror-focused .CodeMirror-selected { background: var(--ds-accent-soft); }
.cm-s-relay .CodeMirror-matchingbracket { color: var(--ds-accent-text) !important; text-decoration: underline; }
.cm-s-relay .cm-keyword, .cm-s-relay .cm-tag, .cm-s-relay .cm-builtin { color: var(--ds-info-text); }
.cm-s-relay .cm-string, .cm-s-relay .cm-string-2 { color: var(--ds-accent-text); }
.cm-s-relay .cm-comment { color: var(--ds-text-muted); font-style: italic; }
.cm-s-relay .cm-number, .cm-s-relay .cm-attribute, .cm-s-relay .cm-atom { color: var(--ds-warn-text); }
.cm-s-relay .cm-def, .cm-s-relay .cm-header { color: var(--ds-text); font-weight: 600; }
.cm-s-relay .cm-variable-2, .cm-s-relay .cm-property { color: var(--ds-text-secondary); }
.cm-s-relay .cm-error { color: var(--ds-danger-text); }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .ide { grid-template-columns: 210px minmax(0, 1fr); }
  .ide-test { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 1120px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 860px) {
  .ide { grid-template-columns: minmax(0, 1fr); }
  .ide-files { position: static; max-height: 240px; }
  .ide-main .CodeMirror { height: 60vh; min-height: 320px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 12px;
    overflow-x: auto; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--ds-border-subtle);
    scrollbar-width: thin;
  }
  .nav-group > .t-micro, .nav-link .n, .who { display: none; }
  .nav-group { flex-direction: row; gap: 2px; flex: none; }
  .nav-link { white-space: nowrap; width: auto; }
  .side-foot { flex-direction: row; align-items: center; margin-top: 0; padding: 0; flex: none; }
  .main { padding-inline: 16px; padding-block: 18px 56px; }
  .cb-row { grid-template-columns: minmax(0, 1fr) 84px; }
  .cb-row .cb-track { grid-column: 1 / -1; grid-row: 2; }
  .frow { grid-template-columns: minmax(0, 1fr) 110px 32px; }
  .frow.fhead { display: none; }
  .frow [data-ff-del] { grid-column: 3; grid-row: 1; }
  .frow .f-req { grid-column: 1; grid-row: 2; justify-content: flex-start; }
  .frow .f-def { grid-column: 2 / 4; grid-row: 2; }
  .frow + .frow-err + .frow, .frow + .frow { margin-top: 6px; }
  .fb-fields { grid-template-columns: minmax(0, 1fr); }
  .pipe { grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 2px; }
  .pipe.pipe-multi { flex-direction: column; }
  .pipe.pipe-multi > .step, .pipe.pipe-multi > .conn { flex: none; }
  .pipe .conn { flex-direction: row; padding: 4px 0; }
  .pipe .conn svg { transform: rotate(90deg); width: 28px; }
  .pipe-fn { grid-template-columns: minmax(0, 1fr); }
  .toast-region { left: 16px; right: 16px; }
  .toast { min-width: 0; max-width: none; }
}
@media (max-width: 520px) {
  .page-actions { width: 100%; justify-content: flex-start; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .v { font-size: 20px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .sel-auto { flex: 1 1 140px; max-width: none; }
  .toolbar .input-group { max-width: none; }
  .login { padding: 22px 18px; }
  .fb-row { grid-template-columns: 18px minmax(0, 1fr); }
  .fb-row .fb-actions, .fb-row > .pill { grid-column: 2; justify-self: start; }
}
