/* Shared attachment UI for DM, request chat and community live chat. */

.chat-media-composer {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.chat-media-composer-row,
.chat-media-action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-media-composer-row > .input {
  flex: 1 1 180px;
  min-width: 0;
}

.chat-media-attach {
  display: inline-flex;
  min-height: 42px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 12px;
  border: 1px solid rgba(37, 99, 235, 0.24);
  border-radius: 11px;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  touch-action: manipulation;
}

.chat-media-attach:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.42);
  background: #dbeafe;
}

.chat-media-attach:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.24);
  outline-offset: 2px;
}

.chat-media-attach:disabled {
  cursor: wait;
  opacity: 0.58;
}

.chat-media-help {
  color: #667085;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.dm-send .chat-media-attach {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 13px;
}

#dmMediaPreview {
  flex: 0 1 auto;
  align-content: start;
  min-height: 0;
  max-height: 260px;
  margin: 0;
  padding: 10px 14px 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.dm-media-slot,
.post-chat-media-slot,
.cp-live-chat-media {
  min-width: 0;
}

.chat-media-grid,
.chat-media-picker-preview,
.chat-media-item,
.chat-media-picker-item {
  --chat-media-ink: #0f1f3a;
  --chat-media-muted: #667085;
  --chat-media-line: rgba(15, 31, 58, 0.14);
  --chat-media-surface: #ffffff;
  --chat-media-soft: #f5f8fc;
  --chat-media-accent: #2563eb;
  --chat-media-danger: #b42318;
}

.chat-media-grid,
.chat-media-picker-preview {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  min-width: 0;
  margin: 8px 0;
}

.chat-media-grid *,
.chat-media-picker-preview *,
.chat-media-grid *::before,
.chat-media-grid *::after,
.chat-media-picker-preview *::before,
.chat-media-picker-preview *::after {
  box-sizing: border-box;
}

.chat-media-item {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--chat-media-line);
  border-radius: 14px;
  background: var(--chat-media-surface);
  color: var(--chat-media-ink);
  box-shadow: 0 3px 12px rgba(15, 31, 58, 0.06);
}

.chat-media-frame,
.chat-media-picker-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 150px;
  overflow: hidden;
  background: #e9eef6;
}

.chat-media-frame[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(37, 99, 235, 0.18);
  border-top-color: var(--chat-media-accent);
  border-radius: 999px;
  animation: chat-media-spin 0.8s linear infinite;
}

.chat-media-preview,
.chat-media-picker-media {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: contain;
  background: #111827;
}

img.chat-media-preview,
img.chat-media-picker-media {
  object-fit: cover;
  background: #eef2f7;
}

.chat-media-fallback {
  display: flex;
  min-height: 150px;
  width: 100%;
  padding: 18px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--chat-media-muted);
  text-align: center;
}

.chat-media-fallback[hidden] {
  display: none !important;
}

.chat-media-fallback-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--chat-media-accent);
  font-size: 20px;
  font-weight: 900;
}

.chat-media-fallback-text {
  font-size: 13px;
  font-weight: 700;
}

.chat-media-caption {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 9px 11px 4px;
}

.chat-media-name,
.chat-media-picker-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--chat-media-ink);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-media-meta,
.chat-media-picker-meta {
  color: var(--chat-media-muted);
  font-size: 11px;
  font-weight: 600;
}

.chat-media-actions {
  display: flex;
  gap: 7px;
  padding: 7px 10px 10px;
  flex-wrap: wrap;
}

.chat-media-action,
.chat-media-picker-remove {
  min-height: 34px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 9px;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 8px 11px;
  touch-action: manipulation;
}

.chat-media-action:hover:not(:disabled),
.chat-media-picker-remove:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.4);
  background: #dbeafe;
}

.chat-media-action:focus-visible,
.chat-media-picker-remove:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.24);
  outline-offset: 2px;
}

.chat-media-action:disabled,
.chat-media-picker-remove:disabled {
  cursor: wait;
  opacity: 0.58;
}

.chat-media-item-status {
  display: block;
  min-height: 0;
  padding: 0 11px 8px;
  color: var(--chat-media-muted);
  font-size: 11px;
}

.chat-media-item-status:empty {
  display: none;
}

.chat-media-status-error {
  color: var(--chat-media-danger) !important;
}

.chat-media-picker-preview {
  grid-template-columns: 1fr;
}

.chat-media-picker-preview[hidden] {
  display: none !important;
}

.chat-media-picker-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--chat-media-line);
  border-radius: 12px;
  background: var(--chat-media-surface);
}

.chat-media-picker-frame {
  width: 88px;
  min-height: 68px;
  height: 68px;
  border-radius: 9px;
}

.chat-media-picker-frame .chat-media-fallback {
  min-height: 68px;
  padding: 6px;
}

.chat-media-picker-frame .chat-media-fallback-icon {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

.chat-media-picker-frame .chat-media-fallback-text {
  font-size: 10px;
}

.chat-media-picker-info {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.chat-media-picker-remove {
  border-color: rgba(180, 35, 24, 0.2);
  background: #fff5f4;
  color: var(--chat-media-danger);
}

.chat-media-picker-remove:hover:not(:disabled) {
  border-color: rgba(180, 35, 24, 0.35);
  background: #fee4e2;
}

@keyframes chat-media-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .chat-media-composer-row {
    flex-wrap: wrap;
  }

  .chat-media-composer-row > .input {
    flex-basis: calc(100% - 96px);
  }

  .chat-media-attach-label {
    display: none;
  }

  .chat-media-grid {
    grid-template-columns: 1fr;
  }

  .chat-media-frame {
    min-height: 180px;
  }

  .chat-media-picker-item {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .chat-media-picker-frame {
    width: 72px;
    height: 62px;
    min-height: 62px;
  }

  .chat-media-picker-remove {
    grid-column: 2;
    justify-self: start;
    min-height: 44px;
  }

  #dmMediaPreview {
    max-height: min(24dvh, 180px);
    padding: 8px 10px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-media-frame[aria-busy="true"]::after {
    animation-duration: 1.8s;
  }
}
