@import '../../define.scss';

$button-border-radius: 8px;

.search-panel-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  font-size: $font-d1;
  pointer-events: none;
}

.selected-point-card {
  position: absolute;
  top: 78px;
  left: 12px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: all;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(20, 30, 58, 0.12);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.16);
}

.selected-point-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: rgba(26, 31, 43, 0.94);
  color: #ffffff;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.selected-point-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  cursor: pointer;

  &:hover {
    background: rgba(255, 255, 255, 0.16);
  }
}

.selected-point-body {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: start;
}

.selected-point-label {
  padding: 0.8rem 0.7rem;
  border-right: 1px solid rgba(20, 30, 58, 0.08);
  color: $gray-600;
  font-size: 0.82rem;
  text-transform: lowercase;
}

.selected-point-value {
  padding: 0.8rem 0.9rem;
  color: $gray-900;
  line-height: 1.45;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.svg-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 1em;
  height: 1em;
  color: currentColor;

  pointer-events: fill;

  :global(svg) {
    fill: currentColor;
    width: 100%;
    height: 100%;
  }
}

$search-h-margin: 10px;

$search-input-width: 250px;
$search-input-height: 18px;

$logo-icon-width: 24px;
$cancel-icon-width: 14px;
$cancel-icon-margin: 8px;

$search-bar-v-padding: 12px;
$search-bar-h-padding: 12px;
$search-bar-gap: 8px;

.search-bar {
  position: absolute;
  top: $search-h-margin;
  left: $search-h-margin;
  color: $gray-600;

  display: flex;
  flex-direction: row;
  gap: $search-bar-gap;
  align-items: center;
  pointer-events: all;

  padding: 0 $search-bar-h-padding;
  border-radius: 12px;
  border: 1px solid rgba(20, 30, 58, 0.08);
  background-color: change-color($color: white, $alpha: 1);
  transition: box-shadow 150ms ease-in-out;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);

  &.focused {
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12);
  }

  &:focus {
    background-color: red;
  }

  #search-bar-input {
    border: none;
    margin: $search-bar-v-padding 0;
    width: $search-input-width;
    height: $search-input-height;

    &:focus {
      border: none;
      outline: none;
    }

    &::placeholder {
      color: $gray-700;
    }
  }

  .logo-icon {
    width: $logo-icon-width;
    height: $logo-icon-width;
  }

  .end-button {
    position: relative;
    margin-left: $cancel-icon-margin;
    width: 1em;
    height: 1em;

    .search-icon {
      position: absolute;
      width: 1em;
      height: 1em;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);

      color: currentColor;
      transition: color 150ms ease-in-out, opacity 150ms ease-in-out;
      opacity: 1;

      &.hidden {
        opacity: 0;
        pointer-events: none;
      }
    }

    .cancel-icon {
      position: absolute;
      width: $cancel-icon-width;
      height: $cancel-icon-width;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);

      color: $gray-500;
      transition: color 150ms ease-in-out, opacity 150ms ease-in-out;
      opacity: 1;
      cursor: default;

      &:hover {
        color: adjust-color($color: $gray-500, $lightness: -10%);
      }

      &:active {
        color: adjust-color($color: $gray-500, $lightness: 10%);
      }

      &.hidden {
        opacity: 0;
        pointer-events: none;
      }
    }
  }
}

$search-panel-width: $search-input-width + $search-bar-gap * 2 +
  $search-h-margin * 2 + $search-bar-h-padding * 2 + $logo-icon-width +
  $cancel-icon-margin + $cancel-icon-width;

.search-list-container {
  display: flex;
  flex-direction: column;

  background: white;
  box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.2),
    0 2px 6px 2px hsla(0, 0%, 0%, 0.08);

  height: 100%;
  width: $search-panel-width;

  opacity: 1;
  transition: opacity 150ms ease-in-out;
  opacity: 0;
  pointer-events: none;

  &.shown {
    opacity: 1;
    pointer-events: all;
  }
}

.search-list {
  height: 100%;
  padding: 0;
  margin-top: $search-input-height + $search-bar-v-padding * 2 +
    $search-h-margin;

  background-color: white;
  overflow-y: hidden;

  display: flex;
  flex-direction: column;
  align-items: center;

  .header-gap {
    margin-top: 12px;
    height: 1px;
    width: 100%;
    flex-shrink: 0;

    background: $gray-300;
    opacity: 1;
    box-shadow: 0 1px 1px hsla(0, 0%, 0%, 0.05), 0 1px 2px hsla(0, 0%, 0%, 0.05);
    transition: opacity 300ms ease-in-out, box-shadow 300ms ease-in-out;

    &.hidden {
      opacity: 0;
      box-shadow: none;
    }
  }

  .result-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    flex-grow: 1;

    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    overscroll-behavior: none;

    .item {
      line-height: 1.2;
      width: 100%;
      padding: 5px ($search-h-margin + $search-bar-h-padding);
      border-bottom: 1px solid $gray-200;
      cursor: default;
      padding-bottom: 3px;

      &.clamp-line {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 4;
        overflow: hidden;
        flex-shrink: 0;
        -webkit-box-pack: end;
      }

      &:hover {
        background-color: change-color($color: $blue-100, $lightness: 96%);
      }

      :global(em) {
        color: $blue-500;
        font-style: normal;
        font-weight: 600;
      }
    }

    .count-label {
      font-size: $font-d1;
      line-height: 1;
      width: 100%;
      padding: 5px ($search-h-margin + $search-bar-h-padding);
      color: $gray-500;
    }

    .add-more-button {
      font-weight: 600;
      cursor: pointer;
      width: 100%;
      text-align: center;

      display: flex;
      justify-content: center;
      align-items: center;

      color: $blue-700;
      background-color: $gray-100;

      user-select: none;
      -webkit-user-select: none;
      transition: color 150ms ease-in-out, background-color 150ms ease-in-out;

      &:hover {
        background-color: $gray-200;
        color: $blue-600;
      }

      &:active {
        color: $blue-800;
      }

      &.hidden {
        display: none;
      }

      span {
        padding: 12px;
      }
    }
  }

  .scroll-up-button {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);

    pointer-events: all;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;

    background-color: white;
    box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.25),
      0 1px 3px 1px hsla(0, 0%, 0%, 0.1);
    border-radius: 8px;
    padding: 4px 8px;
    opacity: 1;

    transition: opacity 150ms ease-in-out;

    .svg-icon {
      width: 16px;
      height: 16px;
      color: $gray-700;
    }

    &.hidden {
      opacity: 0;
      pointer-events: none;
    }

    &:hover {
      background-color: $gray-100;
    }

    &:active {
      background-color: $gray-200;
    }
  }
}
