:root {
  font-family: Inter, system-ui, sans-serif;
  color: #292725;
  background: #f9f6ef;
  --dark: #3c3228;
  --green: #175644;
  --muted: #665b4e;
  --line: #e7ddce;
  --gold: #e8c37c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 14px; }
button,input,textarea,select { font: inherit; }
button { min-height: 36px; padding: 7px 12px; border: 1px solid transparent; border-radius: 8px; background: #f4ede1; color: #3f3933; cursor: pointer; }
button:hover:not(:disabled) { background: #eee0c9; }
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 2px solid #a47524; outline-offset: 2px; }
[data-icon]::before { content: attr(data-icon); margin-right: .55em; font-size: 1.05em; }
input,textarea,select { border: 1px solid #d9c9b4; padding: 9px 11px; border-radius: 8px; color: inherit; background: white; }
label { display: block; margin: 12px 0; }
label input,label select,label textarea { display: block; margin-top: 5px; width: 100%; }
#login { max-width: 440px; width: calc(100% - 32px); margin: min(6vh, 56px) auto; background: #fffefa; padding: 24px clamp(18px, 5vw, 30px); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 18px 55px #162e2814; }
.login-brand { margin-bottom: 21px; text-align: center; color: #292725; }
.login-brand p { color: #5e5549; margin: 6px 0 0; }
.login-mark { display: block; width: min(300px, 95%); height: auto; margin: 0 auto 12px; }
body:has(#login:not([hidden])) { background: #f9f6ef; }
#login h1 { text-align: center; font-size: 23px; margin: 8px 0 23px; }
#login button,#newChat,#send,#confirm,.settings-panel .settings-primary { background: var(--gr-orange); color: var(--gr-orange-ink); font-weight: 650; }
#login button { width: 100%; margin-top: 8px; }
:is(#login button,#newChat,#send,#confirm,.settings-panel .settings-primary):hover:not(:disabled) { background: var(--gr-orange-hover); }

#app { display: grid; grid-template-columns: 208px minmax(280px, 340px) minmax(0, 1fr); height: 100dvh; background: white; }
aside,.conversation { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.workspace-nav { background: var(--dark); color: white; padding: 20px 13px 14px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 3px 32px; font-family: Georgia, serif; font-size: 19px; letter-spacing: -.3px; white-space: nowrap; }
.brand img { width: 39px; height: 39px; object-fit: contain; background: #fbf6e8; padding: 3px; border-radius: 9px; }
.brand strong { color: var(--gold); font-weight: 500; }
.workspace-nav nav,.workspace-nav footer { display: flex; flex-direction: column; gap: 4px; }
.workspace-nav button { display: flex; align-items: center; color: #e2eee7; background: transparent; text-align: left; white-space: nowrap; }
.workspace-nav button::before { color: #a9c5b7; min-width: 16px; }
.workspace-nav button:hover:not(:disabled) { background: #29463c; }
.workspace-nav button[aria-pressed="true"] { background: #335549; color: white; font-weight: 650; box-shadow: inset 3px 0 var(--gold); }
#pendingCount, #unassignedCount { margin-left: auto; padding: 1px 7px; border-radius: 10px; background: #416357; font-size: 11px; }
.workspace-nav footer { margin-top: auto; padding-top: 20px; }
.identity { display: flex; align-items: center; gap: 9px; border-top: 1px solid #3b574d; padding: 12px 4px 8px; }
.identity div { min-width: 0; overflow-wrap: anywhere; }
.identity small { display: block; color: #a9c5b7; }
#agentInitial,.chat-icon { display: grid; place-items: center; width: 37px; height: 37px; flex: 0 0 37px; border-radius: 50%; font-weight: 700; }
#agentInitial { background: #e7d4a9; color: #3b3223; }
.chat-list { border-right: 1px solid var(--line); }
.chat-list header,.conversation header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; min-height: 76px; flex-shrink: 0; background: white; }
.chat-list h1 { margin: 0 0 3px; font-size: 18px; letter-spacing: -.35px; }
#listCount,#responsible { color: var(--muted); }
#newChat { white-space: nowrap; font-size: 13px; }
#search { margin: 3px 14px 10px; background: #fbf8f2; }
#list,#messages { overflow: auto; flex: 1; }
#list { padding-inline: 8px; }
.chat-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; margin: 2px 0; padding-right: 6px; border: 1px solid transparent; border-radius: 8px; }
.chat-row:hover,.chat-row:focus-within { background: #faf5eb; }
.chat-row.active { background: var(--gr-orange-soft); border-color: #f0cba7; box-shadow: inset 3px 0 var(--gr-orange-edge); }
.chat-row .chat-row-main { display: flex; gap: 10px; align-items: center; padding: 10px; min-height: 64px; text-align: left; background: transparent; min-width: 0; }
.chat-row .chat-row-main:hover { background: transparent; }
.chat-row-shortcuts { display: flex; gap: 2px; }
.chat-shortcut { position: relative; display: inline-grid; place-items: center; width: 38px; min-height: 38px; padding: 0; }
.chat-row .chat-shortcut { width: 30px; min-height: 32px; background: transparent; }
.chat-row .chat-shortcut:hover:not(:disabled),.chat-row .chat-shortcut:focus-visible { background: #f0e2cc; }
.chat-shortcut svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.chat-row .chat-shortcut svg { width: 16px; height: 16px; }
.shortcut-tooltip { visibility: hidden; position: absolute; top: calc(100% + 5px); right: 0; z-index: 3; padding: 6px 8px; color: white; background: var(--dark); border-radius: 6px; font-size: 12px; white-space: nowrap; pointer-events: none; }
.chat-shortcut:hover:not(:disabled) .shortcut-tooltip,.chat-shortcut:focus-visible .shortcut-tooltip { visibility: visible; }
.chat-icon { position: relative; overflow: hidden; background: #e8eee8; color: #436255; }
.chat-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chat-row-text { min-width: 0; }
.chat-row-text strong,.chat-row-text small { overflow-wrap: anywhere; }
.chat-row-text strong { display: block; font-size: 14px; }
.chat-metadata { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 4px; color: var(--muted); }
.chat-badge { padding: 2px 6px; border-radius: 6px; background: #eef0ee; font-size: 11px; font-weight: 600; }
.chat-badge[data-state="pending"] { background: #f8ecd3; color: #73520e; }
.chat-badge[data-state="waiting"] { background: #e7edf5; color: #344c69; }
.chat-badge[data-state="done"] { background: #e3efe6; color: #295944; }
.empty-list { padding: 8px 15px; color: var(--muted); }

.conversation header { flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.conversation-heading { min-width: 0; overflow-wrap: anywhere; }
#title { display: block; font-size: 17px; }
#responsible { display: block; margin-top: 3px; }
.chat-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#status { padding: 5px 8px; border-radius: 7px; background: #f9f0db; color: #73520e; }
#status:empty { display: none; }
#status::before { content: '●'; font-size: .7em; margin-right: 5px; }
#status.online { background: #e3efe6; color: #275943; }
#intervention { background: #f6eedc; color: #6c501a; }
#messages { display: flex; flex-direction: column; gap: 10px; padding: 18px clamp(12px, 3vw, 46px); background: #faf8f5; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); }
.empty-chat strong { font-size: 19px; color: #243d34; }
.empty-chat p { margin: 7px 0 0; }
.empty-icon { display: grid; place-items: center; margin: 0 auto 15px; width: 54px; height: 54px; border-radius: 15px; background: var(--gr-orange-soft); color: #a34d0a; font-size: 25px; }
.bubble { align-self: flex-start; background: white; border: 1px solid var(--line); border-radius: 12px 12px 12px 3px; padding: 8px 12px; max-width: min(90%, 690px); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: #dfeee4; border-color: #d1e4d8; border-radius: 12px 12px 3px 12px; }
.bubble small { display: block; font-size: 11px; color: #4e685c; margin-bottom: 3px; }
.bubble button { font-size: 11px; min-height: 26px; }
.share-message { display: block; padding: 2px 6px; margin-top: 5px; background: transparent; color: #4b6558; }
.react-button { padding: 1px 5px; margin-inline-start: 5px; }
.message-date { align-self: center; margin: 8px auto; padding: 4px 9px; border-radius: 20px; background: #e4ebe5; color: #455d52; font-size: 11px; text-align: center; }
.attachment-preview { display: block; max-width: min(320px,100%); max-height: 360px; object-fit: contain; }
#pair { text-align: center; padding: 12px; }
.pairing-methods { display: flex; flex-wrap: wrap; gap: 8px; }
.pairing-methods button[aria-pressed="true"] { background: var(--green); color: white; }
.pairing-qr { display: block; max-width: 100%; height: auto; margin: 12px auto 0; }
#composer { margin: 10px 14px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 12px; background: white; flex-shrink: 0; }
#composer:not([hidden]) { display: grid; gap: 8px; }
#draft { display: block; width: 100%; resize: vertical; min-height: 50px; max-height: 30vh; border: 0; }
#draft:focus-visible { outline-offset: -2px; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.actions button,.actions select { font-size: 12px; }
.actions select { max-width: min(100%, 220px); }
#send { margin-left: auto; }
#feedback,#loginError,#dialogError { color: #9e2b31; }
#feedback { padding: 6px 12px; }
#feedback:empty,#loginError:empty,#dialogError:empty { display: none; }
dialog { border: 1px solid var(--line); border-radius: 14px; width: min(510px,94vw); max-height: 90dvh; padding: 20px; color: inherit; box-shadow: 0 18px 65px #142c2755; overflow: auto; }
dialog::backdrop { background: #392d2266; }
dialog h2 { margin: 0 0 15px; font-size: 20px; }
dialog p { overflow-wrap: anywhere; }
dialog footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--line); }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.handoff-context { min-width: 0; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; }
.handoff-options { max-height: 32vh; overflow: auto; }
.handoff-options label { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 8px 3px; border-top: 1px solid var(--line); overflow-wrap: anywhere; cursor: pointer; }
.handoff-options input { width: auto; flex: none; margin: 3px 0 0; }
.handoff-note { position: sticky; top: 0; z-index: 1; margin: 0; padding: 10px; border: 1px solid #e2d4ac; border-radius: 8px; background: #fbf3df; white-space: pre-wrap; overflow-wrap: anywhere; }
#backChat { display: none; }
@media (max-width: 1080px) {
  #app { grid-template-columns: 168px minmax(230px, 278px) minmax(0, 1fr); }
  .brand { font-size: 16px; gap: 6px; }
  .brand img { width: 32px; height: 32px; }
  .chat-list header,.conversation header { padding-inline: 10px; }
  .chat-list h1 { font-size: 15px; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .workspace-nav { padding: 8px; }
  .brand { margin: 0 0 6px 4px; }
  .workspace-nav nav,.workspace-nav footer { flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .workspace-nav footer { padding: 0; }
  .workspace-nav button { min-height: 32px; font-size: 12px; padding-inline: 6px; }
  .identity { border: 0; padding: 0 5px; font-size: 12px; }
  #agentInitial,.identity small { display: none; }
  #app:not(.chat-open) .conversation { display: none; }
  #app:has(#pair:not([hidden])) .conversation { display: flex; }
  #app:has(#pair:not([hidden])) .chat-list { display: none; }
  #app.chat-open .workspace-nav,#app.chat-open .chat-list { display: none; }
  #app.chat-open .conversation { grid-row: 1 / -1; }
  #backChat { display: inline-block; margin-bottom: 3px; }
}

/* Workspace navigation and settings */
#app { grid-template-columns: 66px minmax(275px,340px) minmax(0,1fr); }
.workspace-nav { overflow: visible; position: relative; z-index: 2; align-items: center; padding: 14px 8px 12px; }
.workspace-nav .brand { margin: 0 0 22px; }
.workspace-nav .brand span,.workspace-nav .identity > div { display: none; }
.workspace-nav .identity { padding: 8px 0 4px; justify-content: center; }
.workspace-nav nav,.workspace-nav footer { align-items: center; gap: 5px; }
.workspace-nav footer { max-width: 100%; }
.workspace-nav button { width: 42px; min-height: 42px; padding: 0; position: relative; justify-content: center; }
.workspace-nav svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.workspace-nav .rail-tooltip { visibility: hidden; position: absolute; top: 50%; left: calc(100% + 8px); transform: translateY(-50%); padding: 7px 10px; border-radius: 6px; color: white; background: #142d25; box-shadow: 0 3px 10px #142d2540; white-space: nowrap; pointer-events: none; }
.workspace-nav button:hover .rail-tooltip,.workspace-nav button:focus-visible .rail-tooltip { visibility: visible; }
#pendingCount, #unassignedCount { position: absolute; top: 1px; right: 1px; margin: 0; padding: 0 4px; background: var(--gold); color: #302717; }
dialog.settings-panel { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(540px,100vw); height: 100dvh; max-width: none; max-height: none; padding: 0; border-radius: 0; background: #faf6ed; overflow: hidden; border: 0; }
.settings-panel form { height: 100%; display: grid; grid-template-rows: auto minmax(0,1fr) auto auto; }
.settings-panel h2 { margin: 0; padding: 21px 24px; background: white; border-bottom: 1px solid var(--line); }
.settings-panel #dialogBody { overflow: auto; padding: 18px 24px; }
.settings-panel footer { padding: 12px 24px; background: white; }
.settings-panel #dialogError { margin: 0; padding: 9px 24px; }
.settings-section,.agent-directory { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.settings-section h3 { margin: 0 0 12px; font-size: 14px; }
.settings-section p:last-child { margin-bottom: 0; }
.agent-directory { margin-top: 14px; padding-block: 0; }
.agent-row { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 9px; padding: 12px 0; overflow-wrap: anywhere; }
.agent-row + .agent-row { border-top: 1px solid var(--line); }
.agent-row small { display: block; color: var(--muted); margin-top: 4px; }
.settings-status { display: inline-block; padding: 4px 7px; border-radius: 7px; background: #f8ecd3; color: #73520e; font-size: 12px; }
.settings-status.connected { background: #e3efe6; color: #275943; }
.danger-action { color: #9e2b31; background: #f9ecec; }
@media (max-width: 760px) {
  #app { grid-template-columns: 51px minmax(0,1fr); grid-template-rows: minmax(0,1fr); }
  .workspace-nav { padding: 8px 4px; }
  .workspace-nav button { width: 38px; min-height: 38px; }
  .workspace-nav nav,.workspace-nav footer { flex-direction: column; flex-wrap: nowrap; }
  #app.chat-open .conversation { grid-column: 1 / -1; }
  .settings-panel #dialogBody,.settings-panel h2,.settings-panel footer { padding-inline: 14px; }
}

.dialog-header { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }
.dialog-header h2 { margin:0; min-width:0; overflow-wrap:anywhere; }
#closeDialog { flex:0 0 36px; padding:0; height:36px; font-size:24px; line-height:1; }
.settings-panel .dialog-header { margin:0; padding:15px 20px 15px 24px; background:white; border-bottom:1px solid var(--line); }
.settings-panel .dialog-header h2 { padding:0; border:0; background:transparent; }
.panel-context { color:var(--muted); margin:5px 0 15px; }
.handoff-options label > span { min-width:0; display:grid; gap:3px; }
.handoff-options label strong { color:var(--muted); font-size:12px; }
.handoff-options label:hover { background:#faf5eb; }
.handoff-timeline { list-style:none; padding:0; margin:0; }
.handoff-timeline li { display:grid; justify-items:start; gap:7px; padding:12px 0; overflow-wrap:anywhere; }
.handoff-timeline li + li { border-top:1px solid var(--line); }
.handoff-timeline time { color:var(--muted); font-size:12px; }
.handoff-timeline p { margin:0; white-space:pre-wrap; }

.workspace-nav .brand img[src="rovira-chat.png"] { padding: 0; background: transparent; }

.handoff-preview { list-style:none; margin:0 0 10px; padding:0 9px; max-height:320px; overflow:auto; border:1px solid var(--line); border-radius:8px; }
.handoff-preview:empty { display:none; }
.handoff-preview li { padding:9px 0; overflow-wrap:anywhere; }
.handoff-preview li + li { border-top:1px solid var(--line); }
.handoff-preview strong { font-size:12px; color:var(--muted); }
.handoff-preview p { margin:3px 0 0; white-space:pre-wrap; }
.handoff-preview ~ button { margin:0 6px 4px 0; }

#authorizationCount, #mentionCount { position:absolute; top:1px; right:0; padding:1px 5px; border-radius:10px; font-size:11px; background:var(--gold); color:#302717; }
.authorization-row { display:flex; gap:8px; flex-wrap:wrap; padding:8px 0; }
.authorization-row + .authorization-row { border-top:1px solid var(--line); }
.visually-hidden { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }

.chat-filters { display: grid; gap: 6px; padding: 0 14px 8px; }
.chat-filters select { width: 100%; min-height: 36px; padding-block: 6px; color: var(--muted); }

.chat-batch, #manageSelection { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-batch button { font-size: 12px; }
.chat-row.selectable { grid-template-columns: auto minmax(0,1fr) auto; }
.chat-select { margin: 0 3px 0 8px; accent-color: var(--green); }
#helpChat { display: none; }
.help-search { margin: 0; font-weight: 600; }
.help-results-count { margin: 8px 0 16px; color: var(--muted); font-size: 12px; }
.help-results h3 { margin: 18px 0 7px; font-size: 14px; color: var(--green); }
.help-results details { margin-bottom: 7px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.help-results summary { cursor: pointer; padding: 11px 13px; font-weight: 600; }
.help-results summary::marker, .help-results li::marker { color: var(--green); }
.help-results .help-path { margin: 0 13px 8px; color: var(--green); font-size: 12px; font-weight: 600; }
.help-results ol { margin: 0 13px 12px; padding-inline-start: 22px; }
.help-results li { padding-inline-start: 3px; line-height: 1.48; }
.help-results li + li { margin-top: 7px; }
@media (max-width: 760px) {
  #helpChat { display: inline-block; margin: 0 0 3px 5px; }
}

.whatsapp-incident {
  flex-shrink: 0;
  margin: 0;
  padding: 10px 16px;
  background: #fff3d8;
  border-bottom: 1px solid #e6cd8d;
  color: #63420a;
  font-size: .9rem;
}

#followupNotice {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: #fff3d8;
  color: #63420a;
}
#followupNotice > div { display: flex; flex-wrap: wrap; gap: 6px; }

#messageFormatting { display: flex; flex-wrap: wrap; gap: 4px; padding: 5px; background: #f7f0e4; border-radius: 8px; }
#messageFormatting button { font-size: 12px; min-height: 30px; padding: 5px 9px; background: white; }
#messageFormatting button:hover { background: #e2eee6; }
#formatToggle[aria-expanded="true"], #formatPreviewToggle[aria-expanded="true"] {
  background: #dfeee4;
  color: #204d3b;
}
#composer .actions { padding-top: 6px; border-top: 1px solid var(--line); }
@media (max-width: 760px) {
  #composer { margin: 6px 8px; }
}
#formatPreview {
  max-height: 130px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  border-left: 3px solid var(--line);
  background: #faf8f5;
}
:is(#formatPreview,.formatted-message) :is(ul,ol,blockquote) { margin: 0; }
:is(#formatPreview,.formatted-message) blockquote { padding-left: 8px; border-left: 2px solid currentColor; }

#login .remember-session { display: flex; align-items: center; gap: 8px; }
#login .remember-session input { width: auto; margin: 0; }


.chat-row-text { flex: 1; }
.chat-row-title { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.chat-row-title strong,.chat-row-preview { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-row-title time { color: var(--muted); white-space: nowrap; font-size: 11px; }
.chat-row-preview { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
#intervention { background: var(--green); color: white; }
#intervention[data-action="reopen"] { background: #f4e9d6; color: #235644; }
#chatMore { position: relative; }
#chatMore summary { display: grid; place-items: center; list-style: none; min-height: 36px; min-width: 36px; border-radius: 8px; background: #f4e9d6; cursor: pointer; font-size: 19px; }
#chatMore summary::-webkit-details-marker { display: none; }
.chat-more-actions {
  position: absolute; z-index: 5; right: 0; top: calc(100% + 6px); width: max-content;
  max-width: min(70vw, 260px); display: grid; gap: 3px; padding: 6px;
  border: 1px solid var(--line); border-radius: 10px; background: white; box-shadow: 0 8px 24px #142c2733;
}
.chat-more-actions button.chat-shortcut { width: auto; display: flex; justify-content: flex-start; gap: 8px; text-align: left; }
.chat-more-actions .shortcut-tooltip { position: static; visibility: visible; display: inline; opacity: 1; transform: none; color: inherit; background: none; padding: 0; box-shadow: none; white-space: normal; }
#interventionNotice { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 14px; background: #f4e9d6; }
#interventionNotice button { min-height: 30px; padding: 4px 8px; }
@media (max-width: 760px) {
  #intervention .shortcut-tooltip { position: static; visibility: visible; opacity: 1; transform: none; padding: 0; background: none; color: inherit; box-shadow: none; white-space: normal; }
  #intervention { width: auto; display: flex; gap: 6px; padding-inline: 8px; }
}

.pending-reason { display: block; margin-top: 4px; color: var(--muted); }
.handoff-summary { margin: 0; font-weight: 600; }
.handoff-settings { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.handoff-settings summary { cursor: pointer; color: #235644; padding-block: 6px; }
.handoff-settings[open] summary { margin-bottom: 6px; }
.handoff-notify { display: flex; align-items: center; gap: 8px; }
.handoff-notify input { width: auto; margin: 0; }

#session-gate { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 24px; text-align: center; color: var(--muted); }
#session-status { margin: 0; }


/* Tareas del cliente en la cabecera del chat */
.chat-tasks { position: relative; }
.chat-tasks summary { list-style: none; display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 9px; border-radius: 9px; background: #f3ece0; color: #5e5242; cursor: pointer; font-weight: 700; font-size: 13px; }
.chat-tasks summary::-webkit-details-marker { display: none; }
.chat-tasks summary svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.chat-tasks[data-has="true"] summary { background: #f6ebdb; color: #6c4c27; box-shadow: inset 0 0 0 1px #e2c99e; }
.chat-tasks-panel { position: absolute; z-index: 20; right: 0; top: calc(100% + 6px); width: min(330px,86vw); display: grid; gap: 4px; padding: 10px; border: 1px solid #e6dac6; border-radius: 12px; background: #fffefa; box-shadow: 0 10px 26px #2a1d0a33; }
.chat-tasks-panel strong { font-size: 13px; margin: 0 2px 4px; }
.chat-tasks-panel a { display: grid; gap: 1px; padding: 7px 8px; border-radius: 8px; color: #2e2a25; text-decoration: none; }
.chat-tasks-panel a:hover { background: #f5ecdc; }
.chat-tasks-panel a small { color: #7a6c58; font-size: 12px; }
.chat-tasks-panel a[data-late="true"] small { color: #a3282a; font-weight: 650; }
.chat-tasks-panel .chat-tasks-new { margin-top: 4px; border-top: 1px solid #eee2d0; border-radius: 0 0 8px 8px; color: #8d5b0a; font-weight: 650; }

/* Reacciones y opciones del mensaje: solo al pasar el ratón (siempre visibles en pantallas táctiles) */
.bubble { position: relative; }
.bubble .react-button { position: absolute; top: -13px; right: 8px; min-height: 26px; padding: 1px 7px; margin: 0; border-radius: 13px; background: #fffefa; border: 1px solid var(--line); box-shadow: 0 2px 6px #0000001f; opacity: 0; pointer-events: none; transition: opacity .12s; }
.bubble .react-button + .react-button { right: 44px; }
.bubble:hover .react-button,.bubble:focus-within .react-button { opacity: 1; pointer-events: auto; }
@media (hover: none) {
  .bubble .react-button { opacity: .85; pointer-events: auto; top: auto; bottom: -12px; }
  .bubble:has(.react-button) { margin-bottom: 10px; }
}
/* Filtros de la lista agrupados en el móvil */
.filters-toggle { display: none; }
@media (max-width: 760px) {
  .filters-toggle { display: inline-flex; align-items: center; gap: 6px; margin: -4px 14px 8px; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 650; align-self: flex-start; }
  .filters-toggle[data-active="true"] { background: var(--gr-orange-soft,#fff0dc); box-shadow: inset 0 0 0 1px #e2c99e; }
  .chat-list:not(.filters-open) .chat-filters { display: none; }
}

/* Contraseña visible y «¿Has olvidado la contraseña?» */
#login .pw-toggle,#forgotForm .pw-toggle { width: 36px; margin: 0; background: transparent; color: #6a5f50; }
#login .pw-toggle:hover:not(:disabled) { background: #0000000d; color: #2e2a25; }
#login .login-link,#forgotForm .login-link { display: block; width: auto; margin: 12px auto 0; padding: 4px 6px; border: 0; background: none; color: #245743; font-weight: 600; text-decoration: underline; }
#login .login-link:hover,#forgotForm .login-link:hover { background: none; color: #163d2e; }
#forgotForm,.mail-access-form { max-width: 440px; width: calc(100% - 32px); margin: min(6vh, 56px) auto; background: #fffefa; padding: 24px clamp(18px, 5vw, 30px); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 18px 55px #162e2814; }
#forgotForm h1,.mail-access-form h1 { text-align: center; font-size: 21px; margin: 8px 0 10px; }
.forgot-text { color: #52655c; margin: 0 0 14px; }
#forgotForm label { display: grid; gap: 4px; }
#forgotForm input { width: 100%; }
#forgotSend { width: 100%; margin-top: 10px; background: var(--gr-orange); color: var(--gr-orange-ink); font-weight: 650; }
#forgotStatus { margin: 10px 0 0; color: #245743; font-weight: 600; }
#forgotStatus:empty { display: none; }
#forgotStatus[data-error="true"] { color: #9e2b31; }

.mail-access-form button:first-of-type { background: var(--gr-orange); color: var(--gr-orange-ink); margin-right: 6px; }
.mail-access-form p[role="alert"] { color: #9e2b31; }

/* v94: botón de reconexión en el aviso de corte */
.whatsapp-incident .incident-reconnect { margin-left: 6px; padding: 4px 10px; border: 1px solid #c58b2a; border-radius: 8px; background: #fffaf0; color: #5b3511; font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; }
.whatsapp-incident .incident-reconnect:disabled { opacity: .6; cursor: default; }

/* v94: atajo «gestionado» en la lista */
.chat-row-shortcuts .chat-shortcut-managed { color: #176049; }
.chat-row-shortcuts .chat-shortcut-managed:hover { background: #e3f2ea; }
/* v95 · Resultados de búsqueda dentro de los mensajes */
.message-results { display: grid; gap: 2px; margin-top: 6px; padding-top: 8px; border-top: 1px solid #ece3d6; }
.message-results h2 { margin: 2px 12px 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #7a6c58; }
.message-result { display: grid; gap: 3px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.message-result:hover, .message-result[aria-current="true"] { background: #fff3e2; }
.message-result-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.message-result-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-result-head time { flex: none; color: #7a6c58; font-size: 12px; }
.message-result-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: #5d5245; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.message-result-text b { font-weight: 600; color: #3d3428; }
.message-result mark, .bubble mark { background: #ffd89a; color: inherit; border-radius: 3px; padding: 0 1px; }
.message-results-more { margin: 4px 12px 8px; color: #7a6c58; font-size: 12.5px; }
.bubble.bubble-found { animation: bubble-found 2.6s ease-out; }
@keyframes bubble-found { 0%, 35% { box-shadow: 0 0 0 3px #f4a450, 0 0 0 7px #f4a45040; } 100% { box-shadow: 0 0 0 0 transparent; } }
/* v99 · idioma con el cliente (ES / CA) */
.chat-lang { display: inline-flex; border: 1px solid #e0cfb2; border-radius: 9px; overflow: hidden; background: #fffefa; }
.chat-lang[hidden] { display: none; }
.actions .chat-lang button { min-width: 38px; padding: 6px 9px; border: 0; border-radius: 0; background: transparent; color: #6a5f50; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.actions .chat-lang button + button { border-left: 1px solid #e0cfb2; }
.actions .chat-lang button[aria-pressed="true"] { background: #302a22; color: #fff; }
/* v100 · adjuntos con vista previa y visor como en WhatsApp */
.attachment { display: grid; gap: 4px; justify-items: start; margin: 4px 0; }
.attachment .attachment-preview { cursor: zoom-in; }
.attachment-download { font-size: 12px; color: #8a5a22; }
.attachment-card { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 320px; padding: 9px 12px; border: 1px solid #e6d8c2; border-radius: 10px; background: #fffaf3; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.attachment-card:hover { background: #fff0db; }
.attachment-icon { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; background: #f3e4cc; font-size: 20px; }
.attachment-card[data-kind="pdf"] .attachment-icon { background: #fbe0dc; }
.attachment-text { display: grid; gap: 2px; min-width: 0; }
.attachment-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.attachment-text small { color: #7a6c58; font-size: 12px; }
.attachment-audio { width: min(300px, 62vw); height: 40px; }
.media-viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #151311; color: #fff; }
.media-viewer::backdrop { background: #000a; }
.media-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.media-viewer header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: #0007; }
.mv-title { display: grid; min-width: 0; }
.mv-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.mv-title small { color: #d9cfc0; font-size: 12px; }
.mv-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.mv-actions :is(a, button) { padding: 7px 12px; border: 1px solid #ffffff40; border-radius: 8px; background: transparent; color: #fff; font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.mv-actions :is(a, button):hover { background: #ffffff1f; }
.mv-actions a[hidden] { display: none; }
.mv-actions .mv-close { width: 36px; padding: 4px; font-size: 22px; line-height: 1; }
.mv-stage { display: grid; place-items: center; min-height: 0; overflow: auto; padding: 14px 56px; }
.mv-image { max-width: 100%; max-height: calc(100dvh - 100px); object-fit: contain; cursor: zoom-in; box-shadow: 0 8px 30px #0008; }
.mv-image.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.mv-pdf { width: min(1000px, 100%); height: calc(100dvh - 100px); border: 0; border-radius: 6px; background: #fff; }
.mv-video { max-width: 100%; max-height: calc(100dvh - 100px); }
.mv-loading { color: #e9e1d6; }
.mv-file { display: grid; justify-items: center; gap: 12px; max-width: 420px; text-align: center; }
.mv-file span { font-size: 54px; }
.mv-file :is(button, a) { padding: 10px 16px; border: 0; border-radius: 10px; background: #f4a450; color: #252524; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.mv-nav { position: fixed; top: 50%; z-index: 2; width: 44px; height: 64px; margin-top: -32px; border: 0; border-radius: 10px; background: #0006; color: #fff; font-size: 34px; cursor: pointer; }
.mv-nav:hover { background: #000a; }
.mv-nav[hidden] { display: none; }
.mv-prev { left: 8px; }
.mv-next { right: 8px; }
@media (max-width: 760px) {
  .mv-stage { padding: 8px; }
  .mv-actions .mv-tab { display: none; }
  .mv-nav { width: 36px; height: 52px; }
}

/* v104 · chats para un departamento */
.dept-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 12px 8px; padding: 10px 12px; border: 1px solid #bcd3e6; border-radius: 10px; background: #eef5fb; color: #1f3d57; font-size: 14px; }
.dept-notice p { flex: 1 1 260px; margin: 0; }
.dept-notice small { color: #4b6278; }
.dept-notice .primary { padding: 7px 14px; border: 0; border-radius: 8px; background: #f4a450; color: #252524; font-weight: 700; cursor: pointer; }
.chat-badge[data-state="dept"] { background: #e3eef8; color: #1f4f7a; }

/* v114 · WhatsApp en el móvil: cabecera compacta y caja de escribir en una línea (herramientas en «+») */
#composerTools { display: none; }
@media (max-width: 760px) {
  .conversation > header { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 8px; align-items: center; min-height: 0; padding: 6px 10px; }
  .conversation > header .conversation-heading { display: contents; }
  .conversation > header #backChat { grid-column: 1; grid-row: 1; display: grid; place-items: center; width: 34px; height: 34px; margin: 0; padding: 0; font-size: 0; border-radius: 9px; }
  .conversation > header #backChat::before { content: "‹"; font-size: 26px; line-height: 1; }
  .conversation > header #title { grid-column: 2; grid-row: 1; align-self: end; min-width: 0; font-size: 16px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .conversation > header #responsible { grid-column: 2; grid-row: 2; align-self: start; margin-top: -3px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .conversation > header .chat-actions { grid-column: 1 / -1; flex-wrap: nowrap; gap: 6px; min-width: 0; }
  .conversation > header .chat-actions #status { display: none; }
  .conversation > header .chat-actions > :is(button, details) { flex: none; }
  .conversation > header .chat-actions button { min-height: 34px; }
  .conversation > header #intervention { font-size: 13px; padding-inline: 8px; }
  /* Caja de escribir */
  #composer:not([hidden]) { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px; margin: 4px 6px 6px; padding: 6px; }
  #composer > :is(#messageFormatting, #formatPreview) { order: 5; flex: 1 1 100%; }
  #composer .actions { display: contents; }
  #composer #composerTools { order: 1; display: grid; place-items: center; flex: none; width: 40px; height: 42px; padding: 0; border-radius: 10px; font-size: 24px; line-height: 1; }
  #composer.gr-tools-open #composerTools { background: #f4e9d6; }
  #composer .send { order: 2; flex: 1 1 calc(100% - 110px); min-width: 0; }
  #composer #draft { min-height: 42px; max-height: 120px; height: 42px; padding: 9px 10px; resize: none; }
  #composer #send { order: 3; flex: none; height: 42px; width: 46px; padding: 0; font-size: 0; display: grid; place-items: center; }
  #composer #send::before { content: "➤"; font-size: 19px; }
  #composer .actions > :not(#send):not(input[type="file"]) { order: 4; }
  #composer:not(.gr-tools-open) .actions > :not(#send):not(#fileName):not(#clearFile) { display: none !important; }
  #composer #fileName:empty { display: none; }
  #composer.gr-tools-open .actions > #quick { flex: 1 1 100%; }
}
@media (max-width: 760px) and (max-height: 560px) {
  .conversation > header .chat-actions, #followupNotice { display: none !important; }
}
/* v120 · número de teléfono del contacto */
#responsible .chat-phone { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; white-space: nowrap; }
#responsible .chat-phone:hover { color: #8d5b0a; }
.rename-phone { font-weight: 650; color: #252524 !important; }

/* v180 · Mensajes con más aire y opciones coherentes con el resto de la app */
#messages { gap: 16px; padding: 34px clamp(14px, 3.5vw, 56px) 26px; }
.bubble { padding: 10px 14px 10px; border-radius: 14px 14px 14px 4px; line-height: 1.55; max-width: min(88%, 680px); box-shadow: 0 1px 2px #3c32280f; }
.bubble.out { border-radius: 14px 14px 4px 14px; }
.bubble small { margin-bottom: 5px; font-size: 11.5px; letter-spacing: .01em; }
.bubble .msg-reactions { display: inline-block; width: auto; margin: 8px 0 0; padding: 1px 9px; border-radius: 999px; background: #f4ede1; color: #3f3933; font-size: 13px; }
.bubble.out .msg-reactions { background: #cfe3d6; }
.message-date { margin: 14px auto 4px; padding: 5px 13px; font-weight: 600; letter-spacing: .02em; }
.bubble .share-message { display: inline-block; width: auto; margin-top: 8px; padding: 3px 11px; min-height: 26px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: #5d5144; font-size: 12px; font-weight: 600; }
.bubble .share-message:hover:not(:disabled) { background: var(--gr-orange-soft, #fff0dc); border-color: #f0cba7; color: #8d4f0a; }
.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; opacity: 0; pointer-events: none; transform: translateY(2px); transition: opacity .12s, transform .12s; }
.bubble:hover .msg-toolbar, .bubble:focus-within .msg-toolbar { opacity: 1; pointer-events: auto; transform: none; }
.msg-toolbar > button, .msg-toolbar .react-button { position: static; display: inline-flex; align-items: center; gap: 2px; width: 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; white-space: nowrap; opacity: 1; pointer-events: auto; transition: background .12s, color .12s; }
.msg-toolbar .msg-tool[data-icon]::before { margin-right: .3em; font-size: 1em; }
.msg-toolbar .react-button { padding: 2px 10px; font-size: 14px; }
.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; justify-content: flex-start; }
  .bubble:has(.react-button) { margin-bottom: 0; }
}

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

/* v190 · Agenda del móvil en la búsqueda (administración) */
.phonebook-results h2 { color: #a2530c; }
.phonebook-result .phonebook-action { font-size: 12px; font-weight: 700; color: #a2530c; background: #fdead5; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.phonebook-result:hover .phonebook-action, .phonebook-result:focus-visible .phonebook-action { background: #f4a450; color: #1f1a17; }

/* v196 · Enlaces, correos y teléfonos que se activan solos en los textos */
.gr-auto-link { color: #8d5b0a; text-decoration: underline; text-underline-offset: 2px; word-break: break-word; cursor: pointer; }
.gr-auto-link:hover { color: #6d4306; }
.bubble.out .gr-auto-link, .message.mine .gr-auto-link { color: inherit; }
.handoff-message { display: grid; gap: 8px; }
.handoff-message.is-off textarea { opacity: .6; background: #f4efe6; cursor: not-allowed; }
.handoff-message .handoff-hint { color: #7a6c58; font-size: 12.5px; }
.handoff-message .link { justify-self: start; }
.handoff-message[hidden] { display: none; }
