/* ===== RAG Search Panel ===== */
.rag-search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.35);
  z-index: 3;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.rag-search-overlay.active {
  opacity: 1;
  visibility: visible;
}

.rag-search-panel {
  position: fixed;
  top: 4.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-0.5rem);
  width: min(680px, calc(100vw - 2rem));
  max-height: calc(100vh - 7rem);
  background: var(--md-default-bg-color, #fff);
  border-radius: 0.4rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15);
  z-index: 4;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.rag-search-panel.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Search input area */
.rag-search-header {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--md-default-fg-color--lightest, #e2e8f0);
  gap: 0.5rem;
}

.rag-search-icon {
  width: 1.2rem;
  height: 1.2rem;
  color: var(--md-default-fg-color--light, #637381);
  flex-shrink: 0;
}

.rag-search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
  color: var(--md-default-fg-color, #1a1a1a);
  min-width: 0;
}

.rag-search-input::placeholder {
  color: var(--md-default-fg-color--light, #888);
}

.rag-search-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 0.2rem;
  cursor: pointer;
  color: var(--md-default-fg-color--light, #637381);
  transition: background 0.15s ease;
}

.rag-search-close:hover {
  background: var(--md-default-fg-color--lightest, #f0f0f0);
}

.rag-search-close svg {
  width: 1.1rem;
  height: 1.1rem;
}

/* Status bar */
.rag-search-status {
  padding: 0.35rem 0.9rem;
  font-size: 0.7rem;
  color: var(--md-default-fg-color--light, #637381);
  background: var(--md-code-bg-color, #f6f8fa);
  border-bottom: 1px solid var(--md-default-fg-color--lightest, #e2e8f0);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rag-search-status:empty {
  display: none;
}

/* Results list */
.rag-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem;
}

.rag-search-result {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: 0.3rem;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}

.rag-search-result:hover,
.rag-search-result:focus {
  background: var(--md-accent-fg-color--transparent, #f0f6ff);
  outline: none;
}

.rag-search-result-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--md-default-fg-color, #1a1a1a);
  line-height: 1.3;
  margin-bottom: 0.15rem;
}

.rag-search-result-title mark {
  background: rgba(255, 214, 102, 0.4);
  color: inherit;
  padding: 0 0.1rem;
  border-radius: 0.1rem;
}

.rag-search-result-heading {
  font-size: 0.7rem;
  color: var(--md-default-fg-color--light, #637381);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-search-result-snippet {
  font-size: 0.72rem;
  color: var(--md-default-fg-color--light, #4a5568);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rag-search-result-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
  font-size: 0.65rem;
  color: var(--md-default-fg-color--lighter, #8899a8);
}

.rag-search-result-module {
  display: inline-block;
  padding: 0.05rem 0.3rem;
  border-radius: 0.2rem;
  background: var(--md-default-fg-color--lightest, #edf2f7);
  color: var(--md-default-fg-color--light, #4a5568);
  text-transform: uppercase;
}

/* Empty / loading states */
.rag-search-empty,
.rag-search-loading {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--md-default-fg-color--light, #637381);
}

.rag-search-loading svg {
  width: 1.5rem;
  height: 1.5rem;
  animation: rag-spin 1s linear infinite;
  margin-bottom: 0.5rem;
}

@keyframes rag-spin {
  to { transform: rotate(360deg); }
}

/* Floating action button */
.rag-search-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 2rem;
  background: linear-gradient(135deg, #1e88e5 0%, #0d47a1 100%);
  color: #fff;
  box-shadow: 0 0.25rem 1rem rgba(13, 71, 161, 0.35);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rag-search-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.4rem 1.25rem rgba(13, 71, 161, 0.45);
}

.rag-search-fab:active {
  transform: translateY(0);
}

.rag-search-fab-icon {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}

.rag-search-fab-text {
  white-space: nowrap;
}

/* Adjust panel for FAB-triggered search: prefer lower placement on desktop */
@media (min-width: 769px) {
  .rag-search-panel {
    top: auto;
    bottom: 5.5rem;
    right: 1.5rem;
    left: auto;
    transform: translateY(0.5rem);
    transform-origin: bottom right;
  }

  .rag-search-panel.active {
    transform: translateY(0);
  }
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .rag-search-panel {
    top: auto;
    bottom: 5rem;
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    transform: translateY(0.5rem);
    max-height: calc(100vh - 6rem);
  }

  .rag-search-panel.active {
    transform: translateY(0);
  }

  .rag-search-fab {
    right: 1rem;
    bottom: 1rem;
    padding: 0.6rem 0.9rem;
    font-size: 0.8rem;
  }

  .rag-search-fab-text {
    display: none;
  }
}
