/* ================================================================
   WA Manager - CSS Premium
   Inspirado en WhatsApp Web + estética Odoo
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Variables ─────────────────────────────────────────────────── */
:root {
  --wa-green: #25D366;
  --wa-green-dark: #128C7E;
  --wa-green-teal: #075E54;
  --wa-green-light: #d9fdd3;
  --wa-bg: #f0f2f5;
  --wa-chat-bg: #efeae2;
  --sidebar-bg: #ffffff;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --border: #e9edef;
  --msg-out-bg: #d9fdd3;
  --msg-in-bg: #ffffff;
  --unread-badge: #25D366;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: 0.2s ease;
  --sidebar-width: 380px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  /* En modo PWA standalone el 100% ocupa toda la pantalla incluyendo el safe-area */
  height: -webkit-fill-available;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--wa-bg);
  -webkit-font-smoothing: antialiased;
  /* Evitar el scroll de rebote de iOS fuera del área de scroll */
  overscroll-behavior: none;
  /* Evitar que el usuario seleccione texto accidentalmente al deslizar */
  -webkit-tap-highlight-color: transparent;
  /* En PWA: ocupar el área segura (notch iPhone, barra home Android) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ── Global Loader ─────────────────────────────────────────────── */
#global-loader {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--wa-green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  padding: 10px 20px;
  border-radius: 24px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  background: #323739;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
  max-width: 340px;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--wa-green-dark); }
.toast-error   { background: #e53e3e; }
.toast-info    { background: #323739; }

/* ── Views ─────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: flex; }

/* ── Auth Views ────────────────────────────────────────────────── */
#view-login,
#view-register {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--wa-green-teal) 0%, var(--wa-green-dark) 50%, var(--wa-green) 100%);
}

.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--wa-green-teal), var(--wa-green));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px rgba(37,211,102,.3);
}

.auth-logo-icon svg { color: #fff; }

.auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.5px;
}

.auth-logo p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-group input {
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  transition: border-color var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37,211,102,.12);
}

.btn-primary {
  padding: 13px;
  background: linear-gradient(135deg, var(--wa-green-dark), var(--wa-green));
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: opacity var(--transition), transform var(--transition);
  letter-spacing: .2px;
}

.btn-primary:hover { opacity: .9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); opacity: 1; }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.auth-switch {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.auth-switch a {
  color: var(--wa-green-dark);
  font-weight: 600;
}
.auth-switch a:hover { text-decoration: underline; }

/* ── App View ──────────────────────────────────────────────────── */
#view-app {
  height: 100vh;
  overflow: hidden;
}

#view-app.active {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  width: 100%;
  flex: 1;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 10;
}

/* Sidebar Header */
.sidebar-header {
  background: var(--wa-green-teal);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text h2 {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1;
}

.brand-text p {
  color: rgba(255,255,255,.7);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.85);
  transition: background var(--transition);
}

.icon-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.icon-btn svg { pointer-events: none; }

/* Account Tabs */
.account-tabs-container {
  padding: 10px 0 4px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
}

.tabs-scroll-btn {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  transition: all var(--transition);
  opacity: 0;
  pointer-events: none;
  border-radius: 50%;
  margin: 0 2px;
}
.tabs-scroll-btn.visible { opacity: 1; pointer-events: all; }
.tabs-scroll-btn:hover { background: var(--wa-bg); color: var(--text-primary); }

#account-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  padding: 0 4px 2px;
  flex: 1;
}
#account-tabs::-webkit-scrollbar { display: none; }

.account-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--wa-bg);
  border: 1.5px solid transparent;
  white-space: nowrap;
  transition: all var(--transition);
  flex-shrink: 0;
}

.account-tab:hover {
  background: var(--wa-bg);
  /* browsers modernos: fondo teñido del color de la cuenta */
  background: color-mix(in srgb, var(--acc-color, var(--wa-green)) 10%, white);
}

.account-tab.active {
  background: color-mix(in srgb, var(--acc-color, var(--wa-green)) 12%, white);
  border-color: var(--acc-color, var(--wa-green));
  font-weight: 600;
}

.tab-add {
  background: var(--wa-bg);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  justify-content: center;
}
.tab-add:hover { background: #e8f5e9; color: var(--wa-green-dark); }

.tab-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  line-height: 1.1;
}

.tab-phone {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.75;
  letter-spacing: 0.01em;
}

.tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: .5;
  flex-shrink: 0;
}
.tab-dot.connected { background: var(--wa-green); opacity: 1; }

.tab-badge {
  background: var(--wa-green);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Search */
.search-container {
  padding: 8px 12px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  color: var(--text-secondary);
  pointer-events: none;
}

#conv-search {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--wa-bg);
  border: none;
  border-radius: 20px;
  font-size: 13.5px;
  color: var(--text-primary);
  outline: none;
  transition: background var(--transition);
}
#conv-search::placeholder { color: var(--text-secondary); }
#conv-search:focus { background: #e8eef0; }

/* Conversation List */
#conv-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#conv-list::-webkit-scrollbar { width: 4px; }
#conv-list::-webkit-scrollbar-track { background: transparent; }
#conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(233,237,239,.7);
  transition: background var(--transition);
}

.conv-item:hover { background: var(--wa-bg); }
.conv-item.active { background: #f0f7f0; }

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-teal), var(--wa-green));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,211,102,.2);
  overflow: hidden;
}

/* Avatar de grupo: fondo más oscuro para diferenciarlo */
.conv-avatar-group {
  background: linear-gradient(135deg, #667781, #455a64) !important;
}

/* Nombre del remitente dentro de mensajes de grupo */
.msg-sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--wa-green-dark);
  margin-bottom: 2px;
}

.conv-info { flex: 1; min-width: 0; }

.conv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-secondary {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 4px;
}

.conv-time {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.conv-preview {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.unread-badge {
  background: var(--unread-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

.conv-account-tag {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 500;
  margin-top: 2px;
  display: inline-block;
}

.conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  gap: 12px;
}

.conv-empty p { font-size: 13px; }

/* ── Chat Panel ────────────────────────────────────────────────── */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  background: var(--wa-chat-bg);
}

/* Empty State */
#chat-empty {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--wa-chat-bg);
}

.empty-icon {
  width: 120px;
  height: 120px;
  background: rgba(37,211,102,.08);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon svg { color: rgba(37,211,102,.4); }

#chat-empty h3 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -.3px;
}

#chat-empty p {
  color: var(--text-secondary);
  font-size: 13.5px;
  max-width: 280px;
  text-align: center;
  line-height: 1.6;
}

/* Chat Main */
#chat-main {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* Chat Header */
.chat-header {
  background: var(--sidebar-bg);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 1;
}

#btn-back-mobile {
  display: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
#btn-back-mobile:hover { background: var(--wa-bg); }

.chat-avatar-wrap {
  position: relative;
}

#chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-teal), var(--wa-green));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(37,211,102,.2);
  overflow: hidden;
}

.chat-info { flex: 1; min-width: 0; }

#chat-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status {
  font-size: 12px;
  margin-top: 1px;
}
.chat-status.online  { color: var(--wa-green); }
.chat-status.offline { color: var(--text-secondary); }

/* Messages Area */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.15) transparent;
  background: var(--wa-chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c5b8a6' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

#messages-container::-webkit-scrollbar { width: 4px; }
#messages-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 2px; }

.msgs-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 40px 0;
  background: rgba(255,255,255,.5);
  border-radius: var(--radius-md);
  margin: 20px 0;
}

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 8px;
}

.date-separator span {
  background: rgba(225,245,254,.9);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* Message Bubbles */
.msg-wrapper {
  display: flex;
  margin: 2px 0;
}
.msg-wrapper.out { justify-content: flex-end; }
.msg-wrapper.in  { justify-content: flex-start; }

/* Fade-in animation */
.msg-new { animation: msgFadeIn .25s ease; }
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  max-width: 65%;
  padding: 8px 12px 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  position: relative;
  word-break: break-word;
}

.msg-wrapper.out .msg-bubble {
  background: var(--msg-out-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
}

.msg-wrapper.in .msg-bubble {
  background: var(--msg-in-bg);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 0;
}

.msg-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.msg-ticks {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  cursor: default;
}
/* ✓ gris — enviado a servidores Meta */
.msg-ticks.tick-sent      { color: var(--text-secondary); }
/* ✓✓ gris — entregado al dispositivo */
.msg-ticks.tick-delivered { color: var(--text-secondary); }
/* ✓✓ azul — leído */
.msg-ticks.tick-read      { color: #53bdeb; }
/* ⚠ rojo — error de entrega */
.msg-ticks.tick-failed    { color: #e53e3e; cursor: help; }

/* Input Bar */
.chat-input-bar {
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.input-attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background var(--transition);
}
.input-attach-btn:hover { background: var(--wa-bg); color: var(--text-primary); }

.input-textarea-wrap {
  flex: 1;
  background: var(--wa-bg);
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 8px 8px 8px 16px;
  min-height: 44px;
  gap: 4px;
}

.input-inline-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.input-inline-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 18px;
  transition: background var(--transition);
  flex-shrink: 0;
}
.input-inline-btn:hover { background: var(--border); color: var(--text-primary); }
.input-inline-btn.gif-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.5px;
  border-radius: 6px;
  width: auto;
  padding: 0 6px;
}

/* ── Emoji Picker ── */
.emoji-picker-container {
  position: absolute;
  bottom: 70px;
  left: 12px;
  z-index: 200;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.emoji-picker-container.hidden { display: none; }

/* ── GIF Modal ── */
.gif-modal {
  position: absolute;
  bottom: 70px;
  right: 12px;
  width: 320px;
  max-width: calc(100% - 24px);
  background: var(--sidebar-bg);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  z-index: 200;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 380px;
  border: 1px solid var(--border);
}
.gif-modal.hidden { display: none; }

.gif-search-bar {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gif-search-bar input {
  flex: 1;
  border: none;
  background: var(--wa-bg);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  outline: none;
  color: var(--text-primary);
}
.gif-search-bar input::placeholder { color: var(--text-secondary); }

.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}
.gif-item {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
}
.gif-item:hover { transform: scale(1.04); opacity: 0.9; }

#msg-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  color: var(--text-primary);
  scrollbar-width: thin;
}
#msg-input::placeholder { color: var(--text-secondary); }

#send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-dark), var(--wa-green));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(37,211,102,.3);
}
#send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(37,211,102,.4); }
#send-btn:active { transform: scale(.97); }

/* ── Modals ────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  padding: 16px;
}

.modal-backdrop.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: modalIn .25s cubic-bezier(.34,1.56,.64,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--wa-bg); color: var(--text-primary); }

.modal-body { padding: 20px 24px 24px; }

/* Add Account Tabs */
.add-tabs {
  display: flex;
  gap: 4px;
  background: var(--wa-bg);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.add-tab-btn {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.add-tab-btn.active {
  background: #fff;
  color: var(--wa-green-dark);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.add-tab-panel { display: none; }
.add-tab-panel.active { display: block; }

/* QR Tab */
.qr-form { display: flex; flex-direction: column; gap: 14px; }

.qr-step-scan {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

/* El QR no puede recortarse ni quedar sobre fondo oscuro: el móvil necesita
   ver entero el margen blanco y los tres cuadrados de las esquinas. Antes el
   recuadro medía 240px con overflow:hidden y la imagen 280px: se cortaban 20px
   por lado y la cámara no reconocía el código. */
#qr-code-container {
  width: 300px;
  max-width: 100%;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  padding: 8px;
  box-sizing: border-box;
}

#qr-code-container img {
  width: 100% !important;
  height: auto !important;
  max-width: 284px;
  background: #ffffff;
  image-rendering: pixelated;
}

.qr-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.qr-hint {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 260px;
}

/* Meta Form */
.meta-form { display: flex; flex-direction: column; gap: 14px; }

.meta-form .form-group input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  outline: none;
}
.meta-form .form-group input:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37,211,102,.12);
}

.webhook-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.webhook-row input {
  flex: 1;
  background: var(--wa-bg) !important;
  color: var(--text-secondary) !important;
  font-size: 12px !important;
  cursor: default;
}

.btn-copy {
  padding: 8px 14px;
  background: var(--wa-bg);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--wa-green-dark);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-copy:hover { background: #e8f5e9; border-color: var(--wa-green); }

.form-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* New Chat Modal */
.new-chat-form { display: flex; flex-direction: column; gap: 14px; }

.new-chat-form input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
}
.new-chat-form input:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37,211,102,.12);
}

/* ── Responsive Mobile ─────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }

  /* Usar altura dinámica del viewport para evitar problemas con la barra del navegador */
  #view-app,
  #view-app.active,
  .app-container {
    height: calc(var(--vh, 1vh) * 100);
  }

  .app-container {
    position: relative;
    overflow: hidden;
  }

  #sidebar {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 20;
    width: 100%;
    transition: transform var(--transition);
    overflow: hidden;
  }

  #sidebar.hidden-mobile {
    transform: translateX(-100%);
  }

  #chat-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: flex;
    flex-direction: row;
    overflow: hidden;
  }

  #chat-main {
    height: 100%;
    overflow: hidden;
  }

  #messages-container {
    /* Asegurar que ocupa el espacio disponible sin desbordar */
    min-height: 0;
  }

  .chat-input-bar {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
  }

  #btn-back-mobile { display: flex !important; }

  .msg-bubble { max-width: 85%; }

  .auth-card { padding: 32px 24px; margin: 16px; }

  .modal-card { margin: 16px; }
}

/* ── Scrollbar global ─────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Context menu ─────────────────────────────────────────────── */
.context-menu {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 6px 0;
  min-width: 200px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  font-size: 13.5px;
  color: var(--text-primary);
  text-align: left;
  transition: background var(--transition);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.ctx-item:hover { background: var(--wa-bg); }
.ctx-danger { color: #e53e3e; }
.ctx-danger:hover { background: #fff5f5; }
.ctx-icon { font-size: 16px; line-height: 1; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-danger {
  padding: 9px 18px;
  background: #fff0f0;
  color: #e53e3e;
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
  font-family: inherit;
}
.btn-danger:hover { background: #e53e3e; color: #fff; border-color: #e53e3e; }

.btn-secondary {
  padding: 9px 18px;
  background: var(--wa-bg);
  color: var(--text-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
  font-family: inherit;
}
.btn-secondary:hover { background: #e8eef0; border-color: #c1cdd4; }

/* ── Edit account modal (dynamically created) ─────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
  width: 100%;
  overflow: hidden;
  animation: modalIn .25s cubic-bezier(.34,1.56,.64,1);
  max-height: 90vh;
  overflow-y: auto;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}
.form-input:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37,211,102,.12);
}

/* ── Account tab settings button ─────────────────────────────── */
.tab-settings-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  flex-shrink: 0;
  margin-left: -2px;
}
.account-tab:hover .tab-settings-btn,
.account-tab.active .tab-settings-btn { opacity: 1; }
.tab-settings-btn:hover { background: rgba(0,0,0,.08); color: var(--text-primary); }

/* ── Contact info panel ───────────────────────────────────────── */
.contact-panel {
  width: 340px;
  min-width: 340px;
  background: #fff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease;
  flex-shrink: 0;
}
.contact-panel.hidden {
  width: 0;
  min-width: 0;
  border-left: none;
}
.cp-header {
  background: var(--wa-green-teal);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 600;
}
.cp-header .icon-btn { color: rgba(255,255,255,.85); }
.cp-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.cp-avatar-wrap {
  background: var(--wa-bg);
  padding: 32px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.cp-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-teal), var(--wa-green));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 38px;
  font-weight: 600;
  overflow: hidden;
}
.cp-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  padding: 0 20px;
}
.cp-phone {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding: 0 20px 12px;
}
.cp-actions {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.cp-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--wa-green-dark);
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.cp-action-icon { font-size: 22px; }
.cp-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.cp-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--wa-green-dark);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}
.cp-notes {
  width: 100%;
  min-height: 80px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-primary);
  resize: vertical;
  outline: none;
}
.cp-notes:focus { border-color: var(--wa-green); }
.cp-media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cp-media-thumb {
  aspect-ratio: 1;
  background: var(--wa-bg);
  overflow: hidden;
  cursor: pointer;
}
.cp-media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cp-media-thumb-doc {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: #f0f2f5;
}
.cp-danger-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-bottom: none;
  padding: 8px 0;
}
.cp-danger-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: #e53e3e;
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition);
}
.cp-danger-btn:hover { background: #fff5f5; }

/* ── Quick Replies Popup ───────────────────────────────────────── */
.quick-replies-popup {
  position: absolute;
  bottom: 70px;
  left: 16px;
  right: 16px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 260px;
  overflow-y: auto;
  z-index: 100;
}
.quick-replies-popup.hidden { display: none; }
.qr-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.qr-popup-item:last-child { border-bottom: none; }
.qr-popup-item:hover { background: var(--wa-bg); }
.qr-popup-shortcut {
  font-size: 12px;
  font-weight: 700;
  color: var(--wa-green-dark);
  background: #e8f5e9;
  padding: 2px 8px;
  border-radius: 12px;
  flex-shrink: 0;
}
.qr-popup-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.qr-popup-empty {
  padding: 16px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}
.qr-popup-manage {
  padding: 10px 16px;
  color: var(--wa-green-dark);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
}
.qr-popup-manage:hover { background: var(--wa-bg); }

/* ── Manage Quick Replies Modal ────────────────────────────────── */
#modal-quick-replies .modal-body { max-height: 70vh; overflow-y: auto; }
.qr-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.qr-list-item:last-child { border-bottom: none; }
.qr-list-shortcut {
  font-weight: 700;
  color: var(--wa-green-dark);
  min-width: 80px;
}
.qr-list-msg {
  flex: 1;
  color: var(--text-secondary);
  font-size: 13px;
}
.qr-list-del {
  color: #e53e3e;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background var(--transition);
}
.qr-list-del:hover { background: #fff5f5; }

/* ── Contact name inline editor ──────────────────────────────────────────── */
.cp-name-input {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  border: none;
  border-bottom: 2px solid var(--primary);
  outline: none;
  background: transparent;
  width: 100%;
  color: var(--text-primary);
  padding: 2px 4px;
}

/* ── Template modal tabs ─────────────────────────────────────────────────── */
.tpl-tab.active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}
.tpl-tab-content select,
.tpl-tab-content input[type=text],
.tpl-tab-content textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-sizing: border-box;
}
.tpl-tab-content select:focus,
.tpl-tab-content input[type=text]:focus,
.tpl-tab-content textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
.tpl-tab-content .form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.tpl-tab-content .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Modal header close button ───────────────────────────────────────────── */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background var(--transition);
}
.btn-icon:hover { background: var(--bg-secondary); }

@media (max-width: 768px) {
  .contact-panel {
    position: absolute;
    inset: 0;
    z-index: 30;
    width: 100% !important;
    min-width: 0 !important;
    border-left: none;
  }
  .contact-panel.hidden { display: none; }
}

/* ── Toggle switch (notificaciones por cuenta) ── */
.wa-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.wa-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.wa-toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
  transition: background .2s;
}
.wa-toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.wa-toggle input:checked + .wa-toggle-slider {
  background: #25D366;
}
.wa-toggle input:checked + .wa-toggle-slider::before {
  transform: translateX(20px);
}

/* ── Acciones de mensaje (reply/forward/save) ───────────────────── */

/* Botón ⋯ — aparece dentro del bubble al hacer hover */
.msg-bubble { position: relative; }

.msg-menu-trigger {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,.08);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 16px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  z-index: 2;
}
.msg-bubble:hover .msg-menu-trigger { display: block; }

/* Táctil (móvil / PWA): no existe :hover, así que el ⋯ debe estar siempre
   visible — si no, responder/reenviar/eliminar quedan inalcanzables.
   Se reserva hueco a la derecha para que no tape el texto del mensaje. */
@media (hover: none), (pointer: coarse) {
  .msg-menu-trigger { display: block; }
  .msg-bubble { padding-right: 34px; }
}

/* Menú desplegable */
.msg-actions {
  display: none;
  position: absolute;
  top: 28px;
  right: 4px;
  background: #fff;
  border: 1px solid #e9edef;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.16);
  z-index: 200;
  overflow: hidden;
  min-width: 150px;
}
.msg-actions.open { display: block; }

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: #111b21;
  white-space: nowrap;
  text-align: left;
  transition: background .15s;
}
.msg-action-btn:hover { background: #f5f6f7; }
.msg-action-btn svg { flex-shrink: 0; opacity: .7; }

.msg-action-btn.danger { color: var(--error, #d32f2f); }
.msg-action-btn.danger:hover { background: #fdecec; }

/* Feedback visual del long-press en móvil */
.msg-bubble.longpress-active { filter: brightness(.93); }

/* Barra de reply preview sobre el input */
#reply-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f0f2f5;
  border-top: 1px solid #e9edef;
  border-left: 3px solid var(--wa-green);
}
#reply-preview.visible { display: flex; }
#reply-preview-content { flex: 1; min-width: 0; }
#reply-preview-sender { font-size: 12px; font-weight: 600; color: var(--wa-green-dark); margin-bottom: 2px; }
#reply-preview-text { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#reply-cancel {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 18px; line-height: 1; padding: 2px 4px;
}
#reply-cancel:hover { color: #111b21; }

/* Quoted message dentro de burbuja */
.msg-quoted {
  background: rgba(0,0,0,.06);
  border-left: 3px solid var(--wa-green-dark);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.msg-out .msg-quoted { background: rgba(0,0,0,.08); }
.msg-quoted-sender { font-size: 11px; font-weight: 600; color: var(--wa-green-dark); margin-bottom: 2px; }
.msg-quoted-text { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }

/* Modal reenviar */
#modal-forward {
  display: none;
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.4);
  align-items: center; justify-content: center;
}
#modal-forward.open { display: flex; }
#modal-forward-box {
  background: #fff;
  border-radius: 12px;
  width: min(400px, 92vw);
  max-height: 70vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  overflow: hidden;
}
#modal-forward-box h3 { padding: 16px 20px; margin: 0; font-size: 16px; border-bottom: 1px solid #e9edef; }
#forward-conv-list { flex: 1; overflow-y: auto; }
.forward-conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; cursor: pointer; transition: background .15s;
}
.forward-conv-item:hover { background: #f5f6f7; }
.forward-conv-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--wa-green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.forward-conv-name { font-size: 14px; color: #111b21; font-weight: 500; }
.forward-conv-account { font-size: 11px; color: var(--text-secondary); }
#modal-forward-cancel {
  padding: 12px 20px; border-top: 1px solid #e9edef;
  background: none; border-left: none; border-right: none; border-bottom: none;
  cursor: pointer; font-size: 14px; color: var(--text-secondary);
  width: 100%; text-align: center;
}
#modal-forward-cancel:hover { background: #f5f6f7; color: #111b21; }

/* ── Llamadas de voz (WhatsApp Business Calling API) ───────────────── */

/* El botón solo aplica a cuentas Meta: en QR se oculta desde JS */
#btn-call.hidden { display: none; }

/* OJO: .icon-btn hereda color blanco porque nació para la cabecera verde del
   sidebar. La cabecera del chat es blanca, así que sin este override el icono
   queda blanco sobre blanco — invisible aunque esté renderizado. */
#btn-call {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--wa-green-dark);
}
#btn-call:hover { background: rgba(18,140,126,.1); }

.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 20, 26, .92);
  backdrop-filter: blur(4px);
}
.call-overlay.hidden { display: none; }

.call-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 28px;
  text-align: center;
  color: #fff;
  max-width: 92vw;
}

.call-avatar {
  width: 96px; height: 96px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 600;
  background: var(--wa-green, #25d366);
  color: #fff;
  margin-bottom: 6px;
  overflow: hidden;
}
.call-avatar img { width: 100%; height: 100%; object-fit: cover; }

.call-peer  { font-size: 20px; font-weight: 600; }
.call-state { font-size: 14px; opacity: .75; }
.call-timer { font-size: 14px; opacity: .9; font-variant-numeric: tabular-nums; min-height: 18px; }

.call-error {
  font-size: 13px;
  color: #ffb4b4;
  background: rgba(211, 47, 47, .18);
  border: 1px solid rgba(211, 47, 47, .4);
  border-radius: 8px;
  padding: 8px 12px;
  max-width: 340px;
  line-height: 1.4;
}
.call-error.hidden { display: none; }

/* Indicador de "sonando" */
.call-state.ringing::after {
  content: '';
  display: inline-block;
  width: 4px; height: 4px;
  margin-left: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: call-pulse 1.2s infinite;
}
@keyframes call-pulse { 0%,100% { opacity: .2 } 50% { opacity: 1 } }

.call-actions { display: flex; gap: 22px; margin-top: 20px; }

.call-btn {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  transition: transform .12s, filter .12s;
}
.call-btn:hover { filter: brightness(1.12); }
.call-btn:active { transform: scale(.94); }
.call-btn.hidden { display: none; }

.call-accept { background: #25d366; }
.call-hangup { background: #e53935; }
.call-mute   { background: rgba(255,255,255,.18); }
.call-mute.muted { background: #fff; color: #111b21; }

@media (max-width: 768px) {
  .call-actions { gap: 30px; }
  .call-btn { width: 66px; height: 66px; }
}

/* ── Aviso de ventana de servicio de 24 h cerrada (cuentas Meta) ───── */
.sw-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: #fff8e1;
  border-top: 1px solid #ffe082;
  border-left: 4px solid #f5a623;
  font-size: 13px;
  line-height: 1.45;
  color: #6b4e00;
}
.sw-warning.hidden { display: none; }
.sw-icon { font-size: 16px; flex-shrink: 0; line-height: 1.3; }
.sw-text { flex: 1; min-width: 0; }

/* Botón de atajo a plantillas dentro del aviso de ventana cerrada */
.sw-btn {
  flex-shrink: 0;
  align-self: center;
  padding: 7px 14px;
  background: #f5a623;
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s;
}
.sw-btn:hover { filter: brightness(1.08); }
.sw-btn:active { filter: brightness(.95); }

/* ── Vista previa de enlaces (compacta, como la app oficial) ── */
.link-preview {
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: 330px;
  margin: 2px 0 6px;
  padding: 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  border-left: 3px solid #25d366;
  color: inherit;
  text-decoration: none;
  overflow: hidden;
}
.link-preview:hover { background: rgba(0, 0, 0, 0.08); }
.link-preview .lp-thumb {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  background: #fff;
}
.link-preview .lp-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.link-preview .lp-title {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview .lp-desc {
  font-size: 12px;
  line-height: 1.3;
  opacity: 0.75;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview .lp-domain {
  font-size: 11px;
  opacity: 0.6;
  margin-top: auto;
}
.msg-text a { color: #027eb5; text-decoration: underline; word-break: break-all; }

/* ── Reenviar: buscador ── */
#forward-search {
  width: 100%;
  box-sizing: border-box;
  margin: 4px 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.forward-empty { padding: 16px; text-align: center; opacity: 0.6; font-size: 13px; }

/* ── Eliminar mensaje ── */
#modal-delete-msg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#modal-delete-msg.open { display: flex; }
.delete-msg-box {
  background: #fff;
  color: #111b21;
  border-radius: 12px;
  padding: 20px 22px 16px;
  width: min(360px, 92vw);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.delete-msg-box h3 { margin: 0 0 8px; font-size: 17px; }
.delete-msg-reason { font-size: 13px; color: #667781; margin: 0 0 10px; }
.delete-msg-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.delete-msg-actions button {
  background: none;
  border: none;
  color: #008069;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 18px;
  cursor: pointer;
}
.delete-msg-actions button:hover { background: rgba(0, 128, 105, 0.08); }
.delete-msg-actions .btn-del-cancel { color: #667781; }

/* ── Botón del agente digital en la cabecera del chat ── */
.agent-toggle {
  margin-left: auto;
  margin-right: 6px;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.agent-toggle.agent-on { background: #e7f8ef; color: #0a7a46; border-color: #bfe9d2; }
.agent-toggle.agent-off { background: #fff4e5; color: #9a5b00; border-color: #ffd9a8; }
.agent-toggle.agent-blocked { background: #fdecec; color: #b42318; border-color: #f7c3c0; }
@media (max-width: 600px) { .agent-toggle { font-size: 11px; padding: 3px 8px; } }
