.messenger-attachments-dialog {
  width: min(880px, calc(100vw - 40px));
  height: min(840px, calc(var(--attachment-gallery-height, 100dvh) - 48px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--messenger-line, #d9e0e7);
  border-radius: 18px;
  background: var(--messenger-surface, #fff);
  color: var(--messenger-text, #18202a);
  box-shadow: 0 24px 90px rgb(15 23 42 / 22%);
}
.messenger-attachments-dialog[open] { display: flex; flex-direction: column; }
.messenger-attachments-dialog::backdrop { background: rgb(15 23 42 / 46%); }
.messenger-attachments-dialog *, .messenger-attachments-dialog *::before { box-sizing: border-box; }
.messenger-attachments-dialog [hidden] { display: none !important; }
.attachment-gallery-header { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 24px 16px; }
.attachment-gallery-heading { min-width: 0; }
.attachment-gallery-heading h2 { margin: 0; font-size: 20px; line-height: 1.4; }
.attachment-gallery-conversation { margin: 5px 0 0; overflow: hidden; color: var(--messenger-muted, #667282); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.attachment-gallery-close { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border: 1px solid var(--messenger-line, #d9e0e7); border-radius: 9px; background: #fff; color: inherit; font-size: 26px !important; line-height: 1; cursor: pointer; }
.attachment-gallery-filters { display: flex; flex: 0 0 auto; gap: 8px; padding: 0 24px 14px; }
.attachment-gallery-filter { flex: 1; min-height: 42px; border: 1px solid var(--messenger-line, #d9e0e7); border-radius: 10px; background: #f7f9fb; color: #556173; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.attachment-gallery-filter[aria-pressed="true"] { border-color: #2563eb; background: #eff6ff; color: #1d4ed8; }
.attachment-gallery-form { display: flex; flex: 0 0 auto; gap: 8px; padding: 0 24px; }
.attachment-gallery-input { flex: 1 1 0; width: 0; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--messenger-line-strong, #c7d0da); border-radius: 9px; background: #f7f9fb; color: inherit; font: inherit; font-size: 16px !important; }
.attachment-gallery-button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 12px; border: 1px solid var(--messenger-line-strong, #c7d0da); border-radius: 9px; background: #fff; color: var(--messenger-text, #18202a); font: inherit; font-size: 13px; font-weight: 600; line-height: 1.4; text-decoration: none; cursor: pointer; }
.attachment-gallery-button.is-primary, .attachment-gallery-download { border-color: #2563eb; background: #2563eb; color: #fff; }
.attachment-gallery-button:disabled { opacity: .6; cursor: progress; }
.messenger-attachments-dialog :is(button, a, input):focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }
.attachment-gallery-status { flex: 0 0 auto; margin: 0; padding: 13px 24px; color: var(--messenger-muted, #667282); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; border-bottom: 1px solid var(--messenger-line, #d9e0e7); }
.attachment-gallery-status.is-error { color: #b42318; }
.attachment-gallery-region { flex: 1 1 0; min-height: 0; padding: 18px 24px 24px; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; background: var(--messenger-surface-muted, #f7f9fb); -webkit-overflow-scrolling: touch; }
.attachment-gallery-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; gap: 14px; padding: 0; margin: 0; list-style: none; }
.attachment-gallery-item { display: flex; flex-direction: column; min-width: 0; padding: 14px; gap: 12px; border: 1px solid var(--messenger-line, #d9e0e7); border-radius: 12px; background: #fff; overflow: hidden; }
.attachment-gallery-info { min-width: 0; flex: 1 1 auto; }
.attachment-gallery-name { margin: 0 0 6px; color: inherit; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.attachment-gallery-meta { margin: 0; color: var(--messenger-muted, #667282); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.attachment-gallery-time { display: block; margin-top: 2px; color: var(--messenger-muted, #667282); font-size: 11px; line-height: 1.6; }
.attachment-gallery-preview { display: flex; width: 100%; height: 185px; min-height: 185px; align-items: center; justify-content: center; padding: 0; overflow: hidden; border: 0; border-radius: 8px; background: #edf2f7; color: #2563eb; cursor: zoom-in; }
.attachment-gallery-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.attachment-gallery-file-icon { display: flex; width: 52px; height: 58px; align-items: center; justify-content: center; border: 1px solid #c7d8ff; border-radius: 9px; background: #eff6ff; color: #1d4ed8; font-size: 11px; font-weight: 700; }
.attachment-gallery-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.attachment-gallery-actions > * { flex: 1 1 auto; }
.attachment-gallery-list[data-type="files"] { grid-template-columns: minmax(0, 1fr); }
.attachment-gallery-list[data-type="files"] .attachment-gallery-item { flex-direction: row; align-items: center; }
.attachment-gallery-list[data-type="files"] .attachment-gallery-file-icon { flex: 0 0 52px; }
.attachment-gallery-list[data-type="files"] .attachment-gallery-actions { flex: 0 0 auto; margin-top: 0; }
.attachment-gallery-empty { margin: 40px auto; max-width: 320px; text-align: center; color: var(--messenger-muted, #667282); font-size: 14px; line-height: 1.7; }
.attachment-gallery-more { width: 100%; margin-top: 18px; }
.attachment-gallery-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; }
@media (max-width: 600px) {
  .messenger-attachments-dialog { inset: 0; width: 100%; height: var(--attachment-gallery-height, 100dvh); max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .attachment-gallery-header { padding: max(12px, env(safe-area-inset-top)) 16px 12px; gap: 12px; }
  .attachment-gallery-heading h2 { font-size: 18px; }
  .attachment-gallery-filters { padding: 0 16px 12px; }
  .attachment-gallery-form { padding-inline: 16px; }
  .attachment-gallery-status { padding: 11px 16px; }
  .attachment-gallery-region { padding: 12px 12px max(20px, env(safe-area-inset-bottom)); scrollbar-gutter: auto; }
  .attachment-gallery-list { gap: 10px; }
  .attachment-gallery-item { padding: 10px; gap: 9px; }
  .attachment-gallery-preview { height: 130px; min-height: 130px; }
  .attachment-gallery-actions { gap: 6px; }
  .attachment-gallery-actions > * { flex: 1 1 100%; }
  .attachment-gallery-name { font-size: 13px; }
  .attachment-gallery-list[data-type="files"] .attachment-gallery-item { display: grid; grid-template-columns: 42px minmax(0, 1fr); }
  .attachment-gallery-list[data-type="files"] .attachment-gallery-file-icon { width: 42px; height: 48px; }
  .attachment-gallery-list[data-type="files"] .attachment-gallery-actions { grid-column: 1 / -1; }
  .attachment-gallery-list[data-type="files"] .attachment-gallery-actions > * { flex: 1 1 0; }
}
@media (max-width: 350px) {
  .attachment-gallery-list { grid-template-columns: minmax(0, 1fr); }
}
