/* Versell Web — estilos según webapp/DESIGN.md (solo tema oscuro).
   Regla de oro: cero colores fuera de estas variables (excepción: el lienzo
   del QR es blanco puro para los escáneres). */
:root {
  --bg: #04080c;
  --bg-2: #070d13;
  --bg-3: #0a141c;
  --glass: rgba(10, 20, 26, .66);
  --glass-2: rgba(13, 25, 32, .8);
  --line: rgba(23, 195, 178, .14);
  --line-2: rgba(23, 195, 178, .32);
  --text: #d9e6e2;
  --muted: #7f958f;
  --teal: #17c3b2;
  --teal-hi: #2af0dc;
  --teal-lo: #0e7a6f;
  --on-teal: #00201c;
  --danger: #ff8a80;
  --ok: #7be0a3;
  --bubble-in: #0d1a22;
  --bubble-out: #0e2f2a;
  --r: 16px;
  --r-sm: 10px;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--teal-hi); outline-offset: 2px; border-radius: 4px; }

/* Lluvia binaria de fondo (solo visible en vinculación/estados vacíos) */
#rain {
  position: fixed; inset: 0; z-index: 0; opacity: .5; pointer-events: none;
}
[hidden] { display: none !important; }

.view { position: relative; z-index: 1; height: 100dvh; }

/* ---------- Vinculación ---------- */
.link-wrap {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; padding: 24px 16px;
  animation: enter .22s cubic-bezier(.2, .7, .3, 1);
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-row .logo { width: 30px; height: 30px; }
.brand-row .name { font-size: 1.15rem; font-weight: 600; letter-spacing: .02em; }
.brand-row .tag {
  font-family: var(--mono); font-size: .66rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px;
}
.eyebrow {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .22em;
  text-transform: uppercase; color: var(--teal);
}
.link-card {
  background: var(--glass-2); border: 1px solid var(--line); border-radius: var(--r);
  backdrop-filter: blur(10px);
  padding: 24px; max-width: 420px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.link-card h1 { font-size: 1.15rem; font-weight: 600; }
.qr-frame {
  background: #ffffff; /* excepción documentada: contraste para escáneres */
  border-radius: var(--r-sm); padding: 8px; line-height: 0;
  animation: qr-in .26s cubic-bezier(.2, .7, .3, 1);
  position: relative;
}
.qr-frame::after {
  content: ""; position: absolute; inset: -8px; border-radius: 14px;
  border: 1px solid var(--line-2); opacity: .25;
  animation: pulse 2.4s ease-in-out infinite;
  pointer-events: none;
}
#qr-canvas { width: 264px; height: 264px; image-rendering: pixelated; }
.link-steps { list-style: none; display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.link-steps li { display: flex; gap: 10px; align-items: baseline; font-size: .92rem; }
.link-steps .n { font-family: var(--mono); font-size: .8rem; color: var(--teal); letter-spacing: .1em; }
.term {
  align-self: stretch; background: rgba(4, 8, 12, .55); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 12px 14px; min-height: 84px; max-height: 120px;
  overflow-y: auto; font-family: var(--mono); font-size: .74rem; line-height: 1.9;
  color: var(--muted);
}
.term .ok { color: var(--ok); }
.term .warn { color: var(--danger); }

/* ---------- Aplicación ---------- */
.app-grid {
  height: 100dvh; display: grid; grid-template-columns: 320px 1fr;
  background: var(--bg);
  animation: enter .22s cubic-bezier(.2, .7, .3, 1);
}
.pane-left {
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  /* min-height 0: sin esto, el hijo con overflow crece en vez de hacer scroll
     (los items de grid/flex no encogen por debajo de su contenido por defecto). */
  min-width: 0; min-height: 0; background: var(--bg-2);
}
.pane-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--line); min-height: 62px;
}
.pane-head .logo { width: 24px; height: 24px; flex: none; }
.pane-head .title { font-weight: 600; font-size: .95rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-head .spacer { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: background .12s, color .12s;
  font-size: 1.05rem;
}
.icon-btn:hover { background: rgba(23, 195, 178, .08); color: var(--teal); }
.icon-btn.danger:hover { background: rgba(255, 138, 128, .08); color: var(--danger); }

.chip { font-family: var(--mono); font-size: .72rem; letter-spacing: .04em; white-space: nowrap; }
.chip-ok { color: var(--ok); }
.chip-muted { color: var(--muted); }
.chip-danger { color: var(--danger); }

#conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.conv-row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 10px 10px; border-radius: var(--r-sm); min-height: 64px;
  transition: background .12s; position: relative;
}
.conv-row:hover { background: rgba(23, 195, 178, .05); }
.conv-row.active { background: rgba(23, 195, 178, .10); }
.conv-row.active::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 2px;
  background: var(--teal); border-radius: 2px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--text); font-size: .95rem;
}
.conv-mid { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-family: var(--mono); font-size: .68rem; color: var(--muted); align-self: flex-start; margin-top: 6px; }

.pane-right { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#btn-back { display: none; }
.chat-head-mid { min-width: 0; flex: 1; }
#chat-title { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-sub { font-family: var(--mono); font-size: .7rem; color: var(--muted); }

#thread {
  flex: 1; min-height: 0; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 8px;
  overflow-anchor: auto;
}
.bubble {
  max-width: 72%; padding: 8px 12px; border-radius: 14px;
  animation: enter .15s cubic-bezier(.2, .7, .3, 1);
  overflow-wrap: break-word;
}
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.pending { opacity: .65; }
.bubble .who { font-size: .72rem; color: var(--teal); margin-bottom: 2px; font-weight: 600; }
.bubble .body { font-size: .92rem; white-space: pre-wrap; }
.bubble .note { font-size: .78rem; color: var(--muted); font-style: italic; margin-top: 2px; }
.bubble .meta { font-family: var(--mono); font-size: .68rem; color: var(--muted); margin-top: 3px; text-align: right; }

#composer {
  display: flex; gap: 10px; align-items: flex-end; padding: 12px 16px;
  border-top: 1px solid var(--line); background: var(--bg-2);
  position: sticky; bottom: 0;
}
#composer-input {
  flex: 1; resize: none; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--text); padding: 10px 12px;
  font: inherit; font-size: .92rem; max-height: 140px; min-height: 42px;
  transition: border-color .12s, box-shadow .12s;
}
#composer-input::placeholder { color: var(--muted); }
#composer-input:focus { outline: none; border-color: var(--line-2); box-shadow: 0 0 16px rgba(23, 195, 178, .12); }
.btn {
  background: var(--teal); color: var(--on-teal); font-weight: 600;
  border-radius: var(--r-sm); padding: 10px 18px;
  transition: background .12s, box-shadow .12s;
}
.btn:hover { background: var(--teal-hi); box-shadow: 0 0 24px rgba(23, 195, 178, .35); }
.btn:active { background: var(--teal-lo); box-shadow: none; }
.btn:disabled { opacity: .45; box-shadow: none; cursor: default; }
.btn-ghost {
  background: none; border: 1px solid var(--line-2); color: var(--teal);
  border-radius: var(--r-sm); padding: 10px 18px; font-weight: 600;
  transition: background .12s;
}
.btn-ghost:hover { background: rgba(23, 195, 178, .08); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(255, 138, 128, .08); }

.empty-note { color: var(--muted); font-size: .88rem; padding: 18px; text-align: center; }
.empty-note.center { margin: auto; }
.foot-note {
  font-family: var(--mono); font-size: .68rem; color: var(--muted);
  padding: 8px 14px; border-top: 1px solid var(--line); text-align: center;
}

/* ---------- Estados finales (revocada / no compatible) ---------- */
.final-card {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; text-align: center; padding: 24px;
  animation: enter .22s cubic-bezier(.2, .7, .3, 1);
}
.final-card h1 { font-size: 1.15rem; }
.final-card p { color: var(--muted); max-width: 380px; font-size: .92rem; }

/* ---------- Modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 10; background: rgba(4, 8, 12, .7);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-panel {
  background: var(--glass-2); border: 1px solid var(--line-2); border-radius: var(--r);
  backdrop-filter: blur(10px); padding: 22px; max-width: 380px; width: 100%;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.modal-panel h2 { font-size: 1rem; }
.modal-panel p { color: var(--muted); font-size: .88rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 8px);
  background: var(--glass-2); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 10px 16px; font-size: .85rem; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; z-index: 20;
  backdrop-filter: blur(10px);
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Animaciones ---------- */
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes qr-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: .45; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  #rain { display: none; }
}

/* ---------- Responsive (<900px: una vista con pila) ---------- */
@media (max-width: 899px) {
  .app-grid { grid-template-columns: 1fr; }
  .pane-right { display: none; }
  body.chat-open .pane-left { display: none; }
  body.chat-open .pane-right { display: flex; }
  #btn-back { display: inline-flex; }
  .bubble { max-width: 92%; }
}
@media (max-width: 360px) {
  #qr-canvas { width: 224px; height: 224px; }
}
