/* ─────────────────────────────────────────────────────────────────────────
   aiwapp · Design system inspirado en WhatsApp
   Paleta: verde / blanco / negro · Mobile-first · Touch targets ≥ 44px
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* ── Verde WhatsApp ── */
  --wa-green:        #25D366;  /* primario CTA */
  --wa-green-dark:   #128C7E;  /* hover, acento */
  --wa-green-deep:   #075E54;  /* sidebar/topbar oscura */
  --wa-green-soft:   #DCF8C6;  /* burbuja saliente */
  --wa-green-tint:   #E7F8E1;  /* fondos sutiles */

  /* ── Neutrales ── */
  --ink:             #111B21;  /* texto principal */
  --ink-2:           #3B4A54;  /* texto secundario */
  --ink-3:           #667781;  /* texto terciario, metadatos */
  --ink-4:           #8696A0;  /* placeholders */
  --line:            #E9EDEF;  /* bordes */
  --line-2:          #D1D7DB;
  --bg:              #F0F2F5;  /* fondo app */
  --bg-2:            #F7F8FA;  /* hover sutil */
  --surface:         #FFFFFF;  /* tarjetas */
  --surface-dim:     #F5F6F6;  /* surface alterno */

  /* ── Estados ── */
  --danger:          #E53935;
  --danger-soft:     #FDECEA;
  --warning:         #F4B400;
  --warning-soft:    #FEF6D8;
  --success:         var(--wa-green);
  --success-soft:    #DCF8C6;

  /* ── Sombras ── */
  --shadow-1:        0 1px 2px rgba(11, 20, 26, 0.06);
  --shadow-2:        0 1px 3px rgba(11, 20, 26, 0.08), 0 1px 2px rgba(11, 20, 26, 0.04);
  --shadow-3:        0 4px 12px rgba(11, 20, 26, 0.10);
  --shadow-modal:    0 24px 48px rgba(11, 20, 26, 0.20);

  /* ── Radios ── */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 999px;

  /* ── Espaciado (escala 4px) ── */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 48px;

  /* ── Tipografía ── */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;

  /* ── Layout ── */
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --bottom-nav-h: 64px;
  --chatlist-w: 360px;

  /* ── Animación ── */
  --t-fast: 120ms;
  --t-base: 200ms;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* ── Z-index ── */
  --z-nav: 30;
  --z-overlay: 50;
  --z-modal: 60;
  --z-toast: 70;
}

/* ── Reset y base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--ink); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-base); }
p { margin: 0; }
a { color: var(--wa-green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

/* ── Iconos SVG ─────────────────────────────────────────────────────────── */
svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Botones ────────────────────────────────────────────────────────────── */
.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1;
  padding: 10px 16px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--bg-2);
  color: var(--ink);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible, button:focus-visible {
  outline: 2px solid var(--wa-green-dark);
  outline-offset: 2px;
}
.btn:disabled, button:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--wa-green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--wa-green-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-2); border-color: var(--line-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #C62828; }
.btn-lg { min-height: 48px; padding: 12px 20px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn .icon { width: 18px; height: 18px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  min-width: 40px;
  padding: 0;
  border: none;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn.ghost { background: transparent; }
.icon-btn.on-dark { color: rgba(255,255,255,.85); }
.icon-btn.on-dark:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
label {
  display: block;
  margin: var(--s-3) 0 var(--s-1);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
}
input, textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: var(--fs-md);
  line-height: 1.4;
  color: var(--ink);
  padding: 10px 14px;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--wa-green-dark);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.18);
}
textarea { min-height: 88px; resize: vertical; }
.error { color: var(--danger); font-size: var(--fs-base); margin-top: var(--s-3); }
.hint { color: var(--ink-3); font-size: var(--fs-sm); }

/* ── Logo ──────────────────────────────────────────────────────────────── */
.logo-dot {
  display: inline-block;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--wa-green);
  position: relative;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 4px var(--wa-green-deep);
}
.logo-dot::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  background: #fff;
  border-radius: 50% 50% 50% 2px;
  bottom: 4px; right: 3px;
  transform: rotate(-12deg);
}
.logo-dot-lg { width: 44px; height: 44px; box-shadow: inset 0 0 0 6px var(--wa-green-deep); }
.logo-dot-lg::after { width: 12px; height: 12px; bottom: 6px; right: 5px; }
.brand { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.3px; color: var(--ink); }
.brand-lg { font-size: var(--fs-3xl); }

/* ─────────────────────────────────────────────────────────────────────────
   Login
   ───────────────────────────────────────────────────────────────────────── */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--s-4);
  position: relative;
  overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 20% 20%, rgba(37,211,102,.12), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(7,94,84,.18), transparent 55%),
    linear-gradient(135deg, #0B141A 0%, #1F2C33 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-modal);
  padding: var(--s-7);
}
.login-brand {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-2);
}
.brand-sub {
  color: var(--ink-3);
  font-size: var(--fs-base);
  margin-bottom: var(--s-6);
}
#login-form button[type="submit"] { width: 100%; margin-top: var(--s-5); }
.login-foot {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--ink-4);
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--line);
}

/* ─────────────────────────────────────────────────────────────────────────
   App shell
   ───────────────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Sidebar (escritorio) ── */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--wa-green-deep);
  color: rgba(255,255,255,.92);
  border-right: 1px solid rgba(0,0,0,.15);
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
}
.sidebar-brand .brand { color: #fff; }
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-2) var(--s-3);
  overflow-y: auto;
}
.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-3);
  min-height: 44px;
  border-radius: var(--r-md);
  color: rgba(255,255,255,.85);
  font-weight: 500;
  font-size: var(--fs-base);
  text-decoration: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.sidebar .nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar .nav-item.active { background: var(--wa-green); color: #fff; }
.sidebar .nav-icon { width: 20px; height: 20px; }
.sidebar-footer {
  padding: var(--s-3);
  border-top: 1px solid rgba(255,255,255,.10);
}
.me-card {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2);
  border-radius: var(--r-md);
}
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.me-name {
  font-size: var(--fs-base);
  color: #fff;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.me-role {
  font-size: var(--fs-xs);
  color: rgba(255,255,255,.65);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Topbar ── */
.content {
  display: flex; flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}
.topbar {
  display: flex; align-items: center; gap: var(--s-3);
  height: var(--topbar-h);
  padding: 0 var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.topbar h1 {
  flex: 1;
  font-size: var(--fs-lg);
  font-weight: 600;
}
.topbar-right { display: flex; align-items: center; gap: var(--s-3); }
.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-4);
  flex-shrink: 0;
  transition: background var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.conn-dot.online {
  background: var(--wa-green);
  box-shadow: 0 0 0 4px rgba(37,211,102,.18);
}

.view-root {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ── Bottom nav (móvil) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: var(--z-nav);
}
.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--ink-3);
  text-decoration: none;
  padding: 6px 4px;
}
.bottom-nav .nav-icon { width: 22px; height: 22px; }
.bottom-nav .nav-item.active { color: var(--wa-green-dark); }
.bottom-nav .nav-item:active { background: var(--bg-2); }

/* ─────────────────────────────────────────────────────────────────────────
   Avatar
   ───────────────────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--wa-green-dark);
  color: #fff;
  font-weight: 600;
  font-size: var(--fs-base);
  flex-shrink: 0;
  text-transform: uppercase;
  user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: var(--fs-sm); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-xl); }
.me-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--wa-green);
  color: #fff;
  font-weight: 600;
  font-size: var(--fs-base);
  flex-shrink: 0;
  text-transform: uppercase;
}

/* ─────────────────────────────────────────────────────────────────────────
   Panel (contenedor de vistas tipo Contactos / Usuarios)
   ───────────────────────────────────────────────────────────────────────── */
.view-root > * { width: 100%; }

.panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  margin: var(--s-4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--topbar-h) - var(--s-4) * 2);
}
.panel-header {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-header h2 { flex: 1; font-size: var(--fs-lg); }
.panel-body { padding: var(--s-4) var(--s-5); overflow-y: auto; flex: 1; }
.panel-body.is-flush { padding: 0; }

/* ── Search bar ── */
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}
.search-wrap svg {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--ink-4);
  pointer-events: none;
}
.search-wrap input {
  padding-left: 38px;
  background: var(--bg-2);
  border-color: transparent;
  min-height: 40px;
}
.search-wrap input:focus { background: var(--surface); border-color: var(--wa-green-dark); }

/* ── Tablas ── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}
.table thead th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-3);
  background: var(--surface);
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.table tbody td {
  padding: 12px var(--s-4);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-2); }
.table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: inline-flex; gap: var(--s-2); }
.row-actions .icon-btn { width: 36px; height: 36px; }

/* ── Tags / chips ── */
.tag {
  display: inline-flex;
  align-items: center;
  background: var(--wa-green-tint);
  color: var(--wa-green-deep);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  margin-right: 4px;
  margin-bottom: 2px;
}

/* ── Status pills ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--bg);
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill.connected { background: var(--success-soft); color: #1F7A30; }
.pill.connecting { background: var(--warning-soft); color: #8A6D00; }
.pill.disconnected, .pill.empty { background: var(--bg); color: var(--ink-3); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }

/* ── Empty / loading states ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--s-8) var(--s-5);
  color: var(--ink-3);
  gap: var(--s-2);
}
.empty-state h3 { color: var(--ink-2); font-size: var(--fs-lg); }
.empty-state p { font-size: var(--fs-base); max-width: 320px; }

/* ─────────────────────────────────────────────────────────────────────────
   Chats (estilo WhatsApp Web)
   ───────────────────────────────────────────────────────────────────────── */
.chats-layout {
  display: grid;
  grid-template-columns: var(--chatlist-w) 1fr;
  flex: 1;
  height: 100%;
  background: var(--bg);
}

/* Lista de chats */
.chat-list {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-list-header {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-list-scroll { flex: 1; overflow-y: auto; }
.chat-list-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.chat-list-item:hover { background: var(--bg-2); }
.chat-list-item.active { background: var(--bg); }
.chat-list-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.chat-list-name {
  font-weight: 600;
  font-size: var(--fs-base);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-list-time {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  flex-shrink: 0;
}
.chat-list-meta {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--wa-green);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

/* Panel de conversación */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background:
    linear-gradient(rgba(229, 221, 213, 0.4), rgba(229, 221, 213, 0.4)),
    repeating-linear-gradient(0deg, transparent 0 14px, rgba(0,0,0,0.015) 14px 15px),
    repeating-linear-gradient(90deg, transparent 0 14px, rgba(0,0,0,0.015) 14px 15px),
    #ECE5DD;
}
.chat-empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--s-7);
  color: var(--ink-3);
}
.chat-empty .logo-dot { margin-bottom: var(--s-3); }

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-header-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-header-name {
  font-weight: 600;
  font-size: var(--fs-base);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-meta {
  font-size: var(--fs-sm);
  color: var(--ink-3);
}
.chat-back-btn { display: none; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-4) var(--s-5);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble {
  position: relative;
  max-width: min(70%, 600px);
  padding: 8px 12px 22px;
  border-radius: 8px;
  font-size: var(--fs-md);
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.bubble.in {
  align-self: flex-start;
  background: #FFFFFF;
  color: var(--ink);
  border-top-left-radius: 0;
}
.bubble.out {
  align-self: flex-end;
  background: var(--wa-green-soft);
  color: var(--ink);
  border-top-right-radius: 0;
}
.bubble + .bubble { margin-top: 2px; }
.bubble-meta {
  position: absolute;
  bottom: 4px;
  right: 10px;
  font-size: 10.5px;
  color: var(--ink-3);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.bubble-meta svg { width: 14px; height: 14px; }
.bubble-meta .status-queued { color: var(--ink-3); }
.bubble-meta .status-sent { color: #4FC3F7; }
.bubble-meta .status-failed { color: var(--danger); }
.bubble.is-queued { opacity: .85; }
.bubble.is-failed { background: var(--danger-soft); }
.bubble.is-failed.out { background: #FDECEA; }

.chat-input-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  padding-bottom: max(var(--s-2), env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1;
  background: var(--surface);
  border-color: transparent;
  border-radius: var(--r-pill);
  padding: 10px 16px;
  font-size: var(--fs-md);
}
.chat-input-row .btn-send {
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--wa-green);
  color: #fff;
  border: none;
}
.chat-input-row .btn-send:hover:not(:disabled) { background: var(--wa-green-dark); }
.chat-input-row .btn-send svg { color: #fff; }

/* ── Adjuntar (clip + menú) ─────────────────────────────────────────────── */
.attach-wrap { position: relative; flex-shrink: 0; }
.attach-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-2);
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.attach-btn:hover { background: var(--bg-2); color: var(--ink); }
.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  z-index: 20;
}
.attach-menu.open { display: flex; }
.attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  border: none;
  width: 100%;
  text-align: left;
  font-size: var(--fs-base);
  cursor: pointer;
  min-height: 44px;
}
.attach-item:hover { background: var(--bg-2); }
.attach-item svg { width: 20px; height: 20px; color: var(--wa-green-dark); }

/* ── Burbujas con tipos ─────────────────────────────────────────────────── */
.bubble-media { display: block; max-width: 100%; border-radius: var(--r-sm); margin-bottom: 4px; }
.bubble img.bubble-media { max-height: 320px; object-fit: cover; }
.bubble video.bubble-media, .bubble audio.bubble-media { width: 280px; max-width: 100%; }
.bubble-doc {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.04);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  margin-bottom: 4px;
}
.bubble-doc svg { color: var(--wa-green-dark); width: 24px; height: 24px; }
.bubble-doc-name { font-weight: 500; font-size: var(--fs-sm); }
.bubble-doc-meta { font-size: var(--fs-xs); color: var(--ink-3); }
.bubble-location {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.04);
  padding: 10px;
  border-radius: var(--r-sm);
}
.bubble-location svg { color: var(--danger); width: 22px; height: 22px; }
.bubble-poll {
  background: rgba(0,0,0,0.04);
  padding: 10px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
}
.bubble-poll-question { font-weight: 600; margin-bottom: 6px; }
.bubble-poll-option {
  padding: 4px 8px;
  background: var(--surface);
  border-radius: var(--r-xs);
  margin-bottom: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────
   Logout en topbar
   ───────────────────────────────────────────────────────────────────────── */
.logout-top {
  padding: 8px 12px;
  min-height: 36px;
  font-size: var(--fs-sm);
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: var(--surface);
}
.logout-top:hover { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ─────────────────────────────────────────────────────────────────────────
   Contactos (CRM completo)
   ───────────────────────────────────────────────────────────────────────── */
.contacts-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  flex: 1;
  height: 100%;
  background: var(--bg);
  min-height: 0;
}
.contacts-list {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.contacts-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.contacts-toolbar .btn-new {
  width: 40px; min-width: 40px; height: 40px;
  padding: 0;
  border-radius: var(--r-pill);
}
.contacts-filters {
  display: flex;
  gap: 6px;
  padding: 8px var(--s-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.contacts-filters::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--t-fast) var(--ease);
}
.filter-chip:hover { background: var(--bg-2); }
.filter-chip.active {
  background: var(--wa-green);
  color: #fff;
  border-color: var(--wa-green);
}
.filter-chip .count {
  background: rgba(0,0,0,.08);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-size: 10px;
}
.filter-chip.active .count { background: rgba(255,255,255,.25); }

.contacts-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast) var(--ease);
}
.contact-row:hover { background: var(--bg-2); }
.contact-row.active { background: var(--bg); border-left: 3px solid var(--wa-green); padding-left: calc(var(--s-4) - 3px); }
.contact-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.contact-row-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.contact-row-name {
  font-weight: 600; font-size: var(--fs-base);
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-row-meta {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Status pills extendidas */
.pill.status-lead { background: #FFF6E0; color: #8A6D00; }
.pill.status-prospecto { background: #DEF1FF; color: #0B4A75; }
.pill.status-cliente { background: var(--wa-green-tint); color: var(--wa-green-deep); }
.pill.status-inactivo { background: #F0F2F5; color: var(--ink-3); }

/* Ficha del contacto */
.contact-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}
.contact-pane-empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--s-7);
  color: var(--ink-3);
}
.contact-pane-back-btn { display: none; }

.contact-card-header {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-6);
  background: var(--wa-green-deep);
  color: #fff;
}
.contact-card-header .avatar {
  background: rgba(255,255,255,.18);
  border: 2px solid rgba(255,255,255,.25);
}
.contact-card-header-body { flex: 1; min-width: 0; }
.contact-card-header-name {
  font-size: var(--fs-2xl);
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-card-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  font-size: var(--fs-base);
  color: rgba(255,255,255,.85);
}
.contact-card-header-meta a { color: #fff; text-decoration: underline; }
.contact-card-actions { display: flex; gap: var(--s-2); flex-shrink: 0; }
.contact-card-actions .icon-btn { color: rgba(255,255,255,.85); }
.contact-card-actions .icon-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

.contact-pane-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-6);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-4);
  align-content: start;
}
.contact-section {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.contact-section.full { grid-column: 1 / -1; }
.contact-section h4 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ink-3);
  font-weight: 600;
  margin-bottom: var(--s-2);
}
.contact-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.contact-field label {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .3px;
  margin: 0;
}
.contact-field input,
.contact-field select,
.contact-field textarea {
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 8px;
  margin: 0;
  font-size: var(--fs-md);
  border-radius: var(--r-sm);
  min-height: 34px;
  color: var(--ink);
}
.contact-field input:hover,
.contact-field select:hover,
.contact-field textarea:hover {
  border-color: var(--line);
  background: var(--surface);
}
.contact-field input:focus,
.contact-field select:focus,
.contact-field textarea:focus {
  background: var(--surface);
  border-color: var(--wa-green-dark);
}
.contact-field-empty { color: var(--ink-4); font-style: italic; }

/* Editor de etiquetas */
.tags-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}
.tags-editor:hover { border-color: var(--line); background: var(--surface); }
.tag-removable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--wa-green-tint);
  color: var(--wa-green-deep);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 4px 4px 4px 10px;
  border-radius: var(--r-pill);
}
.tag-removable button {
  background: rgba(7,94,84,.15);
  color: var(--wa-green-deep);
  border: none;
  border-radius: 50%;
  width: 18px; height: 18px;
  min-height: 18px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.tag-removable button:hover { background: var(--wa-green-deep); color: #fff; }
.tag-input {
  border: none;
  outline: none;
  flex: 1;
  min-width: 100px;
  font-size: var(--fs-sm);
  padding: 4px;
  background: transparent;
  min-height: 28px;
}

.contact-changes-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: var(--s-3) var(--s-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}

.linked-chats { display: flex; flex-direction: column; gap: 6px; }
.linked-chat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--surface-dim);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.linked-chat:hover { background: var(--bg-2); }
.linked-chat-info { flex: 1; min-width: 0; font-size: var(--fs-sm); }
.linked-chat-meta { color: var(--ink-3); font-size: var(--fs-xs); }

/* ─────────────────────────────────────────────────────────────────────────
   Perfil (instancias WhatsApp)
   ───────────────────────────────────────────────────────────────────────── */
.slots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s-4);
  padding: var(--s-4);
  width: 100%;
  align-content: start;
  overflow-y: auto;
}
.slot-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  text-align: center;
  border-top: 4px solid var(--wa-green);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.slot-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); }
.slot-card.is-empty { border-top-color: var(--line-2); }
.slot-card.is-connected { border-top-color: var(--wa-green); }
.slot-card.is-connecting { border-top-color: var(--warning); }
.slot-card.is-disconnected { border-top-color: var(--ink-4); }

.slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.slot-title { font-weight: 600; font-size: var(--fs-lg); }
.slot-phone { font-size: var(--fs-base); color: var(--ink-2); }
.slot-empty-msg { color: var(--ink-3); font-size: var(--fs-sm); }
.qr-wrap {
  background: var(--surface-dim);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: grid; place-items: center;
}
.qr-img {
  display: block;
  max-width: 240px;
  width: 100%;
  height: auto;
  border-radius: var(--r-sm);
}
.slot-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: auto;
}
.slot-actions .btn { flex: 1 1 auto; min-width: 100px; }

/* ─────────────────────────────────────────────────────────────────────────
   Modal
   ───────────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 20, 26, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: var(--s-4);
  z-index: var(--z-modal);
  animation: fadeIn var(--t-base) var(--ease);
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  padding: var(--s-6);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  animation: zoomIn var(--t-base) var(--ease);
}
.modal h3 { font-size: var(--fs-lg); margin-bottom: var(--s-2); }
.modal .modal-sub { color: var(--ink-3); font-size: var(--fs-base); margin-bottom: var(--s-4); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-5);
  flex-wrap: wrap;
}
.modal-actions .btn-danger { margin-right: auto; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes zoomIn { from { opacity: 0; transform: translateY(8px) scale(.98) } to { opacity: 1; transform: none } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ─────────────────────────────────────────────────────────────────────────
   Utilidades de visibilidad
   ───────────────────────────────────────────────────────────────────────── */
.only-mobile { display: none !important; }
.only-desktop { display: initial; }

/* ─────────────────────────────────────────────────────────────────────────
   Tablet (≤ 1024px)
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --chatlist-w: 320px; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 280px;
    z-index: var(--z-overlay);
    transform: translateX(-100%);
    transition: transform var(--t-base) var(--ease);
    box-shadow: var(--shadow-3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: calc(var(--z-overlay) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) var(--ease);
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .only-mobile { display: inline-flex !important; }
  .bottom-nav { display: flex; }
  .content { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); }
  .panel { max-height: calc(100vh - var(--topbar-h) - var(--bottom-nav-h) - var(--s-4) * 2); }
  .chats-layout, .slots-grid { padding-bottom: env(safe-area-inset-bottom); }
}

/* ─────────────────────────────────────────────────────────────────────────
   Móvil (≤ 720px)
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .topbar { padding: 0 var(--s-3); }
  .topbar h1 { font-size: var(--fs-md); }

  .panel { margin: var(--s-3); border-radius: var(--r-md); }
  .panel-header, .panel-body { padding: var(--s-3); }

  .chats-layout { grid-template-columns: 1fr; }
  .chats-layout.show-pane .chat-list { display: none; }
  .chats-layout:not(.show-pane) .chat-pane { display: none; }
  .chat-back-btn { display: inline-flex; }
  .bubble { max-width: 80%; }

  /* Contactos: split → single en móvil */
  .contacts-layout { grid-template-columns: 1fr; }
  .contacts-layout.show-pane .contacts-list { display: none; }
  .contacts-layout:not(.show-pane) .contact-pane { display: none; }
  .contact-pane-back-btn { display: inline-flex; }
  .contact-card-header { padding: var(--s-4); }
  .contact-card-header-name { font-size: var(--fs-xl); }
  .contact-pane-body { padding: var(--s-3); grid-template-columns: 1fr; }

  /* Tabla → cards en móvil */
  .table-responsive { display: none; }
  .contact-cards { display: flex; }

  /* Logout label oculto en móvil, solo el icono */
  .logout-label { display: none; }
  .logout-top { width: 36px; min-width: 36px; padding: 0; }

  .slots-grid { grid-template-columns: 1fr; padding: var(--s-3); gap: var(--s-3); }
  .slot-card { padding: var(--s-4); }

  .modal { padding: var(--s-5); border-radius: var(--r-md); }

  .login-card { padding: var(--s-5); }
}

/* ─────────────────────────────────────────────────────────────────────────
   Móvil pequeño (≤ 380px)
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  :root { --fs-base: 13px; --fs-md: 14px; }
  .bottom-nav .nav-item span { font-size: 10px; }
}
