/* Mortui Vivos Docent — AI Search Widget
   Matches Material slate dark theme + extra.css design language.
   Accent: #ff1744, dark bg: rgba(30, 0, 0, ...) */

/* ============================================================
   1. FLOATING BUTTON
   ============================================================ */

.ai-search-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  background: rgba(30, 0, 0, 0.92);
  border: 1px solid rgba(255, 23, 68, 0.35);
  border-radius: 2rem;
  color: rgba(255, 255, 255, 0.9);
  font-family: var(--md-text-font-family, inherit);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.4),
    0 0 0 0 rgba(255, 23, 68, 0);
  transition:
    border-color 0.2s,
    box-shadow 0.25s,
    transform 0.15s;
  user-select: none;
}

.ai-search-btn:hover {
  border-color: rgba(255, 23, 68, 0.7);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.5),
    0 0 0 3px rgba(255, 23, 68, 0.12);
  transform: translateY(-1px);
}

.ai-search-btn:active {
  transform: translateY(0);
}

.ai-search-btn svg {
  width: 16px;
  height: 16px;
  fill: #ff1744;
  flex-shrink: 0;
}

/* Hide label on very small screens */
@media (max-width: 480px) {
  .ai-search-btn span {
    display: none;
  }
  .ai-search-btn {
    padding: 0.7rem;
    border-radius: 50%;
  }
}

/* ============================================================
   2. MODAL OVERLAY
   ============================================================ */

.ai-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    visibility 0.2s;
}

.ai-search-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ============================================================
   3. MODAL PANEL
   ============================================================ */

.ai-search-modal {
  width: 100%;
  max-width: 800px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--md-default-bg-color, #1e1e2e);
  border: 1px solid rgba(255, 23, 68, 0.2);
  border-radius: 10px;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  transform: translateY(-12px) scale(0.98);
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
  overflow: hidden;
}

.ai-search-overlay.open .ai-search-modal {
  transform: translateY(0) scale(1);
}

/* Mobile: full-screen modal */
@media (max-width: 768px) {
  .ai-search-overlay {
    padding-top: 0;
    align-items: stretch;
  }
  .ai-search-modal {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* ============================================================
   4. MODAL HEADER
   ============================================================ */

.ai-search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-search-header h3 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.7);
}

.ai-search-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.ai-search-close:hover {
  color: #ff1744;
  background: rgba(255, 23, 68, 0.1);
}

/* ============================================================
   5. INPUT AREA
   ============================================================ */

.ai-search-input-wrap {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-search-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--md-default-fg-color, #fff);
  font-family: var(--md-text-font-family, inherit);
  font-size: 0.95rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.ai-search-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.ai-search-input:focus {
  border-color: rgba(255, 23, 68, 0.5);
}

/* ============================================================
   6. RESULTS AREA
   ============================================================ */

.ai-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 120px;
}

/* Empty state */
.ai-search-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ============================================================
   7. LOADING STATES
   ============================================================ */

/* Spinner for AI generation */
.ai-search-spinner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.85rem;
}

.ai-search-spinner::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 23, 68, 0.25);
  border-top-color: #ff1744;
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* Skeleton placeholders for fast search */
.ai-search-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0.5rem 0;
}

.ai-search-skeleton-line {
  height: 12px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 25%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 75%
  );
  background-size: 200% 100%;
  animation: ai-shimmer 1.5s ease infinite;
  border-radius: 4px;
}

.ai-search-skeleton-line:nth-child(1) { width: 85%; }
.ai-search-skeleton-line:nth-child(2) { width: 70%; }
.ai-search-skeleton-line:nth-child(3) { width: 55%; }

@keyframes ai-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   8. ANSWER DISPLAY
   ============================================================ */

.ai-search-answer {
  line-height: 1.75;
  font-size: 0.9rem;
  color: var(--md-default-fg-color, rgba(255, 255, 255, 0.88));
}

.ai-search-answer p {
  margin: 0 0 0.8em;
}

.ai-search-answer strong {
  color: #ff1744;
  font-weight: 700;
}

.ai-search-answer ul,
.ai-search-answer ol {
  padding-left: 1.4em;
  margin: 0.5em 0 1em;
}

.ai-search-answer li {
  margin-bottom: 0.3em;
  line-height: 1.65;
}

/* ============================================================
   9. SOURCE CITATIONS
   ============================================================ */

.ai-search-sources {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-search-sources-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 0.5rem;
}

.ai-search-source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ai-search-source-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  background: rgba(255, 23, 68, 0.08);
  border: 1px solid rgba(255, 23, 68, 0.2);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-search-source-chip:hover {
  border-color: rgba(255, 23, 68, 0.5);
  background: rgba(255, 23, 68, 0.14);
  color: #fff;
}

/* ============================================================
   10. FAST SEARCH RESULTS
   ============================================================ */

.ai-search-fast-results {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ai-search-fast-item {
  padding: 0.6rem 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ai-search-fast-item:hover {
  border-color: rgba(255, 23, 68, 0.3);
  background: rgba(255, 23, 68, 0.04);
}

.ai-search-fast-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--md-default-fg-color, rgba(255, 255, 255, 0.9));
  margin-bottom: 0.2rem;
}

.ai-search-fast-snippet {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   11. ERROR DISPLAY
   ============================================================ */

.ai-search-error {
  padding: 0.8rem 1rem;
  background: rgba(255, 23, 68, 0.06);
  border-left: 3px solid #ff1744;
  border-radius: 0 4px 4px 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ============================================================
   12. DISCLAIMER
   ============================================================ */

.ai-search-disclaimer {
  padding: 0.6rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.3);
  text-align: center;
  flex-shrink: 0;
}

/* ============================================================
   13. COPY BUTTON
   ============================================================ */

.ai-search-copy-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.4rem;
}

.ai-search-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.72rem;
  font-family: var(--md-text-font-family, inherit);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.ai-search-copy-btn:hover {
  color: rgba(255, 255, 255, 0.8);
  border-color: rgba(255, 23, 68, 0.4);
}

.ai-search-copy-btn.copied {
  color: #4caf50;
  border-color: rgba(76, 175, 80, 0.4);
}

.ai-search-copy-btn svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

/* ============================================================
   14. RESPONSE DISCLOSURE
   ============================================================ */

.ai-search-disclosure {
  margin-top: 0.8rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 255, 255, 0.02);
  border-left: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 0 4px 4px 0;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.3);
  line-height: 1.5;
  font-style: italic;
}

/* ============================================================
   15. PRINT — hide widget entirely
   ============================================================ */

@media print {
  .ai-search-btn,
  .ai-search-overlay {
    display: none !important;
  }
}
