/* Chat screen (chats/show, admin/chats/show): one screen like a messaging app. Title
   bar, messages scrolling in between, composer pinned to the bottom; the page itself
   doesn't scroll. Phones first; from 768px the same screen sits in a centred card. */
body.is-chat .site-footer { display: none; }
body.is-chat .site-main { min-height: 0; }

.chat-screen {
  --chat-own: color-mix(in srgb, var(--color-accent) 12%, #fff);
  display: flex; flex-direction: column;
  height: calc(100vh - 3.5rem);
  height: calc(100dvh - 3.5rem);
  background: var(--color-surface-strong);
}

.chat-screen__bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 1rem; background: var(--color-bg); border-bottom: 1px solid var(--color-line); }
.chat-screen__avatar { flex: none; display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 50%; background: var(--color-text); color: #fff; font-weight: 700; }
.chat-screen__titles { min-width: 0; }
.chat-screen__title { margin: 0; font-family: var(--font-sans); font-size: 1rem; font-style: normal; line-height: 1.3; text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__hours, .chat-screen__link { margin: 0; font-size: 0.8125rem; color: var(--color-muted); }

/* "Activar notificaciones": a thin strip under the bar; gone when it has nothing to show. */
.chat-screen .push-optin { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 1rem; background: var(--color-bg); border-bottom: 1px solid var(--color-line); font-size: 0.8125rem; }
.chat-screen .push-optin:not(:has(> :not([hidden]))) { display: none; }
.chat-screen .push-optin p { margin: 0; color: var(--color-muted); }
.chat-screen .push-optin .button { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }

.chat-screen__scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0.75rem 0.75rem 1rem; }
.chat__empty { margin: 2rem auto; max-width: 18rem; text-align: center; color: var(--color-muted); font-size: 0.9375rem; }

/* Bubbles: the other side white on the left, your own tinted on the right. */
.chat__messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.chat__day { align-self: center; margin: 0.75rem 0 0.375rem; padding: 0.125rem 0.75rem; border-radius: 999px; background: var(--color-bg); color: var(--color-muted); font-size: 0.75rem; box-shadow: 0 1px 1px rgba(0, 30, 60, 0.06); }
.chat__message { align-self: flex-start; max-width: min(82%, 34rem); padding: 0.375rem 0.625rem 0.25rem; border-radius: 0.875rem; border-bottom-left-radius: 0.25rem; background: var(--color-bg); box-shadow: 0 1px 1px rgba(0, 30, 60, 0.08); font-size: 0.9375rem; }
.chat__message p { margin: 0; }
.chat__author { font-size: 0.75rem; font-weight: 700; color: var(--color-accent); }
.chat__body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; color: var(--color-text); }
.chat__message time { display: block; margin-top: 0.125rem; text-align: right; font-size: 0.6875rem; color: var(--color-muted); }
.chat__messages--member-view .chat__message--member,
.chat__messages--staff-view .chat__message--staff { align-self: flex-end; border-bottom-left-radius: 0.875rem; border-bottom-right-radius: 0.25rem; background: var(--chat-own); }
.chat__messages--member-view .chat__message--member .chat__author { display: none; } /* "Vos" says nothing in your own bubble */
.chat__audio { display: block; width: min(15rem, 62vw); height: 2.5rem; margin: 0.25rem 0 0.125rem; }
.chat__duration { float: left; margin-top: 0.125rem; font-size: 0.6875rem; color: var(--color-muted); }
.chat__body--muted { color: var(--color-muted); font-style: italic; }

/* Composer: a round text box that grows, and one round button beside it (send, or the
   mic while the box is empty). Never covered by the phone's home bar. */
.chat-composer { position: relative; display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.5rem 0.625rem calc(0.5rem + env(safe-area-inset-bottom)); background: var(--color-bg); border-top: 1px solid var(--color-line); }
.chat-form { flex: 1; display: flex; align-items: flex-end; gap: 0.5rem; min-width: 0; margin: 0; }
.chat-form textarea { flex: 1; min-width: 0; min-height: 2.75rem; max-height: 8.5rem; margin: 0; padding: 0.6875rem 1rem; resize: none; border: 1px solid var(--color-line); border-radius: 1.375rem; background: var(--color-surface-strong); color: var(--color-text); font: inherit; font-size: 1rem; line-height: 1.35; overflow-y: auto; }
.chat-form textarea:focus { outline: none; border-color: var(--color-accent); background: var(--color-bg); }
.chat-form .form-errors { position: absolute; left: 0.75rem; right: 0.75rem; bottom: 100%; margin: 0 0 0.5rem; padding: 0.5rem 0.75rem; border-radius: 0.5rem; background: #fdecea; color: #b3261e; list-style: none; font-size: 0.875rem; }

.chat-form__send, .chat-composer__round { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: var(--color-accent); color: #fff; cursor: pointer; }
.chat-form__send svg, .chat-composer__round svg, .voice-recorder__cancel svg { width: 1.25rem; height: 1.25rem; }
.chat-form__send:active, .chat-composer__round:active { transform: scale(0.94); }

/* Send or mic: the mic while the box is empty, send once there's text. */
.chat-composer--voice[data-empty="true"] .chat-form__send { display: none; }
.chat-composer--voice:not([data-empty="true"]) .voice-recorder { display: none; }
.chat-composer--voice:has(.voice-recorder[data-voice-recorder-state="unsupported"]) .chat-form__send { display: inline-flex; }
/* Recording, sending or failed: the recorder takes the whole bar. */
.chat-composer:has(.voice-recorder:is([data-voice-recorder-state="recording"], [data-voice-recorder-state="uploading"], [data-voice-recorder-state="failed"])) .chat-form { display: none; }
.chat-composer:has(.voice-recorder:is([data-voice-recorder-state="recording"], [data-voice-recorder-state="uploading"], [data-voice-recorder-state="failed"])) .voice-recorder { flex: 1; }

/* Voice recorder (voice_recorder_controller.js): each part shows only in its state. */
.voice-recorder { display: flex; align-items: center; justify-content: flex-end; margin: 0; }
.voice-recorder [data-show-when] { display: none; }
.voice-recorder[data-voice-recorder-state="idle"] [data-show-when~="idle"],
.voice-recorder[data-voice-recorder-state="recording"] [data-show-when~="recording"],
.voice-recorder[data-voice-recorder-state="uploading"] [data-show-when~="uploading"],
.voice-recorder[data-voice-recorder-state="failed"] [data-show-when~="failed"] { display: inline-flex; }
.voice-recorder__live { flex: 1; align-items: center; gap: 0.75rem; min-height: 2.75rem; }
.voice-recorder__cancel { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--color-muted); cursor: pointer; }
.voice-recorder__dot { width: 0.625rem; height: 0.625rem; border-radius: 50%; background: #d93025; animation: voice-recorder-pulse 1s ease-in-out infinite; }
.voice-recorder__timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.voice-recorder__hint { flex: 1; color: var(--color-muted); font-size: 0.875rem; }
.voice-recorder__uploading { flex: 1; align-items: center; min-height: 2.75rem; color: var(--color-muted); font-size: 0.875rem; }
.voice-recorder__status { position: absolute; left: 0.75rem; right: 0.75rem; bottom: 100%; margin: 0 0 0.5rem; padding: 0.5rem 0.75rem; border-radius: 0.5rem; background: var(--color-text); color: #fff; font-size: 0.8125rem; }
.voice-recorder__status:empty { display: none; }
@keyframes voice-recorder-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .voice-recorder__dot { animation: none; } }

/* Offline (chat_outbox_controller.js): banner, and messages waiting in the phone's outbox. */
.chat__offline { margin: 0; padding: 0.5rem 1rem; background: #fff4d6; color: #5c4300; font-size: 0.8125rem; }
.chat__offline[hidden] { display: none; }
.chat__message--pending { opacity: 0.7; }
.chat__pending { display: block; text-align: right; font-size: 0.6875rem; color: var(--color-muted); }
.chat__message--failed { box-shadow: 0 0 0 1px #b3261e; }
.chat__message--failed .chat__pending { color: #b3261e; }

@media (min-width: 768px) {
  .chat-screen { max-width: 48rem; height: calc(100dvh - 3.5rem - 3rem); margin: 1.5rem auto; border: 1px solid var(--color-line); border-radius: 1rem; overflow: hidden; }
  .chat-screen__bar { padding: 0.75rem 1.25rem; }
  .chat-screen__scroll { padding: 1rem 1.5rem; }
  .chat-composer { padding: 0.75rem 1rem; }
}

/* Back to the inbox from a staff chat (back_link_controller.js). */
.chat-screen__back { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; margin-left: -0.5rem; border-radius: 50%; color: var(--color-text); }
.chat-screen__back svg { width: 1.375rem; height: 1.375rem; }
.chat-screen__back:hover { background: var(--color-surface-strong); }

/* Staff inbox (admin/conversations/index), phone first: a messaging-app list. The page
   scrolls (not an inner area), so history back restores the place. */
.inbox-screen { min-height: calc(100dvh - 3.5rem); background: var(--color-bg); }
.inbox-screen__bar { position: sticky; top: 3.5rem; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.75rem 1rem; background: var(--color-bg); border-bottom: 1px solid var(--color-line); }
.inbox-screen__title { margin: 0; font-family: var(--font-sans); font-size: 1.25rem; font-style: normal; line-height: 1.3; text-transform: none; }
.inbox-screen__search { flex: 1 1 100%; min-height: 2.5rem; padding: 0.5rem 1rem; border: 1px solid var(--color-line); border-radius: 1.25rem; background: var(--color-surface-strong); font: inherit; font-size: 1rem; }
.inbox-screen__search:focus { outline: none; border-color: var(--color-accent); background: var(--color-bg); }
.inbox { list-style: none; margin: 0; padding: 0; }
.inbox__row[hidden] { display: none; }
.inbox__link { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 0.75rem; row-gap: 0.125rem; align-items: center; min-height: 4.5rem; padding: 0.625rem 1rem; border-bottom: 1px solid var(--color-line); color: inherit; text-decoration: none; }
.inbox__link:hover, .inbox__link:focus-visible { background: var(--color-surface-strong); }
.inbox__avatar { grid-row: 1 / 3; display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%; background: var(--color-text); color: #fff; font-weight: 700; }
.inbox__name { grid-column: 2; grid-row: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox__preview { grid-column: 2; grid-row: 2; min-width: 0; color: var(--color-muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
.inbox__time { grid-column: 3; grid-row: 1; justify-self: end; color: var(--color-muted); font-size: 0.75rem; }
.inbox__unread { grid-column: 3; grid-row: 2; justify-self: end; min-width: 1.375rem; height: 1.375rem; padding: 0 0.375rem; border-radius: 999px; background: var(--color-accent); color: #fff; font-size: 0.75rem; font-weight: 700; line-height: 1.375rem; text-align: center; }
.inbox__row--unread .inbox__time { color: var(--color-accent); font-weight: 700; }
.inbox__row--unread .inbox__preview { color: var(--color-text); }
.inbox__empty { padding: 2rem 1rem; text-align: center; color: var(--color-muted); }
.inbox__empty[hidden] { display: none; }

@media (min-width: 768px) {
  .inbox-screen { max-width: 48rem; min-height: 0; margin: 1.5rem auto; border: 1px solid var(--color-line); border-radius: 1rem; overflow: clip; }
  .inbox-screen__bar { top: 3.5rem; padding: 0.875rem 1.25rem; }
  .inbox-screen__search { flex: 0 1 18rem; margin-left: auto; }
  .inbox__link { padding: 0.75rem 1.25rem; }
}
