/* Message features (chat/js/mensagens.js, chat/js/localizacao.js) on the customer and attendant chats.
 * Colours come from each screen's own variables, so light/dark themes and the person's colours apply. */
.client-workspace, .attendance-workspace {
    --mx-surface: var(--bg-card, var(--bg-sidebar, #ffffff));
    --mx-text: var(--text-main, #1f2a3a);
    --mx-muted: var(--text-muted, #6b7a90);
    --mx-border: var(--border-color, #e2e8f0);
    --mx-accent: var(--accent-text, var(--primary-color, #00a78c));
    --mx-hover: var(--hover-bg, var(--bg-input, #f1f5f9));
    --mx-soft: var(--accent-soft, var(--sent-bg, #e9f7f4));
    --mx-read: #1a7fd1;
    --mx-danger: #c62828;
    --mx-shadow: 0 10px 30px rgba(15, 23, 42, .14), 0 1px 3px rgba(15, 23, 42, .06);
}
:root[data-client-theme="dark"] .client-workspace, .client-workspace.dark-mode, .attendance-workspace.dark-mode { --mx-read: #53bdeb; --mx-danger: #ff8a80; --mx-shadow: 0 12px 34px rgba(0, 0, 0, .5); }

/* Row extras ------------------------------------------------------------------------------------ */
.stream-message-row .msg-balloon-wrap { position: relative; }
.stream-message-row.is-pending .msg-bubble { opacity: .78; }
.stream-message-row.message-deleted .msg-text { color: var(--mx-muted); font-style: italic; }
.stream-message-row.message-deleted .msg-text .bi { margin-right: 2px; }
.stream-message-row.msg-highlight .msg-bubble { animation: mxHighlight 2.1s ease; }
@keyframes mxHighlight { 0%, 35% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--mx-accent) 55%, transparent); } 100% { box-shadow: 0 0 0 3px transparent; } }
.stream-message-row.is-pressed .msg-bubble { transform: scale(.98); transition: transform .12s ease; }
.stream-message-row .msg-bubble:focus { outline: none; }
.stream-message-row .msg-bubble:focus-visible { outline: 2px solid var(--mx-accent); outline-offset: 2px; }

/* Quote inside a bubble */
.msg-quote { display: grid; gap: 1px; width: 100%; max-width: 100%; min-width: 0; margin: 0 0 8px; padding: 6px 10px; border: 0; border-left: 3px solid var(--mx-accent); border-radius: 6px; background: color-mix(in srgb, var(--mx-accent) 9%, transparent); color: var(--mx-text); text-align: left; font: inherit; font-size: .86em; line-height: 1.45; cursor: pointer; }
.msg-quote:hover { background: color-mix(in srgb, var(--mx-accent) 15%, transparent); }
.msg-quote:focus-visible { outline: 2px solid var(--mx-accent); outline-offset: 2px; }
.msg-quote-author { color: var(--mx-accent); font-weight: 700; font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-quote-text { color: var(--mx-muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; font-style: normal; }
.msg-quote[data-quote-tipo="apagada"] .msg-quote-text { font-style: italic; }

/* Reactions under the bubble */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.stream-message-row.sent .msg-reactions { justify-content: flex-end; }
.msg-reaction { display: inline-flex; align-items: center; gap: 4px; min-height: 26px; padding: 1px 8px; border: 1px solid var(--mx-border); border-radius: 999px; background: var(--mx-surface); color: var(--mx-text); font: inherit; font-size: 12px; line-height: 1; cursor: pointer; }
.msg-reaction-emoji { font-size: 14px; font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif; }
.msg-reaction-count { font-variant-numeric: tabular-nums; color: var(--mx-muted); font-weight: 600; }
.msg-reaction.is-mine { border-color: color-mix(in srgb, var(--mx-accent) 55%, transparent); background: color-mix(in srgb, var(--mx-accent) 12%, var(--mx-surface)); }
.msg-reaction.is-mine .msg-reaction-count { color: var(--mx-accent); }
.msg-reaction:hover:not(:disabled) { border-color: var(--mx-accent); }
.msg-reaction:disabled { cursor: default; opacity: 1; }
.msg-reaction:focus-visible { outline: 2px solid var(--mx-accent); outline-offset: 1px; }

/* Delivery/read ticks next to the time */
.msg-status { display: inline-flex; align-items: center; gap: 3px; color: var(--mx-muted); font-size: 13px; line-height: 1; }
.msg-status[data-status="lida"] { color: var(--mx-read); }
.msg-status[data-status="erro"] { color: var(--mx-danger); }
.msg-status[data-status="enviando"] { font-size: 11px; }
.msg-status-text { font-size: 10px; font-style: italic; }
@media (max-width: 480px) { .msg-status-text { display: none; } }

/* Hover/focus toolbar beside the bubble (desktop) */
.msg-actions { position: absolute; top: 20px; z-index: 3; display: flex; gap: 2px; padding: 3px; border: 1px solid var(--mx-border); border-radius: 10px; background: var(--mx-surface); box-shadow: var(--mx-shadow); opacity: 0; pointer-events: none; transition: opacity .12s ease; }
.stream-message-row.received .msg-actions { left: calc(100% + 6px); }
.stream-message-row.sent .msg-actions { right: calc(100% + 6px); }
.stream-message-row:hover .msg-actions, .stream-message-row:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg-action { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--mx-muted); font-size: 14px; cursor: pointer; }
.msg-action:hover, .msg-action:focus-visible { background: var(--mx-hover); color: var(--mx-accent); }
.msg-action.is-danger:hover, .msg-action.is-danger:focus-visible { color: var(--mx-danger); }
.msg-action:focus-visible { outline: 2px solid var(--mx-accent); outline-offset: -2px; }
@media (hover: none), (max-width: 560px) {
    /* Touch: long press opens the action sheet. The toolbar stays reachable with a keyboard and
       shows up in the flow (no clipping at the screen edge) while it has the focus. */
    .msg-actions { position: absolute; top: auto; left: auto !important; right: auto !important; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); border: 0; opacity: 1; pointer-events: auto; box-shadow: none; }
    .msg-actions:focus-within { position: static; width: max-content; height: auto; margin-top: 4px; padding: 3px; overflow: visible; clip-path: none; border: 1px solid var(--mx-border); }
    .stream-message-row.sent .msg-actions:focus-within { margin-left: auto; }
}

/* Quick reactions (floating) */
.msg-react-bar { position: fixed; z-index: 2147482000; display: flex; gap: 2px; padding: 5px; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 999px; background: var(--mx-surface, #fff); box-shadow: var(--mx-shadow); }
.msg-react-bar[hidden] { display: none; }
.msg-react-quick, .msg-react-more { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--mx-muted, #6b7a90); font-size: 21px; line-height: 1; cursor: pointer; font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif; transition: transform .1s ease; }
.msg-react-more { font-size: 16px; background: var(--mx-hover, #f1f5f9); }
.msg-react-quick:hover, .msg-react-quick:focus-visible { transform: scale(1.18); background: var(--mx-hover, #f1f5f9); }
.msg-react-quick:focus-visible, .msg-react-more:focus-visible { outline: 2px solid var(--mx-accent, #00a78c); outline-offset: 1px; }

/* Touch action sheet (long press) */
.msg-sheet { position: fixed; inset: auto 0 0; width: 100%; max-width: 520px; max-height: 85dvh; margin: auto auto 0; padding: 0; overflow-y: auto; border: 0; border-radius: 18px 18px 0 0; background: var(--mx-surface, #fff); color: var(--mx-text, #1f2a3a); box-shadow: var(--mx-shadow); }
.msg-sheet::backdrop { background: rgba(15, 23, 42, .35); }
.msg-sheet-box { display: grid; gap: 10px; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); font-family: inherit; }
.msg-sheet-title { margin: 0 4px; color: var(--mx-muted, #6b7a90); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-sheet-reactions { display: flex; justify-content: space-between; gap: 4px; padding: 6px; border-radius: 999px; background: var(--mx-hover, #f1f5f9); }
.msg-sheet-actions { display: grid; gap: 2px; }
.msg-sheet-action { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--mx-text, #1f2a3a); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.msg-sheet-action:hover, .msg-sheet-action:focus-visible { background: var(--mx-hover, #f1f5f9); }
.msg-sheet-action .bi { width: 20px; color: var(--mx-accent, #00a78c); font-size: 17px; }
.msg-sheet-action.is-danger, .msg-sheet-action.is-danger .bi { color: var(--mx-danger, #c62828); }
.msg-sheet-action.is-cancel { justify-content: center; color: var(--mx-muted, #6b7a90); }

/* Confirmation dialog */
.msg-confirm { position: fixed; inset: 0; margin: auto; height: fit-content; width: min(92vw, 380px); padding: 0; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 14px; background: var(--mx-surface, #fff); color: var(--mx-text, #1f2a3a); box-shadow: var(--mx-shadow); }
.msg-confirm::backdrop { background: rgba(15, 23, 42, .35); }
.msg-confirm form { display: grid; gap: 10px; padding: 20px; font-family: inherit; }
.msg-confirm h3 { margin: 0; font-size: 16px; }
.msg-confirm p { margin: 0; color: var(--mx-muted, #6b7a90); font-size: 13px; line-height: 1.6; }
.msg-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.msg-confirm-actions button { min-height: 40px; padding: 0 16px; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 9px; background: transparent; color: var(--mx-text, #1f2a3a); font: inherit; font-weight: 600; cursor: pointer; }
.msg-confirm-ok { border-color: transparent !important; background: var(--primary-color, #00a78c) !important; color: var(--action-text, var(--on-primary, #fff)) !important; }
.msg-confirm-ok.is-danger { background: #c62828 !important; color: #fff !important; }

/* Outbox states */
.msg-send-error { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; color: var(--mx-danger); font-size: 11px; line-height: 1.5; }
.stream-message-row.sent .msg-send-error { justify-content: flex-end; text-align: right; }
.msg-send-error-actions { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.msg-send-error button { min-height: 28px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--mx-accent); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.msg-send-error button:hover, .msg-send-error button:focus-visible { background: var(--mx-hover); }
.msg-local-file { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border: 1px dashed var(--mx-border); border-radius: 10px; }
.msg-local-file > .bi { font-size: 20px; color: var(--mx-accent); }
.msg-local-file span { display: grid; min-width: 0; }
.msg-local-file strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-local-file small { color: var(--mx-muted); font-size: 10.5px; }

/* Composer: reply/edit bar and connection banner */
.composer-context { display: flex; align-items: center; gap: 10px; min-width: 0; margin: 0 0 8px; padding: 7px 8px 7px 12px; border-left: 3px solid var(--mx-accent); border-radius: 8px; background: color-mix(in srgb, var(--mx-accent) 8%, var(--mx-surface)); color: var(--mx-text); }
.composer-context[hidden] { display: none; }
.composer-context-icon { color: var(--mx-accent); font-size: 16px; }
.composer-context-text { display: grid; flex: 1; min-width: 0; font-size: 12px; line-height: 1.45; }
.composer-context-text strong { color: var(--mx-accent); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-context-text span { color: var(--mx-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-context-close { flex: 0 0 34px; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--mx-muted); cursor: pointer; }
.composer-context-close:hover, .composer-context-close:focus-visible { background: var(--mx-hover); color: var(--mx-text); }
.chat-connection-banner { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 8px 12px; border: 1px solid color-mix(in srgb, #d97706 35%, transparent); border-radius: 9px; background: color-mix(in srgb, #f59e0b 12%, var(--mx-surface)); color: var(--mx-text); font-size: 12px; line-height: 1.5; }
.chat-connection-banner[hidden] { display: none; }
.chat-connection-banner .bi { color: #b45309; font-size: 15px; }
.chat-connection-banner.is-sending { border-color: color-mix(in srgb, var(--mx-accent) 30%, transparent); background: color-mix(in srgb, var(--mx-accent) 8%, var(--mx-surface)); }
.chat-connection-banner.is-sending .bi { color: var(--mx-accent); animation: mxSpin 1.2s linear infinite; }
@keyframes mxSpin { to { transform: rotate(360deg); } }
.composer-emoji-btn .bi { font-size: 18px; }
/* Attendant on a phone: the system keyboard already has emojis; the textarea keeps its room. */
@media (max-width: 480px) { .attendance-workspace .composer-emoji-btn { display: none; } }

/* Location card */
.msg-location { display: grid; width: 260px; max-width: 100%; overflow: hidden; border: 1px solid var(--mx-border); border-radius: 12px; background: var(--mx-surface); }
.msg-location-map { position: relative; height: 140px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--mx-accent) 6%, transparent) 0 10px, transparent 10px 20px), var(--mx-hover); color: var(--mx-accent); font-size: 26px; }
.msg-location-map .ol-viewport { position: absolute !important; inset: 0; }
.msg-location-map .ol-attribution { font-size: 9px; }
.msg-location-info { display: grid; gap: 2px; padding: 9px 11px 10px; font-size: 11.5px; line-height: 1.5; color: var(--mx-text); }
.msg-location-info strong { font-size: 12px; }
.msg-location-info strong .bi { color: var(--mx-accent); }
.msg-location-info span { color: var(--mx-muted); font-variant-numeric: tabular-nums; }
.msg-location-link { justify-self: start; margin-top: 4px; color: var(--mx-accent); font-weight: 700; text-decoration: none; }
.msg-location-link:hover, .msg-location-link:focus-visible { text-decoration: underline; }

/* Location dialog (customer) */
.chat-location-dialog { position: fixed; inset: 0; margin: auto; height: fit-content; width: min(94vw, 480px); overflow-y: auto; max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 16px; background: var(--mx-surface, #fff); color: var(--mx-text, #1f2a3a); box-shadow: var(--mx-shadow); }
.chat-location-dialog::backdrop { background: rgba(15, 23, 42, .4); }
.chat-location-dialog form { position: relative; display: grid; gap: 12px; padding: 20px; font-family: inherit; }
.chat-location-dialog h3 { margin: 0 36px 0 0; font-size: 16px; }
.loc-consent { margin: 0; color: var(--mx-muted, #6b7a90); font-size: 12.5px; line-height: 1.65; }
.loc-close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--mx-muted, #6b7a90); cursor: pointer; }
.loc-close:hover, .loc-close:focus-visible { background: var(--mx-hover, #f1f5f9); }
.loc-preview { display: grid; gap: 8px; }
.loc-preview[hidden] { display: none; }
.loc-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.loc-map { position: relative; height: 260px; cursor: crosshair; overflow: hidden; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 12px; background: var(--mx-hover, #f1f5f9); display: grid; place-items: center; }
.loc-map .ol-viewport { position: absolute !important; inset: 0; }
.loc-map:focus-visible { outline: 2px solid var(--mx-accent, #00a78c); outline-offset: 2px; }
.loc-center { justify-self: start; min-height: 36px; font-size: 12px; }
.loc-map-off { color: var(--mx-muted, #6b7a90); font-size: 12px; }
.loc-accuracy { margin: 0; font-size: 12px; color: var(--mx-text, #1f2a3a); }
.loc-accuracy .bi { color: var(--mx-accent, #00a78c); }
.loc-accuracy.is-low span { color: #b45309; }
.loc-status { margin: 0; color: var(--mx-muted, #6b7a90); font-size: 12px; }
.loc-status:empty { display: none; }
.loc-btn[hidden] { display: none; }
.loc-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.loc-btn { min-height: 42px; padding: 0 14px; border: 1px solid var(--mx-border, #e2e8f0); border-radius: 10px; background: transparent; color: var(--mx-text, #1f2a3a); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.loc-btn:hover:not(:disabled), .loc-btn:focus-visible { border-color: var(--mx-accent, #00a78c); }
.loc-btn.is-primary { border-color: transparent; background: var(--primary-color, #00a78c); color: var(--action-text, #fff); }
.loc-btn:disabled { opacity: .45; cursor: default; }
@media (max-width: 480px) { .loc-actions { display: grid; grid-template-columns: 1fr 1fr; } .loc-actions .is-primary { grid-column: 1 / -1; grid-row: 1; } }

/* Customer attach menu */
.client-attach-menu { position: fixed; z-index: 2147481000; min-width: 220px; padding: 6px; border: 1px solid var(--mx-border); border-radius: 12px; background: var(--mx-surface); color: var(--mx-text); box-shadow: var(--mx-shadow); }
.client-attach-menu[hidden] { display: none; }
.client-attach-menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.client-attach-menu button:hover, .client-attach-menu button:focus-visible { background: var(--mx-hover); outline: none; }
.client-attach-menu .bi { width: 20px; color: var(--mx-accent); font-size: 17px; }

@media (prefers-reduced-motion: reduce) {
    .stream-message-row.msg-highlight .msg-bubble { animation: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--mx-accent) 55%, transparent); }
    .chat-connection-banner.is-sending .bi, .msg-react-quick { animation: none; transition: none; }
}
