.search-widget {
  color-scheme: light;
  --bg: #dee2e5;
  --panel: #ffffff;
  --text: #222226;
  --line: #e2e2e2;
  --accent: #df202c;
  --accent-dark: #d1081b;
  --danger: #df202c;
  --mark: #fff2a8;
  --open-transition-duration: 0.8s;
}

.search-widget,
.search-widget * {
  box-sizing: border-box;
}

.search-widget img {
  max-width: 100%;
}

.search-widget button {
  border: 0;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.search-widget {
  color: var(--text);
  font-family: "Gotham", sans-serif;
}

.top-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 9px 20px;
  box-shadow: inset 0px 3px 30px #00000029;
  transition: 0.2s ease box-shadow 0.7s;
}

.beta-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent-dark);
  font-weight: 500;
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.language-switcher {
  margin-left: auto;

  a {
    color: var(--text);
    font-size: 14px;
    text-decoration: none;
    font-weight: 500;

    &:not(:last-child):after {
      content: "•";
      display: inline-block;
      margin: 0 0px 0 4px;
    }
  }
}

.toggle-button {
  background-color: white;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0 15px;
  border-radius: 100px;
  height: 38px;
  margin-left: auto;
  font-size: 14px;
  font-weight: 500;

  img {
    width: 18px;
    height: 18px;
  }

  .divider {
    margin: 0 15px;
  }

  .open-text {
    display: flex;
    align-items: center;
    align-items: center;
    gap: 10px;
  }

  .close-text {
    display: none;
    align-items: center;
    gap: 10px;
  }
}

.search-widget {
  width: 100%;
  margin: 0 auto;
  background: var(--bg);

  &.open {
    .top-bar {
      box-shadow: inset 0px 3px 30px #00000000;
      transition: 0.1s ease box-shadow 0s;
    }

    .search-widget-content {
      grid-template-rows: 1fr;
    }

    .search-widget-content-inner {
      visibility: visible;
      transition: visibility 0s ease 0s;
    }

    .toggle-button {
      .open-text {
        display: none;
      }

      .close-text {
        display: flex;
      }
    }
  }
}

.search-widget-content {
  display: grid;
  padding-inline: 20px;
  grid-template-rows: 0fr;
  overflow: clip;
  transition: grid-template-rows var(--open-transition-duration)
    cubic-bezier(0.33, 1, 0.3, 1);
}

.search-widget.open.open-complete .search-widget-content {
  overflow: visible;
}

.search-widget-content-inner {
  min-height: 0;
  min-width: 0;
  visibility: hidden;
  transition: visibility 0s ease var(--open-transition-duration);
}

.top {
  padding-bottom: 40px;
  min-width: 0;
}

.page-switcher-restore {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 0;
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 500;
  transition: max-height 0.28s cubic-bezier(0.33, 1, 0.3, 1),
    opacity 0.2s ease, transform 0.28s cubic-bezier(0.33, 1, 0.3, 1),
    padding 0.28s cubic-bezier(0.33, 1, 0.3, 1),
    margin-bottom 0.28s cubic-bezier(0.33, 1, 0.3, 1);

  img {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }
}

.page-switcher {
  display: grid;
  grid-template-rows: 1fr;
  margin-bottom: 50px;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  transition: grid-template-rows 0.34s cubic-bezier(0.33, 1, 0.3, 1),
    margin-bottom 0.34s cubic-bezier(0.33, 1, 0.3, 1);

  &:has(.page-link:hover:not(.current)) .current {
    background-color: transparent;
  }

  .page-switcher-panel {
    min-height: 0;
    overflow: hidden;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.24s ease, transform 0.34s cubic-bezier(0.33, 1, 0.3, 1),
      visibility 0s ease 0s;
    visibility: visible;
  }

  .page-switcher-title {
    width: 100%;
    margin-bottom: 25px;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 16px;
  }

  .page-switcher-links {
    display: flex;
    flex-wrap: nowrap;
    width: min(100%, calc(100vw - 40px));
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .page-name {
    font-size: 16px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 5px;
  }

  .page-link {
    display: flex;
    flex-direction: column;
    width: 285px;
    text-decoration: none;
    color: var(--text);
    padding: 28px 28px 20px 28px;
    border-radius: 8px;
    flex-shrink: 0;
    transition: 0.2s ease background-color;

    &.current {
      background-color: #c7ced3;
    }

    &:hover {
      background-color: #c7ced3;
    }
  }

  .page-link-img {
    border-radius: 8px;
    margin-bottom: 10px;
  }

  .page-link-bottom {
    display: flex;
    flex-wrap: wrap;
  }

  .page-domain {
    width: 100%;
    font-size: 14px;
    color: var(--accent-dark);
  }
}

.search-widget.page-switcher-collapsed {
  .page-switcher-restore {
    max-height: 42px;
    margin-bottom: 18px;
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
    padding: 0;
  }

  .page-switcher {
    grid-template-rows: 0fr;
    margin-bottom: 18px;
  }

  .page-switcher-panel {
    opacity: 0;
    transform: translateY(-14px);
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.33, 1, 0.3, 1),
      visibility 0s ease 0.28s;
  }

}

.search-widget h1 {
  margin-bottom: 45px;
  font-size: 45px;
  letter-spacing: 0;
  text-align: center;
  font-weight: 400;

  strong {
    font-weight: 700;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0px 3px 6px #00000029;
}

.controls {
  display: grid;
  gap: 14px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
}

.search-row {
  position: relative;
  display: flex;
  gap: 18px;
  background-color: rgb(209 216 223 / 53%);
  border-radius: 100px;
  padding: 15px;
  max-width: 1270px;
  margin: 0 auto;
  box-shadow: 0px 10px 30px #0000001f;

  &.has-value {
    .delete-search-query {
      display: block;
    }
  }

  .ai-tooltip {
    position: absolute;
    left: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    font-size: 14px;
    line-height: 1.7;
  }
}

.search-widget label {
  width: 100%;
}

.search-input-wrapper {
  position: relative;
}

.delete-search-query {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  margin: 0;
  padding: 10px;
  width: auto;
  overflow: visible;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: normal;
  cursor: pointer;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
  appearance: none;
  -webkit-appearance: none;

  &::-moz-focus-inner {
    border: 0;
    padding: 0;
  }
}

.search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 0 40px;
  color: var(--text);
  background: #fff;
  font-weight: 400;
  outline: none;
  height: 70px;
  font-size: 18px;
  font-weight: 500;
  appearance: none;
  padding-right: 75px;

  &:focus {
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
  }
}

.ai-button {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 70px;
  width: 70px;
  border: 0;
  border-radius: 100px;
  padding: 0 18px;
  color: var(--text);
  background: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ai-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 40px 0;
  color: var(--text);
  font-size: 18px;
}

.error {
  display: none;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(180, 35, 24, 0.28);
  border-radius: 8px;
  color: var(--danger);
  background: #fff6f5;
}

.result-wrapper {
  display: none;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 20px;

  &.active {
    display: flex;
  }
}

.results-container {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 50px 40px;

  .results-container-inner {
    display: flex;
    flex-direction: column;
    max-width: 1580px;
    margin: 0 auto;
    width: 100%;

    .results {
      margin: auto 0;
    }
  }
}

.ai-chat-container {
  display: none;
  position: sticky;
  top: 20px;
  height: calc(100svh - 40px);
  width: 100%;
  max-width: 600px;
  flex-direction: column;
  overflow: hidden;

  &.show {
    display: flex;
  }
}

.ai-chat-header {
  font-size: 24px;
  display: flex;
  gap: 20px;
  align-items: center;
  text-wrap: pretty;
  line-height: 1.7;
  padding: 20px;
  border-bottom: 1px solid var(--line);

  .ai-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 70px;
    height: 70px;
    border-radius: 70px;
    border: 1px solid var(--line);

    img {
      width: 40px;
      height: 40px;
    }
  }
}

.ai-chat-body {
  height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 5px;
}

.ai-chat-bubble {
  background: #f4f5f7;
  padding: 5px;
  border-radius: 22px;
  padding: 20px;
  margin: 0 10px;
  line-height: 1.4;
  max-width: calc(100% - 50px);
  position: relative;
  border-bottom-left-radius: 0;
  margin-left: 50px;
  word-wrap: break-word;

  &:before {
    content: "";
    width: 40px;
    height: 40px;
    position: absolute;
    bottom: 0;
    left: -45px;
    background-image: url(icons/sparkles.svg);
    background-position: center;
    background-repeat: no-repeat;
    border: 1px solid var(--line);
    border-radius: 40px;
  }

  &.user {
    align-self: flex-end;
    background-color: #797198;
    color: white;
    border-bottom-left-radius: 22px;
    border-bottom-right-radius: 0px;

    &:before {
      display: none;
    }
  }

  &.loading:after {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.45;
    vertical-align: middle;
    animation: ai-thinking-pulse 1s ease-in-out infinite;
  }

  &.error {
    color: var(--danger);
    background: #fff6f5;
  }

  ul {
    padding-left: 20px;
    margin: 0 0 10px 0;
  }

  p {
    margin: 5px 0 10px 0;
  }
}

@keyframes ai-thinking-pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.82);
  }

  50% {
    opacity: 0.8;
    transform: scale(1.18);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-bubble.loading:after {
    animation: none;
    opacity: 0.45;
    transform: none;
  }
}

.ai-chat-progress {
  margin: -4px 50px 0;
  color: #666;
  font-size: 14px;
  font-style: italic;
}

.ai-chat-sources {
  margin: -4px 10px 0 50px;
  max-width: calc(100% - 50px);
  font-size: 13px;
}

.ai-chat-sources-title {
  margin-bottom: 6px;
  color: #666;
  font-weight: 500;
}

.ai-chat-sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-chat-source {
  display: inline-flex;
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--accent-dark);
  background: #fff;
  text-decoration: none;
}

.ai-chat-footer {
  display: flex;
  gap: 0 10px;
  padding: 20px;
  align-items: center;
  border-top: 1px solid var(--line);

  input {
    appearance: none;
    width: 100%;
    height: 60px;
    border: 1px solid var(--line);
    border-radius: 40px;
    padding: 0 20px;
    font-weight: 500;

    &:disabled {
      cursor: wait;
      opacity: 0.7;
    }
  }

  .ai-chat-send-button {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 0;
    border-radius: 100px;
    padding: 0 18px;
    color: var(--text);
    background: white;
    font: inherit;
    cursor: pointer;
    border: 1px solid var(--line);

    &:disabled {
      cursor: wait;
      opacity: 0.7;
    }
  }
}

.result-headline {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;

  .result-headline-query {
    font-size: 18px;
    font-weight: 500;
  }

  .result-headline-timing {
    font-size: 14px;
  }
}

.result-divider {
  font-size: 14px;

  hr {
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1em 0;
    margin-bottom: 0;
    padding: 0;
  }
}

.hit {
  border-bottom: 1px solid rgb(34 34 38 / 31%);
  padding: 39px 0px;
  opacity: 0;
  transform: translateY(12px);
  animation: hit-appear 0.34s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--hit-delay, 0ms);

  &:last-child {
    border-bottom: none;
  }
}

@keyframes hit-appear {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hit {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

.hit-link {
  display: flex;
  gap: 0 20px;
  color: var(--text);
  text-decoration: none;
}

.hit-left {
  width: 260px;
  flex-shrink: 0;

  img {
    width: 90px;
    border-radius: 8px;
  }

  .hit-domain {
    font-size: 14px;
    font-weight: 400;
    color: var(--accent);
    margin-bottom: 10px;
    margin-top: 10px;
  }

  .hit-site-label {
    font-size: 14px;
    font-weight: 400;
  }

  p {
    margin: 0;
    color: #394456;
  }
}

.hit-right {
  font-size: 18px;

  .page-title {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
  }

  p {
    line-height: 1.7;
    margin: 0;
  }
}

.hit .fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.field {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--text);
  background: #fbfcfe;
  font-size: 12px;
}

.empty {
  padding: 28px 18px;
  color: var(--text);
  text-align: center;
}

mark {
  border-radius: 3px;
  padding: 0 2px;
  background: var(--mark);
  color: inherit;
}

@media (max-width: 760px) {
  .search-widget {
    width: min(100% - 20px, 1040px);
    padding-top: 16px;
  }

  .search-row {
    grid-template-columns: 1fr;
  }
}
