/* ── ImagePicker modal ── */
.imgpick-modal {
  position: fixed;
  z-index: 1100;
  width: 520px;
  max-height: 440px;
  background: #111422;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: imgpickFadeIn 0.15s ease-out;
  overflow: hidden;
}
@keyframes imgpickFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.imgpick-modal--mobile {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: auto;
  width: 100%;
  max-height: 65vh;
  border-radius: 16px 16px 0 0;
  border-bottom: none;
}

/* Search */
.imgpick-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.imgpick-search-icon { font-size: 14px; opacity: 0.4; }
.imgpick-search {
  flex: 1;
  background: none;
  border: none;
  color: #fff;
  font-size: 14px;
  outline: none;
}
.imgpick-search::placeholder { color: rgba(255, 255, 255, 0.3); }

/* Filters */
.imgpick-filters {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  flex-wrap: wrap;
}
.imgpick-filter-btn {
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.imgpick-filter-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.imgpick-filter-btn.active {
  background: var(--accent-primary, #7C6FF7);
  color: #fff;
  border-color: var(--accent-primary, #7C6FF7);
}

/* Sections */
.imgpick-section { padding: 8px 14px 4px; }
.imgpick-section-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.imgpick-thumb-row {
  display: flex;
  gap: 8px;
}

/* Status */
.imgpick-status {
  padding: 4px 14px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  min-height: 20px;
}

/* Results grid */
.imgpick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  padding: 4px 14px 10px;
  overflow-y: auto;
  flex: 1;
  max-height: 240px;
}

/* Thumbnail card */
.imgpick-thumb {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  background: rgba(255, 255, 255, 0.02);
}
.imgpick-thumb:hover,
.imgpick-thumb.focused {
  border-color: var(--accent-primary, #7C6FF7);
  transform: scale(1.03);
}
.imgpick-thumb-img-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}
.imgpick-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}
.imgpick-thumb-img.loaded { opacity: 1; }

.imgpick-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.02) 75%);
  background-size: 200% 100%;
  animation: galShimmer 1.5s infinite;
}

.imgpick-tag-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 600;
  background: rgba(245, 197, 66, 0.85);
  color: #000;
}
.imgpick-used-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 9px;
  background: rgba(0, 0, 0, 0.6);
  color: rgba(255, 255, 255, 0.7);
}

.imgpick-thumb-label {
  padding: 4px 6px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty state */
.imgpick-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
}
.imgpick-empty-text {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 12px;
}
.imgpick-empty-btn {
  display: block;
  width: 100%;
  padding: 8px;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.imgpick-empty-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

/* Bottom actions */
.imgpick-actions {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.imgpick-action-btn {
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.imgpick-action-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.imgpick-close-btn {
  margin-left: auto;
  font-size: 14px;
}

/* ── ImageRefDropdown (inline [[ autocomplete) ── */
.imgref-dropdown {
  position: fixed;
  z-index: 1100;
  background: #111422;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.imgref-dropdown.visible { display: block; }

.imgref-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.imgref-item:hover,
.imgref-item.active {
  background: rgba(124, 111, 247, 0.12);
}
.imgref-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
}
.imgref-info { flex: 1; overflow: hidden; }
.imgref-name {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.imgref-id {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.3);
}
.imgref-empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.3);
}

/* ── Image ref chips in chat bubbles ── */
.img-ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 2px;
  border-radius: 12px;
  background: rgba(124, 111, 247, 0.12);
  border: 1px solid rgba(124, 111, 247, 0.3);
  font-size: 12px;
  color: var(--accent-primary, #7C6FF7);
  vertical-align: middle;
  cursor: default;
}
.img-ref-chip-thumb {
  width: 20px;
  height: 20px;
  border-radius: 8px;
  object-fit: cover;
}
.img-ref-chip-label { white-space: nowrap; }
.img-ref-chip-remove {
  cursor: pointer;
  opacity: 0.5;
  font-size: 10px;
  margin-left: 2px;
  transition: opacity 0.15s;
}
.img-ref-chip-remove:hover { opacity: 1; }

/* Error chips */
.img-ref-chip--error {
  background: rgba(231, 76, 60, 0.12);
  border-color: rgba(231, 76, 60, 0.3);
  color: #e74c3c;
}
.img-ref-chip--archived {
  background: rgba(245, 197, 66, 0.12);
  border-color: rgba(245, 197, 66, 0.3);
  color: #f5c542;
}

/* Loading shimmer chip */
.img-ref-chip--loading {
  background: linear-gradient(90deg, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.02) 75%);
  background-size: 200% 100%;
  animation: galShimmer 1.5s infinite;
  min-width: 80px;
  height: 24px;
  border-radius: 12px;
  display: inline-block;
}

/* Inline rendered image in chat */
.img-ref-inline {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* Image button in compose toolbar */
.action-btn-image svg { fill: none; stroke: currentColor; stroke-width: 2; }

/* ── Interactive chip link ── */
.img-ref-chip--link {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.img-ref-chip--link:hover {
  background: rgba(167, 139, 250, 0.18);
  border-color: rgba(167, 139, 250, 0.5);
}

/* ── Hover preview tooltip ── */
.img-ref-preview {
  position: fixed;
  z-index: 700;
  background: #1a1d2e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 6px;
  max-width: 260px;
  pointer-events: none;
  animation: imgPreviewIn 0.15s ease-out;
}
@keyframes imgPreviewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.img-ref-preview-img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.img-ref-preview-meta {
  padding: 6px 4px 2px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Image lightbox overlay ── */
.img-lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: imgLbIn 0.2s ease-out;
}
@keyframes imgLbIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.img-lightbox-box {
  position: relative;
  max-width: 80vw;
  max-height: 85vh;
  background: #1a1d2e;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}
.img-lightbox-img {
  display: block;
  max-width: 80vw;
  max-height: 70vh;
  object-fit: contain;
}
.img-lightbox-info {
  padding: 12px 16px;
}
.img-lightbox-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.img-lightbox-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 4px;
}
.img-lightbox-id {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  color: rgba(167, 139, 250, 0.7);
  background: rgba(167, 139, 250, 0.1);
  padding: 2px 8px;
  border-radius: 8px;
}
.img-lightbox-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-lightbox-close:hover { background: rgba(0, 0, 0, 0.7); }

@media (max-width: 768px) {
  .imgpick-modal {
    width: 100%;
    max-height: 65vh;
  }
  .imgref-dropdown {
    width: calc(100% - 32px) !important;
    left: 16px !important;
  }
}
