/* Bandeja Unificada Boomzair */
:root {
  --bg: #eceef1;
  --panel: #ffffff;
  --panel-2: #f6f7f8;
  --line: #d9dde2;
  --ink: #1d2126;
  --ink-2: #5b6470;
  --ink-3: #8a929c;
  --accent: #0f6e56;
  --accent-ink: #0b5341;
  --accent-soft: #e2f1ec;
  --gold: #b8862b;
  --gold-soft: #f7efdc;
  --danger: #b4322b;
  --danger-soft: #f9e4e2;
  --ig: #c13584;
  --wa: #1f9d55;
  --em: #4b5b6b;
  --fb: #1877f2;
  --radius: 10px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.only-mobile { display: none; }
[hidden] { display: none !important; }

/* Marca */
.brand { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.brand.small { font-size: 1.05rem; margin: 0; white-space: nowrap; }

/* Páginas centradas (login, instalación) */
.page-center { display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 420px; }
.card.login { max-width: 380px; }
label { display: block; margin: 12px 0; font-weight: 500; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; font-weight: 400;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; font-weight: 500; line-height: 1.2;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.alert { padding: 10px 12px; border-radius: 8px; margin: 10px 0; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--accent-soft); color: var(--accent-ink); }
.alert.warn { background: var(--gold-soft); color: #6b4e12; }
table.checks { width: 100%; border-collapse: collapse; margin: 12px 0 18px; }
table.checks td { padding: 6px 0; border-bottom: 1px solid var(--line); }
table.checks td.ok { color: var(--accent); text-align: right; font-weight: 600; }
table.checks td.bad { color: var(--danger); text-align: right; font-weight: 600; }

/* Estructura de la app */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 16px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.tabs { display: flex; gap: 2px; }
.tabs a { padding: 6px 10px; border-radius: 6px; color: var(--ink-2); text-decoration: none; font-weight: 500; white-space: nowrap; }
.tabs a.active { color: var(--ink); background: var(--panel-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.icon-btn { border: 0; background: transparent; font-size: 1.6rem; line-height: 1; padding: 4px 8px; cursor: pointer; }
#main { flex: 1; min-height: 0; }

/* Bandeja: tres columnas */
.inbox { display: grid; grid-template-columns: 210px 340px 1fr; height: 100%; }
.rail { background: var(--panel-2); border-right: 1px solid var(--line); padding: 14px 10px; overflow-y: auto; }
.rail h3 { font-size: .78rem; color: var(--ink-3); font-weight: 600; margin: 14px 8px 6px; }
.rail h3:first-child { margin-top: 0; }
.rail button {
  display: flex; width: 100%; align-items: center; gap: 8px; padding: 7px 8px; border: 0; background: transparent;
  border-radius: 6px; cursor: pointer; text-align: left; color: var(--ink-2);
}
.rail button.active { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.rail button .count { margin-left: auto; font-size: .78rem; color: var(--ink-3); }
.rail button .count.hot { background: var(--gold); color: #fff; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.instagram { background: var(--ig); } .dot.whatsapp { background: var(--wa); } .dot.email { background: var(--em); } .dot.messenger { background: var(--fb); }

.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-head { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.list-head input { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.list-body { overflow-y: auto; flex: 1; }
.push-banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--gold-soft); border-bottom: 1px solid var(--line); font-size: .85rem; color: #6b4e12; }
.push-banner span { flex: 1; }
.conv {
  display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; min-width: 0; gap: 0 10px; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line);
  cursor: pointer; text-align: left; width: 100%; border-left: 0; border-right: 0; border-top: 0; background: transparent;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-soft); }
.conv .edge { border-radius: 0 3px 3px 0; grid-row: 1 / span 3; }
.conv .edge.instagram { background: var(--ig); } .conv .edge.whatsapp { background: var(--wa); } .conv .edge.email { background: var(--em); } .conv .edge.messenger { background: var(--fb); }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-right: 6px; vertical-align: 1px; }
.conv .when { font-size: .78rem; color: var(--ink-3); white-space: nowrap; }
.conv .acct { font-size: .78rem; color: var(--ink-3); grid-column: 2 / span 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { grid-column: 2 / span 2; font-size: .88rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .preview { color: var(--ink); }
.conv .window { grid-column: 3; font-size: .74rem; padding: 1px 6px; border-radius: 10px; background: var(--gold-soft); color: #6b4e12; align-self: start; }
.conv .window.closed { background: var(--danger-soft); color: var(--danger); }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); }

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.thread-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.thread-head .who { min-width: 0; flex: 1; }
.thread-head .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head .who span { font-size: .85rem; color: var(--ink-2); }
.thread-head select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); object-fit: cover; flex-shrink: 0; display: grid; place-items: center; font-weight: 600; color: var(--ink-2); }
.msgs { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 6px; }
.msgs > * { flex-shrink: 0; }
.msg { max-width: min(72%, 640px); padding: 9px 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); word-wrap: break-word; }
.msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-color: #cfe5dc; border-bottom-right-radius: 4px; }
.msg.error { border-color: var(--danger); }
.msg .subj { font-weight: 600; margin-bottom: 4px; }
.msg .txt { white-space: pre-wrap; }
.msg .meta { display: block; font-size: .74rem; color: var(--ink-3); margin-top: 5px; white-space: normal; }
/* Correo con formato: tarjeta ancha con el HTML original en un marco aislado */
.msg.mail { width: 100%; max-width: 860px; padding: 0; overflow: hidden; background: var(--panel); border-color: var(--line); border-radius: 12px; }
.msg.mail .subj { padding: 10px 14px 8px; margin: 0; border-bottom: 1px solid var(--line); }
.msg.mail .mail-wrap { overflow: auto; -webkit-overflow-scrolling: touch; background: #fff; }
.msg.mail iframe.html-view { display: block; width: 100%; min-width: 100%; height: 160px; border: 0; background: #fff; }
.msg.mail .att { margin: 6px 14px; }
.msg.mail .meta { margin: 0; padding: 6px 14px 8px; border-top: 1px solid var(--line); background: var(--panel-2); }
.msg.error .meta { color: var(--danger); }
.msg .att { display: block; margin-top: 6px; font-size: .85rem; }
.msg .att img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; }
.day { align-self: center; font-size: .76rem; color: var(--ink-3); margin: 10px 0 4px; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px; }
.composer .note { font-size: .82rem; color: var(--ink-2); margin-bottom: 6px; }
.composer .note.closed { color: var(--danger); }
.composer form { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 180px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.composer input.subject { width: 100%; margin-bottom: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }

/* Páginas de administración */
.page { max-width: 880px; margin: 0 auto; padding: 24px 16px 60px; }
.page section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.page section h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page section h2 .btn { margin-left: auto; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 160px; }
.row .grow b { display: block; }
.row .grow span { font-size: .85rem; color: var(--ink-2); display: block; }
.row .grow span.err { color: var(--danger); }
.pill { font-size: .76rem; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); color: var(--ink-2); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
code.box { display: block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: .85rem; word-break: break-all; margin: 4px 0 10px; user-select: all; }
details summary { cursor: pointer; font-weight: 500; margin: 6px 0; }
ol.steps { padding-left: 20px; } ol.steps li { margin: 6px 0; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); }

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

/* Móvil: una columna a la vez */
@media (max-width: 900px) {
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .tabs { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .brand.small { font-size: .95rem; }
  .rail { display: none; }
  .inbox.show-thread .list { display: none; }
  .inbox:not(.show-thread) .thread { display: none; }
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none; }
  .tabs a { padding: 6px 7px; font-size: .9rem; }
  .topbar { gap: 8px; padding: 0 10px; }
  .msg { max-width: 88%; }
  .thread-head { padding: 8px 10px; gap: 8px; }
  .thread-head .who span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .thread-head select { max-width: 130px; }
  .grid2 { grid-template-columns: 1fr; }
  .list-head { flex-wrap: wrap; }
  .mobile-filters { display: flex; gap: 6px; width: 100%; overflow-x: auto; }
  .mobile-filters button { white-space: nowrap; }
}
@media (min-width: 901px) { .mobile-filters { display: none; } }
