/* Tokens copied from motor4/preview/estilos.css (UltraEngine2) and measured on the running
   preview: the same planes, seam, text and steel blue, so both tools read as one. */
@font-face { font-family: 'Geist'; src: url(/fuentes/geist.woff2) format('woff2-variations'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Geist'; src: url(/fuentes/geist-ext.woff2) format('woff2-variations'); font-weight: 100 900; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --hueco: #141414;           /* main area */
  --background: #202020;      /* bars */
  --card: #2b2b2b;            /* panel body */
  --grupo: #343434;           /* group inside a panel, popovers */
  --secondary: #1a1a1a;       /* sunken: fields */
  --border: #141414;          /* the near-black seam */
  --raya: #202020;            /* row separators inside */
  --foreground: #dedede;
  --muted-foreground: #949494;
  --accent: #404040;          /* hover */
  --elegido: #4b6a87;         /* steel blue: selected */
  --elegido-suave: #37495b;
  --primary: #a9c9ea;
  --destructive: hsl(4 62% 58%);
  --ok: oklch(72.3% 0.219 149.579);
  --carril: #272727;
  --carril-raya: #353535;
  --carril-elegido: #484848;
  --radius: 3px;
  --sans: "Geist", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; border-color: var(--border); }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--hueco); color: var(--foreground);
  font-family: var(--sans); font-size: 13px; line-height: 1.45;
  font-feature-settings: "cv01", "cv03"; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: hsl(0 0% 32%); border-radius: 12px; border: 4px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: hsl(0 0% 45%); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: var(--radius); color: rgb(222 222 222 / .8); transition: background-color .15s, color .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--accent); color: #fff; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
  background: var(--grupo); color: var(--foreground); font-size: 11.5px; white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-foreground); }
.pill.ok { background: var(--elegido); color: #fff; }
.pill.ok::before { background: #dedede; }
.pill.bad::before { background: var(--destructive); }
.ghost { color: var(--muted-foreground); font-size: 11px; border-radius: var(--radius); padding: 4px 10px; transition: background-color .15s; }
.ghost:hover { background: var(--accent); color: #fff; }

/* ── login ── */
body.login { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { display: flex; flex-direction: column; gap: 10px; width: min(300px, 100%); padding: 20px; background: var(--card); border: 1px solid var(--raya); border-radius: var(--radius); }
.login h1 { margin: 0 0 6px; font-size: 12px; font-weight: 400; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-foreground); }
.login img { display: none; }
.login input { height: 34px; padding: 0 10px; border-radius: var(--radius); font: 16px var(--sans); background: var(--secondary); border: 1px solid var(--border); color: var(--foreground); outline: none; }
.login input:focus { border-color: var(--primary); }
.login button { height: 32px; border-radius: var(--radius); background: var(--elegido); color: #fff; font-weight: 500; }
.login button:hover { filter: brightness(1.12); }
#e { color: var(--destructive); min-height: 1.45em; margin: 0; font-size: 12px; }

/* ── frame: rail + main, like the preview ── */
#app { display: flex; height: 100%; }
#drawer {
  display: flex; flex-direction: column; width: 232px; flex: none;
  background: var(--carril); border-right: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.carril-head { display: flex; height: 48px; flex: none; align-items: center; gap: 8px; padding: 0 8px; border-bottom: 1px solid var(--carril-raya); }
.brand { flex: 1; padding: 0 4px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-foreground); }
#list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.rail-title { margin: 12px 8px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-foreground); }
.sess {
  display: flex; width: 100%; align-items: center; gap: 10px; padding: 6px 8px; margin-bottom: 1px;
  border-radius: var(--radius); text-align: left; color: rgb(222 222 222 / .8); transition: background-color .15s, color .15s;
}
.sess:hover { background: var(--accent); color: #fff; }
.sess.on { background: var(--carril-elegido); color: #fff; }
.sess .txt { min-width: 0; flex: 1; }
.sess .name { display: block; font-size: 13px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .pie { display: block; font-size: 11px; line-height: 1.25; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess.on .pie { color: rgb(255 255 255 / .6); }
.sess.busy svg { color: var(--primary); animation: pulse 1s infinite alternate; }
.sess.waiting svg, .sess.waiting .pie { color: var(--destructive); }
#sub.waiting { color: var(--destructive); }
#screenBtn.asking { color: #fff; background: var(--destructive); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
.none { color: var(--muted-foreground); padding: 8px; margin: 0; }
.carril-foot { flex: none; border-top: 1px solid var(--carril-raya); padding: 6px; padding-bottom: calc(env(safe-area-inset-bottom) + 6px); }
#openPath {
  width: 100%; height: 30px; padding: 0 8px; border-radius: var(--radius); font: 12px var(--mono);
  background: var(--secondary); border: 1px solid var(--border); color: var(--foreground); outline: none;
}
#openPath:focus { border-color: var(--primary); }
#scrim { display: none; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.bar {
  display: flex; height: 48px; flex: none; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--raya); box-sizing: content-box; padding-top: env(safe-area-inset-top);
}
#main > .bar { padding-top: 0; }
.bar h1 { margin: 0; min-width: 0; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sub { flex: none; font: 12px var(--mono); color: var(--muted-foreground); white-space: nowrap; }
#sub.busy { color: var(--primary); }
.bar-right { margin-left: auto; display: flex; flex: none; align-items: center; gap: 8px; }
#menu { display: none; margin-left: -6px; }

/* ── thread ── */
#thread { flex: 1; overflow-y: auto; padding: 16px 16px 24px; overscroll-behavior: contain; }
.entries { display: flex; flex-direction: column; gap: 10px; max-width: 900px; margin: 0 auto; }
#empty, #agentEmpty { color: var(--muted-foreground); text-align: center; margin-top: 48px; }
#more, #agentMore { display: block; margin: 0 auto 12px; }
.entry { min-width: 0; }
.entry.user { align-self: flex-end; max-width: 88%; }
.entry.user .text {
  background: var(--elegido-suave); color: #fff; padding: 7px 11px; border-radius: var(--radius);
  white-space: pre-wrap; word-break: break-word;
}
.entry.user.pending { opacity: .55; }
.entry.user small { display: block; text-align: right; color: var(--muted-foreground); font-size: 11px; margin-top: 2px; }
.entry.system .text { color: var(--muted-foreground); font: 12px var(--mono); }
.entry.side { opacity: .7; border-left: 2px solid var(--carril-raya); padding-left: 10px; }
.text { word-break: break-word; }
.text > :first-child { margin-top: 0; }
.text > :last-child { margin-bottom: 0; }
.text p { margin: .45em 0; }
.text h1, .text h2, .text h3 { font-size: 13px; font-weight: 600; margin: .9em 0 .35em; }
.text h1 { font-size: 15px; }
.text ul, .text ol { padding-left: 20px; margin: .4em 0; }
.text pre, .text code { font-family: var(--mono); font-size: 12px; }
.text pre { background: var(--secondary); border: 1px solid var(--border); padding: 8px 10px; border-radius: var(--radius); overflow-x: auto; }
.text :not(pre) > code { background: var(--grupo); padding: 1px 4px; border-radius: var(--radius); }
.text table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 12px; margin: .5em 0; }
.text th, .text td { border: 1px solid var(--raya); padding: 4px 8px; text-align: left; }
.text th { background: var(--card); font-weight: 500; }
.text a { color: var(--primary); }
.text blockquote { margin: .45em 0; padding-left: 10px; border-left: 2px solid var(--carril-raya); color: var(--muted-foreground); }
.text hr { border: 0; border-top: 1px solid var(--raya); }

.think summary { color: var(--muted-foreground); font-size: 12px; cursor: pointer; list-style: none; }
.think summary::before { content: '› '; }
.think[open] summary::before { content: '⌄ '; }
.thinktext { color: var(--muted-foreground); font-style: italic; white-space: pre-wrap; font-size: 12px; margin-top: 4px; padding-left: 10px; border-left: 2px solid var(--carril-raya); }

.toolwrap { display: flex; flex-direction: column; gap: 6px; }
.tool { background: var(--card); border: 1px solid var(--raya); border-radius: var(--radius); }
.tool summary { display: flex; gap: 10px; align-items: center; padding: 8px 12px; cursor: pointer; list-style: none; }
.tool summary:hover { background: rgb(64 64 64 / .4); }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-foreground); }
.tool.done summary::before { background: #8d8d8d; }
.tool:not(.done) summary::before { background: var(--primary); animation: pulse 1s infinite alternate; }
.tool.err summary::before { background: var(--destructive); animation: none; }
.tool summary b { flex: none; font: 500 12px var(--mono); color: var(--foreground); }
.tool .sum { min-width: 0; flex: 1; font: 12px var(--mono); color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool pre { margin: 0; padding: 8px 12px; font: 11.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; border-top: 1px solid var(--raya); max-height: 60vh; overflow-y: auto; background: var(--secondary); }
.tool .input { color: var(--muted-foreground); }
.out.err pre { color: var(--destructive); }
.link { color: var(--primary); font-size: 11px; padding: 4px 12px 8px; }

.media { margin: 2px 0; }
.media img, .media video { display: block; max-width: 100%; max-height: 60vh; border-radius: var(--radius); background: #000; border: 1px solid var(--border); }
.media.big img, .media.big video { width: 100%; max-height: 80vh; object-fit: contain; }
.media audio { width: 100%; }
.vnote { font: 11px var(--mono); color: var(--primary); margin-top: 4px; }
.media figcaption { font: 11px var(--mono); color: var(--muted-foreground); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media .pdf { color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { height: 22px; padding: 0 9px; border-radius: 999px; background: var(--grupo); font: 11px var(--mono); color: var(--muted-foreground); }
.chip:hover { background: var(--accent); color: #fff; }

#toBottom { position: absolute; right: 16px; bottom: 76px; z-index: 5; width: 34px; height: 34px; background: var(--grupo); border: 1px solid var(--border); }

/* ── composer ── */
#composer {
  display: flex; gap: 8px; align-items: flex-end; flex: none;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--background); border-top: 1px solid var(--border);
}
#input {
  flex: 1; resize: none; min-height: 34px; max-height: 180px; padding: 8px 10px; border-radius: var(--radius);
  background: var(--secondary); color: var(--foreground); border: 1px solid var(--border); font: 13px/1.35 var(--sans); outline: none;
}
#input:focus { border-color: var(--primary); }
.send { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--elegido); color: #fff; flex: none; }
.send:hover { filter: brightness(1.12); }
.send:disabled { opacity: .5; }

/* ── terminal screen ── */
#screen { position: fixed; z-index: 30; inset: 0; background: var(--hueco); display: flex; flex-direction: column; }
#screen > .bar { background: var(--background); }
.key { min-width: 30px; height: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--grupo); font: 12px var(--mono); }
.key:hover { background: var(--accent); color: #fff; }
#screenText { flex: 1; margin: 0; padding: 12px 16px; overflow: auto; font: 11px/1.4 var(--mono); white-space: pre; }

#viewer { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / .94); display: flex; align-items: center; justify-content: center; }
#viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 64px); z-index: 50;
  max-width: calc(100% - 32px); background: var(--grupo); border: 1px solid var(--border); border-left: 3px solid var(--destructive);
  color: var(--foreground); padding: 8px 12px; border-radius: var(--radius);
}

/* ── phone: the rail becomes a drawer over the thread ── */
@media (max-width: 820px) {
  #drawer { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(300px, 86vw); box-shadow: 0 0 40px rgb(0 0 0 / .6); }
  #scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 19; background: rgb(0 0 0 / .5); }
  #menu { display: inline-flex; }
  #main > .bar { padding: env(safe-area-inset-top) 12px 0; background: var(--background); }
  #sub { display: none; }
  #thread { padding: 12px; }
  #input { font-size: 16px; }   /* below 16px iOS zooms the page on focus */
  .sess { padding: 9px 8px; }
}
@media (min-width: 821px) {
  #drawer[hidden] { display: flex !important; }
  #drawerClose { display: none; }
}

/* ── unread and attention ── */
.sess { position: relative; }
.sess.unread .name { color: #fff; font-weight: 600; }
.badge { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.sess.waiting .badge { background: var(--destructive); }
#menu.attn { position: relative; }
#menu.attn::after { content: ''; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
#agentsBtn { cursor: pointer; }
#agentsBtn.ok::before { background: #dedede; animation: pulse 1s infinite alternate; }

/* ── agents ── */
.agent-link { flex: none; margin-left: auto; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--elegido); color: #fff; font: 11px var(--sans); }
.agent-link:hover { filter: brightness(1.12); }
#agentPanel { position: fixed; z-index: 25; inset: 0; background: var(--hueco); display: flex; flex-direction: column; }
#agentPanel > .bar { background: var(--background); }
#agentSub { flex: none; font: 12px var(--mono); color: var(--muted-foreground); white-space: nowrap; }
#agentSub.busy { color: var(--primary); }
#agentList { flex: 1; overflow-y: auto; padding: 8px 12px; max-width: 900px; width: 100%; margin: 0 auto; }
#agentList .sess { background: var(--card); border: 1px solid var(--raya); margin-bottom: 4px; }
#agentList .sess:hover { background: var(--accent); }
#agentThread { flex: 1; overflow-y: auto; padding: 16px 16px 24px; overscroll-behavior: contain; }
@media (max-width: 820px) {
  #agentThread { padding: 12px; }
  #agentPanel > .bar { padding: env(safe-area-inset-top) 12px 0; }
  #agentsBtn:not(.ok) { display: none; }
}
#agentEntries .entry.side { opacity: 1; border-left: 0; padding-left: 0; }
