/* =========================================================
   Gallery / stuffs page – search, grid, modal, upload form
   ========================================================= */

.gallery {
  padding: var(--space-xl);
}

.gallery__search-bar {
  padding: 0 0 var(--space-xl) 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.gallery__search-form {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  max-width: 560px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.gallery__search-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.gallery__search-submit {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: opacity var(--ease);
}

.gallery__search-submit:hover {
  opacity: 0.8;
}

.gallery__search-submit svg {
  width: 1.25rem;
  height: 1.25rem;
}

.gallery__search-input {
  flex: 1;
  min-width: 0;
  padding: 0 var(--space-md);
  height: 3rem;
  border: none;
  background: transparent;
  font: inherit;
  color: var(--fg);
  outline: none;
}

.gallery__search-input::placeholder {
  color: var(--fg);
  opacity: 0.6;
}

.gallery__search-input:focus {
  outline: none;
}

.gallery__search-input::-webkit-search-cancel-button,
.gallery__search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.gallery__search-clear {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-right: 0.25rem;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--fg);
  opacity: 0.5;
  text-decoration: none;
  background: transparent;
  transition: opacity var(--ease), background-color var(--ease);
}

.gallery__search-clear:hover {
  opacity: 1;
  background: rgba(0,0,0,0.05);
}

.gallery__search-clear:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .gallery__search-form {
    max-width: none;
  }
  .gallery__search-input {
    height: 2.75rem;
  }
  .gallery__search-submit {
    width: 2.75rem;
    height: 2.75rem;
  }
  .gallery__search-clear {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 1.125rem;
  }
}

.gallery__header {
  margin-bottom: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.gallery__title {
  font-size: var(--text-lg);
  padding-right: var(--space-xl);
}

.gallery__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--gallery-min-col), 1fr));
  gap: var(--space-md);
}

.gallery__item,
.gallery__item--ad {
  position: relative;
  aspect-ratio: 4/5;
  min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
}

.gallery__item { cursor: pointer; }
.gallery__item--ad { cursor: default; }

@media (max-width: 768px) {
  .gallery__item--ad {
    cursor: pointer;
  }
}

.gallery__item-image,
.gallery__item-image--ad {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.gallery__item-image img,
.gallery__item-image--ad img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery__item-body,
.gallery__item-body--ad {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  opacity: 0;
  line-height: 1.45;
  transition: opacity var(--ease);
  pointer-events: none;
}

.gallery__item-content {
  width: 100%;
  height: 100%;
  display: flex;
  padding: var(--space);
  box-sizing: border-box;
  overflow-y: hidden;
  background: color-mix(in srgb, var(--bg-overlay) 75%, transparent);
  color: var(--fg);
  flex-direction: column;
  justify-content: space-between;
  font-size: var(--text);
}

.gallery__item-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: var(--space-md);
  word-break: break-all;
  font-size: var(--text-lg);
  line-height: 1.25;
  padding-bottom: 0.5rem;
}

.gallery__item-meta {
  display: flex;
  gap: 0.25rem;
  font-size: var(--text-sm);
  flex-direction: column;
  flex-wrap: wrap;
  align-items: flex-start;
}

.gallery__item-meta div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
}

.gallery__item-meta div:nth-child(2) {
  flex-direction: row;
  flex-wrap: wrap;
}

.gallery__item-meta .gallery__item-tag {
  padding: 0.25rem var(--space);
  font-size: var(--text-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.gallery__item-meta .gallery__item-price {
  white-space: nowrap;
}

.gallery__upload-fab {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space);
}

.gallery__upload-fab-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--fg-inverse);
  cursor: pointer;
  transition: transform var(--ease);
  border: none;
  font-size: var(--text);
  font-weight: 600;
}

.gallery__upload-fab-label:hover {
  transform: scale(1.05);
}

.gallery__upload-fab-label--ad {
  background: #71449f;
  color: var(--fg-inverse);
  font-size: var(--text-sm);
}

.gallery__upload-fab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery__upload-fab-btn svg {
  width: 28px;
  height: 28px;
}

@media (max-width: 768px) {
  .gallery__upload-fab {
    bottom: var(--space-md);
    right: var(--space-md);
  }
  .gallery__upload-fab-label {
    width: 48px;
    height: 48px;
  }
  .gallery__upload-fab-label--ad {
    width: 44px;
    height: 44px;
    font-size: 0.7rem;
  }
  .gallery__upload-fab-btn svg {
    width: 24px;
    height: 24px;
  }
}

.gallery__item-body--ad .gallery__item-content--ad {
  overflow-y: hidden;
  background: #71449fbf;
  color: var(--fg-inverse);
  font-size: var(--text);
}

@media (max-width: 768px) {
  .gallery__item-content {
    overflow-y: scroll;
    touch-action: pan-y;
  }
}

/* Modal */
.modal {
  display: none;
}

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

.modal__backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-xl);
  box-sizing: border-box;
  background: color-mix(in srgb, var(--bg-overlay) 92%, transparent);
  cursor: pointer;
}

.modal__content {
  position: relative;
  display: flex;
  width: 100%;
  max-width: min(1200px, 100%);
  min-width: 0;
  height: 100%;
  max-height: calc(100vh - var(--space-xl) * 2);
  margin: 0;
  padding: var(--space-xl);
  box-sizing: border-box;
  gap: var(--space-xl);
  align-items: stretch;
  overflow: hidden;
}

.modal__content--two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
}

.modal__left {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.modal__seller-info {
  flex-shrink: 0;
}

.modal__seller-info-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.modal__seller-row {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: baseline;
}

.modal__seller-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
  flex-shrink: 0;
}

.modal__seller-info-inner a {
  color: var(--fg);
  word-break: break-all;
  font-size: var(--text-lg);
}

.modal__seller-info-inner a:hover,
.modal__seller-info-inner a:focus-visible {
  text-decoration: underline;
}

.modal__seller-chip {
  display: inline-block;
  padding: 0.25rem var(--space);
  font-size: var(--text-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.modal__seller-info-sep {
  color: #666;
}

.modal__right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  gap: var(--space-md);
}

.modal__comments-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal__image-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.modal__text-wrap {
  flex-shrink: 1;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  font-size: var(--text);
  overflow-y: auto;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.modal__chat-form-wrap {
  flex-shrink: 0;
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.12));
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space);
}

.modal__chat-link {
  font-size: var(--text-sm);
  color: var(--fg);
  text-decoration: underline;
}

.modal__chat-link:hover {
  opacity: 0.85;
}

.modal__chat-form {
  display: flex;
  flex-direction: column;
  gap: var(--space);
  width: 100%;
}

.modal__chat-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg);
  display: block;
}

.modal__chat-input {
  width: 100%;
  padding: var(--space-md) var(--space);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.2));
  border-radius: var(--radius, 0.5rem);
  font: inherit;
  font-size: var(--text);
  color: var(--fg);
  background: var(--surface, #fff);
  box-sizing: border-box;
}

.modal__chat-input::placeholder {
  color: var(--fg);
  opacity: 0.5;
}

.modal__chat-input:focus {
  outline: none;
  border-color: var(--fg);
}

.modal__chat-submit {
  align-self: flex-end;
  padding: var(--space) var(--space-lg);
  border: none;
  border-radius: var(--radius, 0.5rem);
  background: var(--fg);
  color: var(--fg-inverse);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  transition: opacity var(--ease);
}

.modal__chat-submit:hover {
  opacity: 0.9;
}

.modal__chat-submit:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.modal__close {
  position: fixed;
  top: 0;
  left: 0;
  padding: var(--space-xl);
  z-index: 101;
  width: var(--touch);
  height: var(--touch);
  background: none;
  border: none;
  cursor: pointer;
  box-sizing: content-box;
}

.modal__close svg {
  pointer-events: none;
}

/* Upload form */
.upload-form {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  box-sizing: border-box;
  overflow: auto;
  background: var(--bg-overlay-mix);
  backdrop-filter: blur(6px);
}

.upload-form[aria-hidden="false"] {
  display: flex;
}

#js-mypage-product-modal.upload-form {
  cursor: pointer;
}

#js-mypage-product-modal .upload-form__step-btn--submit {
  display: inline-block;
}

.upload-form__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: min(1200px, 100%);
  min-width: 0;
  height: 100%;
  max-height: calc(100vh - var(--space-xl) * 2);
  padding: var(--space-xl);
  box-sizing: border-box;
  overflow: hidden;
  margin: auto;
}

.upload-form__form {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.upload-form__field {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.upload-form__field--two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
  gap: var(--space-xl);
}

.upload-form__left {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.upload-form__image-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-form__preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.upload-form__right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  gap: var(--space-md);
}

.upload-form__input-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-items: center;
}

.upload-form__file-area {
  display: none;
}

.upload-form__fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  width: 100%;
  padding: var(--space-md);
  font-size: var(--text-sm);
  box-sizing: border-box;
}

.upload-form__textarea {
  color: var(--fg);
  width: 100%;
  min-height: 2.5rem;
  font-size: var(--text);
  padding: var(--space) var(--space-md);
  border: 1px solid var(--border);
  transition: border-color var(--ease);
  white-space: nowrap;
  box-sizing: border-box;
}

.upload-form__hint {
  margin: 0.25rem 0 0;
  font-size: var(--text-sm);
  color: var(--fg);
  opacity: 0.85;
  line-height: 1.35;
}

.upload-form__hint a {
  color: inherit;
  text-decoration: underline;
}

.upload-form__field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space);
}

.upload-form__label {
  font-size: var(--text-sm);
  font-weight: 600;
  display: block;
  color: var(--fg);
}

.upload-form__category-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space);
}

.category-btn,
.filter-button {
  padding: var(--space) var(--space-md);
  border: none;
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--fg-inverse);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--ease);
}


.category-btn:hover,
.filter-button:hover {
  opacity: 0.9;
}

.category-btn.active,
.filter-button.active {
  opacity: 1;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--fg);
}

.upload-form__input {
  width: 100%;
  font-size: var(--text);
  padding: var(--space) var(--space-md);
  border: 1px solid var(--border);
}

.upload-form__helper-wrap {
  display: none;
  position: absolute;
  z-index: 10;
  inset: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-md);
  box-sizing: border-box;
  background: color-mix(in srgb, var(--fg) 90%, transparent);
  color: var(--fg-inverse);
}

.upload-form__helper-text {
  padding: 0;
  font-size: var(--text);
}

.upload-form__step-wrap {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  padding-top: var(--space-md);
}

.upload-form__step-btn {
  padding: var(--space) var(--space-lg);
  border: none;
  border-radius: var(--radius);
  font-size: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background, color var(--ease);
}

.upload-form__step-btn:hover {
  background: var(--fg);
  color: var(--fg-inverse);
}

.upload-form__step-btn--prev,
.upload-form__step-btn--submit {
  display: none;
}

@media (max-width: 768px) {
  .upload-form {
    padding: var(--space);
    align-items: center;
    justify-content: center;
  }

  .upload-form__panel {
    width: 100%;
    max-width: none;
    max-height: calc(100vh - var(--space) * 2);
    margin: auto;
  }

  .upload-form__field--two-column {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .upload-form__left {
    min-height: 0;
  }

  .upload-form__image-wrap {
    min-height: 160px;
  }

  .upload-form__right {
    min-height: 0;
  }

  .upload-form__fields {
    padding: var(--space);
  }

  .upload-form__step-wrap {
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space);
  }

  .upload-form__step-btn {
    padding: var(--space) var(--space-md);
  }
}

.gallery__search-results {
  margin-bottom: var(--space-md);
}

.gallery__search-results-text {
  font-size: var(--text);
  color: var(--fg);
}

.gallery__filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space);
}

/* Comment styles (legacy) */
.gallery__item-comments {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--fg-inverse);
  border-top: 1px solid var(--border);
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--ease);
}

.gallery__item-comments[aria-expanded="true"] {
  max-height: 400px;
  overflow-y: auto;
}

.gallery__item-comments-toggle {
  width: 100%;
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  text-align: left;
  transition: opacity var(--ease);
}

.gallery__item-comments-toggle:hover {
  background: var(--accent);
}

.gallery__item-comments-content {
  padding: var(--space-md);
  display: none;
}

.gallery__item-comments[aria-expanded="true"] .gallery__item-comments-content {
  display: block;
}

.gallery__comments-list {
  margin-bottom: var(--space-md);
}

.gallery__comment {
  margin-bottom: var(--space);
}

.gallery__comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
}

.gallery__comment-author {
  font-weight: bold;
  color: var(--fg);
}

.gallery__comment-date {
  font-size: var(--text-sm);
  color: var(--fg);
}

.gallery__comment-content {
  font-size: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}

.gallery__comments-empty {
  padding: var(--space-md);
  text-align: center;
  color: var(--fg);
  font-size: var(--text-sm);
}

.gallery__comment-form {
  margin-top: var(--space-md);
}

.gallery__comment-form-fields {
  display: flex;
  gap: var(--space);
  margin-bottom: var(--space);
}

.gallery__comment-input,
.gallery__comment-textarea {
  width: 100%;
  padding: var(--space);
  border: 1px solid var(--border);
  background: var(--fg-inverse);
  font-size: var(--text);
  font-family: inherit;
  border-radius: var(--radius);
}

.gallery__comment-input:focus,
.gallery__comment-textarea:focus {
  outline: none;
  border-color: var(--fg);
}

.gallery__comment-textarea {
  resize: vertical;
  min-height: 60px;
}

.gallery__comment-submit {
  padding: var(--space) var(--space-md);
  background: var(--fg);
  color: var(--fg-inverse);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text);
  transition: opacity var(--ease);
}

.gallery__comment-submit:hover {
  opacity: 0.9;
}

.modal__comments-header {
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space);
}

.modal__comments-title {
  font-size: var(--text-lg);
  margin: 0;
  color: var(--fg);
}

.modal__comments-list-wrapper {
  flex: 1;
  overflow-y: auto;
  margin-bottom: var(--space-md);
  min-height: 0;
}

.gallery__comments-list--modal {
  max-height: none;
}

.gallery__comment--modal {
  margin-bottom: var(--space-md);
}

.gallery__comment-form--modal {
  margin-top: auto;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.gallery__comment-form--modal .gallery__comment-form-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space);
}

.gallery__comment-form--modal .gallery__comment-textarea {
  margin-bottom: var(--space);
}

@media (max-width: 768px) {
  .modal__close {
    padding: var(--space-lg);
  }

  .modal__backdrop {
    padding: var(--space);
    align-items: center;
    justify-content: center;
  }

  .modal__content {
    max-height: calc(100vh - var(--space) * 2);
    padding: var(--space);
    padding-top: 5rem;
  }

  .modal__content--two-column {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .modal__left {
    min-height: 0;
  }

  .modal__right {
    min-height: 0;
  }
}

.gallery__item-chat {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space);
  background: var(--fg-inverse);
  border-top: 1px solid var(--border);
}

.gallery__item-chat-form {
  margin: 0;
}

.gallery__item-chat-btn {
  display: block;
  width: 100%;
  padding: var(--space) var(--space-md);
  background: var(--fg);
  color: var(--fg-inverse);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--ease);
}

.gallery__item-chat-btn:hover {
  opacity: 0.9;
}
