/* PageCoder RAG Search widget — Phase 1 Day 3 (UI scaffold). */

.pcrag-search-root[hidden] { display: none; }

/* Design tokens duplicated from widget.css rather than shared, because the two
 * stylesheets load independently — rollout mode can hide chat while search stays
 * on, so search cannot rely on widget.css being present. Same names and same
 * values, so the two surfaces read as one product. Change both together. */
.pcrag-search-root {
  --pcrag-bg: #ffffff;
  --pcrag-fg: #1d2327;
  --pcrag-muted: #646970;
  --pcrag-border: #dcdcde;
  --pcrag-primary: #2271b1;
  --pcrag-primary-fg: #ffffff;
  --pcrag-radius: 12px;
  --pcrag-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  position: fixed;
  inset: 0;
  z-index: 2147483640; /* above chat widget; below custom modals/lightboxes that go higher */
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.pcrag-search-root.pcrag-search-theme-dark {
  --pcrag-bg: #1a1a22;
  --pcrag-fg: #e7e7ee;
  --pcrag-muted: #9ea0ab;
  --pcrag-border: rgba(255, 255, 255, 0.08);
  --pcrag-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.pcrag-search-root.pcrag-search-open {
  pointer-events: auto;
}

.pcrag-search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 150ms ease;
}

.pcrag-search-root.pcrag-search-open .pcrag-search-backdrop {
  opacity: 1;
}

.pcrag-search-card {
  position: relative;
  margin: 12vh auto 0;
  width: 92%;
  max-width: 640px;
  background: var(--pcrag-bg);
  color: var(--pcrag-fg);
  border: 1px solid var(--pcrag-border);
  border-radius: var(--pcrag-radius);
  box-shadow: var(--pcrag-shadow);
  overflow: hidden;
  /* A column with a viewport-relative cap, so the results area absorbs whatever
     is left rather than the card growing past the bottom of the screen. The
     header added height here; hard-coding a results max-height would have left
     that to luck on short viewports. */
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  transform: translateY(-12px);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.pcrag-search-root.pcrag-search-open .pcrag-search-card {
  transform: translateY(0);
  opacity: 1;
}

/* Header — same bar, same brand colour and same logo as the chat panel.
 * Mirrors .pcrag-header / .pcrag-header-left / .pcrag-header-logo in widget.css. */
.pcrag-search-header {
  padding: 12px 16px;
  background: var(--pcrag-primary);
  color: var(--pcrag-primary-fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.pcrag-search-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pcrag-search-header-logo {
  height: 24px;
  width: auto;
  max-height: 30px;
  flex-shrink: 0;
  border-radius: 4px;
  display: block;
}

.pcrag-search-header strong {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* In the header the close button sits on the brand colour, so it takes the
 * chat panel's treatment rather than the light-on-white one below. */
.pcrag-search-header .pcrag-search-close {
  opacity: 1;
  width: auto;
  height: auto;
  padding: 4px 8px;
  border-radius: 4px;
}

.pcrag-search-header .pcrag-search-close:hover,
.pcrag-search-theme-dark .pcrag-search-header .pcrag-search-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.pcrag-search-input-wrap {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--pcrag-border);
}

/* Modal leading icon — now a clickable submit button (Day 6 hotfix:
 * explicit submit replaces auto-fetch). Visual identical to prior span. */
.pcrag-search-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0.6;
  flex-shrink: 0;
}

.pcrag-search-submit:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
}

.pcrag-search-theme-dark .pcrag-search-submit:hover {
  background: rgba(255, 255, 255, 0.06);
}

.pcrag-search-submit svg {
  width: 18px;
  height: 18px;
}

.pcrag-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 16px; /* 16px minimum stops iOS zooming the page on focus */
  padding: 13px 4px;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.pcrag-search-input::placeholder {
  color: inherit;
  opacity: 0.45;
}

.pcrag-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.pcrag-search-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  opacity: 0.6;
  flex-shrink: 0;
  padding: 0;
}

.pcrag-search-close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
}

.pcrag-search-theme-dark .pcrag-search-close:hover {
  background: rgba(255, 255, 255, 0.06);
}

.pcrag-search-close svg {
  width: 18px;
  height: 18px;
}

.pcrag-search-results {
  /* Takes the space the header, input and footer do not need. min-height:0 is
     what lets a flex child actually scroll instead of stretching its parent. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0;
}

.pcrag-search-status {
  padding: 24px;
  font-size: 14px;
  opacity: 0.55;
  text-align: center;
}

.pcrag-search-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: pcrag-search-spin 0.7s linear infinite;
  vertical-align: -2px;
}

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

.pcrag-search-error {
  color: #b91c1c;
  opacity: 0.9;
}

.pcrag-search-theme-dark .pcrag-search-error {
  color: #f87171;
}

.pcrag-search-retry {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.85;
}

.pcrag-search-retry:hover {
  opacity: 1;
  background: rgba(185, 28, 28, 0.08);
}

.pcrag-search-theme-dark .pcrag-search-retry:hover {
  background: rgba(248, 113, 113, 0.12);
}

.pcrag-search-result {
  padding: 10px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  text-decoration: none;
  color: inherit;
  display: block;
}

.pcrag-search-result:hover,
.pcrag-search-result.is-active {
  background: rgba(0, 0, 0, 0.04);
  border-left-color: var(--pcrag-primary);
}

.pcrag-search-theme-dark .pcrag-search-result:hover,
.pcrag-search-theme-dark .pcrag-search-result.is-active {
  background: rgba(255, 255, 255, 0.04);
}

.pcrag-search-result-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.pcrag-search-result-snippet {
  font-size: 13px;
  opacity: 0.7;
  line-height: 1.55;
}

.pcrag-search-result-snippet mark {
  background: rgba(255, 235, 59, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.pcrag-search-theme-dark .pcrag-search-result-snippet mark {
  background: rgba(255, 235, 59, 0.25);
}

.pcrag-search-footer {
  flex-shrink: 0;
  padding: 8px 16px;
  font-size: 12px;
  opacity: 0.5;
  border-top: 1px solid var(--pcrag-border);
  text-align: right;
}

.pcrag-search-shortcut kbd {
  display: inline-block;
  padding: 2px 6px;
  font: inherit;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Mono", Menlo, monospace;
}

.pcrag-search-theme-dark .pcrag-search-shortcut kbd {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

body.pcrag-search-body-locked {
  overflow: hidden;
}

/* Nav-menu injected search trigger — minimal styling so theme's own
 * .menu-item / nav-link rules dominate. Just ensures the icon is
 * vertically aligned and cursor shows pointer.
 */
.pcrag-menu-search-item .pcrag-search-trigger {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  text-decoration: none;
}

.pcrag-menu-search-item .pcrag-search-trigger svg {
  flex-shrink: 0;
}

/* D68 floating search icon.
 * Anchored top to avoid bottom-right chat bubble collision; the exact offsets
 * are admin-configurable and arrive as an inline style, which beats the corner
 * defaults below.
 * z-index just below the modal so the modal overlays it when open. */
.pcrag-search-fab {
  position: fixed;
  display: none; /* shown via media query */
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.95);
  color: #1a1a20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  z-index: 2147483630;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Fallback corner offsets. Overridden by the inline style the widget sets from
 * the admin's "from top" / "from side" values. */
.pcrag-search-fab-top-right { top: 12px; right: 12px; }
.pcrag-search-fab-top-left  { top: 12px; left: 12px; }

.pcrag-search-fab svg { width: 22px; height: 22px; opacity: 0.85; }

.pcrag-search-fab.pcrag-search-theme-dark {
  background: rgba(26, 26, 32, 0.95);
  color: #e8e8e8;
}

.pcrag-search-fab:active {
  transform: scale(0.94);
}

/* Viewport gating, one class per admin choice. The 768px line is duplicated in
 * Search_Trigger::MOBILE_BREAKPOINT, which the settings page uses to describe
 * these options — change both together.
 *
 * There is deliberately no rule that shows every .pcrag-search-fab on mobile:
 * that is what used to make "desktop only" impossible to express. */
.pcrag-search-fab-on-both { display: inline-flex; }

@media (max-width: 768px) {
  .pcrag-search-fab-on-mobile { display: inline-flex; }
}

@media (min-width: 769px) {
  .pcrag-search-fab-on-desktop { display: inline-flex; }
}

/* Mobile narrowing — at <500px the card uses full width / less top margin. */
@media (max-width: 500px) {
  .pcrag-search-card {
    margin-top: 6vh;
    width: 96%;
    max-width: none;
    /* Sits higher on a phone, so it can also be taller. Matches the 6vh above. */
    max-height: 88vh;
  }
}

/* ───────────────────────────────────────────────────────────────────
 * Inline dropdown mode (D79) — shortcode + Gutenberg block.
 * Rendered in-page flow; positioned absolutely below input.
 * Shares result-row styling with modal (.pcrag-search-result-* classes)
 * but the wrapping container is independent.
 * ─────────────────────────────────────────────────────────────────── */

.pcrag-search-inline-wrap {
  position: relative;
  display: block;
  width: 100%;
  max-width: 480px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a20;
}

.pcrag-search-inline-style-card { padding: 12px; background: rgba(0,0,0,0.02); border-radius: 12px; }
.pcrag-search-inline-style-minimal { max-width: 320px; }

/* Inline mode: input + submit button laid out side-by-side.
 * Submit button matches input height for clean alignment. */
.pcrag-search-inline-input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.pcrag-search-inline-input {
  flex: 1;
  min-width: 0;
  display: block;
  padding: 10px 14px;
  font: inherit;
  font-size: 16px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  outline: 0;
  background: #ffffff;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
}

.pcrag-search-inline-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: #ffffff;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.pcrag-search-inline-submit:hover {
  background: var(--pcrag-primary, #2271b1);
  border-color: var(--pcrag-primary, #2271b1);
  color: #ffffff;
}

.pcrag-search-inline-submit svg {
  width: 18px;
  height: 18px;
}

.pcrag-search-theme-dark .pcrag-search-inline-submit,
.pcrag-search-inline-wrap.pcrag-search-theme-dark .pcrag-search-inline-submit {
  background: #1a1a20;
  border-color: rgba(255, 255, 255, 0.15);
}

.pcrag-search-inline-input::placeholder { color: inherit; opacity: 0.45; }

.pcrag-search-inline-input:focus {
  border-color: var(--pcrag-primary, #2271b1);
  box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.15);
}

.pcrag-search-inline-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.pcrag-search-inline-dropdown[hidden] { display: none; }

.pcrag-search-inline-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  z-index: 2147483635; /* above page content, below modal */
  padding: 4px 0;
}

.pcrag-search-inline-style-card .pcrag-search-inline-dropdown {
  left: 12px;
  right: 12px;
}

/* Dark theme — applied when search root has .pcrag-search-theme-dark
 * (added by JS based on cfg.theme === 'dark'), OR via prefers-color-scheme
 * fallback for sites without explicit theme config. */
.pcrag-search-theme-dark .pcrag-search-inline-input,
.pcrag-search-inline-wrap.pcrag-search-theme-dark .pcrag-search-inline-input {
  background: #1a1a20;
  border-color: rgba(255, 255, 255, 0.15);
  color: #e8e8e8;
}

.pcrag-search-theme-dark .pcrag-search-inline-dropdown,
.pcrag-search-inline-wrap.pcrag-search-theme-dark .pcrag-search-inline-dropdown {
  background: #1a1a20;
  border-color: rgba(255, 255, 255, 0.1);
  color: #e8e8e8;
}

.pcrag-search-inline-style-card.pcrag-search-theme-dark {
  background: rgba(255, 255, 255, 0.04);
}
