/* ============================================================
   Paternal · Panel de conversaciones
   Colores de marca tomados de paternalsrl.com.ar (#009CD3)
   Todos los colores son variables: el modo oscuro solo las redefine.
   ============================================================ */

:root {
  color-scheme: light;
  --brand: #009cd3;
  --brand-600: #0085b5;
  --brand-700: #006b92;   /* texto de marca sobre fondos claros */
  --brand-deep: #006b92;  /* fondos de marca (no cambia con el tema) */
  --brand-50: #e8f6fc;
  --brand-100: #cdeef9;
  --on-brand: #ffffff;

  --navy: #0d2433;
  --navy-2: #163447;
  --navy-3: #21465d;

  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #e3e9ef;
  --border-strong: #d2dbe3;
  --hover: #f3f6f9;

  --text: #142330;
  --muted: #5d6f7e;
  --subtle: #8b9aa7;

  --ok-bg: #e6f6ee; --ok-border: #c5ead7; --ok-text: #0f7a51;
  --warn-bg: #fff4e0; --warn-border: #f9dfae; --warn-text: #a5620a;
  --violet-bg: #f1edff; --violet-border: #ddd3ff; --violet-text: #5b3fd6;
  --err-bg: #fdecec; --err-text: #b42328;
  --danger: #e5484d;
  --online: #2fd18b;

  --bubble-in: #ffffff;
  --bubble-out: #dff3fb;
  --note: #fff6d8;
  --note-border: #f3dc8a;
  --note-text: #8a6a00;
  --chat-bg: #edf2f6;
  --chat-dots: rgba(0, 156, 211, .07);
  --chip-bg: rgba(255, 255, 255, .92);
  --soft: rgba(13, 36, 51, .05);
  --soft-2: rgba(13, 36, 51, .08);
  --skeleton-a: #edf1f5;
  --skeleton-b: #f6f8fa;
  --avatar-mix: 14%;
  --avatar-base: #ffffff;

  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(13, 36, 51, .06);
  --shadow: 0 6px 24px rgba(13, 36, 51, .08);
  --shadow-lg: 0 24px 60px rgba(13, 36, 51, .18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji';
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-600: #22b0e3;
  --brand-700: #5cc8ef;
  --brand-50: rgba(0, 156, 211, .14);
  --brand-100: rgba(0, 156, 211, .3);

  --navy: #070f15;
  --navy-2: #12212c;
  --navy-3: #1a2f3d;

  --bg: #0a1218;
  --surface: #101b23;
  --surface-2: #15232d;
  --border: #1f2f3b;
  --border-strong: #2b3f4d;
  --hover: #15232d;

  --text: #e4ecf1;
  --muted: #9aacb9;
  --subtle: #6c8191;

  --ok-bg: rgba(22, 163, 110, .16); --ok-border: rgba(22, 163, 110, .32); --ok-text: #4fd49c;
  --warn-bg: rgba(232, 147, 12, .15); --warn-border: rgba(232, 147, 12, .32); --warn-text: #f3b24d;
  --violet-bg: rgba(124, 92, 252, .17); --violet-border: rgba(124, 92, 252, .34); --violet-text: #b3a0ff;
  --err-bg: rgba(229, 72, 77, .15); --err-text: #ff8a8e;

  --bubble-in: #172630;
  --bubble-out: #0b3a4e;
  --note: #33290f;
  --note-border: #57461a;
  --note-text: #f0cf6b;
  --chat-bg: #0b151c;
  --chat-dots: rgba(92, 200, 239, .06);
  --chip-bg: rgba(21, 35, 45, .92);
  --soft: rgba(255, 255, 255, .05);
  --soft-2: rgba(255, 255, 255, .09);
  --skeleton-a: #15232d;
  --skeleton-b: #1c2d39;
  --avatar-mix: 22%;
  --avatar-base: #101b23;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; }
select option { background: var(--surface); color: var(--text); }
a { color: var(--brand-600); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.icon { flex: none; display: block; }
#app { height: 100%; height: 100dvh; }

/* ---------- utilidades ---------- */

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--brand-100); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  height: 44px; border-radius: 11px; font-weight: 600; padding: 0 18px;
  transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: 0 6px 16px rgba(0, 156, 211, .28); }
.btn-primary:hover:not(:disabled) { background: #0085b5; }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--brand-50); border-color: var(--brand-100); }
.link { color: var(--brand-600); font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--brand-50); color: var(--brand-700); }
.icon-btn:disabled { opacity: .45; }

.avatar {
  flex: none; display: inline-grid; place-items: center; border-radius: 50%;
  font-weight: 700; overflow: hidden; letter-spacing: .02em; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.zoomable { cursor: zoom-in; transition: filter .12s, box-shadow .12s; }
.avatar.zoomable:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px var(--brand-100); }
/* foto de perfil en grande */
.photo-viewer { z-index: 70; }
.lightbox .pv-bar { align-self: stretch; align-items: center; padding-left: 22px; }
.pv-who { margin-right: auto; display: flex; flex-direction: column; color: #fff; min-width: 0; }
.pv-who b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-who span { font-size: 12.5px; color: rgba(255, 255, 255, .7); }
.lb-stage img.pv-img { width: min(640px, 86vw); height: auto; max-width: none; max-height: 76vh; object-fit: contain; cursor: default; border-radius: 16px; background: transparent; transition: filter .2s; }
.lb-stage img.pv-img.cargando { filter: blur(5px); }

/* ---------- logo ---------- */

.logo { display: inline-flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(0, 156, 211, .35);
}
.logo-word { font-family: 'Nunito', var(--font); font-weight: 900; font-size: 26px; color: var(--brand); letter-spacing: -.02em; }
.logo-word small { font-size: 12px; font-weight: 800; margin-left: 4px; color: var(--subtle); letter-spacing: 0; }
.logo.light .logo-word { color: #fff; }
.logo.light .logo-word small { color: rgba(255, 255, 255, .6); }
.logo.light .logo-mark { background: #fff; color: var(--brand); box-shadow: none; }

/* ---------- arranque / toast ---------- */

.boot { height: 100%; display: grid; place-content: center; justify-items: center; gap: 22px; }
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
}

/* ============================================================ Login */

.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(0, 156, 211, .16), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(0, 156, 211, .12), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(920px, 100%); display: grid; grid-template-columns: 1.05fr 1fr;
  background: var(--surface); border-radius: 22px; overflow: hidden; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-brand {
  position: relative; padding: 40px; color: #fff; overflow: hidden; min-height: 520px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-deep) 55%, #0d2433 100%);
}
.login-pitch { position: relative; z-index: 1; }
.login-pitch h1 { font-size: 32px; line-height: 1.15; font-weight: 700; }
.login-pitch p { margin: 14px 0 0; color: rgba(255, 255, 255, .78); line-height: 1.55; max-width: 340px; }
.login-dots {
  position: absolute; right: -60px; top: 60px; width: 300px; height: 300px; border-radius: 50%;
  background: radial-gradient(rgba(255, 255, 255, .22) 1.5px, transparent 1.5px) 0 0 / 16px 16px;
  mask-image: radial-gradient(circle, #000 40%, transparent 70%);
}
.login-form { padding: 44px 40px; display: flex; flex-direction: column; gap: 14px; justify-content: center; }
.login-form h2 { font-size: 24px; }
.login-form > p { margin: -8px 0 6px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-form input {
  height: 44px; border: 1px solid var(--border-strong); border-radius: 11px; padding: 0 14px;
  font-size: 14px; color: var(--text); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.login-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(0, 156, 211, .14); }
.form-error {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 10px;
  background: var(--err-bg); color: var(--err-text); font-size: 13px; font-weight: 500;
}
.demo-title { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--subtle); text-align: center; }
.demo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-btns .btn { height: auto; padding: 9px 10px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 13px; }
.demo-btns small { font-weight: 500; color: var(--muted); font-size: 11.5px; }
.login-sep { display: flex; align-items: center; gap: 12px; color: var(--subtle); font-size: 12px; }
.login-sep::before, .login-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ============================================================ Shell */

.app-frame { height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.shell { flex: 1; min-height: 0; display: grid; grid-template-columns: 68px 380px 1fr; overflow: hidden; }
.demo-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px; padding: 7px 16px; flex-wrap: wrap;
  background: #ffc94d; color: #3d2c00; font-size: 13px; text-align: center;
}
.demo-banner button {
  padding: 4px 12px; border-radius: 8px; background: rgba(61, 44, 0, .12); font-weight: 700; font-size: 12.5px; color: #3d2c00;
}
.demo-banner button:hover { background: rgba(61, 44, 0, .22); }
/* cada vista (conversaciones / contactos) ocupa las columnas lista + detalle */
.view { display: contents; }

/* ---------- sidebar ---------- */

.sidebar {
  background: var(--navy); display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 14px 0; z-index: 2;
}
.side-logo {
  width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: #fff;
  display: grid; place-items: center; margin-bottom: 14px; box-shadow: 0 6px 16px rgba(0, 156, 211, .4);
}
.side-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  color: rgba(255, 255, 255, .55); position: relative; transition: background .15s, color .15s;
}
.side-btn:hover:not(:disabled) { background: var(--navy-2); color: #fff; }
.side-btn.active { background: var(--navy-3); color: #fff; }
.side-btn.active::before {
  content: ''; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--brand);
}
.side-spacer { flex: 1; }
.side-btn.side-hide { width: 36px; height: 32px; margin-top: 4px; color: rgba(255, 255, 255, .35); }
/* barra oculta: la lista pasa a la primera columna y queda una pestañita para volver a mostrarla */
.shell.side-hidden { grid-template-columns: 380px 1fr; }
.shell.side-hidden .sidebar { display: none; }
.side-show {
  position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 15; width: 18px; height: 56px;
  border-radius: 0 10px 10px 0; display: grid; place-items: center; background: var(--navy); color: rgba(255, 255, 255, .7);
  box-shadow: var(--shadow); transition: width .15s, color .15s;
}
.side-show:hover { width: 24px; color: #fff; }
.side-btn.needs-attention::after {
  content: ''; position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
  background: #ffc94d; box-shadow: 0 0 0 2px var(--navy);
}
.side-demo {
  font-size: 9px; font-weight: 800; letter-spacing: .08em; color: #0d2433;
  background: #ffc94d; padding: 3px 6px; border-radius: 5px; margin-bottom: 6px;
}
.side-me { position: relative; margin: 4px 0; }
.side-me .avatar { box-shadow: 0 0 0 2px var(--navy-3); }
.presence {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--subtle); border: 2px solid var(--navy);
}
.presence.online { background: var(--online); }
.presence.connecting { background: #f5b83d; }

/* ---------- lista ---------- */

.list { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-head { padding: 18px 16px 12px; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid var(--border); }
.list-title { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.list-title h1 { font-size: 20px; font-weight: 700; flex: 1; }
.list-title h1 + .live, .list-title h1 + .count-chip { margin-left: -2px; }

.live {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 12px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--subtle); }
.live.online { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.live.online i { background: var(--online); animation: pulse 2s infinite; }
.live.connecting { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.live.connecting i { background: #f5b83d; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 209, 139, .55); }
  70% { box-shadow: 0 0 0 6px rgba(47, 209, 139, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 209, 139, 0); }
}
.count-chip {
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); padding: 2px 9px; border-radius: 10px;
}

/* solapas de estado: Abiertos / Con el bot / Resueltos */
.status-tabs { display: flex; margin: -6px -16px 0; padding: 0 8px; border-bottom: 1px solid var(--border); }
.status-tabs button {
  flex: 1; position: relative; height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--muted); white-space: nowrap; transition: color .15s;
}
.status-tabs button:hover { color: var(--text); }
.status-tabs button::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0;
  background: transparent; transition: background .15s;
}
.status-tabs b {
  font-size: 11px; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px;
  display: inline-grid; place-items: center; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.status-tabs .on { color: var(--brand-700); }
.status-tabs .on::after { background: var(--brand); }
.status-tabs .on b { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand-700); }
.status-tabs .st-pending.on { color: var(--violet-text); }
.status-tabs .st-pending.on::after { background: #7c5cfc; }
.status-tabs .st-pending.on b { background: var(--violet-bg); border-color: var(--violet-border); color: var(--violet-text); }
.status-tabs .st-resolved.on { color: var(--ok-text); }
.status-tabs .st-resolved.on::after { background: #16a36e; }
.status-tabs .st-resolved.on b { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }

.search {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; color: var(--subtle);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search:focus-within { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px rgba(0, 156, 211, .12); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); }
.search input::placeholder { color: var(--subtle); }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.tabs button {
  height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, color .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--surface); color: var(--brand-700); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.tabs b {
  font-size: 11px; min-width: 20px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-grid; place-items: center; background: var(--border); color: var(--muted);
}
.tabs button.on b { background: var(--brand-50); color: var(--brand-700); }
.tabs b.warn { background: var(--warn-bg); color: var(--warn-text); }

.filters { display: flex; gap: 8px; align-items: center; }
.select-pill {
  position: relative; display: inline-flex; align-items: center; height: 30px; border-radius: 15px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12.5px; font-weight: 600;
}
.select-pill select { appearance: none; border: 0; background: transparent; height: 100%; padding: 0 28px 0 12px; outline: none; cursor: pointer; font-size: 12.5px; font-weight: 600; color: inherit; }
.select-pill .icon { position: absolute; right: 9px; pointer-events: none; }
.select-pill:hover { border-color: var(--border-strong); color: var(--text); }
.select-pill.on { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand-700); }
.clear-pill { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); }
.clear-pill:hover { background: var(--border); color: var(--text); }

.list-scroll { flex: 1; overflow-y: auto; padding: 6px 8px 16px; }
.list-scroll::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar, .contact-scroll::-webkit-scrollbar { width: 8px; }
.list-scroll::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb, .contact-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box;
}

.conv {
  width: 100%; display: flex; gap: 12px; padding: 12px 10px; border-radius: 12px; text-align: left;
  position: relative; transition: background .12s;
}
.conv + .conv { margin-top: 2px; }
.conv:hover { background: var(--hover); }
.conv.active { background: var(--brand-50); }
.conv.active::before { content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--brand); }
.conv-move-move { transition: transform .35s ease; }
.conv-move-leave-active { display: none; } /* al cambiar de solapa, lo viejo se va en el acto */
/* destello solo para los chats que entran en vivo (no al cargar la lista) */
.conv.fresh { animation: flash 2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--brand-100); } 100% { background: transparent; } }
.conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conv-row { display: flex; align-items: center; gap: 8px; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--subtle); white-space: nowrap; }
.conv.unread .conv-time { color: var(--brand-600); font-weight: 600; }
.conv-preview {
  flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 4px;
}
.conv-preview .icon { color: var(--subtle); }
.conv.unread .conv-preview { color: var(--text); font-weight: 500; }
.conv-prefix { color: var(--subtle); font-weight: 500; flex: none; }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand);
  color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.conv-tags { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
/* respuestas rapidas */
.canned-row { padding-top: 11px; padding-bottom: 11px; }
.canned-code { font-weight: 700; color: var(--brand-700); font-size: 14px; }
.canned-preview { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; margin-top: 2px; }
.canned-form { align-items: stretch; text-align: left; gap: 16px; }
.canned-form textarea {
  width: 100%; resize: vertical; min-height: 150px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px; line-height: 1.45; font-weight: 400;
}
.canned-form textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(0, 156, 211, .14); }
.canned-show { display: flex; flex-direction: column; gap: 6px; }
.canned-bubble { align-self: flex-start; max-width: 100%; background: var(--out-bg, var(--brand-50)); }
.form-error-inline { color: var(--danger); }
.form-actions .spacer { flex: 1; }
.canned-form .form-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.danger-btn { color: var(--danger); }
.danger-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* contactos: empresa y email debajo del telefono */
.contact-extra { display: flex; gap: 12px; margin-top: 3px; min-width: 0; font-size: 12px; color: var(--muted); }
.contact-extra > span { display: block; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-extra > span:first-child { flex: none; max-width: 55%; }
.contact-extra .icon { display: inline-block; color: var(--subtle); vertical-align: -2px; margin-right: 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.tag-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.tag-agent { background: var(--surface); color: var(--text); }
.tag-unassigned { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.tag-pending { background: var(--violet-bg); border-color: var(--violet-border); color: var(--violet-text); }
.tag-snoozed { background: var(--surface-2); color: var(--muted); }
.tag-resolved { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.tag-label { background: transparent; border-style: dashed; }
.tag-test { background: #fff0f6; border-color: #fbc8dd; color: #c2185b; letter-spacing: .04em; }
:root[data-theme="dark"] .tag-test { background: rgba(214, 64, 159, .16); border-color: rgba(214, 64, 159, .4); color: #f48cc4; }

.contact-row { align-items: center; padding: 10px; }

.list-empty { display: grid; justify-items: center; gap: 8px; padding: 60px 28px; color: var(--subtle); text-align: center; line-height: 1.5; }
.list-empty p { margin: 0; }
.list-more { text-align: center; padding: 12px; color: var(--subtle); font-size: 12px; }
.list-error {
  display: flex; align-items: center; gap: 8px; margin: 8px; padding: 10px 12px; border-radius: 10px;
  background: var(--err-bg); color: var(--err-text); font-size: 13px;
}

.skeleton { pointer-events: none; }
.sk-avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; }
.sk-lines { flex: 1; display: grid; gap: 8px; align-content: center; }
.sk-lines i { display: block; height: 11px; border-radius: 6px; }
.sk-lines i:last-child { width: 70%; }
.sk-avatar, .sk-lines i {
  background: linear-gradient(90deg, var(--skeleton-a) 25%, var(--skeleton-b) 50%, var(--skeleton-a) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================================================ Chat */

.chat, .chat-empty, .contact { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }

.chat-empty { align-items: center; justify-content: center; text-align: center; gap: 8px; color: var(--muted); padding: 20px; }
.chat-empty-art {
  width: 92px; height: 92px; border-radius: 28px; display: grid; place-items: center; margin-bottom: 10px;
  background: var(--surface); color: var(--brand); box-shadow: var(--shadow); border: 1px solid var(--border);
}
.chat-empty h2 { font-size: 18px; color: var(--text); }
.chat-empty p { margin: 0; }

.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; min-height: 68px;
  background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1;
}
.chat-head .back { display: none; margin-left: -8px; }
.chat-who { flex: 1; min-width: 0; }
.chat-who h2 { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-who .muted { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; margin-top: 2px; }
.chat-head-right { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: 14px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--muted); white-space: nowrap;
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-open { color: var(--ok-text); background: var(--ok-bg); border-color: var(--ok-border); }
.pill-pending { color: var(--violet-text); background: var(--violet-bg); border-color: var(--violet-border); }
.pill-resolved, .pill-snoozed { color: var(--muted); background: var(--surface-2); }
.pill-unassigned { color: var(--warn-text); background: var(--warn-bg); border-color: var(--warn-border); }
.pill-agent { color: var(--text); }
/* boton Resolver / Reabrir en el encabezado del chat */
.resolve-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 12px; border-radius: 14px;
  font-size: 12px; font-weight: 700; white-space: nowrap; cursor: pointer;
  color: #fff; background: #0f7a51; border: 1px solid transparent; transition: filter .12s, transform .05s;
}
.resolve-btn:hover { filter: brightness(1.08); }
.resolve-btn:active { transform: translateY(1px); }
.resolve-btn.reopen { color: var(--text); background: var(--surface); border-color: var(--border); }
.resolve-btn.reopen:hover { background: var(--brand-50); border-color: var(--brand-100); filter: none; }
.pill-test { background: #fff0f6; border-color: #fbc8dd; color: #c2185b; letter-spacing: .04em; }
:root[data-theme="dark"] .pill-test { background: rgba(214, 64, 159, .16); border-color: rgba(214, 64, 159, .4); color: #f48cc4; }

.chat-scroll {
  flex: 1; overflow-y: auto; padding: 18px 0 10px;
  background: radial-gradient(var(--chat-dots) 1px, transparent 1px) 0 0 / 22px 22px, var(--chat-bg);
}
.chat-inner { max-width: 860px; margin: 0 auto; padding: 0 24px; display: flex; flex-direction: column; }
.chat-loading { display: grid; place-items: center; padding: 60px; }
.chat-loading-older, .chat-start { text-align: center; font-size: 12px; color: var(--subtle); padding: 6px 0 14px; }

.day-sep { display: flex; justify-content: center; margin: 14px 0 10px; }
.day-sep span {
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--chip-bg);
  padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow-sm);
}
.activity { display: flex; justify-content: center; margin: 8px 0; }
.activity span { font-size: 12px; color: var(--muted); background: var(--soft); padding: 4px 12px; border-radius: 8px; }

.msg { display: flex; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.out { justify-content: flex-end; }
.bubble {
  position: relative; max-width: min(560px, 78%); padding: 7px 10px 6px 12px; border-radius: 14px;
  background: var(--bubble-in); box-shadow: var(--shadow-sm); line-height: 1.45; overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.first .bubble { border-top-left-radius: 4px; }
.msg.out.first .bubble { border-top-right-radius: 4px; }
.msg.note .bubble { background: var(--note); border: 1px solid var(--note-border); }
.msg.failed .bubble { box-shadow: 0 0 0 1px var(--danger); }
.sender { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--brand-700); margin-bottom: 2px; }
.note-tag { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; color: var(--note-text); margin-bottom: 3px; }
.text { white-space: normal; font-size: 14px; }
.text a { word-break: break-all; }
.meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 3px;
  font-size: 11px; color: var(--subtle); margin-top: 2px; margin-left: 14px; float: right; position: relative; top: 4px;
}
.bubble::after { content: ''; display: block; clear: both; }
.tick.read { color: var(--brand); }
.tick.failed { color: var(--danger); }

.att + .att, .att + .text, .att + .transcript { margin-top: 6px; }
.transcript {
  margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: var(--soft); border-left: 3px solid var(--brand);
  max-width: 340px;
}
.transcript-head { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; color: var(--brand-700); margin-bottom: 3px; }
.transcript-text {
  font-size: 13.5px; line-height: 1.45; color: var(--text); white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.transcript.full .transcript-text { display: block; }
.transcript .link { font-size: 12px; margin-top: 3px; }
.att-img { display: block; max-width: 100%; width: 300px; max-height: 320px; object-fit: cover; border-radius: 10px; cursor: zoom-in; margin: 2px -4px 0 -6px; }
.att audio { width: 260px; max-width: 100%; height: 40px; display: block; }
.att video { max-width: 100%; width: 320px; border-radius: 10px; display: block; }
.att-file {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 9px; border-radius: 10px; min-width: 220px;
  background: var(--soft); color: var(--text); text-decoration: none; transition: background .15s;
}
.att-file:hover { background: var(--soft-2); }
.att-file > span:nth-child(2) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att-file b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file small { font-size: 11.5px; color: var(--muted); }
.att-file > .icon { color: var(--muted); }
.att-ico { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--brand); color: #fff; flex: none; }

.new-below {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 20px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 12.5px; box-shadow: var(--shadow);
}

/* ---------- cuadro para escribir ---------- */
.composer-wrap { position: relative; background: var(--surface); border-top: 1px solid var(--border); }
.composer-wrap.note { background: var(--note); border-top-color: var(--note-border); }
.composer-tabs { display: flex; align-items: center; gap: 4px; padding: 8px 20px 0; }
.composer-tabs button {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 11px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.composer-tabs button:hover { background: var(--soft); color: var(--text); }
.composer-tabs button.on { background: var(--brand-50); color: var(--brand-700); }
.composer-wrap.note .composer-tabs button.on { background: var(--note-border); color: var(--note-text); }
.composer-hint { margin-left: auto; font-size: 11.5px; color: var(--subtle); }
/* Corrector ortografico */
.spell-wrap { position: relative; margin-left: 4px; }
.composer-tabs .spell-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 999px;
  font-size: 12.5px; color: var(--subtle); border: 1px dashed var(--border); background: transparent; }
.composer-tabs .spell-btn.on { color: var(--brand-700); background: var(--brand-50); border: 1px solid var(--brand-100); }
.composer-tabs .spell-btn.open, .composer-tabs .spell-btn:hover { color: var(--text); border-style: solid; }
.spell-menu { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 30; width: 300px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); animation: ctx-in .12s ease-out; }
.spell-menu-head { padding: 6px 10px 4px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--subtle); }
.composer-tabs .spell-opt { display: flex; align-items: flex-start; gap: 10px; width: 100%; height: auto; padding: 8px 10px; border-radius: 10px;
  text-align: left; color: var(--text); background: transparent; }
.composer-tabs .spell-opt:hover { background: var(--soft); }
.composer-tabs .spell-opt.on { background: var(--brand-50); }
.spell-radio { flex: none; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--border); transition: border .12s; }
.spell-opt.on .spell-radio { border: 5px solid var(--brand); }
.spell-opt-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.spell-opt-text b { font-size: 13.5px; font-weight: 600; }
.spell-opt-text small { font-size: 12px; color: var(--muted); line-height: 1.3; }
.spell-menu-note { margin: 4px 10px 6px; font-size: 11.5px; color: var(--subtle); }
.spell-box { margin: 10px 20px 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--brand); border-radius: 12px; box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,.06)); animation: ctx-in .12s ease-out; }
.spell-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.spell-badge { width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-700); }
.spell-keys { margin-left: auto; font-size: 11.5px; color: var(--subtle); }
.spell-x { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.spell-x:hover { background: var(--soft); color: var(--text); }
.spell-text { white-space: pre-wrap; font-size: 14.5px; line-height: 1.45; }
.spell-text .fix { background: #fff1b8; color: #6b4e00; border-radius: 4px; padding: 0 2px; font-weight: 600; }
.spell-orig { margin-top: 6px; font-size: 12px; color: var(--subtle); white-space: pre-wrap; text-decoration: line-through; text-decoration-color: rgba(0,0,0,.18); }
.spell-btns { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.spell-btns .link { margin-right: auto; display: inline-flex; align-items: center; gap: 4px; }
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 10px 20px 14px;
}
.composer-locked {
  align-items: center; gap: 10px; padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--border);
  color: var(--subtle); font-size: 13px;
}
.composer-locked b { color: #c2185b; }
.composer-text {
  flex: 1; min-height: 42px; max-height: 180px; resize: none; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
  line-height: 1.45; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.composer-text:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px rgba(0, 156, 211, .12); }
.composer-text::placeholder { color: var(--subtle); }
.composer-wrap.note .composer-text { background: rgba(255, 255, 255, .55); border-color: var(--note-border); }
:root[data-theme="dark"] .composer-wrap.note .composer-text { background: rgba(0, 0, 0, .2); }
.composer-wrap.note .composer-text:focus { box-shadow: 0 0 0 4px rgba(242, 207, 107, .25); }
.composer .icon-btn { height: 42px; width: 38px; }
.send-btn { width: 42px; height: 42px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--brand); color: #fff; transition: background .15s, opacity .15s; }
.send-btn:hover:not(:disabled) { background: #0085b5; }
.send-btn:disabled { opacity: .35; }
.composer-wrap.note .send-btn { background: #c79a12; }
/* Nota de voz */
.rec-bar { align-items: center; gap: 10px; }
.rec-bar .rec-cancel { color: var(--danger, #d64545); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; flex: none; animation: rec-blink 1s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 38px; }
.rec-label { flex: 1; color: var(--muted); font-size: 13.5px; }
@keyframes rec-blink { 50% { opacity: .25; } }

.composer-files { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px 0; }
.file-chip {
  display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 6px 6px 6px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.file-chip img { width: 38px; height: 38px; object-fit: cover; border-radius: 7px; }
.file-chip .att-ico { width: 38px; height: 38px; }
.file-chip-name { display: flex; flex-direction: column; min-width: 0; font-size: 12.5px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-chip-name small { font-weight: 500; color: var(--subtle); }
.file-chip button { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.file-chip button:hover { background: var(--border); color: var(--text); }
.icon-btn.on { background: var(--brand-50); color: var(--brand-700); }
.emoji-panel {
  position: absolute; left: 20px; bottom: calc(100% - 4px); z-index: 6; width: 340px; max-width: calc(100% - 40px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.emoji-tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.emoji-tabs button { width: 34px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 17px; color: var(--muted); }
.emoji-tabs button:hover { background: var(--soft); }
.emoji-tabs button.on { background: var(--brand-50); color: var(--brand-700); }
.emoji-tabs .emoji-close { margin-left: auto; }
/* Stickers y GIFs */
.msg.sticker .bubble { background: transparent; box-shadow: none; padding: 0; }
.msg.sticker .bubble { display: flex; flex-direction: column; align-items: flex-start; }
.msg.sticker.out .bubble { align-items: flex-end; }
.msg.sticker .bubble .meta { background: var(--surface); border-radius: 8px; padding: 1px 6px; display: inline-flex; float: none; margin-top: 2px; box-shadow: var(--shadow-sm); }
.att-sticker { display: block; width: 140px; height: 140px; object-fit: contain; cursor: zoom-in; }
.att-gif { position: relative; display: block; }
.att-gif video { width: 240px; max-width: 100%; border-radius: 10px; display: block; }
.att-gif b { position: absolute; left: 8px; bottom: 8px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(0,0,0,.55); border-radius: 5px; padding: 1px 5px; }
.sticker-panel .emoji-tabs { align-items: center; }
.emoji-tabs .stick-tab { width: auto; padding: 0 10px; gap: 6px; display: inline-flex; font-size: 13px; font-weight: 600; }
.gif-mark { font-size: 10px; font-weight: 800; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 3px; line-height: 14px; }
.stick-up { margin-left: 6px; display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--brand-700); background: var(--brand-50); cursor: pointer; }
.stick-up:hover { background: var(--brand-100); }
.stick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; padding: 8px; max-height: 260px; overflow-y: auto; }
.stick-item { position: relative; }
.stick-item > button:first-child { width: 100%; aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; padding: 4px; }
.stick-item > button:first-child:hover { background: var(--brand-50); }
.stick-item img, .stick-item video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.stick-del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; display: none; place-items: center;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow-sm); }
.stick-item:hover .stick-del { display: grid; }
.stick-del:hover { color: var(--danger, #d64545); }
.stick-empty { padding: 26px 18px; text-align: center; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.stick-empty small { color: var(--subtle); font-size: 12px; }
.stick-error { display: flex; align-items: center; gap: 5px; padding: 0 12px 10px; font-size: 12.5px; color: var(--danger, #d64545); }
@media (hover: none) { .stick-del { display: grid; } }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px; max-height: 220px; overflow-y: auto; }
.emoji-grid button { height: 36px; border-radius: 8px; font-size: 21px; line-height: 1; }
.emoji-grid button:hover { background: var(--brand-50); transform: scale(1.12); }
.composer-error { display: flex; align-items: center; gap: 6px; padding: 8px 20px 0; font-size: 12.5px; color: var(--err-text); }

.canned {
  position: absolute; left: 20px; right: 20px; bottom: calc(100% - 4px); z-index: 5; max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.canned button { width: 100%; display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; text-align: left; }
.canned button.on { background: var(--brand-50); }
.canned b { color: var(--brand-700); font-size: 13px; flex: none; }
.canned span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.drop-zone {
  position: absolute; inset: 12px; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--brand); border-radius: 16px; background: color-mix(in srgb, var(--brand) 10%, var(--chat-bg));
  color: var(--brand-700); font-weight: 600; pointer-events: none;
}
.tick.sending { color: var(--subtle); }

/* ---------- citas, borrados, responder ---------- */
.msg { position: relative; align-items: center; gap: 6px; }
.msg-actions { position: relative; display: flex; gap: 4px; flex: none; }
.msg.out .msg-actions { flex-direction: row-reverse; }
.msg:hover .reply-btn, .reply-btn.on { opacity: 1; }
.react-picker {
  position: absolute; bottom: calc(100% + 6px); z-index: 4; display: flex; gap: 2px; padding: 5px 6px; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: ctx-in .12s ease-out;
}
/* puente invisible entre el globo y la barrita: el mouse no "sale" del mensaje al cruzar el hueco */
.react-picker::after { content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 10px; }
.msg.in .react-picker { left: 0; }
.msg.out .react-picker { right: 0; }
.react-picker button { width: 34px; height: 34px; border-radius: 50%; font-size: 20px; line-height: 1; transition: transform .1s, background .1s; }
.react-picker button:hover { background: var(--soft); transform: scale(1.2); }
.react-picker .picker-sep { width: 1px; margin: 6px 3px; background: var(--border); }
.react-picker .picker-act { display: grid; place-items: center; color: var(--muted); font-size: 0; }
.react-picker .picker-act:hover { color: var(--brand-700); transform: none; }
.react-picker .picker-act.danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ventanita (editar contacto) */
.modal-back {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 20, 30, .45); animation: ctx-in .12s ease-out;
}
.modal-card {
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 18px 20px 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); text-align: left;
}
.modal-title { display: flex; align-items: center; justify-content: space-between; font-size: 16px; color: var(--text); }
.modal-card .form-actions { margin-top: 2px; }

/* panelcito de avisos (campanita) */
.pop-back { position: fixed; inset: 0; z-index: 55; }
.avisos-pop {
  position: fixed; z-index: 56; width: 290px; display: flex; flex-direction: column; gap: 12px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); animation: ctx-in .12s ease-out;
}
.avisos-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.avisos-vol { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.avisos-vol span { display: flex; align-items: center; gap: 6px; }
.avisos-vol b { margin-left: auto; color: var(--text); }
.avisos-vol input { width: 100%; accent-color: var(--brand); }
.avisos-vol.off { opacity: .5; }
.avisos-pop .btn-sm { align-self: flex-start; }
.avisos-note { margin: 0; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.switch { flex: none; width: 40px; height: 22px; border-radius: 11px; background: var(--soft-2); position: relative; transition: background .15s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s; }
.switch.on { background: var(--brand); }
.switch.on i { transform: translateX(18px); }
.chat-who .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* reacciones pegadas abajo del globo, como en WhatsApp */
.msg.has-reactions { margin-bottom: 14px; }
.reactions {
  position: absolute; bottom: -14px; display: flex; gap: 2px; padding: 2px 6px; border-radius: 12px; font-size: 14px; line-height: 20px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); cursor: default;
}
.msg.in .reactions { left: 10px; }
.msg.out .reactions { right: 10px; }
.reactions .pending { opacity: .5; }
.msg.out { flex-direction: row-reverse; justify-content: flex-start; }
.reply-btn {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: var(--muted); background: var(--surface); box-shadow: var(--shadow-sm); opacity: 0; transition: opacity .12s;
}
.msg:hover .reply-btn { opacity: 1; }
.reply-btn:hover { color: var(--brand-700); }
.quote {
  display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; margin: 2px 0 5px; padding: 6px 9px;
  border-radius: 8px; border-left: 3px solid var(--brand); background: var(--soft); font-size: 12.5px; cursor: pointer;
}
.quote:hover { background: var(--soft-2); }
.edited-tag { display: flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); margin: 2px 0 2px; }
.quote.missing { cursor: default; border-left-color: var(--subtle); }
.quote b { color: var(--brand-700); font-size: 12px; }
.quote span { color: var(--muted); display: flex; align-items: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.text.deleted { display: flex; align-items: center; gap: 6px; color: var(--subtle); font-style: italic; }
.msg.flash .bubble { animation: flash-bubble 1.6s ease-out; }
@keyframes flash-bubble { 0%, 35% { box-shadow: 0 0 0 3px var(--brand); } 100% { box-shadow: var(--shadow-sm); } }

.reply-bar, .ai-hint {
  display: flex; align-items: center; gap: 10px; margin: 8px 20px 0; padding: 7px 10px; border-radius: 10px; font-size: 12.5px;
}
.reply-bar { background: var(--soft); border-left: 3px solid var(--brand); color: var(--brand-700); }
.reply-bar > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.reply-bar b { font-size: 12px; }
.reply-bar span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar button { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.reply-bar button:hover { background: var(--soft-2); color: var(--text); }
.ai-hint { background: var(--violet-bg); border: 1px solid var(--violet-border); color: var(--violet-text); }
.ai-hint .link { font-size: 12.5px; color: var(--violet-text); }
.ai-hint .link.muted { color: var(--muted); font-weight: 500; }
.ai-btn { color: var(--violet-text); }
.ai-pill {
  flex: none; height: 42px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: 12px;
  background: var(--violet-bg); border: 1px solid var(--violet-border); color: var(--violet-text); font-weight: 700; font-size: 13px;
  transition: filter .15s;
}
.ai-pill:hover:not(:disabled) { filter: brightness(.96); }
.ai-pill:disabled { opacity: .7; cursor: progress; }
.ai-btn:hover:not(:disabled) { background: var(--violet-bg); color: var(--violet-text); }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.composer-hint.bot { color: var(--violet-text); font-weight: 600; }
.bot-banner {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 7px 16px; font-size: 12.5px;
  background: var(--violet-bg); color: var(--violet-text); border-top: 1px solid var(--violet-border);
}
.bot-banner .link { color: var(--violet-text); font-size: 12.5px; text-decoration: underline; }
.send-failed { clear: both; margin-top: 4px; font-size: 12px; color: var(--err-text); text-align: right; }
.send-failed .link { font-size: 12px; color: var(--err-text); text-decoration: underline; }

.lightbox {
  position: fixed; inset: 0; z-index: 20; background: rgba(8, 20, 28, .82); display: flex; flex-direction: column;
  animation: fade .15s; backdrop-filter: blur(2px);
}
.lb-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px 0; align-self: flex-end; }
.lb-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: rgba(255, 255, 255, .12); transition: background .15s;
}
.lb-btn:hover { background: rgba(255, 255, 255, .24); }
/* tamaño comodo: centrada y sin ocupar toda la pantalla */
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 12px 24px; overflow: hidden; }
.lb-stage img {
  max-width: min(860px, 82vw); max-height: 74vh; border-radius: 12px; box-shadow: var(--shadow-lg);
  cursor: zoom-in; background: #fff;
}
.lb-stage.zoom { overflow: auto; place-items: start center; }
.lb-stage.zoom img { max-width: none; max-height: none; cursor: zoom-out; }
.lb-hint { text-align: center; color: rgba(255, 255, 255, .6); font-size: 12px; padding: 0 0 16px; }
@keyframes fade { from { opacity: 0; } }

/* ============================================================ Menu de acciones */

.ctx-backdrop { position: fixed; inset: 0; z-index: 30; }
.ctx {
  position: fixed; width: 250px; padding: 6px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: ctx-in .12s ease-out;
}
@keyframes ctx-in { from { opacity: 0; transform: scale(.97) translateY(-4px); } }
.ctx-title {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px 10px 9px; margin-bottom: 4px;
  font-size: 12px; font-weight: 700; color: var(--subtle); border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.ctx-back { color: var(--text); font-size: 13px; }
.ctx-back:hover { color: var(--brand-700); }
.ctx-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  font-size: 13.5px; font-weight: 500; text-align: left; color: var(--text);
}
.ctx-item .icon { color: var(--muted); }
.ctx-item:hover:not(:disabled) { background: var(--brand-50); color: var(--brand-700); }
.ctx-item:hover:not(:disabled) .icon { color: var(--brand-700); }
.ctx-item.ok:hover:not(:disabled), .ctx-item.ok:hover:not(:disabled) .icon { background: var(--ok-bg); color: var(--ok-text); }
.ctx-item:disabled { opacity: .45; cursor: default; }
.ctx-end { margin-left: auto; }
.ctx-item small { color: var(--subtle); font-size: 11.5px; }
.ctx-agents { max-height: 320px; overflow-y: auto; }
.ctx-foot-test { color: #c2185b; }
:root[data-theme="dark"] .ctx-foot-test { color: #f48cc4; }
.ctx-foot {
  display: flex; align-items: center; gap: 6px; margin-top: 4px; padding: 8px 10px 4px;
  border-top: 1px solid var(--border); font-size: 11.5px; color: var(--subtle);
}

.app-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 40;
  padding: 11px 18px; border-radius: 12px; background: var(--navy); color: #fff; font-weight: 500; font-size: 13.5px;
  box-shadow: var(--shadow-lg); border: 1px solid rgba(255, 255, 255, .08); white-space: nowrap;
}
.toast-enter-active, .toast-leave-active { transition: opacity .2s, transform .2s; }
.toast-enter-from, .toast-leave-to { opacity: 0; transform: translate(-50%, 8px); }

/* ============================================================ Contacto */

.contact-scroll { flex: 1; overflow-y: auto; padding: 24px 0 32px; }
.contact-inner { max-width: 640px; margin: 0 auto; padding: 0 24px; display: flex; flex-direction: column; gap: 10px; }
.contact-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-sm);
  padding: 28px 24px 22px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
}
.contact-card h2 { font-size: 21px; margin-top: 6px; }
/* encabezado del chat: el numero se copia con un clic */
.phone-copy { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; margin-left: -6px; border-radius: 6px; color: inherit; font: inherit; cursor: copy; transition: background .12s, color .12s; }
.phone-copy:hover { background: var(--brand-50); color: var(--brand-700); }
.phone-copy .phone-copy-ico { opacity: 0; transition: opacity .12s; }
.phone-copy:hover .phone-copy-ico { opacity: .8; }
.phone-copy.ok { color: var(--ok, #16a34a); }
.contact-phone {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-weight: 500; font-size: 13.5px;
}
.contact-phone:hover { color: var(--brand-700); border-color: var(--brand-100); background: var(--brand-50); }
.facts { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 14px; text-align: left; }
.fact { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.fact > span:last-child { display: flex; flex-direction: column; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.fact small { font-size: 11.5px; color: var(--subtle); font-weight: 500; }
.fact-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-700); flex: none; }

/* ---------- contactos: editar, escribir, alta ---------- */
.name-row { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.name-row h2 { font-size: 21px; }
.name-edit { display: flex; align-items: center; gap: 4px; margin-top: 6px; width: 100%; max-width: 360px; }
.name-edit input, .new-contact input {
  flex: 1; min-width: 0; height: 40px; border: 1px solid var(--border-strong); border-radius: 10px; padding: 0 12px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.name-edit input:focus, .new-contact input:focus, .phone-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(0, 156, 211, .14); }
.icon-btn.ok { color: var(--ok-text); }
.name-row.in-chat { margin-top: 0; min-width: 0; }
.name-row.in-chat h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name-row.in-chat .name-pencil { width: 26px; height: 26px; opacity: 0; transition: opacity .15s; }
.chat-head:hover .name-pencil, .name-pencil:focus { opacity: 1; }
.name-edit.in-chat { margin: 0 0 2px; max-width: 320px; }
.name-edit.in-chat input { height: 32px; }
.write-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; margin-top: 8px; }
.btn-sm { height: 32px; padding: 0 12px; border-radius: 9px; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; box-shadow: none; }
.new-contact { align-items: stretch; text-align: left; gap: 16px; }
.new-contact label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.new-contact small { font-weight: 500; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.ok-hint { color: var(--ok-text); }
.phone-input { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.phone-input input { border: 0 !important; box-shadow: none !important; border-radius: 0; }
.phone-prefix { display: grid; place-items: center; padding: 0 12px; background: var(--surface-2); color: var(--text); font-weight: 700; border-right: 1px solid var(--border); }
.dup-box { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; flex-wrap: wrap; }
.test-note { margin: 0; display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--subtle); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- buscar dentro del chat ---------- */
.find-bar {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 8px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.find-bar .search { flex: 1; height: 36px; }
.find-count { font-size: 12px; color: var(--subtle); white-space: nowrap; min-width: 80px; text-align: right; }
.find-results {
  position: absolute; left: 20px; right: 20px; top: calc(100% + 4px); max-height: 320px; overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.find-results .hit-top b { font-size: 12.5px; color: var(--brand-700); flex: 1; }

/* ---------- resultados de busqueda en mensajes ---------- */
.hits-title { display: flex; align-items: center; gap: 6px; margin: 14px 10px 6px; font-size: 12px; font-weight: 700; color: var(--subtle); text-transform: uppercase; letter-spacing: .04em; }
.hit { width: 100%; text-align: left; padding: 10px; border-radius: 12px; display: flex; flex-direction: column; gap: 3px; }
.hit + .hit { margin-top: 2px; }
.hit:hover { background: var(--hover); }
.hit-top { display: flex; align-items: center; gap: 8px; }
.hit-text { font-size: 13px; color: var(--muted); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hit mark { background: rgba(255, 201, 77, .45); color: var(--text); border-radius: 3px; padding: 0 1px; }
.hits-more { display: block; margin: 8px auto 4px; }

.section-title { font-size: 14px; font-weight: 700; margin: 14px 4px 2px; display: flex; align-items: center; gap: 8px; }
.section-title b { font-size: 11px; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; display: inline-grid; place-items: center; background: var(--border); color: var(--muted); }
.cc {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); color: var(--subtle); transition: border-color .15s, box-shadow .15s;
}
.cc:hover { border-color: var(--brand-100); box-shadow: var(--shadow); color: var(--brand); }
.cc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.cc-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cc-top .pill { height: 24px; font-size: 11.5px; }
.cc-time { margin-left: auto; font-size: 12px; color: var(--subtle); }
.cc-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }

/* ============================================================ Responsive */

@media (max-width: 1100px) {
  .shell { grid-template-columns: 68px 330px 1fr; }
  .shell.side-hidden { grid-template-columns: 330px 1fr; }
  .chat-head-right .pill-agent { display: none; }
}

@media (max-width: 820px) {
  .login-card { grid-template-columns: 1fr; }
  .login-brand { min-height: 0; padding: 28px; gap: 28px; }
  .login-pitch h1 { font-size: 24px; }
  .login-form { padding: 28px; }

  /* en el celular: lista o detalle, como WhatsApp */
  .shell, .shell.side-hidden { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .shell.side-hidden .sidebar { display: flex; }  /* en el celular la barra de abajo siempre se ve */
  .side-show, .side-hide { display: none !important; }
  .sidebar { order: 2; grid-row: 2; flex-direction: row; justify-content: space-around; padding: 6px 12px; gap: 0; }
  .side-logo, .side-spacer, .side-demo { display: none; }
  .side-btn.active::before { display: none; }
  .list, .chat, .chat-empty, .contact { grid-row: 1; grid-column: 1; }
  .chat-empty { display: none; }
  .view.has-detail > .list { display: none; }
  .shell.detail-open { grid-template-rows: 1fr; }
  .shell.detail-open .sidebar { display: none; }
  .chat-head { padding: 10px 12px; }
  .chat-head .back { display: grid; }
  .chat-head-right .pill-agent { display: none; }
  .chat-inner, .contact-inner { padding: 0 12px; }
  .bubble { max-width: 88%; }
  .composer { padding: 8px 10px calc(12px + env(safe-area-inset-bottom)); gap: 6px; }
  .composer .icon-btn { width: 32px; }
  .sidebar { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  /* iPhone hace zoom si el texto de un campo es menor a 16px */
  .composer-text, .search input, .login-form input, .name-edit input, .new-contact input, .find-bar input { font-size: 16px; }
  /* en el celular los botones de reaccionar/responder se ven siempre (no hay "pasar el mouse") */
  .reply-btn { opacity: .75; }
  .conv { -webkit-touch-callout: none; user-select: none; }
  /* celular: acciones del mensaje manteniendo apretado (la barrita), no al costado del globo */
  .msg-actions { display: none; }
  .msg .bubble { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .react-picker { max-width: calc(100vw - 32px); }
  .chat-head-right .pill { display: none; }
  .resolve-btn { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 50%; }
  .resolve-btn span { display: none; }
  .chat-head-right { flex-wrap: nowrap; gap: 2px; }
  .ai-pill { padding: 0 11px; }
  .ai-pill .ai-label { display: none; }
  .composer-tabs { padding: 8px 12px 0; }
  .composer-hint { display: none; }
  .spell-wrap { margin-left: auto; }
  .spell-menu { left: auto; right: 0; width: min(300px, calc(100vw - 24px)); }
  .spell-keys { display: none; }
  .spell-box { margin: 8px 12px 0; }
  .composer-files, .composer-error { padding-left: 12px; padding-right: 12px; }
  .find-bar { padding: 8px 12px; }
  .find-results { left: 12px; right: 12px; }
  .canned { left: 12px; right: 12px; }
}
