/* ==========================================================================
   Collections & Favorites — CSS
   ========================================================================== */

/* ── Collections page header ────────────────────────────────────────────── */
.collections-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4, 1rem);
  margin-bottom: var(--sp-6, 1.5rem);
}

.collections-section {
  margin-bottom: var(--sp-8, 2rem);
}

.collections-section__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary, #a1a1aa);
  margin-bottom: var(--sp-4, 1rem);
}

/* ── Collection cards grid ──────────────────────────────────────────────── */
.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-4, 1rem);
}

.collection-card {
  display: block;
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
  background: var(--color-surface, #12121a);
  border: 1px solid var(--color-border, #27272a);
  transition: transform 180ms ease, box-shadow 180ms ease;
  text-decoration: none;
  color: inherit;
  position: relative;
}

.collection-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.collection-card--likes {
  max-width: 320px;
}

.collection-card__cover {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--color-surface-alt, #1a1a24);
  position: relative;
}

.collection-card__cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.collection-card__mosaic {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  width: 100%;
  height: 100%;
}

.collection-card__mosaic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.collection-card__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--color-text-muted, #52525b);
}

.collection-card__info {
  padding: var(--sp-3, 0.75rem) var(--sp-4, 1rem);
}

.collection-card__name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text, #fafafa);
  margin: 0 0 2px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.collection-card__count {
  font-size: 0.78rem;
  color: var(--color-text-secondary, #a1a1aa);
}

.collection-card__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--color-danger, #ef4444);
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, transform 150ms ease;
    flex-shrink: 0;
    margin-inline-start: auto;
  }
  .collection-card__delete:hover {
    background: var(--color-danger, #ef4444);
    color: #fff;
    transform: scale(1.08);
  }

/* ── Collection detail ──────────────────────────────────────────────────── */
.collection-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4, 1rem);
  margin-bottom: var(--sp-6, 1.5rem);
  flex-wrap: wrap;
}

.collection-detail-header__left {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3, 0.75rem);
}

.collection-meta {
  display: flex;
  gap: var(--sp-2, 0.5rem);
  font-size: 0.8rem;
  color: var(--color-text-secondary, #a1a1aa);
  margin-top: var(--sp-1, 0.25rem);
}

.collection-photos-grid {
  columns: 3;
  column-gap: var(--sp-4, 1rem);
}

@media (max-width: 900px) {
  .collection-photos-grid { columns: 2; }
}

@media (max-width: 500px) {
  .collection-photos-grid { columns: 1; }
}

/* Remove button on collection detail cards */
.photo-card__remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease;
  z-index: 2;
}

.photo-card:hover .photo-card__remove {
  opacity: 1;
}

.photo-card__remove:hover {
  background: var(--color-danger, #ef4444);
}

/* ── Photo card action buttons (like & save) ────────────────────────────── */
.photo-card__actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

.photo-card:hover .photo-card__actions,
.photo-card__actions.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* Allow dropdown to overflow the photo-card */
.photo-card.dropdown-open {
  overflow: visible;
  contain: layout style;
  /* Ensure dropdown stacks above sibling cards in CSS columns layout */
  position: relative;
  z-index: 10;
}

.photo-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, transform 150ms ease;
}

.photo-action-btn:hover {
  background: rgba(0, 0, 0, 0.85);
  transform: scale(1.1);
}

/* Like button active state */
.photo-action-btn.is-liked .heart-icon,
.photo-like-btn.is-liked .heart-icon {
  fill: #ef4444;
  stroke: #ef4444;
}

/* Pulse animation on like */
@keyframes heartPulse {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.3); }
  50%  { transform: scale(1); }
  75%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.photo-action-btn.is-liking,
.photo-like-btn.is-liking {
  animation: heartPulse 400ms ease;
}

/* ── Save dropdown ──────────────────────────────────────────────────────── */
.save-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 240px;
  background: var(--color-surface, #12121a);
  border: 1px solid var(--color-border, #27272a);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  /* High z-index so dropdown appears above photo cards (previously 50) */
  z-index: 1000;
  /* overflow: visible so the inline-create form is never clipped */
  overflow: visible;
}

/* In the photo-card context, position below the actions buttons */
.photo-card__actions .save-dropdown {
  top: calc(100% + 4px);
  right: 0;
}

.save-dropdown__header {
  padding: 10px 14px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-secondary, #a1a1aa);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border, #27272a);
}

.save-dropdown__list {
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}

.save-dropdown__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--color-text, #fafafa);
  transition: background 100ms ease;
  border: none;
  background: none;
  width: 100%;
  text-align: start;
}

.save-dropdown__item:hover {
  background: var(--color-surface-hover, #1f1f2e);
}

.save-dropdown__checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary, #8b5cf6);
  flex-shrink: 0;
}

.save-dropdown__footer {
  border-top: 1px solid var(--color-border, #27272a);
  padding: 8px 14px;
}

.save-dropdown__create-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--color-primary, #8b5cf6);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 5px 8px;
  margin-inline-start: -8px;
  font-weight: 500;
  border-radius: var(--radius-sm, 4px);
  transition: background 120ms ease, color 120ms ease;
  width: 100%;
}

.save-dropdown__create-btn:hover {
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-primary-light, #a78bfa);
  text-decoration: none;
}

.save-dropdown__inline-create {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

/* CRITICAL: prevent display:flex/grid from overriding the HTML [hidden] attribute
   inside the dropdown (e.g. .save-dropdown__inline-create[hidden] must be hidden) */
.save-dropdown [hidden] {
  display: none !important;
}

.save-dropdown__name-input {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.25));
  border-radius: var(--radius-sm, 4px);
  background: var(--color-surface-2, rgba(255, 255, 255, 0.12));
  color: var(--color-text, #ffffff);
  font-size: 0.82rem;
  caret-color: var(--color-primary, #8b5cf6);
}
.save-dropdown__name-input::placeholder {
  color: var(--color-text-muted, rgba(255, 255, 255, 0.45));
}
.save-dropdown__name-input:focus {
  outline: none;
  border-color: var(--color-primary, #8b5cf6);
  background: var(--color-surface-hover, rgba(255, 255, 255, 0.16));
}

/* ── Sign-in tooltip ────────────────────────────────────────────────────── */
.signin-tooltip {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--color-surface, #12121a);
  border: 1px solid var(--color-border, #27272a);
  border-radius: var(--radius-md, 8px);
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--color-text, #fafafa);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 50;
}

/* Floating variant — positioned via JS using fixed coords (used in modals) */
.signin-tooltip--floating {
  position: fixed;
  right: auto;
  top: auto;
  z-index: 10001;
}

.signin-tooltip a {
  color: var(--color-primary, #8b5cf6);
  font-weight: 500;
}

/* ── Toast notification ─────────────────────────────────────────────────── */
.collections-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-surface, #12121a);
  border: 1px solid var(--color-border, #27272a);
  color: var(--color-text, #fafafa);
  padding: 10px 20px;
  border-radius: var(--radius-md, 8px);
  font-size: 0.85rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  transition: transform 300ms ease;
  pointer-events: none;
}

.collections-toast.is-visible {
  transform: translateX(-50%) translateY(0);
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
@keyframes modal-slide-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop[aria-hidden="false"] {
  display: flex;
}

.modal-content {
  background: var(--color-surface, #12121a);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: var(--sp-6, 1.5rem);
  width: 100%;
  max-width: 440px;
  margin: 0 var(--sp-4, 1rem);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.modal-backdrop[aria-hidden="false"] .modal-content {
  animation: modal-slide-in 200ms ease forwards;
}

/* ── Modal header ── */
.modal-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3, 0.75rem);
  margin-bottom: var(--sp-5, 1.25rem);
}

.modal-header__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-md, 8px);
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-primary, #8b5cf6);
  border: 1px solid rgba(139, 92, 246, 0.2);
}

.modal-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
  color: var(--color-text, #e4e4e7);
}

.modal-close {
  margin-inline-start: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-text-muted, #a1a1aa);
  cursor: pointer;
  padding: 5px;
  border-radius: var(--radius-sm, 6px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, color 150ms ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--color-text, #e4e4e7);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2, 0.5rem);
  margin-top: var(--sp-5, 1.25rem);
  padding-top: var(--sp-4, 1rem);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ── Limite du plan : la fenêtre qui remplace le message du bandeau ── */
.collection-limit-modal .modal-content {
  text-align: center;
  max-width: 400px;
}

/* La carte reçoit le focus à l'ouverture (clavier, lecteurs d'écran) : elle ne doit
   pas s'entourer d'un liseré pour autant. */
.collection-limit-modal .modal-content:focus {
  outline: none;
}

.collection-limit-modal__icon {
  width: 46px;
  height: 46px;
  margin: 0 auto var(--sp-4, 1rem);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-primary, #8b5cf6);
}

.collection-limit-modal .modal-title {
  font-size: 1.05rem;
  margin-bottom: var(--sp-2, 0.5rem);
}

.collection-limit-modal__message {
  color: var(--color-text-secondary, #a1a1aa);
  font-size: 0.875rem;
  line-height: 1.55;
  margin: 0 0 var(--sp-3, 0.75rem);
}

.collection-limit-modal__limit {
  display: inline-block;
  margin: 0;
  padding: 4px 12px;
  border: 1px solid var(--color-border, #27272a);
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.06);
  color: var(--color-text-secondary, #a1a1aa);
  font-size: 0.78rem;
  font-weight: 600;
}

.collection-limit-modal .modal-actions {
  justify-content: center;
  flex-wrap: wrap;
}

/* search.css impose `min-width: 200px` à tout .modal-actions .btn — taillé pour SA
   fenêtre de quota, qui est bien plus large. Ici deux boutons de 200px plus l'écart
   font 408px pour 350px utiles : ils débordaient de la carte des deux côtés. */
.collection-limit-modal .modal-actions .btn {
  min-width: 0;
  flex: 1 1 auto;
  max-width: 100%;
}

/* ── Create Collection modal — scoped form controls ── */
.ccm-form-group {
  margin-bottom: var(--sp-4, 1rem);
}

.ccm-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text, #e4e4e7);
}

.ccm-optional {
  font-weight: 400;
  color: var(--color-text-muted, #a1a1aa);
}

.ccm-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md, 8px);
  color: var(--color-text, #e4e4e7);
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.ccm-input::placeholder {
  color: var(--color-text-muted, #a1a1aa);
}

.ccm-input:focus {
  border-color: var(--color-primary, #8b5cf6);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.ccm-textarea {
  resize: vertical;
  min-height: 80px;
}

.ccm-submit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ── Light theme overrides ── */
[data-theme="light"] .modal-content {
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .modal-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--color-text, #18181b);
}

[data-theme="light"] .modal-actions {
  border-top-color: rgba(0, 0, 0, 0.07);
}

[data-theme="light"] .ccm-input {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.12);
  color: var(--color-text, #18181b);
}

[data-theme="light"] .modal-header__icon {
  background: rgba(124, 58, 237, 0.08);
  border-color: rgba(124, 58, 237, 0.15);
}

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--sp-12, 3rem) var(--sp-4, 1rem);
  color: var(--color-text-secondary, #a1a1aa);
}

.empty-state svg {
  margin-bottom: var(--sp-3, 0.75rem);
  opacity: 0.5;
}

.empty-state h3 {
  color: var(--color-text, #fafafa);
  margin: 0 0 var(--sp-2, 0.5rem);
}

.empty-state p {
  margin: 0 0 var(--sp-4, 1rem);
  font-size: 0.88rem;
}

/* ── Button variants ────────────────────────────────────────────────────── */
.btn-danger-ghost {
  background: none;
  border: 1px solid var(--color-danger, #ef4444);
  color: var(--color-danger, #ef4444);
}

.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn-danger {
  background: var(--color-danger, #ef4444);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .collections-header {
    flex-direction: column;
  }

  .collections-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .collection-detail-header {
    flex-direction: column;
  }
}
