/* Miniaturas de anexos de imagem — composer + bolha da mensagem + lightbox.
 * Carregado depois dos demais estilos para vencer regras genéricas de .exchange img.
 */

.attachment-thumb {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 10px;
  overflow: hidden;
  /* Xadrez neutro: PNGs transparentes e prints escuros ficam visíveis. */
  background-color: #E8EFEC;
  background-image:
    linear-gradient(45deg, #CFDAD5 25%, transparent 25%, transparent 75%, #CFDAD5 75%),
    linear-gradient(45deg, #CFDAD5 25%, transparent 25%, transparent 75%, #CFDAD5 75%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  cursor: zoom-in;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}

.attachment-thumb > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  image-rendering: auto;
}

.attachment-thumb:hover {
  border-color: #22D3EE;
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.16);
}

.attachment-thumb:focus-visible {
  outline: 2px solid #22D3EE;
  outline-offset: 2px;
}

.attachment-thumb:active { transform: scale(0.97); }

/* —— Área de anexos antes de enviar —— */
.file-chip-list {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
}

.file-chip-item {
  flex: 1 1 100%;
  min-width: 0;
  padding: 6px 8px;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.04);
}

.file-chip-item:not(.file-chip-item-image) {
  flex-wrap: nowrap;
}

.file-chip-icon {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.file-chip-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.file-chip-item-image .file-chip-name { font-size: 0.8125rem; }

.file-chip-item-uploading .file-chip-thumb {
  opacity: 0.72;
}

.file-chip-uploading {
  color: #94A3B8;
  font-size: 0.6875rem;
  line-height: 1.3;
}

.file-chip-item-error {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
}

.file-chip-error {
  color: #FCA5A5;
  font-size: 0.6875rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.file-chip-item-image .file-chip-remove {
  align-self: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.1rem;
}

.file-chip-remove:focus-visible {
  outline: 2px solid #22D3EE;
  outline-offset: 1px;
}

/* —— Miniatura dentro da bolha da mensagem enviada —— */
.attachment-preview {
  margin: 8px 0 2px;
  max-width: 100%;
  min-width: 0;
}

.attachment-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-thumb.attachment-preview-thumb {
  width: 190px;
  height: 190px;
  border-radius: 12px;
  border-color: rgba(34, 211, 238, 0.38);
}

.attachment-thumb.attachment-preview-thumb > img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

/* Imagem que o navegador não conseguiu decodificar: fallback explícito. */
.attachment-thumb.is-broken {
  cursor: default;
  border-style: dashed;
}

.attachment-thumb-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 4px;
  text-align: center;
  color: #173B31;
  font-size: 0.5625rem;
  line-height: 1.15;
  overflow: hidden;
}

.attachment-thumb-fallback-icon {
  font-size: 1rem;
  line-height: 1;
}

.attachment-thumb-fallback-text {
  display: block;
  overflow-wrap: anywhere;
}

.attachment-preview-caption {
  margin-top: 5px;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: rgba(244, 244, 245, 0.72);
  font-size: 0.6875rem;
  line-height: 1.3;
}

/* —— Lightbox —— */
.attachment-lightbox {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.attachment-lightbox-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: min(94vw, 1100px);
  max-height: 90vh;
}

.attachment-lightbox-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 14px;
  background: #000000;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
}

.attachment-lightbox-error {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 10px;
  background: rgba(11, 20, 17, 0.94);
  color: #FCA5A5;
  font-size: 0.8125rem;
  text-align: center;
}

.attachment-lightbox-caption {
  margin: 0;
  max-width: min(90vw, 900px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #D7F7EE;
  font-size: 0.8125rem;
  text-align: center;
}

.attachment-lightbox-close {
  position: absolute;
  top: -14px;
  right: -10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 50%;
  background: #0B1411;
  color: #F4F4F5;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.attachment-lightbox-close:hover,
.attachment-lightbox-close:focus-visible {
  background: #123027;
  border-color: #22D3EE;
  outline: none;
}

/* —— Tema claro —— */
html[data-theme="light"] .file-chip-item {
  border-color: rgba(15, 23, 42, 0.14);
  background: rgba(34, 211, 238, 0.06);
}

html[data-theme="light"] .attachment-thumb {
  border-color: rgba(0, 145, 112, 0.35);
  background: #F1F8F5;
}

html[data-theme="light"] .attachment-preview-caption { color: #4A5E56; }

/* —— Celular —— */
@media (max-width: 640px) {
  .file-chip-list { gap: 6px; }

  .file-chip-item { padding: 6px; }

  .attachment-thumb.attachment-preview-thumb {
    width: 124px;
    height: 124px;
  }

  .attachment-thumb-fallback { font-size: 0.5rem; }

  .attachment-lightbox { padding: 16px; }

  .attachment-lightbox-close {
    top: 8px;
    right: 8px;
    background: rgba(11, 20, 17, 0.94);
  }

  .attachment-lightbox-image {
    max-height: 76vh;
    border-radius: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .attachment-thumb { transition: none; }
  .attachment-thumb:active { transform: none; }
}
