/**
 * Search Modal Component
 * Based on Figma nodes: 1739:103558, 1738:103356, 1739:103945, 1739:103761
 */

/* ===========================================
 * MODAL CONTAINER
 * =========================================== */

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(48, 48, 48, 0.65);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.search-modal.is-open {
  opacity: 1;
  visibility: visible;
}

/* Backdrop (clickable overlay) */
.search-modal__backdrop {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

/* ===========================================
 * DIALOG BOX
 * =========================================== */

.search-modal__dialog {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 592px;
  margin: 16px;
  padding: 48px 32px;
  background-color: var(--color-surface, #ffffff);
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
}

.search-modal.is-open .search-modal__dialog {
  transform: translateY(0);
}

/* Close button */
.search-modal__close {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.search-modal__close:hover {
  opacity: 0.7;
}

.search-modal__close svg {
  display: block;
  width: 32px;
  height: 32px;
}

/* ===========================================
 * TITLE
 * =========================================== */

.search-modal__title {
  margin: 0 0 16px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 22px;
  font-weight: 500;
  line-height: 32px;
  color: var(--color-text, #000000);
  text-align: center;
}

/* ===========================================
 * SEARCH FORM
 * =========================================== */

.search-modal__form {
  display: flex;
  gap: 16px;
  align-items: center;
}

/* Input wrapper */
.search-modal__input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-modal__input {
  width: 100%;
  height: 48px;
  padding: 12px 40px 12px 8px;
  background-color: var(--color-background, #F6F6F6);
  border: none;
  border-radius: 8px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 20px;
  color: var(--color-text, #303030);
}

.search-modal__input::placeholder {
  color: var(--color-placeholder, #878787);
}

.search-modal__input:focus {
  outline: 2px solid var(--color-accent, #8FB56C);
  outline-offset: -2px;
}

/* Search icon (shown when input is empty) */
.search-modal__search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  pointer-events: none;
}

/* Clear button (shown when input has value) */
.search-modal__clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
}

.search-modal__clear svg {
  display: block;
  width: 24px;
  height: 24px;
}

/* Show clear button when input has value */
.search-modal__input-wrapper.has-value .search-modal__clear {
  display: flex;
}

.search-modal__input-wrapper.has-value .search-modal__search-icon {
  display: none;
}

/* Submit button */
.search-modal__submit {
  flex-shrink: 0;
  height: 48px;
  padding: 12px 24px;
  background-color: var(--color-accent, #8FB56C);
  border: none;
  border-radius: 10px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 500;
  line-height: 16px;
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.search-modal__submit:hover {
  background-color: var(--color-accent-hover, #7EA35D);
}

/* ===========================================
 * AUTOCOMPLETE RESULTS
 * =========================================== */

.search-modal__results {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  padding: 8px;
  max-height: 400px;
  overflow-y: auto;
  background-color: var(--color-background, #F6F6F6);
  border-radius: 8px;
}

.search-modal__results.is-visible {
  display: flex;
}

/* Result item */
.search-modal__result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background-color: var(--color-surface, #ffffff);
  border-radius: 8px;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.search-modal__result-item:hover,
.search-modal__result-item.is-active {
  background-color: var(--color-border-light, #F0F0F0);
}

/* Result image */
.search-modal__result-image {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background-color: var(--color-background, #F6F6F6);
}

.search-modal__result-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Result content */
.search-modal__result-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-modal__result-title {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 24px;
  color: var(--color-text, #303030);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-modal__result-excerpt {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 20px;
  color: var(--color-text-secondary, #4D4D4D);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===========================================
 * LOADING STATE
 * =========================================== */

.search-modal__loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 24px;
  background-color: var(--color-background, #F6F6F6);
  border-radius: 8px;
}

.search-modal__loading.is-visible {
  display: flex;
}

.search-modal__loading-text {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 20px;
  color: var(--color-text-secondary, #4D4D4D);
}

.search-modal__spinner {
  animation: search-modal-spin 1s linear infinite;
}

@keyframes search-modal-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ===========================================
 * ERROR STATE
 * =========================================== */

.search-modal__error {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 24px;
  background-color: var(--color-background, #F6F6F6);
  border-radius: 8px;
}

.search-modal__error.is-visible {
  display: flex;
}

.search-modal__error-text {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 20px;
  color: var(--color-text-secondary, #4D4D4D);
}

.search-modal__retry {
  padding: 8px 16px;
  background-color: transparent;
  border: 1px solid var(--color-accent, #8FB56C);
  border-radius: 8px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 16px;
  color: var(--color-accent, #8FB56C);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.search-modal__retry:hover {
  background-color: var(--color-accent, #8FB56C);
  color: #ffffff;
}

/* ===========================================
 * RESPONSIVE
 * =========================================== */

@media (max-width: 640px) {
  .search-modal__dialog {
    padding: 40px 20px;
    margin: 12px;
  }

  .search-modal__close {
    top: 16px;
    right: 16px;
  }

  .search-modal__title {
    font-size: 20px;
    line-height: 28px;
    padding-right: 32px;
  }

  .search-modal__form {
    flex-direction: column;
    gap: 12px;
  }

  .search-modal__submit {
    width: 100%;
  }

  .search-modal__result-image {
    width: 56px;
    height: 56px;
  }

  .search-modal__result-title {
    font-size: 16px;
    line-height: 20px;
  }

  .search-modal__result-excerpt {
    font-size: 14px;
    line-height: 18px;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
}
