:root {
  --bg: #0f1720; --panel: #16212c; --panel2: #1c2a37; --line: #253545;
  --text: #e6edf3; --muted: #8aa0b4; --accent: #2ea6ff; --accent2: #1f8fe0;
  --ok: #3fcf8e; --bad: #ff6b6b; --mine: #1f6fb2; --theirs: #22313f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; }
input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; outline: none; width: 100%; }
input:focus { border-color: var(--accent); }
.primary { background: var(--accent); color: #fff; padding: 10px 16px; font-weight: 600; }
.primary:hover { background: var(--accent2); }
.ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.ghost:hover { color: var(--text); background: var(--panel2); }
.danger { background: transparent; color: var(--bad); border: 1px solid #5a2b2b; padding: 6px 12px; }
.ok-btn { background: var(--ok); color: #06281a; font-weight: 600; padding: 6px 14px; }

/* Acceso */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { margin: 0; font-size: 28px; }
.brand.small img { width: 28px; height: 28px; border-radius: 8px; }
.brand.small span { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 6px; margin: 18px 0 14px; background: var(--panel2); padding: 4px; border-radius: 12px; }
.tab { flex: 1; background: transparent; color: var(--muted); padding: 8px; }
.tab.active { background: var(--accent); color: #fff; }
#auth-form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
#auth-form label input { margin-top: 6px; }
#auth-form .primary { width: 100%; margin-top: 6px; }

/* Layout */
.app { display: flex; height: 100%; }
.sidebar { width: 300px; min-width: 260px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 6px; }
.me { padding: 0 16px 10px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #556; margin-left: 4px; }
.dot.on { background: var(--ok); }
.add-form { display: flex; gap: 6px; padding: 0 12px 12px; }
.add-form .primary { padding: 0 14px; font-size: 20px; }
.contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contacts li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.contacts li:hover { background: var(--panel2); }
.contacts li.active { background: #20374b; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: #2b4157; position: relative; flex: none; text-transform: uppercase; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; border: 2px solid var(--panel); width: 12px; height: 12px; margin: 0; }
.contacts .name { flex: 1; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 7px; font-weight: 600; }
.side-foot { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.side-foot p { margin: 8px 4px 0; }
.side-actions { display: flex; flex-direction: column; align-items: flex-start; }

.chat { flex: 1; display: flex; min-width: 0; position: relative; }
.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 20px; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 10px; margin: 8px 0; }
.msg { max-width: min(560px, 78%); padding: 8px 12px; border-radius: 14px; background: var(--theirs); align-self: flex-start;
  word-wrap: break-word; white-space: pre-wrap; }
.msg.mine { background: var(--mine); align-self: flex-end; }
.msg .time { font-size: 11px; color: #b9c8d6; opacity: .75; margin-left: 8px; float: right; margin-top: 6px; }

.file { min-width: 300px; white-space: normal; }
.file .row { display: flex; gap: 10px; align-items: center; }
.file .ico { font-size: 28px; }
.file .fname { font-weight: 600; word-break: break-all; }
.file .fsize { font-size: 13px; color: #b9c8d6; }
.file .state { margin-top: 8px; font-size: 13px; color: #cfdbe6; }
.file .state.ok { color: var(--ok); }
.file .state.bad { color: #ffb3b3; }
.file .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.bar { height: 6px; background: rgba(255,255,255,.15); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.bar > div { height: 100%; background: var(--ok); width: 0; transition: width .25s linear; }

.composer { display: flex; gap: 8px; padding: 12px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.attach { font-size: 20px; }
.drop { position: absolute; inset: 0; background: rgba(46,166,255,.15); border: 3px dashed var(--accent);
  display: grid; place-items: center; font-size: 22px; font-weight: 600; pointer-events: none; z-index: 5; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2a3b4c; color: var(--text);
  padding: 10px 18px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 10; max-width: 90%; }

@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
  .file { min-width: 0; }
}
.msg.mine .danger { color: #fff; border-color: rgba(255,255,255,.45); }
.msg.mine .danger:hover { background: rgba(255,255,255,.12); }

/* Ventana emergente y panel de administración */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 760px;
  max-height: 90vh; display: flex; flex-direction: column; }
.modal-card.narrow { max-width: 400px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.modal-body label input { margin-top: 6px; }
.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.users td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.users .acts button { font-size: 13px; padding: 5px 10px; }
.tag { font-size: 11px; background: #2b4157; color: #cfe3f5; border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.small-btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.small-btn:hover { border-color: var(--accent); }
.temp-pass { font: 600 22px ui-monospace, monospace; background: var(--panel2); border: 1px dashed var(--accent);
  border-radius: 10px; padding: 12px; text-align: center; margin: 12px 0; user-select: all; letter-spacing: 1px; }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
@media (max-width: 720px) {
  .users th:nth-child(2), .users td:nth-child(2) { display: none; }
  .users .acts { justify-content: flex-start; }
}
