:root {
  --bg: #efeae2; --panel: #ffffff; --panel-2: #f0f2f5; --text: #111b21; --muted: #667781;
  --brand: #075e54; --brand-2: #128c7e; --accent: #25d366; --mine: #d9fdd3; --theirs: #ffffff;
  --border: #e2e5e8; --danger: #c62828; --warn-bg: #fff4ce; --shadow: 0 1px 1px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b141a; --panel: #111b21; --panel-2: #202c33; --text: #e9edef; --muted: #8696a0;
    --brand: #00a884; --brand-2: #00a884; --mine: #005c4b; --theirs: #202c33; --border: #2a3942;
    --warn-bg: #3b3420; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
#app { height: 100dvh; display: flex; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.center { margin: auto; padding: 24px 16px; width: 100%; max-width: 420px; }
.spinner { width: 36px; height: 36px; margin: auto; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- tarjetas / formularios --- */
.card { background: var(--panel); border-radius: 14px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand img { width: 48px; height: 48px; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; background: var(--panel-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.field { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); outline: none; }
.field:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 25%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; }
.btn.block { width: 100%; margin-top: 18px; }
.btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { color: var(--brand-2); font-size: 13px; margin-top: 14px; display: inline-block; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }
.lockline { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-bg); padding: 10px 12px; border-radius: 10px; font-size: 12.5px; margin-top: 14px; }

/* --- layout principal --- */
.shell { display: flex; width: 100%; height: 100%; max-width: 1400px; margin: 0 auto; background: var(--panel); }
.side { width: 360px; max-width: 100%; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--panel); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel-2); min-height: 60px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { color: var(--muted); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.iconbtn:hover { background: color-mix(in srgb, var(--muted) 15%, transparent); }
.iconbtn svg { width: 22px; height: 22px; fill: currentColor; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; background: var(--brand-2); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 0; background: var(--panel-2); outline: none; }
.list { flex: 1; overflow-y: auto; }
.section { padding: 14px 16px 6px; font-size: 12px; font-weight: 700; color: var(--brand-2); text-transform: uppercase; letter-spacing: .04em; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 14px; width: 100%; text-align: left; border-bottom: 1px solid var(--border); }
.item:hover, .item.on { background: var(--panel-2); }
.item .meta { flex: 1; min-width: 0; }
.item .meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.item .meta small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); }
.badge { background: var(--accent); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.actions { display: flex; gap: 6px; }
.empty { color: var(--muted); text-align: center; padding: 30px 20px; font-size: 14px; }

/* --- conversación --- */
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 3px;
  background-color: var(--bg); background-image: radial-gradient(color-mix(in srgb, var(--muted) 14%, transparent) 1px, transparent 1px); background-size: 22px 22px; }
.e2e { align-self: center; background: var(--warn-bg); color: var(--text); font-size: 12.5px; padding: 8px 12px; border-radius: 8px; text-align: center; max-width: 440px; margin: 4px 0 12px; box-shadow: var(--shadow); }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 5px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.msg { max-width: min(75%, 520px); padding: 6px 8px 4px 9px; border-radius: 8px; box-shadow: var(--shadow); background: var(--theirs); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; position: relative; }
.msg.mine { background: var(--mine); align-self: flex-end; }
.msg .t { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.msg .t svg { width: 16px; height: 11px; }
.msg .t .read { color: #53bdeb; }
.msg.bad { font-style: italic; color: var(--muted); }
.media { display: block; max-width: 100%; max-height: 360px; border-radius: 6px; margin-bottom: 4px; background: var(--panel-2); }
.media-ph { width: 240px; max-width: 100%; height: 160px; border-radius: 6px; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.filebox { display: flex; gap: 10px; align-items: center; padding: 8px; background: color-mix(in srgb, var(--muted) 10%, transparent); border-radius: 6px; margin-bottom: 4px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; background: var(--panel-2); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 42px; padding: 10px 14px; border-radius: 22px; border: 0; background: var(--panel); outline: none; }
.send { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.send svg { width: 22px; height: 22px; fill: currentColor; }
.banner { padding: 10px 14px; background: var(--warn-bg); font-size: 13px; text-align: center; }
.welcome { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 30px; background: var(--panel-2); }
.welcome h2 { color: var(--text); font-weight: 400; }

/* --- modal / toast --- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 22px; width: 100%; max-width: 420px; max-height: 90dvh; overflow: auto; }
.modal h3 { margin: 0 0 10px; }
.code { font: 600 17px/1.7 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .06em; background: var(--panel-2); padding: 12px; border-radius: 10px; text-align: center; word-spacing: .3em; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #323232; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 25; display: grid; place-items: center; }
.viewer img, .viewer video { max-width: 96vw; max-height: 90dvh; }
.viewer .iconbtn { position: absolute; top: 12px; right: 12px; color: #fff; }

/* --- móvil --- */
@media (max-width: 760px) {
  .side { width: 100%; border-right: 0; }
  .shell.chat-open .side { display: none; }
  .shell:not(.chat-open) .main.admin-main { display: none; }
  .messages { padding: 12px 10px; }
  .msg { max-width: 85%; }
}
@media (min-width: 761px) { .only-mobile { display: none !important; } }
