/* Salón 22 · app del equipo. Estructura de WhatsApp, identidad de salón de color:
   ciruela (tinte) para lo que hace una persona y miel (mechas) para el asistente. */
:root {
  --plum: #5B2A45; --plum-deep: #45203A; --plum-tint: #F2E6EE; --plum-line: #DCC6D4;
  --honey: #E2A33B; --honey-deep: #B9791A; --honey-tint: #FBF0DA;
  --mist: #ECE8EE; --paper: #FFFFFF; --ink: #26212B; --muted: #6E6875; --line: #E3DEE6;
  --read: #2F7FC1; --danger: #B42318; --danger-tint: #FDECEA; --focus: #8E4A72;
  --list-width: 384px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--paper); -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
#app { height: 100dvh; }
#app.booting::before { content: ""; display: block; height: 100%; background: var(--plum); }

/* ---------- acceso ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--plum); color: #fff; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; }
.wordmark { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.wordmark-badge { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: #fff; color: var(--plum);
  font-weight: 800; font-size: 22px; letter-spacing: -0.04em; box-shadow: 0 0 0 4px var(--honey); }
.wordmark strong { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.login label { display: grid; gap: 6px; font-size: 15px; }
.login input { padding: 13px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; }
.login input:focus { outline: 2px solid var(--honey); outline-offset: 1px; }
.login .primary { margin-top: 6px; padding: 13px; border: 0; border-radius: 12px; background: var(--honey); color: var(--plum-deep); font-weight: 700; }
.login .error { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.12); }
.login .hint { margin: 0; font-size: 14px; opacity: .8; line-height: 1.45; }

/* ---------- estructura ---------- */
.shell { height: 100dvh; display: grid; grid-template-columns: var(--list-width) minmax(0, 1fr); overflow: hidden; }
.pane-list { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--line); background: var(--paper); }
.pane-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--mist); }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px; background: var(--plum); color: #fff; min-height: 60px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; color: inherit; font-size: 20px; line-height: 1; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.banner { padding: 8px 14px; font-size: 13px; line-height: 1.4; background: var(--honey-tint); color: #5C3D09; border-bottom: 1px solid #F0DDB6; }
.banner button { margin-left: 6px; border: 0; background: none; color: var(--plum); font-weight: 700; padding: 0; text-decoration: underline; }
.banner.alert { background: var(--danger-tint); color: var(--danger); border-color: #F6C9C4; }

/* ---------- lista de chats ---------- */
.search { padding: 8px 12px; }
.search input { width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: #F3F0F4; }
.chips { display: flex; gap: 8px; padding: 0 12px 8px; overflow-x: auto; }
.chip { flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--plum); border-color: var(--plum); color: #fff; }
.chip .count { margin-left: 6px; font-weight: 700; }
.chats { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-bottom); }
.chat-row { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 14px;
  border: 0; border-bottom: 1px solid #F1EEF2; background: var(--paper); text-align: left; }
.chat-row:hover { background: #FAF8FA; }
.chat-row[aria-current="true"] { background: var(--plum-tint); }
.avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 16px;
  background: #F4EFF3; color: var(--plum); box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--honey); }
.avatar.team { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--plum); background: var(--plum); color: #fff; }
.avatar.quiet { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--line); }
.row-main { min-width: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-name { flex: 1; min-width: 0; font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { flex: none; font-size: 12px; color: var(--muted); }
.row-time.unread { color: var(--plum); font-weight: 700; }
.row-preview { margin-top: 3px; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-need { margin-top: 4px; font-size: 13px; color: var(--plum); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-need.issue { color: var(--danger); }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--plum); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center; }
.empty { padding: 32px 20px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-top)) 10px 8px; background: var(--paper); border-bottom: 1px solid var(--line); min-height: 64px; }
.chat-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who strong { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who span { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; color: var(--plum); }
.take-btn { flex: none; border: 1.5px solid var(--plum); background: var(--paper); color: var(--plum); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; }
.return-btn { flex: none; border: 0; background: var(--honey); color: var(--plum-deep); border-radius: 999px; padding: 9px 14px; font-weight: 750; font-size: 14px; line-height: 1.2; text-align: center; }
.return-btn:hover { background: #EDB04A; }
.summary { margin: 10px auto 0; width: min(760px, calc(100% - 20px)); background: var(--paper); border-radius: 12px; border-left: 4px solid var(--plum); padding: 10px 14px; font-size: 14px; line-height: 1.45; }
.summary summary { font-weight: 700; color: var(--plum); list-style: none; cursor: pointer; }
.summary summary::-webkit-details-marker { display: none; }
.summary dl { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; }
.summary ul { margin: 6px 0 0; padding-left: 18px; }
.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 0 14px; }
.messages-inner { width: min(760px, calc(100% - 20px)); margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; margin: 10px 0 6px; padding: 4px 10px; border-radius: 8px; background: rgba(255,255,255,.85); font-size: 12px; color: var(--muted); }
.bubble { position: relative; max-width: min(78%, 560px); padding: 7px 10px 6px; border-radius: 12px; background: var(--paper); font-size: 15px; line-height: 1.4;
  white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 0 rgba(38,33,43,.06); }
.bubble.in { align-self: flex-start; border-top-left-radius: 4px; }
.bubble.ai { align-self: flex-end; background: var(--honey-tint); border-top-right-radius: 4px; }
.bubble.team { align-self: flex-end; background: var(--plum-tint); border-top-right-radius: 4px; }
.bubble .by { display: block; font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.bubble.ai .by { color: var(--honey-deep); }
.bubble.team .by { color: var(--plum); }
.bubble .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tick.read { color: var(--read); }
.tick.problem { color: var(--danger); font-weight: 700; }
.notice { align-self: center; max-width: 90%; text-align: center; padding: 6px 12px; border-radius: 10px; background: #FFF8E6; color: #5C3D09; font-size: 13px; line-height: 1.4; }
.photo { display: block; width: auto; max-width: 100%; height: auto; max-height: 320px; object-fit: contain; border-radius: 8px; margin: 2px 0 4px; background: #E9E4EA; cursor: zoom-in; min-width: 120px; min-height: 80px; }
.bubble audio { display: block; width: 240px; max-width: 100%; margin: 2px 0; }
.problem-box { margin-top: 6px; padding: 8px; border-radius: 8px; background: var(--danger-tint); color: var(--danger); font-size: 13px; white-space: normal; }
.problem-box .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.problem-box button { border: 1px solid currentColor; background: var(--paper); color: var(--danger); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 600; }
.problem-box button.primary { background: var(--danger); color: #fff; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; line-height: 1.5; }
.placeholder strong { display: block; color: var(--plum); font-size: 20px; margin-bottom: 6px; }

/* ---------- escribir ---------- */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--safe-bottom)); background: #F4F1F5; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 11px 14px; border: 0; border-radius: 22px; background: var(--paper); line-height: 1.35; }
.round { width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; display: grid; place-items: center; font-size: 19px; }
.round.attach { background: transparent; color: var(--muted); }
.round.send { background: var(--plum); color: #fff; }
.round.mic { background: var(--plum); color: #fff; }
.round.recording { background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(180,35,24,.18); } }
.composer-note { padding: 12px 14px calc(12px + var(--safe-bottom)); background: #F4F1F5; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); text-align: center; line-height: 1.45; }
.rec-time { align-self: center; font-variant-numeric: tabular-nums; color: var(--danger); font-weight: 700; min-width: 44px; }

/* ---------- ventanas ---------- */
.overlay { position: fixed; inset: 0; background: rgba(38,33,43,.5); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog { width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--paper); border-radius: 16px; padding: 20px; box-shadow: 0 20px 50px rgba(38,33,43,.25); }
.dialog h2 { margin: 0 0 8px; font-size: 19px; }
.dialog p { margin: 0 0 12px; line-height: 1.5; color: #463F4C; }
.dialog .quote { padding: 10px 12px; border-radius: 10px; background: var(--honey-tint); font-size: 14px; }
.dialog .buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog button { border: 0; border-radius: 999px; padding: 10px 16px; font-weight: 700; }
.dialog .secondary { background: #F1EDF2; color: var(--ink); }
.dialog .confirm { background: var(--plum); color: #fff; }
.dialog .confirm.honey { background: var(--honey); color: var(--plum-deep); }
.dialog .confirm.danger { background: var(--danger); }
.dialog button:disabled { opacity: .45; cursor: not-allowed; }
.dialog > input { width: 100%; }
.dialog label { display: grid; gap: 5px; margin-bottom: 10px; font-size: 14px; }
.dialog input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.dialog .error { color: var(--danger); font-size: 14px; }
.menu { position: fixed; z-index: 21; min-width: 230px; background: var(--paper); border-radius: 12px; padding: 6px; box-shadow: 0 12px 32px rgba(38,33,43,.22); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 11px 12px; border-radius: 8px; font-size: 15px; }
.menu button:hover { background: #F4F0F5; }
.users { list-style: none; margin: 0 0 14px; padding: 0; }
.users li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.users li span { flex: 1; }
.users li small { color: var(--muted); }
.users button { background: #F1EDF2; color: var(--ink); padding: 6px 10px; }
.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(20,16,22,.92); display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); }

/* ---------- móvil: una pantalla cada vez, como WhatsApp ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .shell.chat-open .pane-list { display: none; }
  .shell:not(.chat-open) .pane-chat { display: none; }
  .back { display: grid; }
  .pane-list { border-right: 0; }
  .return-btn { padding: 8px 10px; font-size: 13px; max-width: 150px; }
  .bubble { max-width: 86%; }
}
@media (prefers-reduced-motion: reduce) { .round.recording { animation: none; } }
