@font-face { font-family: "IBM Plex Sans"; src: url("./fonts/IBMPlexSans-Regular.woff2") format("woff2"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("./fonts/IBMPlexSans-Medium.woff2") format("woff2"); font-style: normal; font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("./fonts/IBMPlexSans-SemiBold.woff2") format("woff2"); font-style: normal; font-weight: 600; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("./fonts/IBMPlexMono-Regular.woff2") format("woff2"); font-style: normal; font-weight: 400; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #F1F0EA;
  --surface: #E7E6DF;
  --surface-alt: #DEDDD5;
  --text: #111210;
  --muted: #565750;
  --border: #CAC9C0;
  --control-border: #77786F;
  --signature: #E5482D;
  --accent: #B9341C;
  --accent-hover: #A32D18;
  --accent-text: #FFFFFF;
  --danger: #B9341C;
  --warning-bg: #F1E1DA;
  --success: #347A52;
  --mine: #E4E3DC;
  --theirs: #ECEBE5;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  font-synthesis: none;
  background: var(--bg);
  color: var(--text);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111210;
  --surface: #191A17;
  --surface-alt: #24251F;
  --text: #EDECE5;
  --muted: #96978F;
  --border: #34352F;
  --control-border: #77786F;
  --accent: #FF765C;
  --accent-hover: #FF8E78;
  --accent-text: #111210;
  --danger: #FF8E78;
  --warning-bg: #2D1D18;
  --success: #79B58A;
  --mine: #24251F;
  --theirs: #191A17;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button, a, summary, input, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: var(--text); text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.65rem; font-weight: 600; letter-spacing: -.035em; line-height: 1.2; }
h2 { font-size: 1rem; font-weight: 500; }
h3 { font-size: .9rem; font-weight: 600; }
.muted { color: var(--muted); }
.eyebrow { font-family: var(--mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.button { display: inline-flex; justify-content: center; align-items: center; gap: .4rem; min-height: 40px; padding: .45rem .75rem; border: 1px solid var(--control-border); border-radius: 2px; background: var(--surface); color: var(--text); font-size: .875rem; font-weight: 500; cursor: pointer; }
.button:hover:not(:disabled) { background: var(--surface-alt); }
.button:disabled { cursor: not-allowed; color: var(--muted); }
.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.primary:disabled { background: var(--surface-alt); color: var(--muted); border-color: var(--border); }
.button.subtle { background: transparent; border-color: transparent; }
.button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
#send-button { -webkit-user-select: none; user-select: none; }
.messenger { height: 100vh; height: 100dvh; height: min(100dvh, var(--visual-viewport-height, 100dvh)); display: flex; flex-direction: column; overflow: hidden; }
.client-header { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; gap: .75rem; min-height: 60px; padding: .5rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg); }
.brand-line, .header-controls { display: flex; align-items: center; gap: .85rem; min-width: 0; }
.client-brand { font-family: var(--mono); font-size: 1rem; font-weight: 400; text-decoration: none; white-space: nowrap; }
.client-brand span { color: var(--signature); }
.test-badge { color: var(--muted); font-family: var(--mono); font-size: .7rem; }
.connection-label { display: inline-flex; gap: .4rem; align-items: center; color: var(--muted); font-family: var(--mono); font-size: .75rem; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; background: var(--muted); flex-shrink: 0; }
.status-dot.online { background: var(--success); }
.client-shell { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; overflow-y: auto; }
.client-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; flex: 1; min-height: 0; overflow: hidden; }
.chat-sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.panel-heading, .conversation-heading { display: flex; align-items: center; justify-content: space-between; gap: .65rem; min-height: 72px; padding: .65rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-list { flex: 1; min-height: 0; padding: .5rem; overflow-y: auto; scrollbar-gutter: stable; }
.chat-button { display: flex; flex-direction: column; gap: .2rem; width: 100%; padding: .7rem .75rem; min-height: 64px; border: 1px solid transparent; border-left: 2px solid transparent; border-radius: 2px; text-align: left; font: inherit; color: var(--text); background: transparent; cursor: pointer; overflow-wrap: anywhere; }
.chat-button strong { font-size: .9rem; font-weight: 500; }
.chat-button span { color: var(--muted); font-size: .75rem; }
.chat-button:hover { background: var(--bg); }
.chat-button.active { background: var(--bg); border-color: var(--border); border-left-color: var(--accent); }
.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.conversation-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.conversation-meta { display: flex; flex-wrap: wrap; gap: .3rem .75rem; margin-top: .15rem; color: var(--muted); font-size: .75rem; }
#conversation-details-button { flex-shrink: 0; }
.security-warning { padding: .65rem 1rem; background: var(--warning-bg); color: var(--danger); border-bottom: 1px solid var(--danger); font-size: .85rem; flex-shrink: 0; overflow-wrap: anywhere; }
/* Metadata stays outside the lightweight, content-sized bubbles. */
.message-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-gutter: stable; display: flex; flex-direction: column; padding: 1.25rem max(1.25rem, calc((100% - 860px) / 2)); }
.message-list > * { flex-shrink: 0; }
.empty-state { margin: auto; padding: 1rem; color: var(--muted); text-align: center; font-size: .875rem; }
.message { display: flex; flex-direction: column; align-items: flex-start; align-self: flex-start; width: fit-content; min-width: 0; max-width: min(88%, 38rem); margin-top: .9rem; overflow-wrap: anywhere; }
.message:first-child { margin-top: 0; }
.message.continuation { margin-top: .25rem; }
.message.mine { align-self: flex-end; align-items: flex-end; }
.message-header { display: flex; align-items: baseline; gap: .3rem; max-width: 100%; margin-bottom: .18rem; font-family: var(--sans); line-height: 1.3; }
.message.mine .message-header { justify-content: flex-end; text-align: right; }
.message-sender { min-width: 0; font-size: .675rem; font-weight: 500; }
.message-header time, .message-separator { flex-shrink: 0; color: var(--muted); font-size: .675rem; }
.message-bubble { position: relative; width: fit-content; min-width: 0; max-width: 100%; padding: .45rem .65rem; border-radius: 2px; background: var(--theirs); font-size: .9375rem; line-height: 1.45; }
.message.mine .message-bubble { background: var(--mine); }
.message-content { display: inline; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--sans); }
/* Reserve status space only on the final line, including when it wraps. */
.message.mine .message-content::after { content: ""; display: inline-block; width: calc(28px + .35em); height: 1em; }
.message.system { align-self: center; max-width: min(100%, 42rem); color: var(--muted); }
.message.system .message-bubble { padding: .2rem .5rem; background: transparent; font-size: .75rem; }
.message.system .message-content { font-size: .75rem; }
.message-footer { position: absolute; right: .65rem; bottom: .45rem; display: flex; align-items: center; justify-content: flex-end; }
.message-status { display: inline-flex; align-items: center; justify-content: center; width: 28px; min-height: 22px; padding: 2px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.message-status svg { display: block; width: 20px; height: 15px; flex-shrink: 0; }
.message-status svg[data-icon="check"], .message-status svg[data-icon="double-check"] { width: 14px; height: 10.5px; }
.message-status.status-read { color: var(--signature); }
.message-status.status-failed, .message-status.status-pending { color: var(--danger); }
.message.mine:focus-visible, .message-status:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .65rem; align-items: end; flex-shrink: 0; padding: .75rem max(1rem, calc((100% - 820px) / 2)); padding-bottom: max(.75rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
input:not([type="radio"]), textarea { width: 100%; min-width: 0; border: 1px solid var(--control-border); border-radius: 2px; background: var(--bg); color: var(--text); padding: .65rem .75rem; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[aria-invalid="true"] { border-color: var(--danger); }
textarea { resize: vertical; min-height: 64px; max-height: min(180px, 25dvh); }
textarea:disabled { color: var(--muted); }
.composer .button { min-height: 44px; }
#composer-help { color: var(--muted); font-size: .7rem; }
.pending-sends { grid-column: 1 / -1; border-top: 1px solid var(--danger); padding: .4rem 1rem .65rem; background: var(--surface); overflow-wrap: anywhere; }
.pending-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
#pending-send-list { max-height: 18dvh; overflow-y: auto; margin: .25rem 0 0; padding-left: 1.25rem; font-size: .85rem; }
#pending-send-list li { margin-bottom: .4rem; }
#pending-send-list button { margin-left: .5rem; min-height: 36px; border: 1px solid var(--control-border); border-radius: 2px; color: var(--text); background: var(--bg); padding: .3rem .5rem; cursor: pointer; }
.notifications { flex-shrink: 0; }
.toast { padding: .65rem 1rem; background: var(--surface); color: var(--text); border-top: 1px solid var(--border); font-size: .85rem; overflow-wrap: anywhere; }
.notifications .toast { max-height: 22dvh; overflow-y: auto; }
.toast.error { background: var(--warning-bg); color: var(--danger); border-color: var(--danger); }
.setup-panel { width: min(100%, 440px); margin: auto; padding: 1.5rem; background: var(--bg); }
.setup-panel > .eyebrow { margin-bottom: .65rem; }
.setup-panel > .muted { margin-top: .75rem; font-size: .875rem; }
.activation-form { display: flex; flex-direction: column; margin-top: 1.25rem; gap: .5rem; }
.activation-form > label { margin-top: .4rem; font-size: .85rem; font-weight: 500; }
.activation-form > .button { margin-top: .5rem; }
.activation-form small { color: var(--danger); }
.setup-security { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .8rem; color: var(--muted); }
.setup-security p { margin-top: .4rem; }
.auth-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.auth-main { display: flex; flex: 1; padding: 1.5rem 0; }
.auth-main .setup-panel { border: 1px solid var(--border); }
.auth-main .toast { margin-top: 1rem; }
.invite-panel > p:not(.eyebrow) { margin-top: .75rem; }
.invite-panel > .button { margin-top: 1.25rem; width: 100%; text-decoration: none; }
.invite-panel .small { font-size: .8rem; }
.invite-token { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.invite-token summary { min-height: 40px; cursor: pointer; color: var(--muted); font-size: .85rem; }
.invite-token code { margin-block: .25rem .75rem; }
.client-footer { padding: 1rem; color: var(--muted); font-size: .75rem; text-align: center; }
.context-dialog { width: min(520px, calc(100% - 1.5rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 1px solid var(--control-border); border-radius: 3px; background: var(--bg); color: var(--text); overflow: hidden; }
.context-dialog[open] { display: flex; flex-direction: column; }
.context-dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-shrink: 0; padding: .65rem 1rem; border-bottom: 1px solid var(--border); }
.dialog-content { padding: 1rem; overflow-y: auto; min-height: 0; font-size: .875rem; }
.dialog-content p { margin-bottom: .75rem; }
.dialog-content section + section { margin-top: 1.25rem; }
.dialog-content h3 { margin-bottom: .75rem; }
.context-dialog.message-details { position: fixed; inset: auto; margin: 0; width: min(352px, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem); border-color: var(--border); border-radius: 2px; }
.context-dialog.message-details::backdrop { background: transparent; }
.message-details .dialog-heading { padding: .5rem .75rem; }
.message-details .dialog-heading h2 { font-size: .9375rem; }
.message-details .dialog-content { padding: .75rem; }
.message-details .dialog-content h3 { font-size: .8rem; margin: .75rem 0 .25rem; }
.message-details ul { list-style: none; padding: 0; margin: 0; }
.message-details li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .2rem .75rem; padding: .15rem 0; font-family: var(--sans); font-size: .8125rem; }
.receipt-time { color: var(--muted); font-size: .7rem; }
.message-details summary { cursor: pointer; }
.participant { border-top: 1px solid var(--border); }
.participant:last-child { border-bottom: 1px solid var(--border); }
.participant summary { padding: .8rem .25rem; cursor: pointer; }
.participant-name { font-weight: 500; }
.participant-presence { display: inline-flex; align-items: center; gap: .35rem; margin-left: .6rem; color: var(--muted); font-size: .7rem; }
.participant-presence::before { content: ""; width: .4rem; height: .4rem; border: 1px solid var(--muted); border-radius: 50%; }
.participant-presence.online::before { background: var(--success); border-color: var(--success); }
.participant-presence.offline::before { background: var(--muted); opacity: .5; }
.participant-identity, .key-state { display: block; padding-left: 1.1rem; margin-top: .2rem; color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.participant-identity { font-family: var(--mono); }
.key-state.changed { color: var(--danger); }
.technical-details { margin: .5rem 0 1rem; }
.technical-details dt { font-size: .75rem; color: var(--muted); margin-top: .75rem; }
.technical-details dd { margin: .25rem 0 0; }
.technical-details code, .technical-value { display: block; font-family: var(--mono); font-size: .75rem; overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; }
.technical-details .button { margin-top: .5rem; }
.appearance-controls { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.25rem 0; padding: .5rem 0 1rem; border: 0; border-bottom: 1px solid var(--border); }
.appearance-controls legend { padding: 0; margin-bottom: .5rem; font-size: .875rem; font-weight: 600; }
.appearance-controls label { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; min-height: 40px; border: 1px solid var(--control-border); border-radius: 2px; cursor: pointer; font-size: .875rem; }
.appearance-controls input { margin: 0; accent-color: var(--accent); width: 1rem; height: 1rem; }
.appearance-controls label:has(input:checked) { background: var(--surface); border-color: var(--accent); }
.mobile-back { display: none; }
.mobile-control-icon { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 1rem; top: .5rem; padding: .5rem; background: var(--bg); z-index: 2; transform: translateY(-160%); }
.skip-link:focus { transform: none; }

@media (max-width: 760px) {
  .client-header { flex-wrap: wrap; gap: .25rem .5rem; padding: .5rem .75rem; }
  .brand-line { flex-wrap: wrap; gap: .25rem .5rem; }
  .header-controls { margin-left: auto; gap: .4rem; }
  .messenger .client-header { flex-wrap: nowrap; min-height: 52px; padding: .375rem .65rem; gap: .5rem; }
  .messenger .brand-line { display: grid; flex: 1; gap: .05rem; }
  .messenger .client-brand { font-size: .875rem; white-space: normal; overflow-wrap: anywhere; }
  .messenger .test-badge { font-size: .6875rem; line-height: 1.25; }
  .messenger .header-controls { flex-shrink: 0; margin-left: 0; gap: .5rem; }
  .messenger .connection-label { font-size: .6875rem; }
  .messenger .control-label { display: none; }
  .messenger .mobile-control-icon { display: block; width: 20px; height: 20px; flex-shrink: 0; }
  .messenger #device-settings-button, .messenger #conversation-details-button { width: 40px; min-height: 40px; padding: .5rem; border-color: var(--border); }
  .client-grid { grid-template-columns: minmax(0, 1fr); }
  .chat-sidebar { border-right: 0; }
  .client-grid[data-mobile-view="chats"] .conversation { display: none; }
  .client-grid[data-mobile-view="conversation"] .chat-sidebar { display: none; }
  .mobile-back { display: inline-flex; }
  .messenger .conversation-heading { display: grid; grid-template-columns: auto minmax(0, 1fr) 40px; min-height: 60px; padding: .4rem .65rem; gap: .5rem; }
  .messenger .mobile-back { min-height: 40px; padding: .4rem .5rem; border-color: var(--border); white-space: nowrap; }
  .messenger .conversation-label h2 { font-size: .9375rem; line-height: 1.25; }
  .messenger .conversation-meta { gap: .15rem .5rem; font-size: .6875rem; line-height: 1.25; }
  .message-list { padding: 1rem .75rem; }
  .message { max-width: 92%; }
  .context-dialog.message-details { inset: auto 0 0 !important; width: 100%; max-width: none; max-height: 80dvh; border-radius: 3px 3px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .context-dialog.message-details::backdrop { background: rgb(0 0 0 / .35); }
  .composer { padding-inline: .75rem; }
  .pending-sends { padding-inline: .75rem; }
  .auth-main .setup-panel { border: 0; }
}
@media (max-height: 500px) and (max-width: 760px) {
  .client-header, .messenger .client-header { min-height: 44px; padding-block: .15rem; }
  .messenger .conversation-heading { min-height: 48px; padding-block: .2rem; }
  .composer { padding-block: .4rem; }
  #composer-help { display: none; }
  textarea { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
