.messages-page { max-width: 1120px; padding-block: var(--page-inset) var(--page-end); font-size: 14px; }
.messages-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.messages-heading h1 { margin: 0; font-size: clamp(28px, 3vw, 36px); font-weight: 650; letter-spacing: -.04em; line-height: 1.15; }
.messages-page button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font: inherit; }
.messages-page button:disabled { opacity: .55; cursor: default; }
.messages-page :is(button,a,input):focus-visible { outline: 2px solid var(--accent, #365e78); outline-offset: 3px; }
.messages-page [role="status"] { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.messages-page [role="status"]:empty { display: none; }
.message-inbox { padding: 0; margin: 0; list-style: none; }
.message-inbox li { border-bottom: 1px solid var(--line); }
.message-inbox a { display: flex; align-items: center; gap: 16px; padding: 22px 12px; border-radius: 8px; text-decoration: none; }
.message-inbox a:hover { background: var(--surface); }
.message-avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface); color: var(--muted); }
.message-initial { font-weight: 600; }
.message-inbox-copy { display: grid; gap: 5px; flex: 1; min-width: 0; }
.message-inbox-copy > strong { font-size: 15px; font-weight: 600; }
.message-inbox-copy > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.message-inbox time { color: var(--muted); font-size: 12px; }
.message-inbox-meta { display: grid; justify-items: end; gap: 7px; flex: none; }
.message-unread-count { display: inline-grid; place-items: center; min-width: 21px; height: 21px; padding-inline: 5px; border-radius: 50px; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 650; }
.message-inbox-unread .message-inbox-copy > strong { font-weight: 700; }
.message-inbox-unread .message-inbox-copy > span { color: var(--ink); }
.message-inbox-end { min-height: 1px; }
.message-inbox-error { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding-block: 16px; }
.message-inbox-error [role="status"] { margin: 0; }

/* Conversation owns the remaining viewport; the inbox keeps normal page flow. */
body:has(.messages-page > .message-thread) { --conversation-width: 1440px; --conversation-gutter: clamp(20px, 2.5vw, 40px); --conversation-inset: 10px; }
body:has(.messages-page > .message-thread) > .site-footer { display: none; }
.messages-page:has(> .message-thread) { display: flex; flex-direction: column; width: min(calc(100% - var(--conversation-gutter) * 2), var(--conversation-width)); max-width: none; height: calc(var(--message-viewport-height, 100dvh) - var(--site-header-height, 76px)); min-height: 0; padding-block: var(--conversation-inset) max(10px, env(safe-area-inset-bottom)); }
.message-thread { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); }
.message-thread-heading { display: flex; align-items: center; flex: none; gap: 28px; min-height: 60px; padding: 9px 76px 9px 24px; border-bottom: 1px solid var(--line); }
.messages-back { display: inline-flex; align-items: center; flex: none; gap: 6px; min-height: 40px; margin: 0; color: var(--muted); font-size: 13px; font-weight: 500; text-decoration: none; }
.messages-back:hover { color: var(--ink); }
.message-person { display: flex; align-items: center; min-width: 0; gap: 12px; color: var(--ink); text-decoration: none; }
.message-person h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; min-width: 0; overflow-wrap: anywhere; font: 600 17px/1.3 var(--sans); letter-spacing: -.025em; }
.message-person .message-avatar { width: 38px; height: 38px; }
.message-history-error { display: flex; flex: none; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 14px; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.message-history-error [role="status"] { margin: 0; }
.message-history-error button { padding: 4px 8px; min-height: 30px; border: 0; background: transparent; font-size: 12px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.message-log { display: flex; flex: 1 1 0; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; scrollbar-width: thin; scrollbar-gutter: stable; list-style: none; margin: 0; padding: 28px clamp(20px, 3.5vw, 54px); background: color-mix(in srgb, var(--paper) 60%, var(--surface)); }
.message-log:focus-visible { outline: 2px solid var(--accent, #365e78); outline-offset: -3px; }
.message-log > li { position: relative; flex: none; align-self: flex-start; width: fit-content; max-width: min(76%, 650px); min-width: 0; padding: 11px 15px 9px; border: 1px solid color-mix(in srgb, var(--line) 64%, transparent); border-radius: 17px 17px 17px 5px; background: var(--paper); }
.message-log > .message-sent { align-self: flex-end; border-color: transparent; border-radius: 17px 17px 5px 17px; background: var(--ink); color: var(--paper); }
.message-log p { margin: 0 0 7px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-log p:empty { display: none; }
.message-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 5px 12px; font-size: 11px; line-height: 1.4; color: var(--muted); }
.message-log .message-sent .message-meta { color: color-mix(in srgb, var(--paper) 75%, var(--ink)); }
.message-log time { color: inherit; font-size: inherit; }
.message-receipt { font-size: inherit; white-space: nowrap; }
.message-log > .message-unread-divider { display: flex; align-items: center; gap: 14px; align-self: stretch; width: auto; max-width: none; padding: 6px 0; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; }
.message-unread-divider::before, .message-unread-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.message-thread > [data-empty] { flex: 1; display: grid; place-items: center; margin: 0; padding: 24px; text-align: center; color: var(--muted); background: color-mix(in srgb, var(--paper) 60%, var(--surface)); font-size: 14px; }
.message-thread:has(> [data-empty]:not([hidden])) > .message-log { flex: 0; padding: 0; }

.message-card-context { display: flex; align-items: center; gap: 12px; min-width: 0; margin-block: 8px; padding-block: 10px; border-block: 1px solid color-mix(in srgb, currentColor 18%, transparent); }
.message-card-context--draft { margin: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.message-context-scan { display: block; width: 40px; flex: none; }
.message-context-scan .card-image-slot { display: block; width: 100%; aspect-ratio: 5 / 7; }
.message-context-scan img { max-width: 100%; }
.message-context-copy { display: grid; gap: 3px; min-width: 0; flex: 1; }
.message-context-copy strong { font-size: 14px; line-height: 1.3; }
.message-context-copy a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
.message-context-copy :is(small, span) { color: inherit; opacity: .75; font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.message-card-context [data-remove-context] { flex: none; align-self: flex-start; padding: 4px; min-width: 28px; min-height: 28px; border: 0; background: transparent; font-size: 22px; line-height: 1; }
.message-photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; width: 440px; max-width: 100%; margin-block: 2px 8px; }
.message-photos button { display: block; min-width: 0; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--paper); cursor: zoom-in; }
.message-photos button:only-child { grid-column: 1 / -1; }
.message-photos img { display: block; width: 100%; aspect-ratio: 4 / 3; max-height: 320px; object-fit: contain; }
.message-photos button:focus-visible, .message-photo-viewer button:focus-visible { outline: 2px solid var(--accent, #365e78); outline-offset: 3px; }

.message-compose { display: flex; flex: none; flex-direction: column; gap: 10px; margin: 0; padding: 7px 24px; border-top: 1px solid var(--line); border-radius: 0 0 16px 16px; background: var(--paper); }
.message-compose [data-message-context]:empty { display: none; }
.message-compose > .message-compose-bar { display: flex; align-items: flex-end; gap: 10px; }
.message-input-shell { display: flex; flex: 1; align-items: flex-end; min-width: 0; gap: 10px; padding: 6px 12px 6px 6px; border: 1px solid var(--line); border-radius: 25px; background: var(--paper); }
.message-input-shell:focus-within { border-color: color-mix(in srgb, var(--ink) 55%, var(--line)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 6%, transparent); }
.message-compose textarea { display: block; flex: 1; min-width: 0; width: 100%; resize: none; min-height: 34px; max-height: min(144px, 20dvh); padding: 6px 0; border: 0; border-radius: 0; background: transparent; color: var(--ink); font: 400 16px/22px var(--sans); scrollbar-width: thin; }
.message-compose textarea::placeholder { color: var(--muted); opacity: 1; }
.message-compose textarea:focus, .message-compose .message-compose-bar textarea:focus-visible { outline: none; }
.messages-page .message-compose .message-compose-bar :is(.message-attach-toggle,.message-send) { display: grid; place-items: center; flex: none; width: 36px; height: 36px; min-height: 36px; padding: 0; border: 0; border-radius: 50%; }
.messages-page .message-compose .message-compose-bar .message-attach-toggle { background: var(--surface); color: var(--muted); }
.messages-page .message-compose .message-compose-bar .message-send { margin-bottom: 7px; background: var(--ink); color: var(--paper); }
.messages-page .message-compose .message-compose-bar .message-send:disabled { background: var(--surface); color: var(--muted); opacity: 1; }
.message-attachment-control { position: relative; flex: none; }
.message-attachment-menu { position: absolute; z-index: 4; left: 0; bottom: calc(100% + 12px); width: 220px; display: grid; gap: 7px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: 0 8px 28px #00000014; }
.message-attachment-menu small { padding-inline: 5px; }
.message-compose small { color: var(--muted); font-size: 12px; }
.message-photo-previews { display: grid; grid-template-columns: repeat(5, minmax(0, 64px)); gap: 8px; padding: 0; margin: 0; list-style: none; }
.message-photo-previews li { position: relative; min-width: 0; }
.message-photo-previews img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 7px; }
.message-photo-previews button { position: absolute; right: 2px; top: 2px; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border-radius: 50%; background: var(--paper); line-height: 1; }
.message-thread > .message-compose-status { flex: none; margin: 0; padding: 0 24px 12px; font-size: 12px; overflow-wrap: anywhere; }
body:has(.messages-page > .message-thread) > .theme-toggle { inset-block-start: calc(var(--site-header-height, 76px) + var(--conversation-inset) + 10px); inset-block-end: auto; inset-inline-end: calc(max(var(--conversation-gutter), (100vw - var(--conversation-width)) / 2) + 20px); inline-size: 40px; block-size: 40px; border-radius: 50%; box-shadow: none; }

body:has(.message-photo-viewer[open]) { overflow: hidden; }
.message-photo-viewer { width: min(1100px, calc(100vw - 48px)); height: min(900px, calc(100dvh - 48px)); max-width: none; max-height: none; margin: auto; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); box-sizing: border-box; }
.message-photo-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; }
.message-photo-viewer::backdrop { background: rgb(0 0 0 / .78); }
.message-photo-viewer header, .message-photo-viewer nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.message-photo-viewer h2 { margin: 0; font-size: 16px; font-weight: 600; }
.message-photo-viewer button { min-height: 44px; cursor: pointer; }
.message-photo-viewer [data-photo-close] { width: 44px; padding: 0; font-size: 26px; line-height: 1; }
.message-photo-stage { display: grid; place-items: center; min-height: 0; min-width: 0; }
.message-photo-stage img, .message-photo-stage [role="status"] { grid-area: 1 / 1; }
.message-photo-stage img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.message-photo-stage [role="status"] { padding: 16px; text-align: center; }

@media (max-width: 700px) {
  body:has(.messages-page > .message-thread) { --conversation-gutter: 0px; --conversation-inset: 0px; }
  .messages-page:has(> .message-thread) { padding-bottom: env(safe-area-inset-bottom); }
  .message-thread { border: 0; border-radius: 0; }
  .message-thread-heading { min-height: 66px; gap: 16px; padding: 10px 64px 10px 16px; }
  .messages-back { font-size: 12px; }
  .message-person { gap: 9px; }
  .message-person h1 { font-size: 16px; }
  .message-person .message-avatar { width: 34px; height: 34px; }
  .message-log { padding: 20px 14px; gap: 12px; }
  .message-log > li { max-width: 88%; padding: 10px 13px 8px; }
  .message-log p { font-size: 15px; }
  .message-compose { gap: 8px; padding: 11px 14px 12px; border-radius: 0; }
  .message-thread > .message-compose-status { padding: 0 14px 10px; }
  .message-photos { width: 310px; }
  .message-photo-previews { grid-template-columns: repeat(5, minmax(0, 54px)); gap: 7px; }
  .message-photo-viewer { width: calc(100vw - 16px); height: calc(100dvh - 16px); padding: 10px; border-radius: 8px; }
  body:has(.messages-page > .message-thread) > .theme-toggle { inset-block-start: calc(var(--site-header-height, 76px) + 13px); inset-inline-end: 14px; }
}
@media (max-width: 420px) {
  .messages-page { width: calc(100% - 28px); }
  .message-inbox a { padding-inline: 0; gap: 10px; }
  .message-inbox-meta { max-width: 76px; }
  .message-inbox time { font-size: 10px; text-align: right; }
  .message-person .message-avatar { display: none; }
  .message-thread-heading { gap: 12px; }
  .message-log > li { max-width: 92%; }
}
@media (max-height: 560px) {
  body:has(.messages-page > .message-thread) { --conversation-inset: 0px; }
  .messages-page:has(> .message-thread) { padding-bottom: env(safe-area-inset-bottom); }
  .message-thread-heading { min-height: 56px; padding-block: 8px; }
  .message-person .message-avatar { width: 32px; height: 32px; }
  .message-compose { gap: 6px; padding-block: 8px; }
  .message-compose textarea { max-height: 68px; }
  .message-photo-previews { grid-template-columns: repeat(5, minmax(0, 40px)); }
  .message-card-context--draft { padding-block: 6px; }
  .message-card-context--draft .message-context-scan { width: 28px; }
  .message-log { padding-block: 14px; }
  body:has(.messages-page > .message-thread) > .theme-toggle { inset-block-start: calc(var(--site-header-height, 76px) + 8px); }
}

@media (pointer: coarse) {
  .messages-page .message-compose .message-compose-bar :is(.message-attach-toggle,.message-send) { width: 42px; height: 42px; min-height: 42px; }
  .message-photo-viewer button { min-width: 44px; min-height: 44px; }
  .message-compose { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
