/* Media opens in an app-owned full-screen surface, without file-name chrome. */
#dialog:is([data-view="media-viewer"],[data-view="media-save"],[data-view="message-context"],[data-view="forward-picker"]) { inset:0; width:100%; height:100dvh; max-width:none; max-height:none; margin:0; padding:0; border:0; border-radius:0; box-shadow:none; }
#dialog:is([data-view="media-viewer"],[data-view="media-save"],[data-view="message-context"],[data-view="forward-picker"]) > .dialog-header { display:none; }
#dialog:is([data-view="media-viewer"],[data-view="media-save"]) { background:#000; color:#fff; overflow:hidden; color-scheme:dark; }
.media-viewer { display:grid; grid-template-rows:auto minmax(0,1fr) auto; height:100%; min-height:0; }
.media-viewer-header { display:flex; align-items:center; justify-content:space-between; gap:14px; padding:calc(env(safe-area-inset-top) + 8px) 14px 8px; background:#101010; }
.media-viewer-header strong { font-size:16px; font-weight:500; }
.media-viewer-control { display:grid; place-items:center; width:44px; height:44px; flex:none; padding:0; border:0; border-radius:50%; background:#ffffff15; color:#fff; box-shadow:none; }
.media-viewer-control.media-back { display:flex; gap:3px; width:auto; padding:0 12px 0 8px; border-radius:24px; font-size:15px; }
.media-save { grid-template-rows:auto minmax(0,1fr); }
.media-save-content { align-self:center; display:grid; justify-items:center; gap:18px; max-width:420px; margin:auto; padding:24px 24px max(24px,env(safe-area-inset-bottom)); text-align:center; }
.media-save-icon { display:grid; place-items:center; width:96px; height:96px; border-radius:28px; background:#ffffff12; color:#70b6ff; }
.media-save-content h2 { margin:0; font-size:23px; color:inherit; }
.media-save-content p { margin:0; color:#b7b7bf; line-height:1.5; }
.media-save-primary { display:flex; align-items:center; justify-content:center; gap:10px; min-height:50px; width:100%; padding:12px 24px; border-radius:25px; background:#3488f7; color:#fff; font-weight:600; }
.media-viewer-stage { display:flex; align-items:center; justify-content:center; min-width:0; min-height:0; overflow:hidden; padding:8px 0 max(8px,env(safe-area-inset-bottom)); }
.media-viewer-stage img { display:block; width:auto; height:auto; max-width:100%; max-height:100%; object-fit:contain; }
.media-viewer-stage video { display:block; width:100%; height:100%; max-width:100%; max-height:100%; object-fit:contain; }
.media-viewer-caption { max-height:24dvh; overflow:auto; margin:0; padding:12px 20px max(16px,env(safe-area-inset-bottom)); color:#fff; background:#101010; white-space:pre-wrap; overflow-wrap:anywhere; font-size:15px; text-align:center; }
.conversation .message-media { position:relative; max-width:100%; width:min(320px,65vw); overflow:hidden; border-radius:10px; }
.conversation .message-media > :is(img,video) { width:100%; max-width:100%; max-height:340px; object-fit:cover; }
.conversation .message-video > video { min-height:160px; pointer-events:none; }
.message-video-play { position:absolute; top:50%; left:50%; translate:-50% -50%; display:grid; place-items:center; width:48px; height:48px; border-radius:50%; color:white; background:#0009; pointer-events:none; }
#dialog .group-media-tile:has(.message-video-play) { position:relative; }
.shared-media-tile { position:relative; display:block; width:100%; padding:0; overflow:hidden; border:0; border-radius:12px; background:#101010; box-shadow:none; }
.shared-media-tile > :is(img,video) { display:block; width:100%; max-height:300px; object-fit:contain; pointer-events:none; }

/* Long-press lifts the message above a compact action menu. */
#dialog[data-view="message-context"] { background:transparent; color:#fff; overflow:hidden; }
#dialog[data-view="message-context"]::backdrop { background:#0009; -webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px); }
.message-context-dismiss { position:absolute; inset:0; width:100%; height:100%; padding:0; border:0; border-radius:0; background:transparent; box-shadow:none; }
.message-context-layout { position:relative; display:flex; flex-direction:column; align-items:flex-start; gap:10px; width:min(100%,400px); max-height:100%; overflow-y:auto; margin:0 auto; padding:max(16px,env(safe-area-inset-top)) 16px max(20px,env(safe-area-inset-bottom)); pointer-events:none; }
.message-context-layout > * { pointer-events:auto; flex-shrink:0; }
.message-context-layout.is-mine { align-items:flex-end; }
.message-context-reactions { display:flex; align-items:center; justify-content:space-around; gap:2px; width:100%; padding:7px 5px; border:1px solid #ffffff20; border-radius:999px; background:#202020; }
.message-context-reaction { display:grid; place-items:center; min-width:38px; min-height:40px; padding:0; color:#fff; background:transparent; border:0; border-radius:50%; box-shadow:none; font-size:27px; line-height:1; }
.message-context-reaction[aria-pressed="true"] { background:#ffffff25; }
.message-context-preview { max-width:88%; max-height:25dvh; overflow:auto; padding:9px 12px; border-radius:18px 18px 18px 5px; background:#302333; color:white; }
.is-mine .message-context-preview { border-radius:18px 18px 5px 18px; background:#913ff5; }
.message-context-preview p { margin:0; white-space:pre-wrap; overflow-wrap:anywhere; font-size:17px; line-height:1.35; }
.message-context-preview > span:last-child { display:block; margin-top:4px; color:#ffffffa0; font-size:11px; text-align:end; }
.message-context-preview img { display:block; max-width:100%; max-height:140px; border-radius:9px; }
.message-context-file { display:flex; align-items:center; gap:8px; }
.message-context-menu { width:min(240px,88%); padding:7px 0; border:1px solid #ffffff20; border-radius:22px; background:#202020; box-shadow:0 12px 32px #0005; overflow:hidden; }
.message-context-action { display:flex; align-items:center; gap:15px; width:100%; min-height:44px; padding:10px 20px; border:0; border-radius:0; color:#fff; background:transparent; font-size:17px; text-align:start; box-shadow:none; }
.message-context-action > .app-icon { flex:none; }
.message-context-action.danger { color:#ff453a; }
.message-context-action:is(:hover,:focus-visible,:active) { background:#ffffff10; }
.message-context-select { border-top:1px solid #ffffff20; margin-top:7px; padding-top:15px; padding-bottom:13px; }
@media (min-height:700px) { .message-context-layout { position:absolute; bottom:0; right:0; left:0; } }
@media (prefers-reduced-transparency:reduce) { #dialog[data-view="message-context"]::backdrop { -webkit-backdrop-filter:none; backdrop-filter:none; background:#000c; } }

/* Forwarding follows the reference's searchable Chats / Contacts picker. */
#dialog[data-view="forward-picker"] { background:#000; color:#fff; color-scheme:dark; overflow:hidden; }
.forward-panel { display:grid; grid-template-rows:auto auto minmax(0,1fr) auto; height:100%; min-height:0; width:min(100%,620px); margin:auto; }
.forward-header { display:grid; grid-template-columns:80px minmax(0,1fr) 80px; align-items:center; gap:8px; padding:calc(env(safe-area-inset-top) + 15px) 16px 14px; }
.forward-header h2 { margin:0; font-size:18px; font-weight:600; text-align:center; }
.forward-round { min-width:44px; min-height:44px; display:grid; place-items:center; justify-self:end; padding:0 14px; border:1px solid #ffffff18; border-radius:999px; background:#1c1c1e; color:white; box-shadow:none; font-size:16px; }
.forward-round:first-child { justify-self:start; width:44px; padding:0; }
.forward-search { display:flex; align-items:center; justify-content:center; gap:7px; margin:0 16px 10px; min-height:44px; padding:0 16px; border-radius:999px; background:#1c1c1e; color:#8e8e93; }
.forward-search input { min-width:0; width:100%; min-height:44px; padding:0; background:transparent; border:0; border-radius:0; color:#fff; box-shadow:none; font-size:17px; }
.forward-search input::placeholder { color:#8e8e93; }
.forward-list { overflow-y:auto; min-height:0; padding:0 16px; overscroll-behavior:contain; }
.forward-target { position:relative; display:flex; align-items:center; gap:12px; width:100%; min-height:58px; padding:7px 0; color:white; background:transparent; border:0; border-radius:0; box-shadow:none; text-align:start; }
.forward-target + .forward-target::before { position:absolute; top:0; left:52px; right:0; height:1px; background:#ffffff12; content:''; }
.forward-target > .avatar,.forward-saved-face { display:grid; place-items:center; width:40px; height:40px; flex:none; border-radius:50%; font-size:20px; }
.forward-saved-face { color:white; background:#2ba9e7; }
.forward-target-name { min-width:0; font-size:17px; overflow-wrap:anywhere; }
.forward-check { display:grid; place-items:center; width:23px; height:23px; flex:none; color:transparent; border:1px solid #636366; border-radius:50%; }
.forward-check.is-selected { background:#0a84ff; color:white; border-color:transparent; }
.forward-target:active { background:#ffffff10; }
.forward-footer { display:grid; justify-items:center; gap:10px; padding:12px 16px max(18px,env(safe-area-inset-bottom)); background:#000; }
.forward-message-count { color:#8e8e93; font-size:12px; }
.forward-tabs { display:flex; width:min(240px,80%); padding:3px; border-radius:999px; background:#1c1c1e; }
.forward-tabs button { flex:1; min-width:0; min-height:32px; padding:5px 10px; background:transparent; color:#fff; border:0; border-radius:999px; box-shadow:none; font-size:15px; }
.forward-tabs button.active { background:#636366; }
.forward-send { width:100%; min-height:46px; border:0; border-radius:999px; background:#0a84ff; color:white; font-size:17px; }
.forward-empty { color:#8e8e93; padding:24px 16px; text-align:center; }
.message-selection-bar [data-action="forward-selected-messages"] { flex:none; color:var(--accent-text); }
@media (max-width:360px) { .message-selection-bar .message-selection-count { font-size:11px; } .message-selection-bar > .text-button { padding-inline:4px; font-size:12px; } .message-context-reaction { min-width:32px; font-size:24px; } }

/* Compact attachment popover with the same icon language as chat actions. */
.conversation .composer #attachment-menu {
  inset:auto auto calc(100% + 8px) 6px;
  width:min(300px,calc(100% - 12px)); min-width:0; max-height:min(380px,55dvh);
  overflow-y:auto; overscroll-behavior:contain; padding:6px;
  border:1px solid var(--line); border-radius:22px;
  background:var(--surface); color:var(--text); box-shadow:0 12px 32px #0005;
}
#attachment-menu .attachment-action {
  position:relative; display:flex; align-items:center; gap:12px;
  width:100%; min-height:54px; padding:8px 10px;
  border:0; border-radius:14px; background:transparent; color:inherit;
  font-size:16px; line-height:1.3; text-align:start; box-shadow:none;
}
#attachment-menu .attachment-action:is(:hover,:focus-visible,:active) { background:var(--hover); }
#attachment-menu :is(.attachment-action + .attachment-action,.phone-only .attachment-action)::before {
  content:''; position:absolute; inset:0 10px auto 58px; height:1px; background:var(--line);
}
#attachment-menu .attachment-action-icon {
  display:grid; place-items:center; width:34px; height:34px; flex:none;
  border-radius:10px; color:#fff; background:#8761d8;
}
#attachment-menu .attachment-action-icon[data-tone="document"] { background:#3488db; }
#attachment-menu .attachment-action-icon[data-tone="contact"] { background:#30a66c; }
#attachment-menu .attachment-action-icon[data-tone="quick"] { background:#d38924; }
#attachment-menu .attachment-action-icon .app-icon { color:inherit; }
#attachment-menu .attachment-action-label { min-width:0; overflow-wrap:anywhere; }
.conversation[data-selecting-messages] #attachment-menu { display:none; }

/* A native-emoji palette, shared by the composer and full reaction picker. */
#dialog[data-view="emoji-picker"] {
  inset:auto 0 0; width:min(100%,560px); height:min(480px,72dvh); max-height:calc(100dvh - env(safe-area-inset-top) - 12px);
  max-width:none; max-height:calc(var(--phone-app-height,100dvh) - env(safe-area-inset-top) - 12px); padding:0; margin:0 auto; overflow:hidden; border-radius:24px 24px 0 0;
  background:var(--surface); color:var(--text);
}
#dialog[data-view="emoji-picker"] > .dialog-header { display:none; }
#dialog[data-view="emoji-picker"]::backdrop { background:#0007; }
.emoji-panel { height:100%; display:grid; grid-template-rows:auto auto minmax(0,1fr) auto; min-height:0; }
.emoji-panel-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px 4px 20px; gap:12px; }
.emoji-panel-header h2 { margin:0; font-size:17px; font-weight:600; }
.emoji-close { display:grid; place-items:center; width:40px; height:40px; padding:0; border-radius:50%; background:var(--hover); color:inherit; }
.emoji-search { display:flex; align-items:center; gap:8px; margin:4px 14px 8px; padding:0 12px; border-radius:14px; background:var(--hover); color:var(--muted); }
.emoji-search input { width:100%; min-width:0; min-height:40px; padding:0; background:transparent; color:var(--text); font-size:16px; }
.emoji-results { overflow-y:auto; min-height:0; padding:4px 12px 14px; overscroll-behavior:contain; }
.native-emoji-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(44px,1fr)); gap:4px; align-content:start; }
.emoji-choice { display:grid; place-items:center; min-height:46px; min-width:0; padding:4px; border-radius:14px; background:transparent; color:inherit; }
.emoji-symbol,.reaction-emoji { font-family:"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif; line-height:1.15; }
.emoji-choice .emoji-symbol { display:block; font-size:30px; }
.emoji-choice:is(:hover,[aria-pressed="true"]) { background:var(--hover); }
.emoji-categories { display:flex; gap:3px; overflow-x:auto; padding:8px 10px max(10px,env(safe-area-inset-bottom)); background:var(--surface); scrollbar-width:none; }
.emoji-categories button { flex:1 0 48px; display:grid; justify-items:center; gap:4px; min-height:48px; padding:5px 4px; color:var(--muted); background:transparent; border-radius:14px; font-size:10px; }
.emoji-categories button.active { color:var(--accent-text); background:var(--hover); }
.emoji-empty { margin:24px 12px; text-align:center; color:var(--muted); font-size:15px; }
.message-context-reactions { gap:0; padding:5px; }
.message-context-reaction { flex:1; min-width:0; min-height:42px; }
.message-context-reaction .emoji-symbol { font-size:27px; }
.message-context-reaction.reaction-more { flex:0 0 32px; min-height:32px; border-radius:50%; background:#ffffff15; }
.conversation .reaction-emoji { font-size:17px; }
.message-context-reactions,.message-context-menu { transform-origin:bottom center; }
.attachment-menu { transform-origin:bottom left; }
@media (min-width:761px) { #dialog[data-view="emoji-picker"] { inset:0; margin:auto; border-radius:24px; } }
@media (prefers-reduced-motion:no-preference) {
  .reaction-chip .reaction-emoji { display:inline-block; animation:reaction-arrive 220ms cubic-bezier(.16,1,.3,1); }
}
@keyframes reaction-arrive { from { transform:translateY(3px) scale(.7); opacity:.4; } to { transform:none; opacity:1; } }

/* Albums remain one message; each tile opens its own full-size photo. */
.photo-album { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:3px; width:min(340px,72vw); overflow:hidden; border-radius:14px; }
.conversation .photo-album .album-photo { position:relative; width:100%; min-width:0; aspect-ratio:1; padding:0; overflow:hidden; border-radius:0; background:#1b1b1b; }
.conversation .photo-album .album-photo img { display:block; width:100%; height:100%; max-height:none; object-fit:cover; }
.photo-album[data-count="3"] .album-photo:first-child { grid-row:span 2; aspect-ratio:auto; }
.album-overflow { position:absolute; inset:0; display:grid; place-items:center; color:#fff; font-size:28px; background:#0008; }
.album-viewer-navigation { display:flex; justify-content:center; gap:24px; padding:8px 16px; }
.chat-preview { display:flex; align-items:center; gap:4px; }
.chat-preview-text { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-photo-strip { display:inline-flex; align-items:center; flex:none; gap:3px; vertical-align:middle; }
.chat-photo-strip img { display:block; width:24px; height:24px; flex:none; border-radius:5px; object-fit:cover; }
.chat-photo-overflow { display:inline-flex; align-items:center; gap:1px; min-width:20px; color:var(--muted); font-size:11px; }
#dialog[data-view="group-profile"] .group-profile-staff-row { width:100%; background:transparent; color:inherit; text-align:start; }
#dialog[data-view="group-profile"] .group-profile-staff-row:is(:hover,:active) { background:#ffffff0c; border-radius:14px; }
.staff-profile-hero { margin:12px 0; display:grid; gap:14px; justify-items:center; }
.staff-profile-hero .staff-profile-bio { font-size:16px; line-height:1.45; white-space:pre-wrap; overflow-wrap:anywhere; }

/* Local-only photo review and editor. Upload happens only after confirmation. */
#dialog[data-view="photo-review"] { inset:0; width:100%; height:var(--phone-app-height,100dvh); max-width:none; max-height:none; margin:0; padding:0; overflow:hidden; background:#101010; color:#fff; border-radius:0; }
#dialog[data-view="photo-review"] > .dialog-header { display:none; }
.photo-review { height:100%; width:min(100%,780px); margin:auto; display:grid; grid-template-rows:auto minmax(0,1fr) auto auto auto auto auto; gap:8px; padding:max(8px,env(safe-area-inset-top)) 12px max(12px,env(safe-area-inset-bottom)); }
.photo-review header { display:flex; align-items:center; justify-content:space-between; gap:12px; min-height:46px; }
.photo-review h2 { margin:0; font-size:17px; font-weight:600; }
.photo-round { display:grid; place-items:center; width:44px; height:44px; padding:0; border-radius:50%; background:#ffffff14; color:white; }
.photo-review-stage { display:flex; justify-content:center; align-items:center; min-height:0; overflow:hidden; }
.photo-review-stage :is(img,canvas) { display:block; width:auto; height:auto; max-width:100%; max-height:100%; object-fit:contain; }
.photo-review-stage canvas { touch-action:none; cursor:crosshair; }
.photo-review-thumbs { display:flex; justify-content:center; gap:6px; overflow:auto; min-height:54px; padding:4px; }
.photo-review-thumbs button { position:relative; flex:0 0 48px; height:48px; padding:0; border-radius:10px; background:transparent; }
.photo-review-thumbs button.selected img { opacity:.55; }
.photo-review-thumbs .app-icon { position:absolute; top:50%; left:50%; translate:-50% -50%; color:#fff; }
.photo-review-thumbs img { width:100%; height:100%; object-fit:cover; border-radius:7px; }
.photo-review-tools { display:flex; gap:4px; align-items:center; flex-wrap:wrap; justify-content:center; }
.photo-review-tools:empty { display:none; }
.photo-review-tools > button { display:grid; justify-items:center; gap:3px; min-width:48px; min-height:44px; padding:5px; border-radius:12px; background:#ffffff0c; color:#fff; font-size:11px; }
.photo-review-tools > button.active { background:#ffffff25; }
.photo-mark-colors { display:flex; gap:5px; }
.photo-mark-colors button { display:grid; place-items:center; width:34px; height:38px; padding:6px; border-radius:10px; background:transparent; }
.photo-mark-colors button.active { background:#ffffff30; }
.photo-mark-colors span { display:block; width:20px; height:20px; border-radius:50%; }
.photo-color-red { background:#ff453a; }.photo-color-blue { background:#0a84ff; }.photo-color-white { background:#fff; }
.photo-caption { display:grid; gap:4px; font-size:12px; color:#aaa; }
.photo-caption textarea { width:100%; min-height:52px; max-height:90px; padding:10px 12px; border-radius:14px; background:#252525; color:#fff; resize:none; font-size:16px; }
.photo-review footer { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.photo-review footer button { display:flex; align-items:center; justify-content:center; gap:8px; min-height:44px; padding:10px 20px; border-radius:999px; }
.photo-edit-button { background:#ffffff16; color:#fff; }
.photo-review-error { margin:0; color:#ff7c74; font-size:13px; text-align:center; }
.photo-review [aria-busy="true"] { opacity:.7; }
.photo-review[data-photo-editing] .photo-edit-button { visibility:hidden; }
@media(max-height:520px) { .photo-review { gap:3px; } .photo-review-thumbs { display:none; } .photo-review[data-photo-editing] .photo-caption { display:none; } .photo-caption textarea { min-height:36px; height:36px; } }
.photo-crop-hint { flex-basis:100%; margin:2px 0; text-align:center; color:#aaa; font-size:12px; }
