/* Diseño "Consola" (dirección A): grafito, verde trabajando, ámbar
   esperándote, coral pide permiso. Geist y Geist Mono vienen con la app. */
@font-face { font-family: "Geist"; src: url("fonts/Geist.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("fonts/GeistMono.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
:root {
  color-scheme: dark;
  --bg: #0e0f11;
  --panel: #121317;
  --surface: #16181c;
  --raised: #1c1e24;
  --text: #e7e9ee;
  --text2: #c9ccd3;
  --muted: #8b909a;
  --faint: #6e7480;
  --line: #23252b;
  --line2: #2a2d34;
  --accent: #3ddc97;
  --on-accent: #0e0f11;
  --ok: #3ddc97;
  --warn: #f5a524;
  --err: #ff6b5e;
  --chip: #1c1e24;
  --chip-on: #e7e9ee;
  --chip-on-text: #0e0f11;
  --user: #12201a;
  --assistant: #16181c;
  --term-bg: #0e0f11;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* nada puede desbordar de costado (en una app de inicio de iOS, un desborde
   aleja la página entera). clip y no hidden: hidden convierte al body en un
   contenedor con scroll propio y en iOS la cabecera fija y el espacio de la
   muesca se desacomodan (margen arriba que tapa la lista) */
html { overflow-x: clip; }
body {
  font: 16px/1.4 "Geist", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
code { font: 13px var(--mono); }
button { font: inherit; color: inherit; }
.mark { color: var(--accent); }

/* ── Lista */
/* en modo app (standalone) el contenido va debajo de la barra de estado */
.top { position: sticky; top: env(safe-area-inset-top); z-index: 2; background: var(--bg); padding: 12px 0 8px; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.bell { border: 0; background: none; font-size: 20px; padding: 4px; line-height: 1; filter: grayscale(1); opacity: 0.7; }
.bell.on { filter: none; opacity: 1; }
.notif { background: var(--surface); border-radius: 12px; padding: 12px 14px; margin: 0 0 10px; font-size: 14px; }
.notif p { margin: 0 0 8px; }
.notif-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.notif-actions button { border: 0; border-radius: 8px; padding: 8px 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.notif-actions button.secondary { background: var(--chip); color: var(--text); font-weight: 400; }
.notif-result { margin: 8px 0 0 !important; color: var(--muted); }
.live { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live.on { background: var(--ok); }
.live.off { background: var(--err); }
.summary { margin: 2px 0 10px; color: var(--muted); font-size: 14px; }
#search {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 16px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px;
  background: var(--chip); color: var(--text); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-text); }
.chip.down { color: var(--err); }
.chip-sep { flex: none; width: 1px; background: var(--line); margin: 4px 2px; }
.hosts-error { color: var(--err); font-size: 14px; margin: 4px 0; }

.sessions { list-style: none; margin: 0; padding: 0 0 24px; }
.session {
  display: block; width: 100%; text-align: left; border: 0; background: var(--surface);
  border-radius: 12px; padding: 12px 14px; margin: 8px 0; cursor: pointer;
}
.session:active { opacity: 0.7; }
.session.attention { box-shadow: inset 3px 0 0 var(--accent); }
.s-live { font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.s-live.permission { color: var(--err); }
.s-live.waiting { color: var(--accent); }
.s-live.working { color: var(--muted); font-weight: 400; }
.s-label {
  font-weight: 600; margin: 0 0 4px; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.s-where, .s-stats { font-size: 13px; color: var(--muted); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-where { margin-bottom: 2px; }
.acct { color: var(--accent); }
.tag { color: var(--accent); }
.badge { font-size: 12px; margin-right: 4px; }
.badge.active { color: var(--ok); }
.badge.orphan { color: var(--err); }
.badge.pinned { color: var(--accent); }
.recent { color: var(--ok); }
.today { color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.diag { text-align: center; font-size: 13px; margin: 8px 0 28px; }
.diag a { color: var(--muted); }

/* ── Detalle */
.detail { padding-bottom: 32px; }
.detail-top { position: sticky; top: env(safe-area-inset-top); background: var(--bg); padding: 10px 0; z-index: 2; }
.back { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 4px 0; }
.detail h2 { font-size: 22px; margin: 4px 0 12px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 16px; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.resume { background: var(--surface); border-radius: 12px; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.resume-label { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.resume code { overflow-wrap: anywhere; }
.resume button { border: 0; border-radius: 8px; padding: 6px 12px; background: var(--chip); }
.detail h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 20px 0 8px; }
.messages { list-style: none; margin: 0; padding: 0; }
.older { text-align: center; margin: 4px 0 10px; }
.older button { border: 0; border-radius: 10px; padding: 9px 14px; background: var(--chip); color: var(--text); font-size: 14px; }
.msg { border-radius: 12px; padding: 10px 12px; margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg.user { background: var(--user); margin-left: 24px; }
.msg.assistant { background: var(--assistant); margin-right: 24px; }
.msg .who { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.clamped { max-height: 16em; overflow: hidden; position: relative; }
.msg.clamped::after { content: "tocá para ver todo"; position: absolute; bottom: 0; left: 0; right: 0; padding: 18px 12px 6px; font-size: 12px; color: var(--muted); background: linear-gradient(transparent, var(--bg) 70%); }

/* ── Acciones */
.actions:empty { display: none; }
.actions { margin: 0 0 16px; display: grid; gap: 10px; }
.actions .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions button { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; font-size: 16px; }
.actions button.primary { background: var(--accent); color: var(--on-accent); }
.actions button.secondary { background: var(--chip); color: var(--text); font-weight: 400; }
.actions button:disabled { opacity: 0.5; }
.ask { background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: inset 3px 0 0 var(--err); }
.ask-title { margin: 0 0 6px; font-weight: 600; }
.ask-text { margin: 0 0 10px; font: 14px ui-monospace, "SF Mono", Menlo, monospace; overflow-wrap: anywhere; }
.ask-text.muted, .hint { color: var(--muted); font: 14px/1.4 inherit; }
.hint { font-size: 14px; margin: 0; }
.compose { display: grid; gap: 8px; }
.composer { width: 100%; resize: vertical; min-height: 64px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 16px/1.4 inherit; }
.note { margin: 0; font-size: 14px; color: var(--muted); }

/* ── Terminal */
.term-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); z-index: 5; }
.term-top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.term-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-status { flex: none; font-size: 12px; color: var(--muted); white-space: nowrap; }
.term-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.term { flex: 1; min-height: 0; min-width: 0; padding: 0 4px; background: var(--term-bg); touch-action: none; }
.term-bottom { position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border: 0; border-radius: 22px; background: var(--accent); color: var(--on-accent); font-size: 20px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.term .xterm { height: 100%; }
/* el resto que no llena una fila entera: mismo fondo que la terminal */
.term .xterm, .term .xterm-viewport, .term .xterm-scrollable-element { background-color: var(--term-bg) !important; }
.term-status.is-live { color: var(--ok); }
.term-view, .term-wrap { overflow: hidden; }
.term-font { flex: none; border: 0; border-radius: 8px; padding: 4px 8px; background: var(--chip); color: var(--text); font-size: 13px; font-weight: 600; }
.term-fit { flex: none; border: 0; border-radius: 8px; padding: 4px 10px; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600; }
.keybar { display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px; scrollbar-width: none; }
.keybar::-webkit-scrollbar { display: none; }
.keybar button { flex: none; min-width: 42px; border: 0; border-radius: 8px; padding: 8px 10px; background: var(--chip); color: var(--text); font: 14px ui-monospace, "SF Mono", Menlo, monospace; }
.keybar button:active { background: var(--chip-on); color: var(--chip-on-text); }
.term-compose { display: flex; gap: 8px; padding: 0 8px 8px; }
.term-compose textarea { flex: 1; min-width: 0; resize: none; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 16px/1.3 inherit; }
.term-compose button { border: 0; border-radius: 10px; padding: 0 16px; background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ── Servidores (modo sin VPN) */
.servers { max-width: 640px; margin: 0 auto; padding-bottom: 32px; }
.servers h2 { font-size: 24px; margin: 4px 0 8px; }
.servers h3 { font-size: 16px; margin: 22px 0 8px; }
.servers .row { display: flex; gap: 8px; flex-wrap: wrap; }
.servers button { border: 0; border-radius: 10px; padding: 10px 16px; font-size: 16px; }
.servers button.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.servers button.secondary { background: var(--chip); color: var(--text); }
.servers .warn { background: var(--surface); border-radius: 10px; padding: 10px 12px; box-shadow: inset 3px 0 0 var(--warn); font-size: 14px; }
.srv-list { list-style: none; padding: 0; margin: 0; }
.srv { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface); border-radius: 10px; padding: 10px 12px; margin: 6px 0; font-size: 15px; }
.srv-id { color: var(--muted); font-size: 13px; }
.srv-st.on { color: var(--ok); font-size: 13px; }
#scan-video { width: 100%; max-height: 300px; border-radius: 10px; margin-top: 10px; background: #000; object-fit: cover; }
.pair-form { display: grid; gap: 8px; margin-top: 12px; }
.pair-form textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 13px ui-monospace, "SF Mono", Menlo, monospace; }
.hint.small { font-size: 12px; margin-top: 18px; overflow-wrap: anywhere; }

/* ── Login */
.login { max-width: 420px; margin: 18vh auto 0; }
.login h2 { font-size: 26px; }
.login p { color: var(--muted); }
#login-form { display: flex; gap: 8px; }
#token { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; }
#login-form button { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.login-error { color: var(--err); }


/* ── Diseño "Consola": lista */
h1 { font-weight: 700; letter-spacing: -0.03em; }
#search { background: var(--surface); border-color: var(--line2); }
.chip { background: var(--chip); color: var(--text2); border: 1px solid var(--line); }
.chip[aria-pressed="true"] { border-color: var(--chip-on); }
.sessions { display: grid; gap: 8px; }
.session {
  width: 100%; text-align: left; border: 1px solid transparent; border-radius: 14px;
  background: var(--surface); padding: 12px 14px; color: var(--text);
}
.session.attention { box-shadow: none; }
.session.perm { background: #1a1416; border-color: #4a2a2c; }
.session.wait { background: #19170f; border-color: #4a3e1e; }
.s-live { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 7px; margin-bottom: 6px; }
.s-live.permission { background: var(--err); color: var(--on-accent); }
.s-live.waiting { background: var(--warn); color: var(--on-accent); }
.s-live.working { background: none; padding: 0; color: var(--ok); font-weight: 500; }
.s-label { font-weight: 600; }
.s-where { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.s-stats { color: var(--faint); }
/* acciones rápidas en la tarjeta (sin abrir la sesión) */
.quick { display: grid; gap: 8px; margin: -2px 0 0; padding: 0 14px 12px; }
li:has(.quick) .session { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0; padding-bottom: 8px; }
li:has(.quick.perm) .quick { background: #1a1416; border: 1px solid #4a2a2c; border-top: 0; border-radius: 0 0 14px 14px; }
li:has(.quick.wait) .quick { background: #19170f; border: 1px solid #4a3e1e; border-top: 0; border-radius: 0 0 14px 14px; }
.quick .q-prompt { font: 13px var(--mono); color: var(--text2); background: var(--panel); border-radius: 10px; padding: 8px 10px; margin: 0; overflow-wrap: anywhere; max-height: 7.5em; overflow: hidden; }
.quick .row { display: flex; gap: 8px; }
.quick button { flex: 1; min-height: 44px; border-radius: 12px; font-weight: 600; font-size: 15px; border: 1px solid var(--line2); background: transparent; color: var(--text); }
.quick button.go { background: var(--ok); border-color: var(--ok); color: var(--on-accent); }
.quick button.send { flex: none; width: 44px; background: var(--warn); border-color: var(--warn); color: var(--on-accent); }
.quick input { flex: 1; min-width: 0; min-height: 44px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel); color: var(--text); padding: 0 12px; font: 16px "Geist", system-ui, sans-serif; }
.quick button:disabled, .quick input:disabled { opacity: 0.5; }
.quick .q-note { margin: 0; font-size: 13px; color: var(--err); }
.quick .q-note:empty { display: none; }

/* ── Diseño "Consola": detalle y terminal */
.back { color: var(--accent); }
.msg { font-size: 15px; }
.msg.user { border: 1px solid #1f3a2e; }
.msg.assistant { border: 1px solid var(--line); }
.msg .who { font-family: var(--mono); }
.actions button.secondary, .term-font { background: var(--raised); border: 1px solid var(--line2); }
.term-top { border-bottom: 1px solid var(--line); background: var(--panel); }
.term-title { font-family: var(--mono); font-size: 14px; }

/* ── Barra inferior (modo hub): Sesiones · Shells · Servidores */
body.has-nav { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
#bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
#bottom-nav button {
  flex: 1; max-width: 120px; min-height: 48px; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px;
}
#bottom-nav button[aria-current="true"] { color: var(--accent); }
#bottom-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* dentro de una sesión o de la terminal no hace falta */
body:has(#detail-view:not([hidden])) #bottom-nav, body:has(#term-view:not([hidden])) #bottom-nav { display: none; }
body:has(#detail-view:not([hidden])), body:has(#term-view:not([hidden])) { padding-bottom: env(safe-area-inset-bottom); }

/* ── Pantallas Shells y Archivos */
.tool-view { padding-bottom: 24px; }
.tool-top { position: sticky; top: env(safe-area-inset-top); z-index: 2; background: var(--bg); padding: 12px 0 8px; }
.tool-top h1 { margin: 2px 0; }
.tool-block { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; }
.tool-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tool-head b { flex: 1; font-size: 16px; }
.tool-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tool-list li { display: flex; align-items: stretch; gap: 6px; }
.tool-row {
  flex: 1; min-width: 0; min-height: 48px; text-align: left; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); padding: 8px 12px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.tool-actions { display: flex; gap: 8px; margin: 6px 0 10px; }
.tool-actions button, .tool-view > button { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; min-height: 44px; }
.tool-view button.primary { background: var(--accent); color: var(--on-accent); }
.tool-view button.secondary { background: var(--raised); color: var(--text); border: 1px solid var(--line2); font-weight: 400; }
.tool-view button.small { padding: 8px 12px; min-height: 40px; border-radius: 10px; font-size: 14px; }
.tool-view button:disabled { opacity: 0.5; }
.icon-btn { flex: none; width: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--muted); font-size: 20px; }
.mono { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono.strong { font-size: 14px; color: var(--text); }
.mono.dim { font-size: 12px; color: var(--muted); }
.tool-view .hint { color: var(--muted); font-size: 14px; }
.tool-view .note { color: var(--warn); font-size: 14px; min-height: 1em; }

/* ── Ícono del agente de cada sesión (monocromo, teñido) */
.agent-ico { display: inline-block; width: 15px; height: 15px; margin-right: 7px; vertical-align: -2px; background: var(--text2); -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.agent-ico.letter { -webkit-mask: none; mask: none; background: var(--raised); color: var(--text2); border-radius: 4px; font: 600 10px/15px var(--mono); text-align: center; }
.chip .agent-ico { width: 13px; height: 13px; margin-right: 5px; }
.legal { color: var(--faint); font-size: 12px; margin-top: 16px; }
