/* ===== Tema Metachat (estilo WhatsApp) — claro y oscuro ===== */
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-strong: #008069;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --bubble-text: #e9edef;
  --drawer: #111b21;
  --topbar: #202c33;
  --topbar-text: #e9edef;
  --hover: #202c33;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
  --wallpaper-op: .06;
}
[data-theme="light"] {
  --bg: #efeae2;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --accent: #00a884;
  --accent-strong: #008069;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-text: #111b21;
  --drawer: #ffffff;
  --topbar: #008069;
  --topbar-text: #ffffff;
  --hover: #f5f6f6;
  --shadow: 0 8px 30px rgba(0,0,0,.15);
  --wallpaper-op: .5;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ===== Barra superior ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--topbar); color: var(--topbar-text);
  box-shadow: 0 1px 6px rgba(0,0,0,.2);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .3px; }
.brand span, .drawer-head span, .pp-logo span { color: var(--accent); }
[data-theme="light"] .brand span, [data-theme="light"] .drawer-head span { color: #b9f6d5; }
.icon-btn {
  background: transparent; border: 0; color: inherit; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
.conn { font-size: 13px; opacity: .9; }

/* Hamburguesa animada */
.hamburger { flex-direction: column; gap: 4px; }
.hamburger span {
  width: 20px; height: 2px; background: currentColor; border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
.hamburger.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ===== Drawer ===== */
.drawer {
  position: fixed; top: 56px; left: 0; bottom: 0; width: 280px; z-index: 25;
  background: var(--drawer); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  padding: 12px 0; overflow-y: auto;
  display: flex; flex-direction: column;
}
/* Pie del menú: firma + versión (compacto, pegado abajo del todo) */
.nav-foot { margin-top: auto; padding: 8px 22px 10px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.nav-sign { font-size: 10px; font-weight: 500; color: var(--muted); opacity: .65; font-style: italic; }
.nav-ver { font-size: 9.5px; font-weight: 600; color: var(--muted); opacity: .5; letter-spacing: .3px; }
.drawer.open { transform: translateX(0); }
.drawer-overlay {
  position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.45);
  z-index: 24; opacity: 0; pointer-events: none; transition: opacity .28s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer-head { display: none; }
.nav-item {
  display: flex; align-items: center; gap: 14px; padding: 13px 22px;
  color: var(--text); cursor: pointer; font-size: 15px; font-weight: 500;
  transition: background .15s; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--hover); border-left-color: var(--accent); color: var(--accent); }
.nav-item .ni { font-size: 18px; width: 22px; text-align: center; }
.nav-sep {
  padding: 14px 22px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); font-weight: 700;
}
.drawer-inboxes { display: flex; flex-direction: column; }
.nav-sub {
  display: flex; align-items: center; gap: 9px; padding: 8px 22px 8px 40px;
  color: var(--muted); cursor: pointer; font-size: 13.5px; font-weight: 500; transition: background .15s;
}
.nav-sub:hover { background: var(--hover); color: var(--text); }
.nav-sub.active { color: var(--accent); background: var(--hover); }
.nav-sub .dot { width: 8px; height: 8px; }
.nav-sub .badge { margin-left: auto; }

.inbox-badge {
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  background: var(--panel-2); padding: 1px 7px; border-radius: 8px; margin-left: 6px; vertical-align: middle;
}
.account-card { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.account-card .acc-name { padding: 7px 10px; font-size: 14px; }
.inbox-swatch { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.18); flex: none; }
.account-card .inbox-name { font-size: 15px; font-weight: 700; }
.inbox-color { width: 34px; height: 30px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--bg); cursor: pointer; flex-shrink: 0; }
.inbox-color::-webkit-color-swatch { border: 0; border-radius: 5px; }
.inbox-color::-webkit-color-swatch-wrapper { padding: 0; }

/* ===== Main / vistas ===== */
#main { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; }
.view { height: 100%; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ===== Vista Chats ===== */
/* grid-template-rows: minmax(0,1fr) fija la fila a la altura disponible;
   sin esto, con muchos mensajes la fila crece y empuja la barra de escribir fuera. */
#view-chats { display: grid; grid-template-columns: minmax(320px, 30%) 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; }
.chatlist { min-height: 0; }
.chatlist { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); min-width: 0; }
.list-head { padding: 10px 12px; }
.search {
  width: 100%; background: var(--panel-2); border: 0; color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; outline: none;
}
.search::placeholder { color: var(--muted); }
.list-filters { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel-2); color: var(--muted); border: 1px solid transparent;
  padding: 4px 12px; border-radius: 14px; font-size: 12.5px; cursor: pointer; font-weight: 600;
  transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); border-color: var(--accent); }
/* Selector compacto de filtros: desplegable propio (estado / bandejas / etiquetas con color) */
.filterdd { position: relative; width: 100%; }
.filterdd-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border, transparent);
  border-radius: 10px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.filterdd-btn:hover { border-color: var(--accent); }
.filterdd-label { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; }
.filterdd-caret { color: var(--muted); font-size: 11px; flex: none; }
.filterdd-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--border, #2a3942); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); padding: 6px; max-height: 340px; overflow-y: auto;
}
.filterdd-menu[hidden] { display: none; }
.filterdd-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 8px 8px 4px; }
.filterdd-item { padding: 7px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.filterdd-item:hover { background: var(--panel-2); }
.filterdd-item.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.conv-scroll { flex: 1; overflow-y: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }

.conv {
  display: flex; gap: 12px; padding: 11px 14px; cursor: pointer; align-items: center;
  border-bottom: 1px solid var(--border); position: relative; transition: background .12s;
}
.conv:hover { background: var(--hover); }
.conv.active { background: var(--hover); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #fff;
}
.avatar.group { background: linear-gradient(135deg, #6b7b8c, #3b4a54); }
.conv .info { flex: 1; min-width: 0; }
.conv .name { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .snippet { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.conv .time { color: var(--muted); font-size: 11.5px; }
.badge { background: var(--accent); color: #04210f; border-radius: 11px; font-size: 11px; font-weight: 800; padding: 1px 7px; min-width: 20px; text-align: center; }
.conv-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.tagdot { font-size: 10.5px; padding: 1px 7px; border-radius: 8px; color: #fff; font-weight: 700; }
.dots {
  opacity: .45; background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 20px; width: 30px; height: 30px; border-radius: 50%; transition: all .12s; flex-shrink: 0;
}
.conv:hover .dots { opacity: 1; }
.dots:hover { background: var(--panel-2); color: var(--text); }

/* ===== Panel de conversación ===== */
.chatpane { display: flex; flex-direction: column; position: relative; background: var(--bg); min-height: 0; overflow: hidden; }
.chatpane::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: url("wallpaper.svg"); background-size: 380px; opacity: var(--wallpaper-op);
}
.pane-placeholder {
  margin: auto; text-align: center; color: var(--muted); z-index: 1;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.pp-logo { font-size: 34px; font-weight: 800; }
.thread-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel-2); z-index: 2; border-bottom: 1px solid var(--border);
}
.thread-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.thread-head .name { font-weight: 600; }
.thread-head .phone { color: var(--muted); font-size: 12.5px; }
.thread-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 6px; z-index: 1; }
.composer-wrap { flex-shrink: 0; }
.bubble {
  max-width: 62%; padding: 7px 10px 5px; border-radius: 10px; font-size: 14.2px; line-height: 1.4;
  word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.15); position: relative; animation: pop .18s ease;
  color: var(--bubble-text);
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 3px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 3px; }
/* Mensaje programado: fondo amarillo muy tenue */
.bubble.scheduled { align-self: flex-end; background: rgba(240,205,70,.16); border: 1px dashed rgba(240,205,70,.5); color: var(--text); }
[data-theme="light"] .bubble.scheduled { background: #fdf6c4; border-color: #e6cf5a; color: #5a4a00; }
.bubble .t.sched { color: #b8860b; font-weight: 600; }
[data-theme="light"] .bubble .t.sched { color: #8a6d00; }
.bubble .t { display: block; font-size: 10.5px; color: var(--muted); margin-top: 3px; text-align: right; }
.bubble .t .tick { margin-left: 3px; color: var(--muted); }
.bubble .t .tick.read { color: #53bdeb; }
.bubble .t .tick.pending { font-size: 9px; }
.bubble .t .star { color: #f5b400; }
.bubble { margin-bottom: 10px; }
/* Barra de acciones al pasar el cursor sobre el mensaje (como WhatsApp) */
.hover-actions {
  display: none; position: absolute; top: -20px; z-index: 6; align-items: center; gap: 1px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); padding: 3px 6px;
}
.bubble.in .hover-actions { left: 0; }
.bubble.out .hover-actions { right: 0; }
.bubble:hover .hover-actions { display: flex; }
.hover-actions span { font-size: 17px; cursor: pointer; padding: 2px; border-radius: 50%; line-height: 1; transition: transform .1s; }
.hover-actions span:hover { transform: scale(1.3); }
.hover-actions .ha-more { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 17px; padding: 0 4px; border-left: 1px solid var(--border); margin-left: 3px; }
.hover-actions .ha-more:hover { color: var(--text); }
/* Remitente en grupos: azul, negrita, clicable */
.bubble .sender {
  font-weight: 700; font-size: 13px; margin-bottom: 2px; cursor: pointer;
  color: #1f9cf0;
}
[data-theme="light"] .bubble .sender { color: #146fe0; }
.bubble .sender:hover { text-decoration: underline; }

/* Cita (respuesta) dentro de la burbuja — clicable para ir al original */
.quote {
  border-left: 3px solid var(--accent); background: rgba(0,0,0,.10); border-radius: 5px;
  padding: 4px 8px; margin-bottom: 4px; font-size: 12.5px; color: var(--muted); white-space: pre-wrap;
  max-height: 46px; overflow: hidden; cursor: pointer;
}
.quote:hover { background: rgba(0,0,0,.18); }
/* Separador de fecha (como WhatsApp) */
.day-sep { text-align: center; margin: 12px 0 6px; }
.day-sep span {
  background: var(--panel-2); color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 4px 12px; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.1); text-transform: capitalize;
}
/* Resaltado al saltar a un mensaje */
.bubble.flash { animation: flashMsg 1.5s ease; }
@keyframes flashMsg {
  0%, 100% { box-shadow: 0 1px 1px rgba(0,0,0,.15); }
  20%, 60% { box-shadow: 0 0 0 3px var(--accent); }
}
/* Reacción sobre la burbuja */
.reaction {
  position: absolute; bottom: -12px; font-size: 13px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 1px 5px; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.bubble.in .reaction { left: 8px; }
.bubble.out .reaction { right: 8px; }
/* Barra de reacciones en el menú */
.react-bar { display: flex; gap: 4px; padding: 6px 8px; justify-content: space-between; }
.react-bar span { font-size: 22px; cursor: pointer; border-radius: 50%; padding: 3px; transition: transform .1s, background .1s; }
.react-bar span:hover { transform: scale(1.25); background: var(--hover); }
/* Barra de respuesta sobre el compositor */
.composer-wrap { z-index: 2; }
.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel-2);
  border-top: 1px solid var(--border); border-left: 3px solid var(--accent);
}
.reply-bar .rb-text { flex: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .rb-text b { color: var(--accent); }
.sync-row { margin-top: 8px; }
/* Panel de emojis del compositor */
.emoji-panel {
  display: none; flex-wrap: wrap; gap: 2px; max-height: 220px; overflow-y: auto;
  padding: 10px 14px; background: var(--panel-2); border-top: 1px solid var(--border);
}
.emoji-panel.open { display: flex; }
.emoji-panel span { font-size: 22px; cursor: pointer; padding: 3px; border-radius: 6px; line-height: 1; transition: transform .1s; }
.emoji-panel span:hover { background: var(--hover); transform: scale(1.2); }
/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 18px; font-size: 14px; box-shadow: var(--shadow); z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.composer {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px;
  background: var(--panel-2); z-index: 2;
}
.composer input, .composer textarea {
  flex: 1; background: var(--panel); border: 0; color: var(--text);
  padding: 12px 16px; border-radius: 22px; font-size: 14.5px; outline: none;
  font-family: inherit; resize: none; line-height: 1.35; max-height: 140px;
}
.composer textarea { overflow-y: auto; }
.schedule-btn { color: var(--muted); }
.schedule-btn:hover { color: var(--accent); }
.composer { position: relative; }
/* Botón "+" y menú desplegable del compositor (por defecto ocultos: en escritorio van los botones sueltos) */
.plus-btn { display: none; font-weight: 400; transition: transform .25s cubic-bezier(.4,0,.2,1); }
.plus-btn.active { transform: rotate(135deg); color: var(--accent); }
.composer-menu { display: none; position: absolute; bottom: calc(100% + 6px); left: 8px; z-index: 9; flex-direction: column; gap: 8px; }
.composer-menu.open { display: flex; }
.cm-item {
  display: flex; align-items: center; gap: 12px; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 24px; padding: 11px 18px 11px 14px; font-size: 15px;
  font-weight: 600; cursor: pointer; box-shadow: var(--shadow); white-space: nowrap;
  opacity: 0; transform: translateY(14px) scale(.85); transform-origin: bottom left;
}
.cm-item span { font-size: 21px; }
.composer-menu.open .cm-item { animation: cmIn .28s cubic-bezier(.34,1.4,.5,1) forwards; }
.composer-menu.open .cm-item:nth-child(1) { animation-delay: .02s; }
.composer-menu.open .cm-item:nth-child(2) { animation-delay: .07s; }
.composer-menu.open .cm-item:nth-child(3) { animation-delay: .12s; }
.composer-menu.open .cm-item:nth-child(4) { animation-delay: .17s; }
@keyframes cmIn { to { opacity: 1; transform: translateY(0) scale(1); } }
.composer .icon-btn { color: var(--muted); }
.composer .icon-btn:hover { background: var(--panel); }
.send-btn {
  background: var(--accent); color: #04210f; border: 0; width: 46px; height: 46px;
  border-radius: 50%; cursor: pointer; font-size: 18px; flex-shrink: 0; transition: transform .1s;
}
.send-btn:active { transform: scale(.92); }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
.linkbtn:hover { color: var(--accent); }

/* Media en burbujas */
.media-img { display: block; max-width: 260px; max-height: 260px; border-radius: 8px; margin-bottom: 4px; cursor: pointer; }
.filecard { display: flex; gap: 12px; align-items: center; background: rgba(0,0,0,.12); border-radius: 10px; padding: 10px 12px; margin-bottom: 4px; }
.fileicon { font-size: 26px; }
.filename { font-weight: 600; font-size: 14px; margin-bottom: 6px; word-break: break-all; }
.fileactions { display: flex; gap: 8px; margin-top: 2px; }
.fbtn { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 5px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.fbtn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Paneles (otras vistas) ===== */
.panel { max-width: 560px; margin: 30px auto; padding: 26px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.panel.wide { max-width: 820px; }
.view > .panel { max-height: calc(100% - 60px); overflow-y: auto; }
.panel h2 { margin: 0 0 6px; font-size: 20px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel .sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.panel-head h2 { margin: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.field {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-size: 14.5px; outline: none; font-family: inherit;
}
.field:focus { border-color: var(--accent); }
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04210f; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { background: transparent; border-color: #ef4444; color: #ef4444; }
.btn.danger:hover { background: #ef4444; color: #fff; }
.btn.sm { padding: 7px 13px; font-size: 13px; }
#btnNewSend { margin-top: 18px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

/* Listas genéricas */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-weight: 600; font-size: 15px; }
.list-row .lr-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.list-row .lr-actions { display: flex; gap: 6px; }

/* Bandejas de entrada (grid de canales) */
.inbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 14px; }
.inbox-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 18px;
  cursor: pointer; transition: all .15s; position: relative;
}
.inbox-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.inbox-card.soon { opacity: .55; cursor: default; }
.inbox-card.soon:hover { transform: none; border-color: var(--border); }
.inbox-card .ic-icon { font-size: 30px; }
.inbox-card .ic-name { font-weight: 700; margin-top: 10px; font-size: 16px; }
.inbox-card .ic-count { color: var(--muted); font-size: 13px; margin-top: 3px; }
.inbox-card .ic-unread { position: absolute; top: 14px; right: 14px; background: var(--accent); color: #04210f; border-radius: 11px; font-size: 11px; font-weight: 800; padding: 2px 8px; }
.soon-tag { position: absolute; top: 14px; right: 14px; font-size: 10px; background: var(--panel-2); color: var(--muted); padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.inbox-card.add { border-style: dashed; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: var(--muted); }
.inbox-card.add:hover { color: var(--accent); }
.ni-ch { font-size: 17px; }

/* Diálogo añadir inbox */
.modal-box.dialog { width: 460px; max-width: 92vw; align-items: stretch; }
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.type-card {
  position: relative; border: 1.5px solid var(--border); border-radius: 12px; padding: 14px 8px;
  text-align: center; cursor: pointer; transition: all .15s; background: var(--bg);
}
.type-card:hover { border-color: var(--accent); }
.type-card.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.type-card .tc-icon { font-size: 26px; }
.type-card .tc-label { font-size: 13px; font-weight: 600; margin-top: 5px; }
.type-card .ts { position: absolute; top: 6px; right: 6px; font-size: 9px; color: var(--muted); background: var(--panel-2); padding: 1px 5px; border-radius: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-box.dialog label { margin: 12px 0 5px; }
.modal-box.dialog h3 { margin: 0 0 10px; }

/* Lista de etiquetas compacta (chips) */
.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip { display: inline-flex; align-items: center; gap: 6px; color: #fff; font-size: 13px; font-weight: 700; padding: 4px 6px 4px 12px; border-radius: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.tag-chip button { background: rgba(0,0,0,.22); border: 0; color: #fff; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.tag-chip button:hover { background: rgba(0,0,0,.45); }

/* Paleta de colores para etiquetas (compacta, círculos perfectos) */
.color-grid { display: flex; flex-wrap: wrap; gap: 9px; margin: 6px 0 4px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; position: relative; transition: transform .1s; border: 2px solid transparent; flex: 0 0 auto; padding: 0; }
.swatch:hover { transform: scale(1.12); }
.swatch.sel { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.swatch.sel::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
/* Muestra de color personalizado (selector libre) */
.swatch.custom { background: conic-gradient(red, orange, yellow, lime, aqua, blue, magenta, red); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.swatch.custom input[type="color"] { opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; position: absolute; inset: 0; }

/* Diálogo de programación */
.sched-preview { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; font-style: italic; }
.quick-times { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
input[type="datetime-local"].field { color-scheme: light dark; }

/* Página de Logs (grande, con filtros) */
.logs-page { height: 100%; display: flex; flex-direction: column; padding: 20px 28px; overflow: hidden; }
.logs-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 6px 0 14px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat-card .sc-name { font-weight: 700; font-size: 15px; }
.stat-card .sc-nums { font-size: 13px; margin-top: 4px; }
.stat-card .sc-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.log-warn { color: #ef4444; font-weight: 700; }
.logs-filters { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.logs-filters .field { max-width: 240px; }
.logs-filters #logSearch { flex: 1; max-width: none; }
.logs-table-wrap { flex: 1; min-height: 0; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.logs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.logs-table thead th { position: sticky; top: 0; background: var(--panel-2); text-align: left; padding: 9px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.logs-table td { padding: 8px 12px; border-top: 1px solid var(--border); }
.logs-table td.lt { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.logs-table td.ld { color: var(--muted); }
.logs-table tr:hover td { background: var(--hover); }

/* Panel de info */
.info-head { text-align: center; margin-bottom: 14px; }
.info-title { font-size: 18px; font-weight: 700; }
.info-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-top: 1px solid var(--border); font-size: 14px; }
.info-row span { color: var(--muted); }
.info-row b { text-align: right; word-break: break-all; }

/* Ficha del contacto: notas + pedidos */
.ficha-sec { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.ficha-h { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 8px; }
.ficha-notes { width: 100%; resize: vertical; min-height: 56px; font-family: inherit; }
.ficha-add { display: flex; gap: 6px; margin-top: 8px; }
.ficha-add .field { flex: 1; }
.ficha-order { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--panel-2); border-radius: 8px; margin-bottom: 6px; }
.ficha-order-txt { flex: 1; font-size: 14px; word-break: break-word; }
.ficha-order-date { color: var(--muted); font-size: 11px; flex: none; }
.ficha-del { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.ficha-del:hover { background: rgba(255,80,80,.15); color: #ff6b6b; }
.ficha-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.list-row .lr-note { color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-inbox { font-size: 10.5px; font-weight: 700; color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); padding: 1px 8px; border-radius: 9px; margin-left: 8px; vertical-align: middle; }

/* Diálogo de usuario */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inbox-checks { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }
.role-badge { font-size: 10px; background: var(--accent); color: #04210f; padding: 1px 7px; border-radius: 8px; font-weight: 800; vertical-align: middle; margin-left: 4px; }
.role-badge.admin { background: #3b82f6; color: #fff; }

/* Interruptor de ajustes */
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14.5px; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* Marcador de conversación resuelta */
.resolved-badge { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; background: var(--accent); color: #fff; border-radius: 50%; font-size: 10px; font-weight: 800; vertical-align: middle; }

/* Ajustes */
.setting-block { padding: 18px 0; border-top: 1px solid var(--border); }
.setting-block:first-of-type { border-top: 0; }
.conn-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.connected { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.dot.qr, .dot.reconnecting { background: #f59e0b; }
.dot.logged_out { background: #ef4444; }
.qr-box { margin-top: 16px; text-align: center; }
.qr-box img { width: 260px; height: 260px; background: #fff; padding: 10px; border-radius: 12px; }
.pairing-code { display: inline-block; font-size: 30px; font-weight: 800; letter-spacing: 8px; font-family: ui-monospace, "SF Mono", monospace; background: var(--panel-2); border: 2px dashed var(--accent); border-radius: 12px; padding: 14px 20px; margin: 6px 0 10px; color: var(--accent); }
.pairing-steps { text-align: left; margin: 6px 0 4px; padding-left: 20px; font-size: 14px; line-height: 1.7; color: var(--text); }
.pairing-status { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.5; text-align: left; }
.pairing-status.wait { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }
.pairing-status.ok { background: color-mix(in srgb, #22c55e 20%, transparent); color: var(--text); font-weight: 600; }
.pairing-status.err { background: color-mix(in srgb, #ef4444 16%, transparent); color: var(--text); }

/* ===== Menú contextual (3 puntos) ===== */
.ctx-menu {
  position: fixed; z-index: 40; min-width: 200px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: none; animation: pop .12s ease;
}
.ctx-menu.open { display: block; }
.ctx-item { padding: 10px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: #ef4444; }
.ctx-sep { height: 1px; background: var(--border); margin: 5px 0; }
.ctx-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 8px 14px 4px; font-weight: 700; }

/* ===== Popup de atajos (autocompletado con /) ===== */
.slash-pop {
  position: fixed; z-index: 45; max-height: 260px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: none; animation: pop .12s ease;
}
.slash-pop.open { display: block; }
.slash-item { padding: 9px 12px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.slash-item.sel, .slash-item:hover { background: var(--hover); }
.slash-item b { color: var(--accent); font-size: 13.5px; }
.slash-item span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Modal previsualización ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 50; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-width: 92vw; max-height: 92vh; display: flex; flex-direction: column; gap: 8px; }
.modal-close { align-self: flex-end; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 600; }
.modal-close:hover { color: var(--text); }
#modalInner img, #modalInner video { max-width: 86vw; max-height: 80vh; border-radius: 8px; display: block; }
#modalInner iframe { width: 86vw; height: 80vh; border: 0; border-radius: 8px; background: #fff; }

/* Botón "volver" (solo visible en móvil) */
.back-btn { display: none; }

/* ===== Responsive (móvil) ===== */
@media (max-width: 720px) {
  /* Lista y conversación no caben juntas: se muestra una u otra */
  #view-chats { grid-template-columns: 1fr; }
  #view-chats.show-thread .chatlist { display: none; }
  #view-chats:not(.show-thread) .chatpane { display: none; }
  .back-btn { display: flex; margin-right: 2px; }

  /* En móvil no hay hover: el menú ⋮ de cada chat debe verse siempre */
  .dots { opacity: 1; width: 34px; height: 34px; font-size: 22px; }

  .bubble { max-width: 84%; }
  .thread-body { padding: 12px 4%; }

  /* Barra superior más ajustada */
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { font-size: 18px; }
  .conn { font-size: 11px; }

  /* Menú lateral casi a pantalla completa */
  .drawer { width: 84%; max-width: 320px; }

  /* Compositor MÁS GRANDE en móvil, con las opciones agrupadas bajo "+" */
  .compose-inline { display: none; }        /* ocultamos los botones sueltos */
  .plus-btn { display: flex; }              /* mostramos el botón "+" */
  .composer { padding: 12px 12px; gap: 8px; }
  .plus-btn { width: 46px; height: 46px; font-size: 30px; }
  .composer textarea { padding: 14px 16px; font-size: 16px; border-radius: 24px; }
  .send-btn { width: 50px; height: 50px; font-size: 21px; }
  .cm-item { padding: 13px 20px 13px 16px; font-size: 16px; }

  /* Paneles y páginas a ancho completo */
  .panel { margin: 12px; max-width: none; padding: 18px 16px; }
  .view > .panel { max-height: calc(100% - 24px); }
  .logs-page { padding: 14px 14px; }
  .logs-filters { flex-direction: column; }
  .logs-filters .field { max-width: none; }
  .inbox-grid { grid-template-columns: 1fr 1fr; }
  .logs-stats { grid-template-columns: 1fr; }

  /* Diálogos a ancho de pantalla */
  .modal-box, .modal-box.dialog { width: 94vw !important; }
  .grid2 { grid-template-columns: 1fr; }

  /* Filtros de la lista de chats: permitir scroll horizontal si no caben */
  .list-filters { overflow-x: auto; flex-wrap: nowrap; }
  .chip { white-space: nowrap; }
}
