/**
 * Baseline styles for the AI search components.
 *
 * Every selector is prefixed `ais-` and every custom property `--ais-`, because
 * these ship into whatever theme is active and `.btn`, `.error` and `--primary`
 * are not ours to claim. Nothing here styles a bare element selector for the
 * same reason.
 *
 * Restyle by redefining the properties below, or drop the lot with
 * wp_dequeue_style( 'ionata-ai-search' ) and start over.
 */

:root {
    --ais-primary: var(--bs-primary, #1c4b8b);
    --ais-ink: #1a1a1a;
    --ais-muted: #5c6470;
    --ais-line: #d8dce3;
    --ais-surface: #f6f7f9;
    --ais-danger: #8b1c1c;
    --ais-gap: 1rem;
    --ais-title-size: 1.325rem;
}

/* ---------- icons ---------- */

/**
 * Font-icon style: `<i class="ais-icon--search"></i>` draws the glyph at the
 * current font size in the current text colour. Masks rather than backgrounds,
 * so `color` reaches the artwork. Add an icon by dropping an SVG in
 * assets/icons and pairing it with one more `ais-icon--*` rule.
 */
[class*="ais-icon--"] {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.ais-icon--search {
    -webkit-mask-image: url("../icons/search.svg");
    mask-image: url("../icons/search.svg");
}

/* ---------- search form ---------- */

.ais-form { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }

.ais-form__field { position: relative; display: grid; }

.ais-form__input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    font: inherit;
    border: 1px solid var(--ais-line);
    border-radius: 4px;
}
/* Hide the native clear button; .ais-form__clear replaces it and also resets results. */
.ais-form__input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.ais-form__clear {
    position: absolute;
    right: 0.5rem;
    align-self: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 0;
    border-radius: 50%;
    background: var(--ais-line);
    color: var(--ais-ink);
    font: inherit;
    line-height: 1;
    cursor: pointer;
}

.ais-form__submit {
    display: flex;
    align-items: center;
    gap: 0.25em;
    padding: 0 1.25rem;
    font: inherit;
    color: #fff;
    background: var(--ais-primary);
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}
.ais-form__submit[disabled] { opacity: 0.55; cursor: not-allowed; }
/* Icons size off font-size, so this scales the 1em box rather than the label. */
.ais-form__submit .ais-icon--search { font-size: 1.5em; }

/* ---------- status, error ---------- */

.ais-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: var(--ais-gap);
    color: var(--ais-muted);
    font-size: 0.9rem;
}

.ais-spinner {
    width: 0.85em;
    height: 0.85em;
    border: 2px solid var(--ais-line);
    border-top-color: var(--ais-primary);
    border-radius: 50%;
    animation: ais-spin 0.7s linear infinite;
}
@keyframes ais-spin { to { transform: rotate(360deg); } }

.ais-error {
    margin-top: var(--ais-gap);
    padding: 0.75rem 1rem;
    border: 1px solid var(--ais-danger);
    border-radius: 4px;
    color: var(--ais-danger);
    background: #fdf6f6;
}
.ais-error__detail { margin-top: 0.5rem; font-size: 0.8rem; opacity: 0.8; }
.ais-error__detail code { word-break: break-all; }

/* ---------- links between the two searches ---------- */

/*
 * Placed by the theme rather than by a template, so these can land under a form
 * or under an error and have no one neighbour to space themselves against.
 *
 * `.ais-ai-link` renders on the classic page, which does not load this
 * stylesheet unless the theme enqueues it there. Treat it as a starting point
 * rather than as the styling.
 */
.ais-classic-link,
.ais-ai-link { margin-top: 0.5rem; font-size: 0.9rem; }

.ais-classic-link a,
.ais-ai-link a { color: var(--ais-primary); }

/* ---------- summary ---------- */

.ais-summary { margin-top: var(--ais-gap); }
.ais-summary a { color: var(--ais-primary); }
/* A link whose excerpt has not streamed in yet has no href to point at. */
.ais-summary__link--pending {
    color: var(--ais-muted);
    text-decoration-style: dotted;
    cursor: default;
}

.ais-skeleton__line {
    margin-top: var(--ais-gap);
    height: 1.1em;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--ais-surface), #eceef2, var(--ais-surface));
    background-size: 200% 100%;
    animation: ais-shimmer 1.2s linear infinite;
}
.ais-skeleton__line + .ais-skeleton__line { width: 70%; }
@keyframes ais-shimmer { to { background-position: -200% 0; } }

/* ---------- results ---------- */

.ais-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ais-result {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    padding: 0.85rem;
    border: 1px solid var(--ais-line);
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
}
.ais-result:hover { border-color: var(--ais-primary); background: var(--ais-surface); text-decoration: none; }

.ais-result__body { flex: 1 1 auto; min-width: 0; }
.ais-result__title { display: block; margin: 0 0 0.25rem; color: var(--ais-primary); font-size: var(--ais-title-size); }
.ais-result__excerpt { margin: 0; color: var(--ais-muted); }
.ais-result__meta { display: block; margin-top: 0.35rem; font-size: 0.875rem; color: var(--ais-muted); }
.ais-result__thumb { flex: 0 0 88px; width: 88px; aspect-ratio: 1; object-fit: cover; border-radius: 3px; }

.ais-no-results { margin-top: var(--ais-gap); color: var(--ais-muted); }

/* ---------- feedback ---------- */

.ais-feedback {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.625rem;
    margin-top: 1.5rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--ais-line);
    font-size: 0.875rem;
}
.ais-feedback__spacer { margin-left: auto; }
.ais-feedback__note { color: var(--ais-muted); }

.ais-btn {
    padding: 0.35rem 0.7rem;
    font: inherit;
    font-size: 0.875rem;
    color: inherit;
    background: #fff;
    border: 1px solid var(--ais-line);
    border-radius: 4px;
    cursor: pointer;
}
.ais-btn:not([disabled]):hover { border-color: var(--ais-muted); }
/* Filled: a toggle that is on, or a one-shot button whose action has landed. */
.ais-btn[aria-pressed="true"],
.ais-btn--filled { background: var(--ais-primary); border-color: var(--ais-primary); color: #fff; }
.ais-btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.ais-btn--link {
    border: 0;
    background: none;
    padding: 0;
    text-decoration: underline;
    cursor: pointer;
}
.ais-btn--link:not([disabled]):hover { text-decoration: none; }

.ais-panel {
    margin-top: 0.85rem;
    margin-bottom: 0.85rem;
    padding: 1rem;
    border: 1px solid var(--ais-line);
    border-radius: 4px;
    background: var(--ais-surface);
}
.ais-panel__head { display: flex; align-items: flex-start; gap: 1rem; }
.ais-panel__title { margin: 0; color: var(--ais-primary); font-size: var(--ais-title-size); }
.ais-panel__dismiss { margin-left: auto; }

.ais-reasons {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0.85rem 0 0;
    padding: 0;
    list-style: none;
}
.ais-reason { display: flex; width: 100%; text-align: left; align-items: center; gap: 0.5rem; font-size: inherit; }
.ais-reason__tick { margin-left: auto; }

.ais-field { margin-top: 0.85rem; }
.ais-field > label { display: block; margin-bottom: 0.35rem; font-weight: 600; }

.ais-field textarea {
    box-sizing: border-box;
    display: block;
    width: 100%;
    min-height: 5.5rem;
    padding: 0.6rem;
    font: inherit;
    border: 1px solid var(--ais-line);
    border-radius: 4px;
    resize: vertical;
}

.ais-rating { display: flex; gap: 0.35rem; }
.ais-actions { display: flex; align-items:center; justify-content: flex-end; gap: 0.5rem; margin-top: 0.85rem; }
.ais-sent { color: var(--ais-muted); font-size: 0.875rem; }
