/* ============================================================
   Joypixel · Panel de atención WhatsApp
   Tema oscuro. Acento oro/naranja (marca Joypixel). Un solo acento.
   ============================================================ */

:root {
  --bg:           #0e0f12;   /* off-black, no negro puro */
  --bg-2:         #15171c;   /* paneles */
  --bg-3:         #1c1f26;   /* elevación */
  --bg-hover:     #232732;
  --line:         #262a33;
  --text:         #e8eaed;
  --text-dim:     #9aa0ab;
  --text-faint:   #6b7280;

  --accent:       #f5a623;   /* oro/naranja Joypixel */
  --accent-2:     #e8821a;
  --accent-soft:  rgba(245, 166, 35, 0.14);

  --in-bg:        #1d2129;   /* burbuja del cliente */
  --out-bg:       #5a3c0e;   /* burbuja saliente (oro oscuro) */
  --ai-bg:        #243042;   /* burbuja de la IA (azulado, se distingue) */

  --ok:           #34c759;
  --warn:         #ffb020;
  --danger:       #ff5a52;

  --radius:       14px;
  --radius-sm:    10px;
  --shadow:       0 18px 50px rgba(0, 0, 0, 0.45);

  --sidebar-w:    360px;
  --font:         "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

input, textarea, button { font-family: inherit; }

/* ───────────────── Login ───────────────── */
.auth-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(245,166,35,0.10), transparent 60%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 30px;
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-logo, .brand-logo {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  flex: none;
}
.auth-logo img, .brand-logo img { display: block; }
.brand-logo.lg { width: 64px; height: 64px; border-radius: 16px; font-size: 22px; }
.auth-brand h1 { margin: 0; font-size: 20px; letter-spacing: -0.3px; }
.auth-brand p  { margin: 2px 0 0; color: var(--text-dim); font-size: 13px; }

.auth-form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field span { font-size: 12.5px; color: var(--text-dim); }
.field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14.5px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-error {
  background: rgba(255,90,82,0.12);
  border: 1px solid rgba(255,90,82,0.35);
  color: #ffb4b0;
  padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 18px;
}
.btn-primary {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1206; font-weight: 700; font-size: 15px;
  border: none; border-radius: var(--radius-sm);
  padding: 12px; cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: translateY(1px); }

/* ───────────────── App shell ───────────────── */
.app-body { overflow: hidden; }
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; }
.brand-img { height: 20px; width: auto; display: block; }
.sidebar-actions { display: flex; align-items: center; gap: 10px; }
.me { color: var(--text-dim); font-size: 12.5px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  color: var(--text-dim); background: transparent;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-tools { padding: 12px 14px; display: grid; gap: 11px; border-bottom: 1px solid var(--line); }
.search { display: flex; align-items: center; gap: 9px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; color: var(--text-faint); }
.search input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 14px; }
.filters { display: flex; gap: 8px; }
.chip {
  background: var(--bg); border: 1px solid var(--line); color: var(--text-dim);
  padding: 6px 13px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
  transition: all .15s;
}
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.conv-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.conv {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px;
  align-items: center; padding: 11px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .12s;
}
.conv:hover { background: var(--bg-hover); }
.conv.is-active { background: var(--accent-soft); }
.conv .avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg-3); color: var(--text-dim);
  font-weight: 700; font-size: 16px; text-transform: uppercase;
}
.conv-main { min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-faint); flex: none; }
.conv-preview { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: #1a1206; font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center; }
.status-icon { display: flex; align-items: center; width: 18px; height: 18px; flex-shrink: 0; }
.status-icon.waiting { color: var(--warn); }
.status-icon.human   { color: var(--ok); }
.status-icon.bot     { color: #8fb6ff; }

.list-empty { text-align: center; color: var(--text-faint); font-size: 13px; padding: 36px 16px; }

/* ── Chat ── */
.chat { position: relative; min-width: 0; overflow: hidden;
  background: linear-gradient(var(--bg), var(--bg));
  display: flex; flex-direction: column; height: 100%; overflow: auto; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--text-faint); }
.chat-empty-inner { text-align: center; display: grid; gap: 16px; justify-items: center; }
.chat-empty-inner p { max-width: 280px; font-size: 14px; }

.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.back-btn { display: none; }
.chat-peer { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.chat-peer .avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; background: var(--bg-3);
  color: var(--text-dim); font-weight: 700; text-transform: uppercase;
}
.chat-peer-text { min-width: 0; }
.chat-peer-text strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-peer-text small { color: var(--text-dim); font-size: 12.5px; }
.chat-head-right { display: flex; align-items: center; gap: 12px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-dim); white-space: nowrap; }
.status-pill svg { flex-shrink: 0; }
.status-pill.waiting { color: var(--warn); border-color: rgba(255,176,32,0.4); background: rgba(255,176,32,0.10); }
.status-pill.human   { color: var(--ok);   border-color: rgba(52,199,89,0.4);  background: rgba(52,199,89,0.10); }
.status-pill.bot     { color: #8fb6ff;     border-color: rgba(143,182,255,0.35); background: rgba(143,182,255,0.08); }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  padding: 7px 13px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--text-faint); color: var(--text); }
/* "Atender yo" con acento dorado */
#toHumanBtn { border-color: var(--accent); color: var(--accent); }
#toHumanBtn:hover { background: var(--accent-soft); }
/* "Pasar a IA" neutro */
#toBotBtn:hover { border-color: #8fb6ff; color: #8fb6ff; }

.messages {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 22px 8%;
  display: flex; flex-direction: column; gap: 8px;
  background:
    radial-gradient(1200px 600px at 50% -20%, rgba(245,166,35,0.04), transparent 60%);
}
.day-sep { align-self: center; font-size: 11.5px; color: var(--text-faint);
  background: var(--bg-2); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; margin: 8px 0; }

.msg { max-width: min(74%, 560px); padding: 9px 13px 7px; border-radius: 12px; font-size: 14.5px; line-height: 1.42; position: relative; word-wrap: break-word; }
.msg .meta { display: block; font-size: 10.5px; color: var(--text-faint); margin-top: 4px; text-align: right; }
.msg .who { display: block; font-size: 11px; font-weight: 700; margin-bottom: 3px; opacity: .85; }
.msg.in  { align-self: flex-start; background: var(--in-bg); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; border-top-right-radius: 4px; }
.msg.out.human { background: var(--out-bg); }
.msg.out.ai    { background: var(--ai-bg); }
.msg.out.ai .who { color: #8fb6ff; }
.msg.out.human .who { color: var(--accent); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 13px 18px; border-top: 1px solid var(--line); background: var(--bg-2);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); padding: 11px 14px; font-size: 14.5px; line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a1206;
  border: none; cursor: pointer; display: grid; place-items: center;
  transition: transform .08s, filter .15s;
}
.send-btn:hover { filter: brightness(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: var(--radius-sm); font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.error { border-color: rgba(255,90,82,0.5); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #2a2f3a; border-radius: 8px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: #353b48; }

/* ───────────────── Móvil ───────────────── */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .25s ease; }
  .app.show-chat .chat { transform: translateX(0); }
  .back-btn { display: grid; }
  .messages { padding: 18px 14px; }
  .me { display: none; }
}

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