/*
 * ARX F.A.Q. — Frontend Base Styles
 *
 * Minimal structural base — intended to be overridden per project.
 * All colors come from 4 CSS variables injected by Arx_Faq_Options:
 *
 *   --arx-faq-primary      Accent (question background, active borders)
 *   --arx-faq-secondary    Subtle background (answer area, container)
 *   --arx-faq-text-light   Text on primary background
 *   --arx-faq-text-dark    Text on secondary/light background
 *
 * Accordion animation uses the CSS grid-template-rows trick (0fr → 1fr).
 * Closed panels use the HTML hidden attribute (removed by JS when open) so
 * focus cannot reach collapsed answer content.
 */

/* ---- Screen reader only (visible label for search, live status) ---- */
.arx-faq-screen-reader-text {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ---- Container ---- */
.arx-faq-container {
    width: 100%;
    margin: 1rem 0;
}

/* ---- Title ---- */
.arx-faq-title {
    margin: 0 0 0.5rem;
    color: var(--arx-faq-primary, #3a7bd5);
}

.arx-faq-icon-title {
    margin-right: 0.35em;
}

.arx-faq-icon-img {
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    object-fit: contain;
    vertical-align: -0.15em;
}

.arx-faq-description {
    margin: 0 0 0.75rem;
    color: var(--arx-faq-text-dark, #222);
}

/* ---- Search ---- */
.arx-faq-search-wrap {
    margin-bottom: 0.75rem;
}

.arx-faq-search {
    display: block;
    width: 100%;
    padding: 0.45rem 0.75rem;
    font-size: inherit;
    font-family: inherit;
    color: var(--arx-faq-text-dark, #222);
    background: var(--arx-faq-secondary, #f0f4fb);
    box-sizing: border-box;
}

.arx-faq-search-status {
    margin: 0;
}

/* ---- List / Items ---- */
.arx-faq-list {
    
}

.arx-faq-item + .arx-faq-item {
    border-top: 1px solid var(--arx-faq-primary, #3a7bd5);
}

/* ---- Question button (accordion) ---- */
.arx-faq-question {
    display: flex;
    align-items: center;
    font-size: 30px;
    width: 100%;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    font-family: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    background: transparent;
    color: var(--arx-faq-text-dark, #000);
    border: none;
    outline: none;
}

.arx-faq-question:focus-visible {
    outline: 2px solid var(--arx-faq-text-light, #fff);
    outline-offset: -2px;
}

/* ---- Question heading (flat layout — non-interactive) ---- */
.arx-faq-question-heading {
    display: flex;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    font-size: inherit;
    font-family: inherit;
    font-weight: 600;
    text-align: left;
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
    box-sizing: border-box;
}

.arx-faq-icon-question {
    flex-shrink: 0;
}

.arx-faq-question-text {
    flex: 1;
}

.arx-faq-toggle-icon {
    flex-shrink: 0;
    margin-left: auto;
    min-width: 1em;
    text-align: center;
    transition: transform 0.25s ease;
    transform-origin: center;
}

img.arx-faq-toggle-icon {
    width: 1.1em;
    height: 1.1em;
}

.arx-faq-accordion[data-icon-yflip="1"] .arx-faq-item.is-open .arx-faq-toggle-icon {
    transform: scaleY(-1);
}

/* ---- Answer panel — animation via grid-template-rows ---- */
.arx-faq-answer {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s ease;
}

.arx-faq-answer[hidden] {
    display: none;
}

.arx-faq-item.is-open > .arx-faq-answer {
    display: grid;
    grid-template-rows: 1fr;
}

.arx-faq-answer-inner {
    overflow: hidden;
    /* Preserve intentional line breaks inside HTML text nodes (e.g. <p>line1\nline2</p>). */
    white-space: pre-line;
    /* Padding at 0 when closed, animated to normal when open */
    padding: 0 1rem;
    background: transparent;
    color: var(--arx-faq-text-dark, #222);
    transition: padding 0.25s ease;
}

.arx-faq-item.is-open > .arx-faq-answer > .arx-faq-answer-inner {
    padding: 0.75rem 1rem;
}

.arx-faq-answer-inner > *:first-child { margin-top: 0; }
.arx-faq-answer-inner > *:last-child  { margin-bottom: 0; }

/* ---- Flat style — always fully open, no animation ---- */
.arx-faq-flat .arx-faq-answer {
    grid-template-rows: 1fr;
    transition: none;
}

.arx-faq-flat .arx-faq-answer-inner {
    padding: 0.75rem 1rem;
    transition: none;
}

/* ---- No result message ---- */
.arx-faq-no-result {
    margin: 0.5rem 0;
    color: var(--arx-faq-text-dark, #222);
    font-style: italic;
}

/* ---- All wrapper ---- */
.arx-faq-all > .arx-faq-container {
    margin-bottom: 1.5rem;
}

/* ---- JS search filter ---- */
.arx-faq-item.arx-faq-hidden {
    display: none;
}

/* ---- FAQ lite assistant (popup) ---- */
body.arx-faq-ai-open {
    overflow: hidden;
}

.arx-faq-ai-root {
    /* Launcher + panel sit above page content */
    z-index: 99990;
}

.arx-faq-ai-launcher {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
    /* Above backdrop/panel so "?" always toggles the popup */
    z-index: 99994;
}

.arx-faq-ai-launcher:hover,
.arx-faq-ai-launcher:focus-visible {
    filter: brightness(1.08);
    outline: 2px solid var(--arx-faq-primary, #3a7bd5);
    outline-offset: 2px;
}

/* Closed by default: author display:flex must not override HTML hidden (some themes break [hidden]). */
.arx-faq-ai-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 99992;
    display: none;
    pointer-events: none;
}

.arx-faq-ai-panel {
    position: fixed;
    right: 1rem;
    bottom: 5rem;
    width: min(22rem, calc(100vw - 2rem));
    max-height: min(32rem, calc(100vh - 6rem));
    display: none;
    flex-direction: column;
    background: var(--arx-faq-secondary, #f0f4fb);
    color: var(--arx-faq-text-dark, #222);
    border: 1px solid var(--arx-faq-primary, #3a7bd5);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    z-index: 99993;
    box-sizing: border-box;
    pointer-events: none;
}

.arx-faq-ai-root.arx-faq-ai--open .arx-faq-ai-backdrop {
    display: block;
    pointer-events: auto;
}

.arx-faq-ai-root.arx-faq-ai--open .arx-faq-ai-panel {
    display: flex;
    pointer-events: auto;
}

.arx-faq-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
    flex-shrink: 0;
}

.arx-faq-ai-header-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.arx-faq-ai-close {
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.35rem;
    border-radius: 2px;
}

.arx-faq-ai-close:focus-visible {
    outline: 2px solid var(--arx-faq-text-light, #fff);
    outline-offset: 2px;
}

.arx-faq-ai-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.65rem 0.75rem;
    min-height: 6rem;
    max-height: 18rem;
}

.arx-faq-ai-msg {
    margin-bottom: 0.65rem;
    font-size: 0.9rem;
    line-height: 1.45;
}

.arx-faq-ai-msg-user {
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
    margin-left: 1.5rem;
    word-break: break-word;
}

.arx-faq-ai-msg-bot {
    padding: 0.35rem 0;
    margin-right: 0.5rem;
    word-break: break-word;
}

.arx-faq-ai-msg-system {
    font-style: italic;
    color: var(--arx-faq-text-dark, #222);
    opacity: 0.85;
}

.arx-faq-ai-msg-loading {
    opacity: 0.8;
}

.arx-faq-ai-form {
    display: flex;
    gap: 0.35rem;
    padding: 0.65rem 0.75rem;
    border-top: 1px solid var(--arx-faq-primary, #3a7bd5);
    flex-shrink: 0;
    box-sizing: border-box;
}

.arx-faq-ai-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.45rem 0.55rem;
    font: inherit;
    border: 1px solid var(--arx-faq-primary, #3a7bd5);
    box-sizing: border-box;
    background: #fff;
    color: var(--arx-faq-text-dark, #222);
}

.arx-faq-ai-submit {
    flex-shrink: 0;
    padding: 0.45rem 0.65rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
}

.arx-faq-ai-submit:focus-visible {
    outline: 2px solid var(--arx-faq-primary, #3a7bd5);
    outline-offset: 2px;
}

.arx-faq-ai-lite-result + .arx-faq-ai-lite-result {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.arx-faq-ai-lite-source {
    margin: 0 0 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.85;
}

.arx-faq-ai-lite-question {
    margin: 0 0 0.35rem;
    font-size: 0.9rem;
    color: var(--arx-faq-primary, #3a7bd5);
}

.arx-faq-ai-lite-answer {
    font-size: 0.875rem;
}

.arx-faq-ai-lite-answer > *:first-child {
    margin-top: 0;
}

.arx-faq-ai-lite-answer > *:last-child {
    margin-bottom: 0;
}

/* ---- AI assistant — no answer fallback block ---- */
.arx-faq-ai-no-answer {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.arx-faq-ai-no-answer-text {
    margin: 0;
}

.arx-faq-ai-no-answer-img {
    display: block;
    max-width: 50%;
    height: auto;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.arx-faq-ai-no-answer-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font: inherit;
    border: none;
    background: var(--arx-faq-primary, #3a7bd5);
    color: var(--arx-faq-text-light, #fff);
    width: fit-content;
}

.arx-faq-ai-no-answer-cta:hover,
.arx-faq-ai-no-answer-cta:focus-visible {
    filter: brightness(1.08);
    outline: 2px solid var(--arx-faq-primary, #3a7bd5);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .arx-faq-ai-launcher,
    .arx-faq-ai-panel {
        transition: none;
    }
}

@media (max-width: 480px) {
    .arx-faq-ai-panel {
        right: 0.5rem;
        left: 0.5rem;
        width: auto;
        bottom: 4.5rem;
    }
}
