/* Consola nocturna: fondo grafito, acento verde fósforo para lo que hace el agente. Pensada primero para el celular. */
:root {
  --bg: #0e1116; --bg-2: #151a21; --bg-3: #1d242d; --line: #28313c;
  --fg: #e6edf3; --muted: #8b98a7; --accent: #63e6be; --accent-ink: #062b20;
  --bad: #ff7b72; --user: #1f3b5a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: .6rem 1rem; background: var(--bg-3); display: inline-flex; align-items: center; justify-content: center; gap: .35rem; touch-action: manipulation; }
button:disabled { opacity: .4; cursor: default; }
button svg { width: 18px; height: 18px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.danger { background: var(--bad); color: #2b0805; }
.ghost { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.sm { padding: .45rem .8rem; font-size: .88rem; }
.sm svg { width: 16px; height: 16px; }
.icon { width: 44px; height: 44px; padding: 0; background: transparent; color: var(--muted); border-radius: 12px; }
.icon svg { width: 22px; height: 22px; }
.icon:active { background: var(--bg-3); }
@media (hover: hover) { .icon:hover { background: var(--bg-3); color: var(--fg); } .primary:hover { filter: brightness(1.08); } }
.muted { color: var(--muted); }
code { font-family: var(--mono); font-size: .88em; background: var(--bg-3); padding: .1em .35em; border-radius: 5px; }
.prompt { font-family: var(--mono); color: var(--accent); font-weight: 700; }

/* ---------- Acceso ---------- */
.auth { min-height: 100%; display: grid; place-items: center; align-content: center; gap: 1.2rem; padding: calc(2rem + var(--sat)) max(16px, var(--sar)) calc(2rem + var(--sab)) max(16px, var(--sal)); }
.brand { font: 700 1.4rem var(--mono); letter-spacing: -.01em; }
.brand small { font: 500 .8rem var(--sans); color: var(--muted); margin-left: .3rem; }
.brand.sm { font-size: 1.05rem; }
.card { width: min(100%, 400px); display: grid; gap: .45rem; padding: 1.6rem; background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; }
.card h1 { margin: 0 0 .2rem; font-size: 1.3rem; }
.card p { margin: 0 0 .5rem; font-size: .92rem; }
.card label { font-size: .85rem; color: var(--muted); margin-top: .4rem; }
.card input { width: 100%; min-height: 50px; padding: .7rem .9rem; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.card input:focus { border-color: var(--accent); outline: none; }
.card input.otp { font: 600 1.4rem var(--mono); letter-spacing: .4em; text-align: center; }
.card button { margin-top: .9rem; min-height: 52px; font-size: 1rem; border-radius: 12px; }
.err { color: var(--bad); font-size: .9rem !important; margin: .4rem 0 0 !important; }
.qr { justify-self: center; width: 210px; height: 210px; border-radius: 12px; background: #fff; padding: 6px; }
.secret { text-align: center; font-size: .8rem !important; color: var(--muted); word-break: break-all; }

/* ---------- App ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 290px minmax(0, 1fr); overflow: hidden; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--bg-2); border-right: 1px solid var(--line); padding-top: var(--sat); padding-left: var(--sal); }
.side-h, .side-f { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .9rem 1rem; }
.side-f { border-top: 1px solid var(--line); padding-bottom: max(.9rem, var(--sab)); font-size: .85rem; }
.who { display: inline-flex; align-items: center; gap: .45rem; font: .8rem var(--mono); color: var(--muted); min-width: 0; }
.who .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.chats { list-style: none; margin: 0; padding: .25rem .5rem; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.chats li button { width: 100%; min-height: 48px; justify-content: flex-start; text-align: left; gap: .6rem; padding: .6rem .8rem; background: transparent; border-radius: 10px; color: var(--muted); font-size: .95rem; }
.chats li button span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chats li button.on { background: var(--bg-3); color: var(--fg); }
@media (hover: hover) { .chats li button:hover { background: var(--bg-3); color: var(--fg); } }
.chats .live { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; flex: none; }
.chats .none { padding: .9rem; color: var(--muted); font-size: .9rem; }
.chats .when { flex: none; font-size: .72rem; color: var(--muted); opacity: .8; }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; }
.bar { display: flex; align-items: center; gap: .25rem; padding: calc(.35rem + var(--sat)) max(.5rem, var(--sar)) .35rem max(.5rem, var(--sal)); border-bottom: 1px solid var(--line); background: var(--bg); }
.bar h1 { flex: 1; min-width: 0; margin: 0 .25rem; font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menu, #new2 { display: none; }
#del.armed { width: auto; padding: 0 .75rem; color: var(--bad); font-size: .85rem; font-weight: 600; }

.log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 1.1rem max(1rem, var(--sar)) 1.4rem max(1rem, var(--sal)); display: flex; flex-direction: column; gap: .85rem; -webkit-overflow-scrolling: touch; }
.log > * { width: 100%; max-width: 860px; margin-inline: auto; }
.empty { margin-block: auto; text-align: center; display: grid; gap: .45rem; justify-items: center; }
.empty h2 { margin: 0; font-size: 1.5rem; }
.empty p { margin: 0; max-width: 34em; }
.prompt.big { font-size: 2.4rem; margin: 0; }
.ideas { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: 1rem; }
.idea { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg); font-size: .92rem; text-align: left; min-height: 44px; border-radius: 14px; }
@media (hover: hover) { .idea:hover { border-color: var(--accent); } }

.msg-user .bubble { margin-left: auto; width: fit-content; max-width: min(88%, 680px); background: var(--user); padding: .65rem .95rem; border-radius: 18px 18px 6px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { line-height: 1.65; overflow-wrap: anywhere; }
.msg-ai .md > :first-child { margin-top: 0; } .msg-ai .md > :last-child { margin-bottom: 0; }
.msg-ai .md p, .msg-ai .md ul, .msg-ai .md ol { margin: .5em 0; }
.msg-ai .md ul, .msg-ai .md ol { padding-left: 1.3em; }
.msg-ai pre { position: relative; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; overflow-x: auto; font: .84rem/1.5 var(--mono); overflow-wrap: normal; }
.msg-ai pre code { background: none; padding: 0; }
.msg-ai pre .cp { position: absolute; top: .35rem; right: .35rem; width: 34px; height: 34px; padding: 0; background: var(--bg-3); color: var(--muted); opacity: .85; }
.msg-ai a { color: var(--accent); }
.msg-ai table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg-ai th, .msg-ai td { border: 1px solid var(--line); padding: .35rem .6rem; }
.msg-ai blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--muted); }
.acts { display: flex; gap: .25rem; margin-top: .3rem; }
.acts button { min-height: 34px; padding: .3rem .6rem; background: transparent; color: var(--muted); font-size: .8rem; border-radius: 8px; }
.acts button svg { width: 15px; height: 15px; }
.acts button:active { background: var(--bg-3); }

/* Pasos del agente agrupados */
.steps { border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); overflow: hidden; }
.steps > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .6rem; min-height: 46px; padding: .55rem .85rem; font: .84rem var(--mono); color: var(--muted); }
.steps > summary::-webkit-details-marker { display: none; }
.steps > summary .st-n { flex: none; display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 .35rem; border-radius: 999px; background: var(--bg-3); color: var(--accent); font-weight: 700; font-size: .75rem; }
.steps > summary .st-l { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps > summary .st-c { flex: none; transition: transform .2s ease; }
.steps[open] > summary .st-c { transform: rotate(90deg); }
.steps.live > summary .st-n { animation: pulse 1s ease-in-out infinite; }
.steps.err > summary .st-n { color: var(--bad); }
.steps-body { display: grid; gap: .2rem; padding: 0 .55rem .55rem; }
.tool { border-radius: 10px; font: .8rem/1.5 var(--mono); color: var(--muted); }
.tool summary { cursor: pointer; list-style: none; display: flex; gap: .55rem; align-items: baseline; padding: .45rem .5rem; border-radius: 10px; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary:active { background: var(--bg-3); }
.tool .tn { color: var(--accent); font-weight: 700; flex: none; }
.tool .ts { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg); opacity: .8; min-width: 0; }
.tool.err .tn { color: var(--bad); }
.tool.wait .tn::after { content: " …"; animation: pulse 1s infinite; }
.tool pre { margin: 0 .5rem .5rem; max-height: 280px; overflow: auto; padding: .6rem .7rem; background: var(--bg); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

.done { font: .78rem var(--mono); color: var(--muted); display: flex; gap: .5rem; align-items: center; }
.done.bad { color: var(--bad); white-space: pre-wrap; overflow-wrap: anywhere; }
.working { display: flex; align-items: center; gap: .45rem; font: .85rem var(--mono); color: var(--accent); }
.working i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.working i:nth-child(2) { animation-delay: .15s; } .working i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.down { position: absolute; right: max(1rem, var(--sar)); bottom: calc(5.2rem + var(--sab)); width: 44px; height: 44px; padding: 0; border-radius: 50%; background: var(--bg-3); color: var(--fg); box-shadow: 0 6px 20px rgba(0,0,0,.45), inset 0 0 0 1px var(--line); z-index: 5; }

.composer { display: flex; gap: .5rem; align-items: flex-end; padding: .6rem max(.75rem, var(--sar)) max(.6rem, var(--sab)) max(.75rem, var(--sal)); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; min-width: 0; min-height: 46px; max-height: 40dvh; resize: none; padding: .7rem 1rem; border-radius: 23px; border: 1px solid var(--line); background: var(--bg-2); line-height: 1.4; font-size: 16px; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.round { width: 46px; height: 46px; padding: 0; border-radius: 50%; flex: none; }
.round svg { width: 22px; height: 22px; }
.scrim { display: none; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: min(84vw, 320px); z-index: 30; transform: translateX(-102%); transition: transform .25s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .app.open .side { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  .app.open .scrim { opacity: 1; pointer-events: auto; }
  #menu, #new2 { display: inline-flex; }
  .bar h1 { text-align: center; }
  .log { padding-inline: max(.85rem, var(--sal)) max(.85rem, var(--sar)); }
  .ideas { flex-direction: column; align-items: stretch; width: 100%; }
  .idea { width: 100%; }
  .msg-user .bubble { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
