:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6f6a64;
  --line: #e4ded6;
  --accent: #c2603f;
  --ok: #3f8a3a;
  --warn: #a8791b;
  --err: #c0443a;
  --chip: #ece6de;
  --chip-on: #1f1d1a;
  --chip-on-text: #f6f3ef;
  --user: #f3e6d8;
  --assistant: #ffffff;
  --term-bg: #fbf9f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1917;
    --surface: #25221f;
    --text: #ece8e3;
    --muted: #9b958d;
    --line: #36322e;
    --accent: #d97757;
    --ok: #98cd78;
    --warn: #e1be6e;
    --err: #eb6e64;
    --chip: #302c28;
    --chip-on: #ece8e3;
    --chip-on-text: #1b1917;
    --user: #3a2e26;
    --assistant: #25221f;
    --term-bg: #1b1917;
  }
}

* { 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 -apple-system, BlinkMacSystemFont, "SF Pro Text", 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 ui-monospace, "SF Mono", Menlo, monospace; }
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: #fff; 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: #fff; }
.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: #fff; 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: #fff; 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: #fff; 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: #fff; 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: #fff; font-weight: 600; }
.login-error { color: var(--err); }
