/* Club San Miguel · Bandeja — Modelo A · Clásico (claro, tres columnas) + modo noche */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; -webkit-font-smoothing: antialiased; }
h1, p, ul { margin: 0; padding: 0; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:root {
  --bg: #f0f2f5; --panel: #ffffff; --panel2: #f7f8fa; --line: #e3e6ea; --text: #1d2125; --muted: #667781;
  --accent: #1a6fd8; --accent-ink: #ffffff; --hover: #f2f4f7; --sel: #e8f0fb;
  --in: #ffffff; --out: #dbeafe; --chatbg: #efeae2;
  --wa: #0d7038; --ig: linear-gradient(135deg, #e1306c 0%, #c13584 45%, #833ab4 100%);
  --err: #c62828; --err-bg: #fdecea; --unread: #0d7038; --unread-ink: #ffffff;
  --r: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="noche"] {
  --bg: #121212; --panel: #1e1e1e; --panel2: #242424; --line: #2f2f2f; --text: #e8e8e8; --muted: #9a9a9a;
  --accent: #6aa9ff; --accent-ink: #0b1a2e; --hover: #262626; --sel: #1d2a3c;
  --in: #2a2a2a; --out: #1f3550; --chatbg: #161616;
  --err: #ff8a80; --err-bg: #3a1f1f; --unread: #3ecf7a; --unread-ink: #0e2a19;
  color-scheme: dark;
}
html, body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.4; height: 100%; }

.b-boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* botones */
.b-btn { min-height: 44px; padding: 0 18px; border: 0; border-radius: var(--r); background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.b-btn:disabled { opacity: .55; cursor: default; }
.b-btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.b-btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.b-link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; min-height: 44px; }
.b-icon { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.b-logo { width: 52px; height: 52px; border-radius: 14px; background: var(--ig); color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: .5px; }
.b-logo-sm { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }

/* login */
.b-auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.b-authcard { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.b-authcard h1 { font-size: 20px; margin: 10px 0 12px; }
.b-authcard label { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.b-authcard input { min-height: 44px; border: 1px solid var(--line); border-radius: var(--r); padding: 0 12px; background: var(--panel2); }
.b-authmsg { min-height: 20px; color: var(--err); font-size: 14px; }
.b-authnote { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }
.b-noaccess { color: var(--err); font-weight: 600; margin: 8px 0 12px; }

/* layout */
.b-app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.b-top { height: 56px; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); gap: 12px; }
.b-title { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; }
.b-title span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-topright { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.b-user { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 4px; }
.b-user #userName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.b-user #userName { color: var(--text); font-weight: 600; }
.b-cols { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 240px 360px minmax(0, 1fr); }

/* rail */
.b-rail { background: var(--panel2); border-right: 1px solid var(--line); padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.b-filter { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 0; border-radius: var(--r); background: transparent; cursor: pointer; text-align: left; width: 100%; }
.b-filter:hover { background: var(--hover); }
.b-filter.is-on { background: var(--sel); font-weight: 700; }
.b-flabel { flex: 1; font-size: 14px; }
.b-fcount { min-width: 22px; padding: 0 6px; height: 20px; line-height: 20px; border-radius: 10px; background: var(--unread); color: var(--unread-ink); font-size: 12px; font-weight: 700; text-align: center; }
.b-fcount:empty { display: none; }
.b-fico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; flex: 0 0 auto; }
.b-fico-all { background: var(--muted); font-size: 15px; }
.b-fico-unread { background: var(--unread); font-size: 10px; }
.b-badge-ig { background: var(--ig); }
.b-badge-wa { background: var(--wa); }

/* lista */
.b-list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.b-search { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.b-search input { width: 100%; min-height: 40px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel2); padding: 0 16px; }
.b-convs { list-style: none; overflow-y: auto; flex: 1 1 auto; }
.b-conv { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 72px; align-items: start; }
.b-conv:hover { background: var(--hover); }
.b-conv.is-on { background: var(--sel); }
.b-avatar { position: relative; width: 46px; height: 46px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; color: var(--muted); flex: 0 0 auto; }
.b-avatar .b-chb { position: absolute; right: -3px; bottom: -3px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--panel); display: grid; place-items: center; font-size: 8px; font-weight: 800; color: #fff; }
.b-cmain { min-width: 0; }
.b-cname { display: flex; align-items: center; gap: 6px; min-width: 0; }
.b-cname b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-tag { flex: 0 0 auto; font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.b-prev { color: var(--muted); font-size: 14px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.b-conv.is-unread .b-prev { color: var(--text); }
.b-cside { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.b-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.b-conv.is-unread .b-time { color: var(--unread); font-weight: 700; }
.b-unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--unread); color: var(--unread-ink); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.b-empty { padding: 28px 20px; color: var(--muted); text-align: center; line-height: 1.5; }

/* chat */
.b-chat { background: var(--chatbg); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.b-chat-none { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }
.b-chat-on { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.b-chathead { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 60px; }
.b-chathead .b-avatar { width: 40px; height: 40px; }
.b-chatwho { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.b-chatwho b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-chatwho span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-back { display: none; width: 44px; height: 44px; border: 0; background: transparent; font-size: 22px; cursor: pointer; }
.b-msgs { flex: 1 1 auto; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.b-day { align-self: center; margin: 10px 0 6px; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 3px 10px; border-radius: 8px; }
.b-bub { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 10px; background: var(--in); box-shadow: 0 1px 1px rgba(0,0,0,.06); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.b-bub.is-out { align-self: flex-end; background: var(--out); }
.b-bub.is-err { background: var(--err-bg); border: 1px solid var(--err); }
.b-meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; flex-wrap: wrap; }
.b-by { font-style: italic; }
.b-st-leido { color: var(--accent); }
.b-errtxt { color: var(--err); font-size: 12px; margin-top: 4px; white-space: normal; }
.b-retry { background: none; border: 0; color: var(--err); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 6px 2px; font-size: 12px; line-height: 1.2; }
.b-quick { background: var(--panel); border-top: 1px solid var(--line); padding: 6px 12px 0; }
.b-quick-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.b-quick-row { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 4px; scrollbar-width: thin; }
.b-chip { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-size: 13px; white-space: nowrap; }
.b-chip:hover { border-color: var(--accent); }
.b-composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px 10px; background: var(--panel); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.b-composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel2); padding: 11px 16px; }

.b-toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; max-width: 90vw; z-index: 10; }
.b-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.b-toast.is-err { background: var(--err); }

/* móvil: lista → chat apilados */
@media (max-width: 899px) {
  .b-top { padding: 0 8px 0 12px; }
  .b-top { gap: 8px; }
  .b-title .b-logo { display: none; }
  .b-title span:last-child { font-size: 14px; }
  .b-topright { gap: 6px; }
  .b-user #userName { max-width: 64px; }
  .b-cols { display: flex; flex-direction: column; }
  .b-rail { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
  .b-filter { width: auto; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 22px; }
  .b-filter .b-flabel { white-space: nowrap; font-size: 13px; }
  .b-list { flex: 1 1 auto; border-right: 0; }
  .b-chat { display: none; }
  .b-app.show-chat .b-rail, .b-app.show-chat .b-list { display: none; }
  .b-app.show-chat .b-chat { display: flex; flex: 1 1 auto; }
  .b-back { display: grid; place-items: center; }
  .b-msgs { padding: 12px 10px; }
  .b-bub { max-width: 86%; }
  .b-conv { min-height: 76px; }
}
