/* Modern modal styling (matches site) */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 4000;
  padding: 0;
  background: rgba(2, 6, 23, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal.is-open {
  display: block;
}

.modal-content {
  width: 100%;
  height: 100%;
  background: var(--surface, #fff);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  direction: rtl;
  text-align: right;
  display: flex;
  flex-direction: column;
}

.modal.is-open .modal-content {
  animation: modal-pop 160ms ease-out;
}

@keyframes modal-pop {
  from {
    transform: translateY(6px) scale(0.985);
    opacity: 0.01;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal.is-open .modal-content {
    animation: none;
  }
}

.modal-header {
  padding: 12px 16px;
  background: var(--surface-2, #f6f6f6);
  color: var(--text, #111827);
  border-bottom: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  gap: 10px;
}

.modal-header::after {
  content: "";
  grid-column: 3;
  width: 34px;
  height: 34px;
}

.modal-header .close {
  grid-column: 1;
  justify-self: start;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 850;
  grid-column: 2;
  justify-self: center;
  text-align: center;
}

/* Close button scoped only to this modal */
.modal .close {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  background: #ffffff;
  color: #0f172a;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.modal .close:hover {
  background: var(--surface-2, #f6f6f6);
}

.modal .close:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(47, 74, 63, 0.22),
    0 0 0 1px rgba(15, 23, 42, 0.18);
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

#imageModal.is-busy .pool-images-container {
  pointer-events: none;
  opacity: 0.55;
}

#imageModal .modal-busy-status {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  border-radius: 10px;
  padding: 7px 12px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

#imageModal .modal-busy-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-top-color: #fff;
  border-radius: 50%;
  animation: pool-spin 0.7s linear infinite;
}

/* Footer optional; keep style if re-added later */
.modal-footer {
  padding: 12px 16px;
  background: var(--surface-2, #f6f6f6);
  border-top: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  display: flex;
  justify-content: center;
  gap: 10px;
}

#imageModal-confirm {
  min-width: 168px;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid rgba(47, 74, 63, 0.42);
  background: linear-gradient(180deg, #355949 0%, #2f4a3f 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.1px;
  box-shadow: 0 6px 16px rgba(47, 74, 63, 0.24);
  transition:
    transform 0.12s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    opacity 0.18s ease;
}

#imageModal-confirm:hover:not(:disabled) {
  background: linear-gradient(180deg, #3a6250 0%, #345447 100%);
  box-shadow: 0 8px 18px rgba(47, 74, 63, 0.3);
}

#imageModal-confirm:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 4px 10px rgba(47, 74, 63, 0.2);
}

#imageModal-confirm:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(47, 74, 63, 0.25),
    0 0 0 1px rgba(15, 23, 42, 0.18);
}

#imageModal-confirm:disabled {
  background: #d1d5db;
  border-color: #cbd5e1;
  color: #64748b;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 1;
}

.pool-images-container {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.pool-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  background: #f3f4f6;
  overflow: hidden;
}

.pool-img-wrap.is-category-match {
  border-color: rgba(59, 130, 246, 0.75);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.pool-img-wrap .pool-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  cursor: pointer;
  display: block;
  opacity: 1;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    opacity 0.15s ease;
}

.pool-img-wrap.is-loading .pool-img {
  opacity: 0;
}

.pool-img-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.pool-img-wrap.is-loading .pool-img-spinner::after {
  content: "";
  width: 26px;
  height: 26px;
  border: 3px solid #d1d5db;
  border-top-color: #6b7280;
  border-radius: 50%;
  animation: pool-spin 0.7s linear infinite;
}

.pool-img-wrap:not(.is-loading) .pool-img-spinner {
  display: none;
}

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

.pool-img-wrap.selected {
  border-color: rgba(47, 74, 63, 0.85);
  box-shadow: 0 0 0 2px rgba(47, 74, 63, 0.5);
}

.modal .no-content,
.modal .error {
  text-align: center;
  padding: 30px 10px;
  color: #6b7280;
  font-weight: 650;
}

.modal .error {
  color: #b91c1c;
}
