/* =====================================================================
   Local Smart Search — widget styles
   CSS variables set per-instance by the Widget/Shortcodes renderers.
   Theming: data-theme = light | dark | auto
   Radius:  data-radius = none | small | medium | large | pill
   ===================================================================== */

:root,
#lss-widget-root,
.lss-inline-wrap {
  --lss-brand: #2563eb;
  --lss-brand-soft: color-mix(in srgb, var(--lss-brand) 12%, transparent);
  --lss-button-bg: var(--lss-brand);
  --lss-button-icon: #ffffff;
  --lss-header-bg: var(--lss-brand);
  --lss-header-text: #ffffff;
  --lss-panel-bg: #ffffff;
  --lss-surface-2: #f8fafc;
  --lss-text: #0f172a;
  --lss-muted: #64748b;
  --lss-border: #e5e7eb;
  --lss-bubble-user-bg: var(--lss-brand);
  --lss-bubble-user-text: #ffffff;
  --lss-bubble-assistant-bg: #f1f5f9;
  --lss-bubble-assistant-text: var(--lss-text);
  --lss-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  --lss-shadow-lift: 0 18px 60px rgba(15, 23, 42, 0.24);
  --lss-radius: 14px;
  --lss-radius-bubble: 18px;
  --lss-radius-button: 14px;
  --lss-transition: 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

#lss-widget-root[data-theme="dark"],
.lss-inline-wrap[data-theme="dark"] {
  --lss-panel-bg: #0f172a;
  --lss-surface-2: #1e293b;
  --lss-text: #f8fafc;
  --lss-muted: #94a3b8;
  --lss-border: #334155;
  --lss-bubble-assistant-bg: #1e293b;
  --lss-bubble-assistant-text: #f8fafc;
  --lss-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  #lss-widget-root[data-theme="auto"],
  .lss-inline-wrap[data-theme="auto"] {
    --lss-panel-bg: #0f172a;
    --lss-surface-2: #1e293b;
    --lss-text: #f8fafc;
    --lss-muted: #94a3b8;
    --lss-border: #334155;
    --lss-bubble-assistant-bg: #1e293b;
    --lss-bubble-assistant-text: #f8fafc;
    --lss-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

#lss-widget-root[data-radius="none"],
.lss-inline-wrap[data-radius="none"] { --lss-radius: 0; --lss-radius-bubble: 4px; --lss-radius-button: 0; }
#lss-widget-root[data-radius="small"],
.lss-inline-wrap[data-radius="small"] { --lss-radius: 6px; --lss-radius-bubble: 10px; --lss-radius-button: 8px; }
#lss-widget-root[data-radius="medium"],
.lss-inline-wrap[data-radius="medium"] { --lss-radius: 14px; --lss-radius-bubble: 18px; --lss-radius-button: 14px; }
#lss-widget-root[data-radius="large"],
.lss-inline-wrap[data-radius="large"] { --lss-radius: 20px; --lss-radius-bubble: 22px; --lss-radius-button: 18px; }
#lss-widget-root[data-radius="pill"],
.lss-inline-wrap[data-radius="pill"] { --lss-radius: 28px; --lss-radius-bubble: 24px; --lss-radius-button: 999px; }

#lss-widget-root,
#lss-widget-root *,
.lss-inline-wrap,
.lss-inline-wrap * {
  box-sizing: border-box;
}

/* --- Floating button --------------------------------------------------- */
.lss-button {
  position: fixed;
  z-index: 2147483640;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--lss-button-bg);
  color: var(--lss-button-icon);
  border: none;
  box-shadow: var(--lss-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
  transition: transform var(--lss-transition), box-shadow var(--lss-transition);
}

.lss-button:hover { transform: scale(1.06); box-shadow: var(--lss-shadow-lift); }
.lss-button:focus-visible { outline: 3px solid var(--lss-brand-soft); outline-offset: 3px; }

.lss-button-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 2px var(--lss-panel-bg);
  animation: lss-pulse 2s ease-in-out infinite;
}
@keyframes lss-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.85); opacity: 0.6; }
}

#lss-widget-root[data-position="bottom-right"] .lss-button { right: 24px; bottom: 24px; }
#lss-widget-root[data-position="bottom-left"]  .lss-button { left: 24px;  bottom: 24px; }
#lss-widget-root[data-position="top-right"]    .lss-button { right: 24px; top: 24px; }
#lss-widget-root[data-position="top-left"]     .lss-button { left: 24px;  top: 24px; }

/* --- Panel ------------------------------------------------------------- */
.lss-panel {
  position: fixed;
  z-index: 2147483641;
  width: 400px;
  max-width: calc(100vw - 24px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--lss-panel-bg);
  color: var(--lss-text);
  border: 1px solid var(--lss-border);
  border-radius: var(--lss-radius);
  box-shadow: var(--lss-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity var(--lss-transition), transform var(--lss-transition);
  pointer-events: none;
}

.lss-panel[data-open="true"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#lss-widget-root[data-position="bottom-right"] .lss-panel { right: 24px; bottom: 96px; }
#lss-widget-root[data-position="bottom-left"]  .lss-panel { left: 24px;  bottom: 96px; }
#lss-widget-root[data-position="top-right"]    .lss-panel { right: 24px; top: 96px; }
#lss-widget-root[data-position="top-left"]     .lss-panel { left: 24px;  top: 96px; }

@media (max-width: 480px) {
  .lss-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    max-height: 85vh;
  }
  #lss-widget-root[data-position$="-right"] .lss-panel { right: 8px; }
  #lss-widget-root[data-position$="-left"]  .lss-panel { left: 8px; }
  #lss-widget-root[data-position^="bottom-"] .lss-panel { bottom: 88px; }
  #lss-widget-root[data-position^="top-"]    .lss-panel { top: 88px; }
}

/* --- Header ------------------------------------------------------------ */
.lss-header {
  background: var(--lss-header-bg);
  color: var(--lss-header-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.lss-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  position: relative;
}

.lss-header-avatar::after {
  content: "";
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--lss-header-bg);
}

.lss-header-text {
  flex: 1;
  min-width: 0;
}

.lss-header-title {
  margin: 0 !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  line-height: 1.1 !important;
  color: var(--lss-header-text) !important;
  font-family: inherit !important;
  text-shadow: none !important;
  background: transparent !important;
  -webkit-text-fill-color: var(--lss-header-text) !important;
}

.lss-header-status {
  font-size: 11px;
  opacity: 0.85;
  display: block;
  margin-top: 2px;
  color: var(--lss-header-text) !important;
  -webkit-text-fill-color: var(--lss-header-text) !important;
}

.lss-close {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background var(--lss-transition);
}

.lss-close:hover { background: rgba(255, 255, 255, 0.15); }
.lss-close:focus-visible { outline: 2px solid var(--lss-header-text); outline-offset: 2px; }

/* --- Conversation (scrollable) ---------------------------------------- */
.lss-conversation {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--lss-panel-bg);
}

.lss-conversation::-webkit-scrollbar { width: 6px; }
.lss-conversation::-webkit-scrollbar-thumb { background: var(--lss-border); border-radius: 3px; }
.lss-conversation::-webkit-scrollbar-thumb:hover { background: var(--lss-muted); }

/* --- Message bubbles --------------------------------------------------- */
.lss-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: lss-msg-in 280ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  max-width: 100%;
}

@keyframes lss-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lss-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--lss-brand);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.lss-msg-bubble {
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  border-radius: var(--lss-radius-bubble);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.lss-msg[data-role="assistant"] .lss-msg-bubble {
  background: var(--lss-bubble-assistant-bg);
  color: var(--lss-bubble-assistant-text);
  border-bottom-left-radius: 6px;
}

.lss-msg[data-role="user"] {
  justify-content: flex-end;
}

.lss-msg[data-role="user"] .lss-msg-bubble {
  background: var(--lss-bubble-user-bg);
  color: var(--lss-bubble-user-text);
  border-bottom-right-radius: 6px;
}

.lss-msg[data-role="user"] .lss-msg-avatar {
  display: none;
}

/* --- Typing indicator -------------------------------------------------- */
.lss-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.lss-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lss-muted);
  animation: lss-typing 1.4s infinite ease-in-out;
}

.lss-typing span:nth-child(2) { animation-delay: 0.2s; }
.lss-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lss-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Result cards (inside assistant bubbles) -------------------------- */
.lss-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.lss-result {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--lss-panel-bg);
  border: 1px solid var(--lss-border);
  border-radius: calc(var(--lss-radius-bubble) - 4px);
  text-decoration: none;
  color: var(--lss-text);
  transition: border-color var(--lss-transition), transform var(--lss-transition), box-shadow var(--lss-transition);
  position: relative;
}

.lss-result:hover,
.lss-result:focus-visible {
  border-color: var(--lss-brand);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--lss-brand-soft);
  outline: none;
}

.lss-result-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--lss-brand-soft);
  color: var(--lss-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.lss-result-body {
  flex: 1;
  min-width: 0;
}

.lss-result-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--lss-brand);
  line-height: 1.3;
  margin: 0 0 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.lss-result-title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lss-result-arrow {
  color: var(--lss-muted);
  transition: transform var(--lss-transition), color var(--lss-transition);
  font-size: 14px;
}

.lss-result:hover .lss-result-arrow,
.lss-result:focus-visible .lss-result-arrow {
  color: var(--lss-brand);
  transform: translateX(2px);
}

.lss-result-excerpt {
  font-size: 12.5px;
  color: var(--lss-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lss-result-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.lss-chip {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--lss-surface-2);
  color: var(--lss-muted);
  font-weight: 600;
}

.lss-chip[data-confidence="high"] { background: #dcfce7; color: #166534; }
.lss-chip[data-confidence="medium"] { background: #fef3c7; color: #854d0e; }
.lss-chip[data-confidence="low"] { background: #fee2e2; color: #991b1b; }

#lss-widget-root[data-theme="dark"] .lss-chip[data-confidence="high"],
.lss-inline-wrap[data-theme="dark"] .lss-chip[data-confidence="high"] { background: rgba(34, 197, 94, 0.2); color: #86efac; }
#lss-widget-root[data-theme="dark"] .lss-chip[data-confidence="medium"],
.lss-inline-wrap[data-theme="dark"] .lss-chip[data-confidence="medium"] { background: rgba(234, 179, 8, 0.2); color: #fde047; }
#lss-widget-root[data-theme="dark"] .lss-chip[data-confidence="low"],
.lss-inline-wrap[data-theme="dark"] .lss-chip[data-confidence="low"] { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

/* --- Suggestion chips (first open) ------------------------------------ */
.lss-suggestions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.lss-suggestion {
  background: transparent;
  border: 1px solid var(--lss-border);
  color: var(--lss-text);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: all var(--lss-transition);
  font-family: inherit;
}

.lss-suggestion:hover,
.lss-suggestion:focus-visible {
  background: var(--lss-brand-soft);
  border-color: var(--lss-brand);
  color: var(--lss-brand);
  outline: none;
}

/* --- Recent history section ------------------------------------------- */
.lss-msg-history .lss-msg-bubble {
  background: transparent;
  padding: 2px 0;
}

.lss-history-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px dashed var(--lss-border);
  border-radius: calc(var(--lss-radius-bubble) - 4px);
  padding: 10px 12px;
  background: var(--lss-surface-2);
}

.lss-history-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--lss-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.lss-history-icon { display: inline-flex; }

.lss-history-chips { margin-top: 0; }

.lss-history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lss-history-link {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--lss-text);
  text-decoration: none;
  font-size: 13px;
  transition: background var(--lss-transition);
  overflow: hidden;
}

.lss-history-link:hover,
.lss-history-link:focus-visible {
  background: var(--lss-brand-soft);
  outline: none;
}

.lss-history-link-icon { flex-shrink: 0; }
.lss-history-link-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.lss-history-clear {
  align-self: flex-start;
  background: transparent;
  border: 0;
  color: var(--lss-muted);
  padding: 2px 4px;
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}

.lss-history-clear:hover { color: var(--lss-brand); }

/* --- Composer (stuck at bottom) --------------------------------------- */
.lss-composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--lss-border);
  padding: 10px 12px;
  background: var(--lss-panel-bg);
}

.lss-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--lss-surface-2);
  border: 1px solid var(--lss-border);
  border-radius: var(--lss-radius-button);
  padding: 6px 6px 6px 14px;
  transition: border-color var(--lss-transition), box-shadow var(--lss-transition);
}

.lss-composer-row:focus-within {
  border-color: var(--lss-brand);
  box-shadow: 0 0 0 3px var(--lss-brand-soft);
}

.lss-input {
  flex: 1;
  min-height: 20px;
  max-height: 120px;
  border: 0;
  background: transparent;
  color: var(--lss-text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  padding: 8px 0;
  resize: none;
  outline: none;
  width: 100%;
}

.lss-input::placeholder { color: var(--lss-muted); }

.lss-submit {
  background: var(--lss-brand);
  color: var(--lss-button-icon);
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: calc(var(--lss-radius-button) - 2px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background var(--lss-transition), transform var(--lss-transition), opacity var(--lss-transition);
  flex-shrink: 0;
}

.lss-submit svg,
.lss-close svg,
.lss-button svg,
.lss-result-arrow svg,
.lss-history-icon svg {
  stroke: currentColor !important;
  fill: none !important;
  color: inherit !important;
  display: inline-block !important;
  vertical-align: middle;
  min-width: 18px;
}

.lss-submit svg *,
.lss-close svg *,
.lss-button svg *,
.lss-result-arrow svg *,
.lss-history-icon svg * {
  stroke: currentColor !important;
  fill: none !important;
}

.lss-close { color: var(--lss-header-text) !important; }
.lss-button { color: var(--lss-button-icon) !important; }
.lss-submit { color: var(--lss-button-icon) !important; }

.lss-submit:hover:not(:disabled) { transform: scale(1.05); }
.lss-submit:disabled { opacity: 0.45; cursor: not-allowed; }
.lss-submit:focus-visible { outline: 2px solid var(--lss-brand); outline-offset: 2px; }

/* --- Footer ----------------------------------------------------------- */
.lss-footer {
  flex: 0 0 auto;
  padding: 6px 12px 8px;
  font-size: 10.5px;
  color: var(--lss-muted);
  text-align: center;
  background: var(--lss-panel-bg);
  border-top: 1px solid var(--lss-border);
}

.lss-footer a { color: var(--lss-muted); text-decoration: none; }
.lss-footer a:hover { color: var(--lss-brand); }

/* --- Inline mode (shortcode) ------------------------------------------ */
.lss-inline-wrap .lss-panel {
  position: relative;
  inset: auto;
  width: 100%;
  height: 520px;
  max-height: 70vh;
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.lss-inline-wrap .lss-header { display: none; }

/* --- Accessibility ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .lss-panel,
  .lss-button,
  .lss-msg,
  .lss-result,
  .lss-submit,
  .lss-suggestion,
  .lss-typing span,
  .lss-button-badge {
    animation: none !important;
    transition: none !important;
  }
}
