:root {
  /* Fixed, always-legible muted text for body content on light
     backgrounds (answer list items, reference popover, etc). Kept
     separate from --ptai-text-secondary, which sites may set to a
     light color (e.g. white) for text on dark UI chrome like the
     mode-toggle indicator. */
  --ptai-muted-text: #555555;
}

/* ---------- Container ---------- */
#ptai-widget {
  max-width: 700px;
  margin: 30px auto;
  color: var(--ptai-text-primary);
  text-align: center;
}

/* ---------- Toggle Section ---------- */
#ptai-mode-switch,
#ptai-modal-mode-switch {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 180px;
  height: 60px;
  margin: 0 auto 25px;
}

#ptai-mode-switch .mode-btn {
  position: absolute;
  top: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  font-weight: 600;
  z-index: 2;
  transition: all 0.4s ease;
  color: var(--ptai-text-secondary);
  background: var(--ptai-toggle-bg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

#ptai-mode-switch .mode-btn:nth-child(1) {
  left: 0;
}

#ptai-mode-switch .mode-btn:nth-child(2) {
  right: 0;
}

#ptai-mode-switch .mode-btn.active {
  background: var(--ptai-search-bg);
  color: var(--ptai-text-secondary);
  transform: scale(1.1);
}

#ptai-mode-switch::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2rem;
  height: 0.3rem;
  background: var(--ptai-border-color);
  transform: translate(-50%, -50%);
  border-radius: 20px;
}

/* ---------- Search Form ---------- */
#ptai-search-form,
#ptai-modal-search-form {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 30px;
  padding: 0.5rem 1rem;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
  gap: 10px;
  transition: all 0.3s ease;
  border: 1px solid var(--ptai-border-color);
  background-color: #fff;
}

#ptai-modal-search-form {
  margin-bottom: 20px;
}

#ptai-search-form input,
#ptai-modal-search-form input {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 15px;
  border-radius: 30px;
  font-size: 1.5rem;
  color: var(--ptai-text-primary);
  background: transparent;
}

#ptai-search-form input::placeholder,
#ptai-modal-search-form input::placeholder {
  color: var(--ptai-muted-text);
  font-size: 1.5rem;
}

/* Search + Microphone Buttons */
#ptai-search-form .mic-btn,
#ptai-search-form button[type="submit"],
#ptai-modal-search-form .mic-btn,
#ptai-modal-search-form button[type="submit"] {
  border: none;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ptai-search-form .mic-btn,
#ptai-modal-search-form .mic-btn {
  background: transparent;
  color: var(--ptai-mic-color);
  font-size: 2rem;
  width: 36px;
  height: 36px;
}

#ptai-search-form .mic-btn img,
#ptai-modal-search-form .mic-btn img {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

#ptai-search-form button[type="submit"],
#ptai-modal-search-form button[type="submit"] {
  background: var(--ptai-search-bg);
  color: var(--ptai-text-secondary);
  padding: 10px;
  width: 42px;
  height: 42px;
}

#ptai-search-form button[type="submit"]:hover,
#ptai-modal-search-form button[type="submit"]:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

/* ---------- Modal Popup ---------- */
.ptai-modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  justify-content: center;
}

.ptai-modal-content {
  background: #fff;
  border-radius: 15px;
  width: 80%;
  max-width: 800px;
  margin: 135px auto;
  padding: 30px;
  position: relative;
  text-align: left;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  animation: popupFade 0.3s ease forwards;
  max-height: 80vh;
  height: 100%;
  /* Scrolling happens in .ptai-modal-scroll, not here — a native
     scrollbar on this element would sit flush against the rounded
     corners and visually square them off. */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ptai-modal-scroll {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

@keyframes popupFade {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.ptai-modal-close {
  position: absolute;
  right: 15px;
  top: 15px;
  font-size: 28px;
  cursor: pointer;
  color: var(--ptai-text-primary);
}

/* ---------- Results ---------- */
.ptai-answer {
  padding-left: 15px;
  font-size: 1rem;
  line-height: 1.6;
}

.ptai-simple-results {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ptai-simple-item {
  border: 1px solid var(--ptai-border-color);
  border-radius: 12px;
  padding: 16px 20px;
  background: #fff;
  text-align: left;
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.ptai-simple-item:hover {
  border-color: var(--ptai-search-bg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.ptai-simple-item h4 {
  margin: 0 0 6px;
  font-size: 1.3rem;
  line-height: 1.4;
}

.ptai-simple-item a {
  color: var(--ptai-search-bg) !important;
  text-decoration: none;
  font-weight: 600;
  transition: 0.3s;
}

.ptai-simple-item a:hover,
.ptai-simple-item a:focus-visible {
  text-decoration: underline;
}

.ptai-simple-item p {
  color: var(--ptai-muted-text);
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.6;
}

/* ---------- Utility ---------- */
button {
  cursor: pointer;
}

/* Voice Overlay */
#ptai-voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}
#ptai-voice-overlay.hidden {
  display: none;
}

#ptai-wave-canvas {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.ptai-close-voice {
  position: absolute;
  top: 30px;
  right: 40px;
  background: none;
  border: none;
  color: var(--ptai-text-secondary);
  font-size: 3rem;
  cursor: pointer;
  z-index: 2;
}

/* ---------- Animated Toggle ---------- */
.ptai-toggle {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  position: relative;
  height: 3.5rem;
  width: 8rem;
  margin: 0 auto 25px;
}

.ptai-left-cycle,
.ptai-right-cycle {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 100%;
  background: var(--ptai-toggle-bg);
  display: flex;
  justify-content: center;
  align-items: center;
}
.ptai-left-cycle:hover,
.ptai-right-cycle:hover {
  cursor: pointer;
}

.ptai-line {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-self: center;
  width: 2rem;
  height: 3.5rem;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.ptai-upper-line {
  width: 100%;
  height: 50%;
  background: radial-gradient(
    110% 100% at top,
    transparent 50%,
    var(--ptai-toggle-bg) 51%
  );
  border-radius: 2rem 2rem 0 0;
}
.ptai-lower-line {
  width: 100%;
  height: 50%;
  background: radial-gradient(
    110% 100% at bottom,
    transparent 50%,
    var(--ptai-toggle-bg) 51%
  );
  border-radius: 0 0 2rem 2rem;
}

.ptai-toggle p {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--ptai-muted-text);
}

.ptai-toggle .ptai-simple-text,
.ptai-toggle .ptai-ai-text {
  color: var(--ptai-search-bg);
}

.ptai-ai-cycle {
  background: var(--ptai-search-bg);
  border: none;
  width: 4rem;
  height: 4rem;
  border-radius: 100%;
  position: absolute;
  top: 50%;
  left: 26%;
  transform: translate(-6.5%, -50%);
  transition: all 0.4s ease;
  box-shadow:
    0 1px 3px 0 rgba(0, 0, 0, 0.1),
    0 1px 2px -1px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

.ptai-ai-cycle.moved {
  left: 75%;
  transform: translate(-95%, -50%);
  background: var(--ptai-search-bg);
}

.ptai-ai-cycle p {
  color: var(--ptai-text-secondary);
  font-size: 1.2rem;
  margin: 0;
}

.ptai-hidden-text {
  display: none;
}

/* ---------- Animation ---------- */
.ptai-ai-cycle.moved .ptai-open-text {
  display: none;
}
.ptai-ai-cycle.moved .ptai-hidden-text {
  display: block;
}

/* Hover and shadows */
.ptai-ai-cycle:hover {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  transform: scale(1.05) translate(-6.5%, -50%);
  cursor: pointer;
}
.ptai-ai-cycle.moved:hover {
  transform: scale(1.05) translate(-95%, -50%);
  cursor: pointer;
}

#ptai-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  transition: opacity 0.3s ease;
}
#ptai-loading.hidden {
  display: none;
}
#ptai-loading-animation {
  width: 200px;
  height: 200px;
}

.ptai-answer {
  padding: 20px;
  background: #fafafa;
  border-radius: 10px;
  font-size: 1.5rem;
  line-height: 1.6;
  color: var(--ptai-text-primary);
}

.ptai-answer a {
  color: var(--ptai-search-bg);
  text-decoration: none;
  font-weight: 600;
}

.ptai-answer ul,
.ptai-answer ol {
  padding-left: 1.5rem;
  margin: 1rem 0;
}

.ptai-answer li {
  margin-bottom: 0.6rem;
  color: var(--ptai-muted-text);
}

.ptai-inline-ref {
  margin-left: 4px;
  color: var(--ptai-search-bg);
  opacity: 0.6;
  font-size: 0.85em;
  text-decoration: none;
  vertical-align: middle;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.ptai-inline-ref:hover {
  opacity: 1;
}

.ptai-ref-popover {
  position: fixed;
  z-index: 10001;
  background: #fff;
  border: 1px solid var(--ptai-border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 14px 16px;
  width: 280px;
  max-width: calc(100vw - 24px);
  font-size: 1.2rem;
  line-height: 1.5;
  text-align: left;
}

.ptai-ref-popover-uri {
  color: var(--ptai-muted-text);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.ptai-ref-popover-title {
  font-weight: 700;
  color: var(--ptai-text-primary);
  margin-bottom: 6px;
}

.ptai-ref-popover-content {
  color: var(--ptai-muted-text);
  margin-bottom: 10px;
}

.ptai-ref-popover-link {
  display: inline-block;
  color: var(--ptai-search-bg);
  font-weight: 600;
  text-decoration: none;
}
.ptai-ref-popover-link:hover {
  text-decoration: underline;
}
.ptai-answer {
  background: #fafafa;
  border-radius: 10px;
  padding: 20px;
  line-height: 1.7;
  color: var(--ptai-text-primary);
  padding: 1rem;
}
.ptai-answer strong {
  color: var(--ptai-text-primary);
}
.ptai-answer ul {
  margin-top: 10px;
  padding-left: 20px;
}
.ptai-answer li {
  margin-bottom: 5px;
  color: var(--ptai-muted-text);
}

.ptai-related-questions {
  margin-top: 20px;
}

.ptai-related-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ptai-muted-text);
  margin-bottom: 10px;
}

.ptai-related-scroll {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: thin;
}

.ptai-related-question {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: #fff;
  border: 1px solid var(--ptai-border-color);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 1.4rem;
  color: var(--ptai-text-primary);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.ptai-related-question:hover {
  background: var(--ptai-toggle-bg);
  border-color: var(--ptai-search-bg);
}

.ptai-related-icon {
  color: var(--ptai-search-bg);
  font-weight: 700;
}

@media screen and (max-width: 787px) {
  .ptai-modal-content {
    width: 95%;
  }
}
