:root {
  --brand: #0b3d6b;
  --brand-2: #14548f;
  --accent: #c8102e;
  --bg: #eef2f6;
  --panel: #ffffff;
  --text: #17212b;
  --muted: #6b7a89;
  --line: #dde4eb;
  --mine: #d7e9fb;
  --theirs: #ffffff;
  --hover: #f1f5f9;
  --danger: #b3261e;
  --ok: #1f9d55;
  --shadow: 0 6px 24px rgba(10, 30, 60, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1620; --panel: #16212d; --text: #e6edf3; --muted: #8b9bab; --line: #25323f;
    --mine: #1d4a75; --theirs: #1d2b3a; --hover: #1b2835; --brand: #14548f; --brand-2: #1b6bb3;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
code { background: var(--hover); padding: 1px 5px; border-radius: 4px; }

/* ---- botones y formularios ---- */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  border: 0; background: transparent; border-radius: 8px; width: 36px; height: 36px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--brand-2); }
input[type=text], input[type=password], input:not([type]), textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(20, 84, 143, .18); }
label { display: block; font-weight: 600; margin: 12px 0 0; }
label input, label select { margin-top: 5px; font-weight: 400; }

/* ---- login ---- */
.login-page, .boot { display: flex; min-height: 100%; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; color: var(--brand); }
.login-card .logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 10px; }
.login-card form .btn { margin-top: 18px; width: 100%; justify-content: center; padding: 11px; }

/* ---- estructura ---- */
.shell { display: flex; height: 100%; max-width: 1500px; margin: 0 auto; background: var(--panel); }
.side { width: 330px; border-right: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--brand); color: #fff; }
.me .who { flex: 1; min-width: 0; }
.me .who strong, .me .who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who small { opacity: .8; font-size: 12px; }
.me .icon-btn { color: #fff; opacity: .85; }
.me .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.side-tools { padding: 10px 12px 6px; display: flex; gap: 8px; }
.side-tools input { flex: 1; }
.rooms { flex: 1; overflow-y: auto; padding: 4px 6px 12px; }
.room {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; cursor: pointer; border: 0;
  background: transparent; width: 100%; text-align: left;
}
.room:hover { background: var(--hover); }
.room.active { background: var(--mine); }
.room .meta { flex: 1; min-width: 0; }
.room .row1, .room .row2 { display: flex; gap: 8px; align-items: baseline; }
.room .name { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .time { font-size: 11px; color: var(--muted); }
.room .preview { flex: 1; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room.unread .name { color: var(--brand-2); }
.badge {
  background: var(--accent); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px;
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.section-title { padding: 10px 12px 4px; font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* ---- avatares ---- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; flex-shrink: 0; position: relative; font-size: 15px;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.c0 { background: #2d7ff9; } .c1 { background: #e0457b; } .c2 { background: #26a69a; } .c3 { background: #8e5bd6; }
.c4 { background: #e6892b; } .c5 { background: #4c9a2a; } .c6 { background: #c0392b; } .c7 { background: #00838f; }
.avatar.group { background: var(--muted); }
.dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--panel); }

/* ---- cabecera del chat ---- */
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title strong, .chat-head .title small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title small { color: var(--muted); font-size: 12px; }
.back { display: none; }
.menu {
  position: absolute; right: 12px; top: 56px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; z-index: 20; min-width: 200px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }

/* ---- mensajes ---- */
.messages { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; background: var(--panel); color: var(--muted); border-radius: 999px; padding: 2px 12px; font-size: 12px; margin: 10px 0 6px; border: 1px solid var(--line); }
.msg { display: flex; gap: 8px; max-width: 78%; align-items: flex-end; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.first { margin-top: 8px; }
.bubble {
  background: var(--theirs); border-radius: 14px; padding: 7px 11px; position: relative; min-width: 60px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06); overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--mine); }
.bubble .who { font-size: 12px; font-weight: 700; margin-bottom: 1px; }
.bubble .text { white-space: pre-wrap; }
.bubble .text a { color: var(--brand-2); }
.bubble .foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 8px; justify-content: flex-end; }
.bubble .del { border: 0; background: transparent; color: var(--muted); font-size: 11px; padding: 0; display: none; }
.bubble:hover .del { display: inline; }
.bubble .del:hover { color: var(--danger); }
.bubble.removed { font-style: italic; color: var(--muted); }
.bubble img.pic { display: block; max-width: min(320px, 100%); max-height: 300px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; }
.filechip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(120, 140, 160, .15); text-decoration: none; color: inherit; margin: 2px 0 4px; }
.filechip .ico { font-size: 22px; }
.filechip small { display: block; color: var(--muted); }
.spacer-avatar { width: 32px; flex-shrink: 0; }
.more { align-self: center; margin: 4px 0; }
.placeholder { margin: auto; color: var(--muted); text-align: center; padding: 30px; }
.placeholder .big { font-size: 44px; }

/* ---- compositor ---- */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { resize: none; max-height: 140px; min-height: 40px; line-height: 1.35; flex: 1; }
.attach-chip { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 13px; }
.attach-chip .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropzone { position: absolute; inset: 0; background: rgba(11, 61, 107, .75); color: #fff; font-size: 22px; font-weight: 700; display: flex; align-items: center; justify-content: center; z-index: 30; border: 3px dashed #fff; }
.emoji-pop { position: absolute; bottom: 64px; left: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 20; }
.emoji-pop button { border: 0; background: transparent; font-size: 22px; border-radius: 8px; padding: 3px; }
.emoji-pop button:hover { background: var(--hover); }

/* ---- ventanas ---- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.wide { max-width: 640px; }
.modal header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.modal header h2 { margin: 0; font-size: 18px; flex: 1; }
.modal .body { padding: 6px 16px 16px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 14px; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px 8px 0 0; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand-2); border-bottom-color: var(--brand-2); }
.userlist { display: flex; flex-direction: column; margin-top: 8px; }
.useritem { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; border: 0; background: transparent; text-align: left; }
.useritem:hover { background: var(--hover); }
.useritem input[type=checkbox] { width: 18px; height: 18px; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.admin-table td, .admin-table th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); }
.tag.admin { background: rgba(200, 16, 46, .12); color: var(--accent); }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 94vw; max-height: 92vh; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 70; box-shadow: var(--shadow); max-width: 90vw; }
.banner { background: #fff3cd; color: #664d03; padding: 8px 14px; font-size: 13px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #ecd98b; }
.banner .grow { flex: 1; }
.offline { background: #f8d7da; color: #58151c; border-color: #eaa6ad; }

/* ---- celular ---- */
@media (max-width: 760px) {
  .side { width: 100%; border-right: 0; }
  .chat { position: absolute; inset: 0; transform: translateX(100%); transition: transform .18s; }
  .shell { position: relative; overflow: hidden; }
  .shell.show-chat .chat { transform: none; }
  .back { display: inline-flex; }
  .msg { max-width: 92%; }
}

#app { height: 100%; }
#app.boot { height: 100%; }
.c0-t { color: #2d7ff9; } .c1-t { color: #e0457b; } .c2-t { color: #26a69a; } .c3-t { color: #8e5bd6; }
.c4-t { color: #e6892b; } .c5-t { color: #4c9a2a; } .c6-t { color: #c0392b; } .c7-t { color: #00838f; }
.grow { flex: 1; }
.tabs + .body { padding-top: 10px; }
h3 { margin: 18px 0 0; font-size: 15px; }
