/* Loaded after base styles in both the document and shadow tree. Public integration contract. */
#cg4wp-chat-root[data-cg4wp-tokens="inherit"],
#cg4wp-chat-root-inline[data-cg4wp-tokens="inherit"] {
    --cg4wp-chat-ink: var(--cg4wp-site-ink, #111827);
    --cg4wp-body-color: var(--cg4wp-site-text, #111827);
    --cg4wp-chat-accent: var(--cg4wp-site-accent, #2563eb);
    --cg4wp-chat-accent-dark: var(--cg4wp-site-accent, #2563eb);
    --cg4wp-chat-panel: var(--cg4wp-site-panel, #fff);
    --cg4wp-chat-soft: var(--cg4wp-site-surface, #f6f7fb);
    --cg4wp-chat-line: var(--cg4wp-site-border, #e5e7eb);
    --cg4wp-chat-muted: var(--cg4wp-site-muted, #6b7280);
    --cg4wp-chat-font-family: var(--cg4wp-site-font, system-ui, sans-serif);
    --cg4wp-chat-font-size: var(--cg4wp-site-font-size, 15px);
    --cg4wp-chat-radius: var(--cg4wp-site-radius, 20px);
}
.cg4wp-launcher, .cg4wp-modal { right: var(--cg4wp-side-offset, 20px); }
#cg4wp-chat-root.cg4wp-position-left .cg4wp-launcher,
#cg4wp-chat-root.cg4wp-position-left .cg4wp-modal { left: var(--cg4wp-side-offset, 20px); right: auto; }
.cg4wp-body { height: var(--cg4wp-messages-height, clamp(470px, 68vh, 680px)); color: var(--cg4wp-body-color, var(--cg4wp-chat-ink, #111827)); }
.cg4wp-bubble { padding: var(--cg4wp-message-padding, 11px 13px); }
.cg4wp-msg-user { padding: var(--cg4wp-message-padding, 9px 13px); }
.cg4wp-bubble-assistant { color: var(--cg4wp-body-color, var(--cg4wp-chat-ink)); }
.cg4wp-modal-inner, .cg4wp-bubble-assistant, .cg4wp-input { border-color: var(--cg4wp-control-border, rgba(17, 24, 39, .08)); }
.cg4wp-modal-inner { border-width: var(--cg4wp-border-width, 1px); max-width: calc(100vw - 24px); max-height: calc(100dvh - 100px); }
.cg4wp-send { color: var(--cg4wp-button-text, #fff); }
:where(button, a, textarea, input, select):focus-visible { outline: 3px solid var(--cg4wp-chat-accent, #2563eb); outline-offset: 3px; }
button:disabled { opacity: .55; cursor: wait; }
a:hover { text-decoration: underline; }
[aria-busy="true"] .cg4wp-send { cursor: progress; }
.cg4wp-consent { font-size: .85em; color: var(--cg4wp-chat-muted, #6b7280); margin: 8px 14px; }
/* Voice controls are separate native buttons, with a visible Stop during capture. */
.cg4wp-input-actions { flex-wrap: wrap; }
[data-cg4wp-voice-state] .cg4wp-input-shell { padding: 9px 12px; }
[data-cg4wp-voice-state] .cg4wp-input-main { flex-direction: row; align-items: flex-end; gap: 6px; }
[data-cg4wp-voice-state] .cg4wp-input-actions { position: static; justify-content: flex-end; }
.cg4wp-input-actions .cg4wp-voice-record,
.cg4wp-voice-stop, .cg4wp-voice-cancel {
    width: auto; height: auto; min-height: 40px; min-width: 44px; padding: 8px 10px;
    font: inherit; font-size: var(--cg4wp-voice-font-size, .875em); line-height: 1.3;
    border: 1px solid var(--cg4wp-chat-line, #ddd); border-radius: var(--cg4wp-voice-radius, 8px);
    color: var(--cg4wp-voice-color, var(--cg4wp-chat-ink)); background: var(--cg4wp-voice-background, var(--cg4wp-chat-panel));
    cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.cg4wp-voice-stop { background: var(--cg4wp-voice-stop-background, #a11212); color: var(--cg4wp-voice-stop-color, #fff); font-weight: 700; }
.cg4wp-voice-cancel { background: var(--cg4wp-voice-cancel-background, var(--cg4wp-chat-panel)); }
.cg4wp-voice-stop[hidden], .cg4wp-voice-cancel[hidden] { display: none !important; }
.cg4wp-voice-status, .cg4wp-voice-privacy { margin: 4px 14px; font-size: .8em; overflow-wrap: anywhere; }
.cg4wp-voice-status { color: var(--cg4wp-voice-status-color, var(--cg4wp-chat-ink)); }
.cg4wp-voice-privacy { color: var(--cg4wp-chat-muted); }
.cg4wp-voice-error { color: var(--cg4wp-voice-error-color, #a11212); font-weight: 600; }
[data-cg4wp-voice-state="transcribing"] .cg4wp-voice-status { font-weight: 600; }
/* Keep layout, visibility, scrolling, hit targets, focus and ARIA behavior in external mode. */
#cg4wp-chat-root[data-cg4wp-presentation="external"] *,
#cg4wp-chat-root-inline[data-cg4wp-presentation="external"] * {
    background-color: transparent; background-image: none; color: inherit;
    border-color: transparent; border-radius: 0; box-shadow: none; text-shadow: none;
}
@media (max-width: 600px) {
    .cg4wp-modal { max-width: calc(100vw - 24px); }
    .cg4wp-body { height: min(var(--cg4wp-messages-height, 58dvh), 65dvh); }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Compact, shared composer contract, loaded in inline and Shadow DOM views. */
.cg4wp-input-shell { padding: 5px 6px; border-radius: var(--cg4wp-composer-radius, 22px); }
.cg4wp-input-main .cg4wp-input { flex: 1 1 0; min-width: 0; width: 0; padding: 10px 2px; }
.cg4wp-input-main .cg4wp-input-actions { position: static; flex: 0 0 auto; flex-wrap: nowrap; gap: 3px; }
.cg4wp-input-main .cg4wp-send, .cg4wp-input-actions .cg4wp-voice-record, .cg4wp-attach { width: 40px; height: 44px; min-width: 40px; padding: 0; flex-shrink: 0; border-radius: 50%; }
.cg4wp-voice-record-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.cg4wp-attach { font: inherit; font-size: 26px; border: 0; color: var(--cg4wp-attachment-color, var(--cg4wp-chat-ink)); background: var(--cg4wp-attachment-background, transparent); cursor: pointer; }
.cg4wp-attachment-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; max-height: 140px; overflow: auto; }
.cg4wp-attachment { display: flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; padding: 4px; border: 1px solid var(--cg4wp-chat-line); border-radius: var(--cg4wp-attachment-radius, 8px); }
.cg4wp-attachment-name { overflow-wrap: anywhere; min-width: 0; font-size: .8em; }
.cg4wp-attachment-preview { width: 40px; height: 40px; object-fit: cover; flex-shrink: 0; }
.cg4wp-attachment-remove, .cg4wp-attachment-cancel { min-height: 44px; font: inherit; cursor: pointer; flex-shrink: 0; }
.cg4wp-attachment-cancel { margin: 4px 12px; }
.cg4wp-attachment-cancel[hidden] { display: none; }
.cg4wp-upload-status, .cg4wp-attachment-privacy { margin: 4px 14px; font-size: .8em; overflow-wrap: anywhere; }
.cg4wp-upload-status[role="alert"] { color: var(--cg4wp-attachment-error-color, #a11212); }
.cg4wp-attachment-privacy { color: var(--cg4wp-chat-muted); }
@media(max-width: 360px) {
 [data-cg4wp-voice-state="recording"] .cg4wp-input-main { flex-wrap: wrap; }
 [data-cg4wp-voice-state="recording"] .cg4wp-input-actions { margin-left: auto; }
}

/* During capture, keep long localized Stop/Cancel labels usable on narrow screens. */
@media(max-width: 640px) {
 [data-cg4wp-voice-state="recording"] .cg4wp-input-main,
 [data-cg4wp-voice-state="requesting"] .cg4wp-input-main,
 [data-cg4wp-voice-state="transcribing"] .cg4wp-input-main { display: grid; grid-template-columns: 40px minmax(0, 1fr); }
 [data-cg4wp-voice-state="recording"] .cg4wp-input-main .cg4wp-input,
 [data-cg4wp-voice-state="requesting"] .cg4wp-input-main .cg4wp-input,
 [data-cg4wp-voice-state="transcribing"] .cg4wp-input-main .cg4wp-input { width: 100%; }
 [data-cg4wp-voice-state="recording"] .cg4wp-input-main .cg4wp-input-actions,
 [data-cg4wp-voice-state="requesting"] .cg4wp-input-main .cg4wp-input-actions,
 [data-cg4wp-voice-state="transcribing"] .cg4wp-input-main .cg4wp-input-actions { grid-column: 1 / -1; flex-wrap: wrap; }
 [data-cg4wp-voice-state="recording"] .cg4wp-voice-record,
 [data-cg4wp-voice-state="requesting"] .cg4wp-voice-record,
 [data-cg4wp-voice-state="transcribing"] .cg4wp-voice-record { display: none; }
}

.cg4wp-body > .cg4wp-attachment-list,
.cg4wp-body > .cg4wp-upload-status,
.cg4wp-body > .cg4wp-attachment-cancel,
.cg4wp-body > .cg4wp-attachment-privacy,
.cg4wp-body > .cg4wp-voice-status,
.cg4wp-body > .cg4wp-voice-privacy { flex-shrink: 0; }
.cg4wp-messages { min-height: 0; }

.cg4wp-document-context-notice { margin: 4px 14px; font-size: .8em; overflow-wrap: anywhere; flex-shrink: 0; }
.cg4wp-document-context-clear { margin: 4px 14px; min-height: 44px; font: inherit; flex-shrink: 0; }
.cg4wp-document-context-clear[hidden], .cg4wp-document-context-notice[hidden] { display:none; }

/* Allow footer controls to remain reachable when keyboard/landscape leaves very little height. */
.cg4wp-body { overflow-y: auto; }
