/*
 * Base AI widget: structure only. Zero specificity (:where) so any child-theme
 * rule wins without !important. Contract: docs/base-ai-widget.md.
 */
:where(.base-ai) {
	--base-ai-accent: var(--base-primary, #111);
	--base-ai-on-accent: var(--base-on-primary, #fff);
	--base-ai-surface: var(--wp--preset--color--base, #fff);
	--base-ai-text: var(--wp--preset--color--contrast, #111);
	--base-ai-muted: color-mix(in srgb, var(--base-ai-text) 60%, transparent);
	--base-ai-line: color-mix(in srgb, var(--base-ai-text) 14%, transparent);
	--base-ai-radius: 12px;
	--base-ai-font: inherit;
	--base-ai-z: 9990;
	--base-ai-control: 38px; /* Send button size = the composer's resting height. */
	font-family: var(--base-ai-font);
	color: var(--base-ai-text);
	font-size: 15px;
	line-height: 1.5;
}
:where(.base-ai) [hidden] { display: none !important; }
:where(.base-ai) .base-ai__icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }

:where(.base-ai) .base-ai__launcher {
	position: fixed; inset-block-end: 20px; inset-inline-end: 20px; z-index: var(--base-ai-z);
	display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border: 0;
	border-radius: 999px; background: var(--base-ai-accent); color: var(--base-ai-on-accent);
	font: inherit; cursor: pointer;
}
:where(.base-ai) .base-ai__launcher .base-ai__icon { width: 20px; height: 20px; }
:where(.base-ai) .base-ai__launcher--icon { padding: 14px; } /* No text: a round icon button. */

:where(.base-ai) .base-ai__panel {
	position: fixed; inset-block-end: 84px; inset-inline-end: 20px; z-index: var(--base-ai-z);
	display: flex; flex-direction: column; width: min(400px, calc(100vw - 24px)); height: min(620px, calc(100dvh - 110px));
	background: var(--base-ai-surface); color: var(--base-ai-text);
	border: 1px solid var(--base-ai-line); border-radius: var(--base-ai-radius); overflow: hidden;
}
:where(.base-ai--inline) .base-ai__panel { position: static; width: 100%; height: 640px; }
@media (max-width: 480px) {
	:where(.base-ai) .base-ai__panel { inset: 0; width: 100%; height: 100dvh; border-radius: 0; }
	:where(.base-ai--inline) .base-ai__panel { height: 560px; }
}

:where(.base-ai) .base-ai__header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-block-end: 1px solid var(--base-ai-line); }
:where(.base-ai) .base-ai__title { font-weight: 600; flex: 1; }
:where(.base-ai) .base-ai__status { font-size: 12px; color: var(--base-ai-muted); }
:where(.base-ai) .base-ai__close, :where(.base-ai) .base-ai__new { background: none; border: 0; padding: 4px; color: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
:where(.base-ai) .base-ai__new:disabled { opacity: .4; cursor: default; }
/* Phones: 44 px tap targets for the header buttons; the header row stays one line. */
@media (pointer: coarse), (max-width: 480px) {
	:where(.base-ai) .base-ai__close, :where(.base-ai) .base-ai__new { min-width: 44px; min-height: 44px; margin-block: -10px; }
	:where(.base-ai) .base-ai__close { margin-inline-end: -10px; }
}
:where(.base-ai) .base-ai__notice { margin: 0; padding: 8px 14px; font-size: 12px; color: var(--base-ai-muted); }

:where(.base-ai) .base-ai__log { flex: 1; overflow-y: auto; padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
:where(.base-ai) .base-ai__msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
:where(.base-ai) .base-ai__msg[data-role="user"] { align-self: flex-end; max-width: 85%; }
:where(.base-ai) .base-ai__msg[data-role="user"] .base-ai__text { background: var(--base-ai-accent); color: var(--base-ai-on-accent); padding: 8px 12px; border-radius: var(--base-ai-radius); white-space: pre-wrap; overflow-wrap: anywhere; }
:where(.base-ai) .base-ai__text p, :where(.base-ai) .base-ai__text ul { margin: 0 0 6px; }
:where(.base-ai) .base-ai__text > :last-child { margin-block-end: 0; }
:where(.base-ai) .base-ai__text ul { padding-inline-start: 1.2em; }
:where(.base-ai) .base-ai__msg[data-error] .base-ai__text { color: var(--base-ai-muted); }

/* Activity steps. Checklist (A): summary under the answer. Timeline (C): rail, summary above. */
:where(.base-ai) .base-ai__activity { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
:where(.base-ai[data-activity="checklist"]) .base-ai__msg[data-state="done"] .base-ai__activity { order: 5; }
:where(.base-ai) .base-ai__activity[data-collapsed="true"] .base-ai__steps { display: none; }
:where(.base-ai) .base-ai__steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
:where(.base-ai) .base-ai__step { display: flex; gap: 8px; align-items: flex-start; color: var(--base-ai-muted); animation: base-ai-in .2s ease-out; }
:where(.base-ai) .base-ai__step[data-state="running"] { color: var(--base-ai-text); }
:where(.base-ai) .base-ai__mark { display: inline-flex; width: 16px; height: 20px; align-items: center; justify-content: center; flex: none; color: var(--base-ai-accent); }
:where(.base-ai) .base-ai__step[data-state="failed"] .base-ai__mark { color: var(--base-ai-muted); }
:where(.base-ai) .base-ai__step-body { display: flex; flex-direction: column; min-width: 0; }
:where(.base-ai) .base-ai__found { font-size: 12px; color: var(--base-ai-muted); }
:where(.base-ai) .base-ai__meta { font-size: 11px; color: var(--base-ai-muted); background: none; padding: 0; overflow-wrap: anywhere; }
:where(.base-ai) .base-ai__spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--base-ai-line); border-top-color: var(--base-ai-accent); animation: base-ai-spin .8s linear infinite; }
:where(.base-ai[data-activity="timeline"]) .base-ai__steps { position: relative; padding-inline-start: 2px; }
:where(.base-ai[data-activity="timeline"]) .base-ai__step { position: relative; }
:where(.base-ai[data-activity="timeline"]) .base-ai__step:not(:last-child)::after { content: ""; position: absolute; inset-inline-start: 7px; top: 18px; bottom: -6px; width: 1.5px; background: var(--base-ai-line); }
:where(.base-ai) .base-ai__summary { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0; font: inherit; font-size: 12px; color: var(--base-ai-muted); cursor: pointer; }
:where(.base-ai) .base-ai__summary .base-ai__icon { transition: transform .15s; }
:where(.base-ai) .base-ai__summary[aria-expanded="true"] .base-ai__icon { transform: rotate(90deg); }
:where(.base-ai) .base-ai__summary[aria-expanded="true"] + .base-ai__steps { margin-block-start: 4px; }

:where(.base-ai) .base-ai__sources, :where(.base-ai) .base-ai__card, :where(.base-ai) .base-ai__prompts { display: flex; flex-wrap: wrap; gap: 6px; }
:where(.base-ai) .base-ai__source, :where(.base-ai) .base-ai__action, :where(.base-ai) .base-ai__prompt {
	display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--base-ai-line);
	border-radius: 999px; font: inherit; font-size: 13px; color: inherit; text-decoration: none; background: none; cursor: pointer;
}
:where(.base-ai) .base-ai__foot { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--base-ai-muted); }
:where(.base-ai) .base-ai__msg[data-role="user"] .base-ai__foot { justify-content: flex-end; }
:where(.base-ai) .base-ai__feedback { display: flex; gap: 2px; order: 2; }

:where(.base-ai) .base-ai__rate { background: none; border: 0; padding: 4px; color: var(--base-ai-muted); cursor: pointer; display: inline-flex; }
:where(.base-ai) .base-ai__thanks { font-size: 12px; color: var(--base-ai-muted); }

/* Lead card. Fields may take the theme's own input styles. */
:where(.base-ai) .base-ai__card[data-type="lead"] { display: block; padding: 12px; border: 1px solid var(--base-ai-line); border-radius: var(--base-ai-radius); }
:where(.base-ai) .base-ai__lead { display: grid; gap: 8px; }
:where(.base-ai) .base-ai__field { display: grid; gap: 2px; font-size: 12px; color: var(--base-ai-muted); }
:where(.base-ai) .base-ai__field-input { font: inherit; font-size: 14px; color: var(--base-ai-text); padding: 6px 8px; border: 1px solid var(--base-ai-line); border-radius: 8px; background: var(--base-ai-surface); }
:where(.base-ai) .base-ai__consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; line-height: 1.4; }
:where(.base-ai) .base-ai__consent input { margin-block-start: 2px; flex: none; }
:where(.base-ai) .base-ai__lead-error { margin: 0; font-size: 12px; color: #b42318; }
:where(.base-ai) .base-ai__lead-send { justify-self: start; background: var(--base-ai-accent); color: var(--base-ai-on-accent); border-color: transparent; }
:where(.base-ai) .base-ai__lead-done { display: flex; gap: 6px; align-items: center; margin: 0; }
:where(.base-ai) .base-ai__lead-done .base-ai__icon { width: 16px; height: 16px; }
.base-ai .base-ai__field-input { width: 100%; box-sizing: border-box; margin: 0; }

:where(.base-ai) .base-ai__composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-block-start: 1px solid var(--base-ai-line); }
:where(.base-ai) .base-ai__input { flex: 1; resize: none; font: inherit; line-height: 1.4; padding: calc((var(--base-ai-control) - 1.4em - 2px) / 2) 10px; border: 1px solid var(--base-ai-line); border-radius: 10px; background: transparent; color: inherit; }
/* Functional, so above a theme's generic textarea rules (one class deep; a child theme still wins with two). */
/* At rest the input is as tall as the send button; it grows for more lines (widget.js caps it at 4). */
.base-ai .base-ai__input { min-height: var(--base-ai-control, 38px); box-sizing: border-box; overflow-y: hidden; }
:where(.base-ai) .base-ai__send { display: inline-flex; align-items: center; justify-content: center; flex: none; width: var(--base-ai-control); height: var(--base-ai-control); border: 0; border-radius: 10px; background: var(--base-ai-accent); color: var(--base-ai-on-accent); cursor: pointer; }
:where(.base-ai[data-busy="true"]) .base-ai__send { opacity: .5; }
:where(.base-ai) .screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes base-ai-spin { to { transform: rotate(360deg); } }
@keyframes base-ai-in { from { opacity: 0; transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) {
	:where(.base-ai) .base-ai__step, :where(.base-ai) .base-ai__summary .base-ai__icon { animation: none; transition: none; }
	:where(.base-ai) .base-ai__spin { animation-duration: 2.4s; }
}
