:root { --ink: #302a22; --muted: #665b4e; --line: #e7ddce; --accent: #8d5b0a; --blue: #f4e9d6; color: var(--ink); font: 14px/1.5 system-ui, sans-serif; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body,h1,h2,p { margin: 0; }
button,textarea { font: inherit; }
a,button { cursor: pointer; }
:focus-visible { outline: 3px solid #a47524; outline-offset: 2px; }
.team { display: grid; grid-template-columns: 106px minmax(220px,290px) minmax(0,1fr); height: 100dvh; }
.badge { display: inline-block; margin-inline-start: 3px; background: var(--accent); color: white; border-radius: 14px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
.directory { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.directory header,.chat-header { padding: 15px 18px; border-bottom: 1px solid var(--line); }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
header p { color: var(--muted); font-size: 12px; }
#people { flex: 1; overflow: auto; padding: 7px; }
.person { display: flex; align-items: center; gap: 9px; padding: 10px; width: 100%; text-align: left; background: white; color: inherit; border: 1px solid transparent; border-radius: 9px; }
.person:hover,.person[aria-current] { background: var(--blue); }
.person[aria-current] { border-color: #e5cda3; }
.person-name { min-width: 0; flex: 1; }
.person-name strong,.person-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-name small { color: var(--muted); }
.avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: #f4e9d6; color: #6f4b19; font-weight: 700; }
.interior { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #faf8f5; }
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: white; }
.channel { background: var(--blue); color: #704b18; border-radius: 7px; padding: 4px 8px; font-weight: 700; white-space: nowrap; }
#scroll { flex: 1; min-height: 0; overflow: auto; padding: 14px 18px; }
#messages { display: flex; flex-direction: column; gap: 9px; }
.message { align-self: flex-start; max-width: min(580px,92%); border-radius: 10px; border: 1px solid var(--line); background: white; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.mine { align-self: flex-end; background: var(--blue); }
.message time { display: block; text-align: right; font-size: 11px; color: var(--muted); }
#older { display: block; margin: 0 auto 10px; background: white; color: var(--accent); border: 1px solid var(--line); padding: 5px 10px; border-radius: 7px; }
#team-form { display: grid; gap: 6px; margin: 0 14px 14px; padding: 10px; background: white; border: 1px solid var(--line); border-radius: 10px; }
#draft-label { color: #704b18; font-weight: 600; }
#team-draft { width: 100%; min-height: 45px; max-height: 25vh; resize: vertical; border: 1px solid var(--line); border-radius: 7px; padding: 7px; color: inherit; }
.team-compose-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
#team-keyboard-hint { color: var(--muted); font-size: 11px; }
#team-send { margin-inline-start: auto; color: var(--gr-orange-ink); background: var(--gr-orange); font-weight: 650; border: 0; border-radius: 7px; padding: 8px 12px; }
#team-send:hover:not(:disabled) { background: var(--gr-orange-hover); }
#team-send:disabled { opacity: .65; cursor: wait; }
#team-error { color: #922932; padding: 5px 14px; }
@media (max-width: 670px) {
  .team { grid-template-columns: minmax(0,1fr); grid-template-rows: auto auto minmax(0,1fr); }
  .directory { border: 0; }
  .directory header { padding: 5px 12px; }
  .directory header p { display: none; }
  h1 { font-size: 16px; }
  #people { display: flex; overflow-x: auto; }
  .person { width: auto; flex: none; }
  .person-name small { display: none; }
  .chat-header,#scroll { padding: 8px 11px; }
  #team-form { margin: 0 8px 8px; }
}

/* Canal «Toda la oficina» y adjuntos */
.channel-entry { margin-bottom: 6px; border-color: #ecd4b4; background: #fff8eb; }
.channel-avatar { background: var(--gr-orange,#ffad42); color: #2e2620; }
.channel-avatar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message-author { display: block; font-size: 12px; color: #8d5b0a; margin-bottom: 2px; }
.team-file { display: grid; gap: 4px; margin-top: 4px; }
.team-file img { display: block; max-width: min(280px,100%); max-height: 260px; border-radius: 8px; object-fit: cover; }
.team-file-name { color: #704b18; font-weight: 600; overflow-wrap: anywhere; }
.team-file-name small { color: var(--muted); font-weight: 400; }
#team-attach { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fffdf8; color: #5e5242; }
#team-attach:hover { background: #f5ecdc; }
.interior.dropping { outline: 3px dashed #cf650b; outline-offset: -8px; }

/* Una sola lista, como en WhatsApp: lo pendiente de leer, resaltado */
.directory header p { margin-top: 2px; }
#directory-status[data-alert="true"] { color: #8d5b0a; font-weight: 700; }
.person.unread .person-name strong { font-weight: 800; }
.person.unread .person-name small { color: var(--ink); font-weight: 600; }
.person.unread .badge { background: var(--gr-orange,#ffad42); color: var(--gr-orange-ink,#2e2620); font-size: 12px; min-width: 22px; text-align: center; }
.team-placeholder { margin: 40px auto; max-width: 420px; color: var(--muted); text-align: center; }

/* Editar y eliminar mensajes propios */
.message { position: relative; }
.message-more { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 26px; height: 22px; padding: 0; border: 0; border-radius: 6px;
  background: #fffefa; color: #5e5242; font-size: 16px; line-height: 1; opacity: 0; box-shadow: 0 1px 4px #4a351822; }
.message.mine:hover .message-more,.message-more:focus-visible,.message-more[aria-expanded="true"] { opacity: 1; }
.message-more:hover { background: #f1ebe0; }
.message.mine { padding-right: 34px; }
.message.deleted { background: #f6f2ea !important; }
.message-deleted { color: var(--muted); font-style: italic; }
.message-edit { display: grid; gap: 6px; min-width: min(420px,70vw); }
.message-edit textarea { width: 100%; padding: 7px; border: 1px solid #d0b88f; border-radius: 7px; font: inherit; resize: vertical; }
.message-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.message-edit-actions button { padding: 5px 11px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.message-edit-actions button:last-child { border-color: transparent; background: var(--gr-orange); color: var(--gr-orange-ink); font-weight: 650; }
@media (hover: none) { .message-more { opacity: .8; } }

/* v102 · leído, reacciones y emojis */
.read-tick { margin-left: 3px; letter-spacing: -2px; color: #9a8f80; font-weight: 700; }
.read-tick.read { color: #2a83c9; }
.seen-by { margin-top: 2px; font-size: 11.5px; color: var(--muted); white-space: normal; }
.seen-by summary { cursor: pointer; list-style: none; text-align: right; }
.seen-by summary::-webkit-details-marker { display: none; }
.seen-by.all summary { color: #2a83c9; font-weight: 600; }
.seen-by p { margin-top: 4px; padding-top: 4px; border-top: 1px solid #e7ddce; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 -2px; white-space: normal; }
.reaction { padding: 1px 8px; border: 1px solid #e3d5bf; border-radius: 999px; background: #fffdf8; font-size: 13px; line-height: 1.6; }
.reaction.mine { border-color: #e6a85a; background: #fff1dc; }
.reaction:hover { background: #f5ecdc; }
.react-button { position: absolute; top: 50%; right: -34px; display: grid; place-items: center; width: 28px; height: 28px; margin-top: -14px; padding: 0; border: 1px solid #e7ddce; border-radius: 50%;
  background: #fff; color: #7a6c58; font-size: 16px; line-height: 1; opacity: 0; box-shadow: 0 1px 4px #4a351822; }
.message.mine .react-button { right: auto; left: -34px; }
.message:hover .react-button,.react-button:focus-visible { opacity: 1; }
.message:not(.mine) { margin-right: 36px; }
.message.mine { margin-left: 36px; }
.emoji-pop { position: fixed; z-index: 1000; display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border: 1px solid #e7ddce; border-radius: 14px; background: #fff; box-shadow: 0 10px 30px #3a2a1530; }
.emoji-pop.quick { border-radius: 999px; flex-wrap: nowrap; }
.emoji-pop.compose { width: min(300px, calc(100vw - 16px)); }
.emoji-pop button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: none; font-size: 20px; line-height: 1; }
.emoji-pop button:hover,.emoji-pop button:focus-visible { background: #f5ecdc; }
#team-emoji { padding: 4px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fffdf8; font-size: 17px; line-height: 1.3; }
#team-emoji:hover { background: #f5ecdc; }
.team-compose-actions { justify-content: flex-start; }
@media (hover: none) { .react-button { opacity: .7; } }

/* v103 · departamentos */
.dept-entry { margin-bottom: 6px; border-color: #e3d9ca; background: #fffdf8; }
.dept-entry .avatar { font-size: 13px; }

/* v111 · Móvil: caja de escribir compacta en una línea y, con el teclado abierto, solo lo esencial
   (barra de módulos, nombre de la conversación, mensajes y caja de escribir) */
@media (max-width: 760px) {
  #team-form:not([hidden]) { grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: end; gap: 6px; margin: 0 6px 6px; padding: 6px; }
  #team-form #draft-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #team-form .team-compose-actions { display: contents; }
  #team-form #team-keyboard-hint { display: none; }
  #team-form #team-draft { grid-column: 3; grid-row: 1; min-height: 42px; max-height: 120px; padding: 9px 10px; resize: none; }
  #team-form #team-emoji { grid-column: 1; grid-row: 1; }
  #team-form #team-attach { grid-column: 2; grid-row: 1; font-size: 0 !important; }
  #team-form #team-attach::before { content: "📎"; font-size: 19px; }
  #team-form :is(#team-emoji, #team-attach) { width: 40px; height: 42px; padding: 0; display: grid; place-items: center; }
  #team-form #team-send { grid-column: 4; grid-row: 1; height: 42px; padding: 0 14px; }
}
/* v116 · Móvil: misma caja de escribir que WhatsApp (texto que crece y ➤ para enviar) */
@media (max-width: 760px) {
  #team-form #team-draft { height: 42px; }
  #team-form #team-send { width: 46px; padding: 0 !important; font-size: 0 !important; display: grid; place-items: center; }
  #team-form #team-send::before { content: "➤"; font-size: 19px; }
}

/* v118 · Móvil como WhatsApp: lista de conversaciones a pantalla completa y, al abrir una, la conversación
   a pantalla completa con «‹» para volver. Solo se desplazan la lista o los mensajes. */
#team-back { display: none; }
@media (max-width: 760px) {
  .team { grid-template-rows: auto minmax(0, 1fr) !important; }
  .team:not(.chat-open) .interior { display: none !important; }
  .team.chat-open .directory { display: none !important; }
  .team .directory { display: flex; flex-direction: column; min-height: 0; border: 0; }
  .team .directory > header { display: block; padding: 12px 14px 8px; }
  .team #people { display: block !important; flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px 20px !important; }
  .team #people .person { width: 100%; padding: 10px; margin-bottom: 4px; border-radius: 10px; }
  .team #people .person-name small { display: block; }
  .team #people .avatar { width: 40px; height: 40px; font-size: 14px; }
  .team .chat-header { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
  .team .chat-header > div { flex: 1; min-width: 0; }
  .team .chat-header h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .team .chat-header .channel { display: none; }
  .team #person-status { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #team-back { display: grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 26px; line-height: 1; }
}
/* v175 · Deja sitio al dock de tiempo para que no tape «Enviar». */
@media (min-width: 681px) { #team-form { margin-bottom: 66px; } }
/* v176 · Vaciar chat */
.team-clear { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 6px 10px; border: 1px solid var(--line, #e3d9c6); border-radius: 10px; background: #fff; color: #6d675f; font: 600 13px/1 system-ui, sans-serif; cursor: pointer; }
.team-clear svg { width: 17px; height: 17px; }
.team-clear:hover, .team-clear:focus-visible { border-color: #d98b3a; color: #8a4b0e; background: #fdf6ec; }
@media (max-width: 760px) { .team-clear span { display: none; } .team-clear { padding: 7px; } }

/* v181 · Mensajes con más aire y opciones coherentes con el resto de la app (mismo estilo que WhatsApp) */
#scroll { padding: 30px clamp(14px, 3.5vw, 44px) 18px; }
#messages { gap: 16px; }
.message { max-width: min(640px, 88%); padding: 10px 14px 9px; border-radius: 14px 14px 14px 4px; line-height: 1.55; box-shadow: 0 1px 2px #3c32280f; }
.message.mine { border-radius: 14px 14px 4px 14px; padding-right: 14px; margin-left: 0; }
.message:not(.mine) { margin-right: 0; }
.message-author { margin-bottom: 4px; }
.message time { margin-top: 6px; }
.reactions { margin: 8px 0 0; }
.team-file { margin-top: 6px; }
.msg-toolbar { position: absolute; top: -25px; right: 12px; z-index: 2; display: flex; align-items: center; gap: 1px; padding: 2px; background: #fffefa; border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 3px 12px #3c32282e; white-space: nowrap; opacity: 0; pointer-events: none; transform: translateY(2px); transition: opacity .12s, transform .12s; }
.message:hover .msg-toolbar, .message:focus-within .msg-toolbar { opacity: 1; pointer-events: auto; transform: none; }
.msg-toolbar > button, .msg-toolbar .react-button, .msg-toolbar .message-more { position: static; display: inline-flex; align-items: center; justify-content: center; gap: 2px; width: auto; height: auto; min-height: 28px; margin: 0; padding: 2px 11px; border: 0; border-radius: 999px; background: transparent; box-shadow: none; color: #5d5144; font-size: 12px; font-weight: 600; line-height: 1; opacity: 1; transition: background .12s, color .12s; }
.msg-toolbar .msg-tool[data-icon]::before { content: attr(data-icon); margin-right: .3em; font-size: 1em; }
.msg-toolbar .react-button { padding: 2px 10px; font-size: 14px; }
.msg-toolbar .message-more { padding: 2px 10px; font-size: 15px; }
.msg-toolbar > button:hover:not(:disabled) { background: var(--gr-orange-soft, #fff0dc); color: #8d4f0a; }
.msg-toolbar > button:focus-visible { outline: 2px solid var(--gr-orange-edge, #e08a2c); outline-offset: 1px; }
@media (hover: none) {
  .msg-toolbar { position: static; opacity: 1; pointer-events: auto; transform: none; margin: 8px -4px 0; padding: 6px 0 0; border: 0; border-top: 1px solid #3c32280f; border-radius: 0; background: transparent; box-shadow: none; }
}
@media (max-width: 670px) { #scroll { padding: 28px 11px 12px; } }

/* v182 · La barra de opciones de un mensaje recibido se ancla a su izquierda para no salirse de la conversación */
.message:not(.mine) .msg-toolbar { right: auto; left: 12px; }
