/* Nexo — estilo WhatsApp oscuro */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel2: #202c33;
  --border: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --frank: #005c4b;
  --claude: #7c5cff;
  --gpt: #10a37f;
}
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 340px; min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
#sidebar header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel2);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand h1 { font-size: 18px; letter-spacing: 1px; }
#newChat {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 20px; cursor: pointer;
}
#newChat:hover { filter: brightness(1.1); }

#convList { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(134,150,160,.08);
}
.conv-item:hover { background: var(--panel2); }
.conv-item.active { background: var(--panel2); }
.conv-avatars { display: flex; flex-shrink: 0; }
.pav {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
}
.pav.claude { background: var(--claude); }
.pav.gpt { background: var(--gpt); }
.pav.grok { background: #f59e0b; }
.pav.seedance { background: #ec4899; }
.conv-avatars .pav + .pav { margin-left: -10px; border: 2px solid var(--panel); }
.conv-mid { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last {
  font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-right { text-align: right; flex-shrink: 0; }
.conv-time { font-size: 11px; color: var(--muted); }
.conv-busy { font-size: 11px; color: var(--accent); margin-top: 4px; visibility: hidden; }
.conv-busy.on { visibility: visible; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.conv-empty { padding: 30px 20px; color: var(--muted); text-align: center; font-size: 14px; }
#sidebarFoot {
  display: flex; gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
#sidebarFoot button {
  flex: 1;
  border: none; border-radius: 8px;
  background: none; color: var(--muted);
  padding: 8px; font-size: 13px; cursor: pointer;
}
#sidebarFoot button:hover { background: var(--panel2); }
#sidebarFoot button.on { background: var(--panel2); color: var(--text); }
.conn-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(134,150,160,.1);
}
.conn-on { color: var(--accent); font-size: 11px; margin-left: 6px; }
.conn-hint { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; display: block; }
.restore-btn.off { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.arch-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(134,150,160,.08);
}
.arch-item .conv-name { font-weight: 600; font-size: 14px; }
.arch-item .conv-last { font-size: 12px; }
.restore-btn {
  border: none; border-radius: 8px;
  background: var(--accent); color: #fff;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
  flex-shrink: 0;
}

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#emptyView { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-inner { text-align: center; color: var(--muted); }
.empty-logo { font-size: 60px; margin-bottom: 12px; }
.empty-inner h2 { color: var(--text); margin-bottom: 8px; letter-spacing: 2px; }

#chatView { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chatView[hidden] { display: none; }

#chatHeader {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px;
  background: var(--panel2);
  border-bottom: 1px solid var(--border);
}
.chat-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-avatars { display: flex; }
.chat-avatars .pav + .pav { margin-left: -10px; border: 2px solid var(--panel2); }
.chat-name-row { display: flex; align-items: baseline; gap: 8px; }
.chat-name-row strong { font-size: 16px; }
.chat-id { font-size: 12px; color: var(--muted); }
.chat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-sub .working { color: var(--accent); }
#chatTitle { cursor: pointer; border-radius: 10px; padding: 2px 8px 2px 2px; flex: 1; }
#chatTitle:hover { background: var(--panel); }
#chatSettings { font-size: 19px; }
.icon-btn {
  background: none; border: none; font-size: 16px; cursor: pointer;
  padding: 6px; border-radius: 8px; color: var(--text);
}
.icon-btn:hover { background: var(--panel); }

/* ---------- barras de contexto + handoff (Fase 2) ---------- */
#agentBars {
  display: flex; flex-direction: column; gap: 5px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#agentBars:empty { display: none; }
.abar { display: flex; align-items: center; gap: 10px; }
.abar .pav { width: 24px; height: 24px; font-size: 11px; flex-shrink: 0; }
.abar .meter {
  flex: 1; height: 8px;
  background: var(--panel2);
  border-radius: 4px; overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width .4s;
}
.meter-fill.hot { background: #e9772e; }
.meter-txt { font-size: 11.5px; color: var(--muted); min-width: 140px; text-align: right; }
.abar select {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 6px; font-size: 12px; cursor: pointer;
}
.abar.tool .tool-cost { min-width: 80px; }
.handoff {
  border: none; border-radius: 8px;
  padding: 5px 12px; font-size: 12px; cursor: pointer;
  background: var(--panel2); color: var(--muted);
  flex-shrink: 0;
}
.handoff:disabled { opacity: .45; cursor: not-allowed; }
.handoff.ready:not(:disabled) { background: var(--accent); color: #fff; }
.handoff.urgent:not(:disabled) { animation: urgentBlink .9s infinite; }
@keyframes urgentBlink {
  50% { filter: brightness(1.7); box-shadow: 0 0 12px rgba(233,119,46,.85); }
}
.msg.handoff-msg .bubble { border: 1px solid var(--accent); }

/* ---------- mensajes ---------- */
#chat {
  flex: 1; overflow-y: auto;
  padding: 20px 8%;
  background:
    radial-gradient(circle at 20% 20%, rgba(124,92,255,.05), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(0,168,132,.05), transparent 40%),
    var(--bg);
}
.msg { display: flex; gap: 10px; margin-bottom: 14px; max-width: 78%; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
  background: var(--claude);
}
.msg.gpt .avatar { background: var(--gpt); }
.msg.grok .avatar { background: #f59e0b; }
.msg.seedance .avatar { background: #ec4899; }
.msg.mine { margin-left: auto; flex-direction: row-reverse; }
.msg.mine .avatar { background: var(--frank); }
.msg.frank .avatar { background: var(--frank); }
.meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.mine .meta { text-align: right; }
.bubble {
  background: var(--panel2);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14.5px; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--frank); }
.bubble pre {
  background: #0d1418; border-radius: 8px; padding: 10px;
  overflow-x: auto; margin: 8px 0; font-size: 13px;
}
.bubble code { font-family: Consolas, monospace; font-size: 13px; }
.bubble img, .bubble video {
  max-width: 100%; max-height: 420px;
  border-radius: 8px; display: block; margin: 6px 0;
}
.bubble h1, .bubble h2, .bubble h3 { margin: 8px 0 4px; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble a { color: #53bdeb; }
.notice {
  text-align: center; color: var(--muted); font-size: 12.5px;
  margin: 10px auto; background: var(--panel2);
  display: table; padding: 5px 14px; border-radius: 12px;
}
.typing i {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); margin-right: 3px;
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- composer ---------- */
footer { padding: 10px 16px 14px; background: var(--panel2); }
.composer { display: flex; align-items: flex-end; gap: 10px; }
.recipient {
  display: flex; gap: 4px; background: var(--panel); border-radius: 10px; padding: 4px;
  flex-wrap: nowrap; overflow-x: auto; flex-shrink: 0; max-width: 40%;
  align-self: center;
}
.recipient[hidden] { display: none; }
.recipient button {
  border: none; background: none; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  white-space: nowrap; flex-shrink: 0;
}
.recipient button.active { background: var(--accent); color: #fff; }
.recipient .r-abbr { display: none; font-weight: 700; }
.input-wrap { position: relative; flex: 1; display: flex; align-items: flex-end; min-width: 0; }
#input {
  width: 100%; resize: none;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 44px 10px 14px; font-size: 14.5px; font-family: inherit;
  max-height: 160px; outline: none;
}
#input:focus { border-color: var(--accent); }
#mic {
  position: absolute; right: 5px; bottom: 4px;
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: none; color: var(--muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#mic:hover { color: var(--text); background: var(--border); }
#mic.rec { background: #c0392b; color: #fff; animation: pulse 1.2s infinite; font-size: 12px; font-weight: 700; }
#send {
  width: 42px; height: 42px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 17px; cursor: pointer; flex-shrink: 0;
}
#send:hover { filter: brightness(1.1); }

/* ---------- modal ---------- */
#modal, #connModal, #chatModal, #teamModal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 14px) 12px calc(env(safe-area-inset-bottom) + 14px);
}
#modal[hidden], #connModal[hidden], #chatModal[hidden], #teamModal[hidden] { display: none; }
.modal-box {
  background: var(--panel2); border-radius: 14px;
  padding: 22px; width: 380px; max-width: 92vw;
  border: 1px solid var(--border);
  max-height: 100%;
  overflow-y: auto;
  position: relative;
}
.modal-x {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--panel); color: var(--muted);
  font-size: 14px; cursor: pointer;
}
.modal-x:hover { color: var(--text); }
.modal-box h3 { margin-bottom: 16px; }
.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.field input[type="text"], .field select {
  display: block; width: 100%; margin-top: 6px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font-size: 14px;
}
.part-row { display: flex; flex-wrap: wrap; gap: 12px 18px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 7px; color: var(--text); font-size: 14px; cursor: pointer; }
.check .pav { width: 26px; height: 26px; font-size: 12px; }
.models-row { display: flex; gap: 12px; }
.models-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-actions button {
  border: none; border-radius: 9px; padding: 9px 18px;
  font-size: 14px; cursor: pointer;
  background: var(--accent); color: #fff;
}
.modal-actions .ghost { background: none; color: var(--muted); border: 1px solid var(--border); }

/* ---------- panel ⚙️ del chat: switches por sección ---------- */
.cm-section { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.cm-head { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.cm-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.cm-row .cm-name { flex: 1; font-size: 14.5px; display: flex; align-items: center; gap: 9px; min-width: 0; }
.cm-row select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 7px; font-size: 13px; cursor: pointer; max-width: 130px;
}
.cm-opts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 2px 0 8px 35px; }
.cm-opts select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 6px; font-size: 12px; cursor: pointer;
}
.cm-opts .tool-cost { font-size: 11.5px; color: var(--muted); }
.cm-btn-row { display: flex; gap: 10px; }
.cm-btn-row button {
  flex: 1; border: 1px solid var(--border); border-radius: 9px;
  background: none; color: var(--text);
  padding: 9px; font-size: 13.5px; cursor: pointer;
}
.cm-btn-row button:hover { background: var(--panel); }
.switch { position: relative; width: 44px; height: 25px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.switch i {
  display: block; position: absolute; inset: 0; pointer-events: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 13px;
  transition: background .18s, border-color .18s;
}
.switch i::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--muted); transition: left .18s, background .18s;
}
.switch input:checked + i { background: var(--accent); border-color: var(--accent); }
.switch input:checked + i::after { left: 21px; background: #fff; }

/* ---------- 👤 equipo ---------- */
.team-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; border-bottom: 1px solid rgba(134,150,160,.1);
}
.team-item .conv-name { font-size: 14.5px; }
.team-item .conv-last { font-size: 12px; }
.team-item .t-btns { display: flex; gap: 6px; flex-shrink: 0; }
.team-item .t-btns button {
  border: 1px solid var(--border); border-radius: 8px;
  background: none; color: var(--text);
  padding: 5px 8px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.team-item .t-btns button:hover { background: var(--panel); }
.team-add { display: flex; gap: 8px; margin: 14px 0 4px; }
.team-add input {
  flex: 1; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; font-size: 14px;
}
.team-add button {
  border: none; border-radius: 9px; background: var(--accent); color: #fff;
  padding: 9px 14px; font-size: 13.5px; cursor: pointer; white-space: nowrap;
}
#teamLinkBox { margin-top: 12px; border: 1px solid var(--accent); border-radius: 12px; padding: 12px; }
#teamLinkBox[hidden] { display: none; }
#teamLinkBox input {
  width: 100%; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; margin-bottom: 8px;
}
#teamLinkCopy {
  width: 100%; border: none; border-radius: 9px;
  background: var(--accent); color: #fff;
  padding: 10px; font-size: 14px; cursor: pointer;
}

/* ---------- vista restringida de empleado (Fase 7a): solo sus chats, sin taller ---------- */
body.employee #newChat, body.employee #sidebarFoot,
body.employee #chatSettings, body.employee #agentBars { display: none !important; }
body.employee #chatTitle { cursor: default; }
body.employee #chatTitle:hover { background: none; }

/* ---------- composer: adjuntos y voz ---------- */
.comp-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--panel); color: var(--text);
  font-size: 17px; cursor: pointer; flex-shrink: 0;
}
.comp-btn:hover { background: var(--border); }
#attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
#attachments:empty { display: none; }
.thumb { position: relative; display: flex; align-items: center; }
.thumb img { height: 54px; border-radius: 8px; }
.thumb .chip, .file-chip {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 10px; font-size: 12.5px; color: var(--text);
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-block; text-decoration: none;
}
.file-chip { margin: 4px 6px 4px 0; }
.thumb .rm {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  border: none; background: #c0392b; color: #fff;
  font-size: 10px; cursor: pointer; line-height: 1;
}
.bubble audio { display: block; margin: 6px 0; max-width: 100%; }
#backBtn { display: none; font-size: 18px; }

/* ---------- móvil (tipo WhatsApp: lista ↔ hilo) ---------- */
@media (max-width: 720px) {
  html, body, #app { height: 100dvh; }
  #app { position: relative; }
  #sidebar { width: 100%; min-width: 0; border-right: none; }
  #main { position: absolute; inset: 0; background: var(--bg); display: none; z-index: 10; }
  body.chat-open #main { display: flex; }
  body.chat-open #sidebar { display: none; }
  #backBtn { display: inline-flex; }
  #chatHeader { gap: 4px; padding: 8px 10px; }
  #agentBars { padding: 6px 10px; }
  .abar { flex-wrap: wrap; gap: 6px; }
  .abar .meter { min-width: 90px; }
  .meter-txt { min-width: 0; font-size: 10.5px; }
  #chat { padding: 14px 3%; }
  .msg { max-width: 94%; }
  footer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer { gap: 6px; }
  /* destinatarios en UN renglón, solo la letra (T todos, C Claude, G GPT, X Grok, S Seedance…) */
  .recipient { max-width: 38vw; }
  .recipient button { padding: 7px 9px; font-size: 13px; }
  .recipient .r-full { display: none; }
  .recipient .r-abbr { display: inline; }
  #input { font-size: 16px; padding-right: 42px; } /* 16px evita el auto-zoom de iOS */
  #mic { width: 32px; height: 32px; bottom: 4px; }
  .comp-btn, #send { width: 38px; height: 38px; }
  .empty-inner { padding: 0 20px; }
  /* modales a PANTALLA COMPLETA estilo WhatsApp: página propia, siempre debajo de la hora */
  #modal, #connModal, #chatModal, #teamModal { align-items: stretch; padding: 0; }
  .modal-box {
    width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; border: none;
    padding: calc(max(env(safe-area-inset-top), 24px) + 16px) 18px calc(env(safe-area-inset-bottom) + 22px);
    overflow-y: auto;
  }
  .modal-x { top: calc(max(env(safe-area-inset-top), 24px) + 10px); }
  .modal-box h3 { font-size: 20px; margin-bottom: 20px; }
  .field input[type="text"], .field select { font-size: 16px; } /* anti-zoom iOS */
  .modal-actions { margin-top: 16px; }
  .modal-actions button { flex: 1; padding: 13px; font-size: 15px; }
  .models-row { flex-direction: column; gap: 0; }
}

/* scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
