.analytics-consent {
    position: fixed;
    z-index: 1500;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    left: calc(268px + 22px);
    display: flex;
    width: min(640px, calc(100vw - 312px));
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    margin-inline: auto;
    padding: 14px 16px;
    border: 1px solid var(--line, rgba(21, 23, 25, .15));
    border-radius: 13px;
    background: var(--surface, #fff);
    color: var(--text, #17191c);
    box-shadow: var(--shadow-md, 0 18px 48px rgba(15, 17, 20, .16));
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif;
}

.analytics-consent > div:first-child {
    min-width: 0;
}

.analytics-consent strong {
    font-size: 14px;
    font-weight: 730;
}

.analytics-consent p {
    margin: 3px 0 0;
    color: var(--text-soft, #50575f);
    font-size: 13px;
    line-height: 1.55;
}

.analytics-consent p a {
    color: var(--brand-strong, #2647b3);
    font-weight: 650;
}

.analytics-consent-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 7px;
}

.analytics-consent-actions button {
    min-height: 44px;
    padding: 0 13px;
    border: 1px solid var(--line-strong, rgba(21, 23, 25, .22));
    border-radius: 8px;
    background: var(--surface, #fff);
    color: var(--text, #17191c);
    font: 700 12.5px/1 var(--font);
    cursor: pointer;
}

.analytics-consent-actions button:last-child {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--surface);
}

.analytics-consent-actions button:focus-visible,
.ai-chat-widget button:focus-visible,
.ai-chat-widget textarea:focus-visible,
.ai-chat-widget a:focus-visible {
    outline: 2px solid var(--brand, #3157d5);
    outline-offset: 2px;
}

.ai-chat-widget {
    position: fixed;
    z-index: 1450;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    color: var(--text, #17191c);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif;
    transition: opacity .16s ease, visibility .16s ease, transform .16s ease;
}

.analytics-consent-pending .ai-chat-widget,
.legal-site .ai-chat-widget,
.error-body .ai-chat-widget {
    display: none;
}

.ai-chat-widget.ai-chat-avoid-overlap:not(.is-open) {
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
}

.ai-chat-toggle {
    display: grid;
    width: 50px;
    height: 50px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 14px;
    background: #17191c;
    color: #fff;
    box-shadow: 0 12px 30px rgba(15, 17, 20, .22);
    cursor: pointer;
}

.ai-chat-toggle:hover {
    background: #252a31;
}

.ai-chat-toggle svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-chat-orbit {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border: 2px solid #17191c;
    border-radius: 999px;
    background: #4ade80;
    box-sizing: content-box;
}

.ai-chat-panel {
    position: absolute;
    right: 0;
    bottom: 62px;
    display: flex;
    width: min(390px, calc(100vw - 32px));
    max-height: min(650px, calc(100dvh - 102px));
    flex-direction: column;
    overflow: hidden;
    visibility: hidden;
    border: 1px solid var(--line-strong, rgba(21, 23, 25, .22));
    border-radius: 16px;
    background: var(--surface, #fff);
    color: var(--text, #17191c);
    box-shadow: var(--shadow-md, 0 22px 60px rgba(15, 17, 20, .22));
    opacity: 0;
    transform: translateY(7px);
    transition: opacity .16s ease, visibility .16s ease, transform .16s ease;
}

.ai-chat-widget.is-open .ai-chat-panel,
.ai-chat-open .ai-chat-panel {
    visibility: visible;
    opacity: 1;
    transform: none;
}

.ai-chat-head {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 14px 12px 16px;
    border-bottom: 1px solid var(--line, rgba(21, 23, 25, .12));
    background: var(--surface-soft, #f8f8f6);
}

.ai-chat-head > div {
    display: grid;
    gap: 1px;
}

.ai-chat-head span {
    color: var(--text-muted, #737b84);
    font-size: 11px;
    font-weight: 730;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.ai-chat-head strong {
    font-size: 15px;
    font-weight: 720;
}

.ai-chat-close {
    position: relative;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid var(--line, rgba(21, 23, 25, .12));
    border-radius: 9px;
    background: var(--surface, #fff);
    color: var(--text, #17191c);
    cursor: pointer;
}

.ai-chat-close::before,
.ai-chat-close::after {
    position: absolute;
    top: 21px;
    left: 13px;
    width: 16px;
    height: 1.5px;
    background: currentColor;
    content: "";
    transform: rotate(45deg);
}

.ai-chat-close::after {
    transform: rotate(-45deg);
}

.ai-chat-feed {
    display: grid;
    min-height: 130px;
    flex: 1 1 auto;
    align-content: start;
    gap: 11px;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ai-chat-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.ai-chat-message.is-user {
    align-items: flex-end;
}

.ai-chat-message > span {
    color: var(--text-muted, #737b84);
    font-size: 11px;
    font-weight: 650;
}

.ai-chat-bubble {
    max-width: 88%;
    padding: 9px 11px;
    border-radius: 11px;
    background: var(--surface-strong, #e8e9e6);
    color: var(--text, #17191c);
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.ai-chat-message.is-user .ai-chat-bubble {
    background: var(--brand, #3157d5);
    color: #fff;
}

.ai-chat-suggestions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
}

.ai-chat-suggestions button {
    min-height: 44px;
    padding: 0 11px;
    border: 1px solid var(--line, rgba(21, 23, 25, .12));
    border-radius: 8px;
    background: var(--surface, #fff);
    color: var(--text-soft, #50575f);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
}

.ai-chat-suggestions button:hover {
    border-color: var(--line-strong, rgba(21, 23, 25, .22));
    background: var(--surface-soft, #f8f8f6);
}

.ai-chat-status {
    padding: 8px 16px;
    border-top: 1px solid var(--line, rgba(21, 23, 25, .12));
    color: var(--text-muted, #737b84);
    font-size: 12px;
    line-height: 1.45;
}

.ai-chat-status[data-tone="success"] {
    background: var(--positive-soft, #eaf4ef);
    color: var(--positive, #176b4a);
}

.ai-chat-status[data-tone="hint"] {
    background: var(--warning-soft, #f7f0e4);
    color: var(--warning, #87560f);
}

.ai-chat-status[data-tone="error"] {
    background: var(--negative-soft, #f8ebeb);
    color: var(--negative, #a23a3a);
}

.ai-chat-form {
    position: relative;
    flex: 0 0 auto;
    padding: 11px 16px 16px;
}

.ai-chat-consent {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 7px;
    margin: 0 0 9px;
    color: var(--text-muted, #737b84);
    font-size: 12px;
    line-height: 1.45;
}

.ai-chat-consent.is-error {
    color: var(--negative, #a23a3a);
}

.ai-chat-consent input[aria-invalid="true"] {
    outline: 2px solid var(--negative, #a23a3a);
    outline-offset: 2px;
}

.ai-chat-consent input {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    margin: 0;
    accent-color: var(--brand, #3157d5);
}

.ai-chat-consent a {
    color: var(--brand-strong, #2647b3);
}

.ai-chat-input-wrap {
    display: grid;
}

.ai-chat-input-wrap textarea {
    width: 100%;
    min-height: 72px;
    max-height: 128px;
    padding: 10px 60px 10px 11px;
    border: 1px solid var(--line-strong, rgba(21, 23, 25, .22));
    border-radius: 10px;
    outline: 0;
    background: var(--surface, #fff);
    color: var(--text, #17191c);
    font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    resize: none;
}

.ai-chat-input-wrap textarea:focus {
    border-color: var(--brand, #3157d5);
    box-shadow: 0 0 0 3px var(--brand-soft, #edf0fc);
}

.ai-chat-send {
    position: absolute;
    right: 21px;
    bottom: 21px;
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: var(--brand, #3157d5);
    color: #fff;
    cursor: pointer;
}

.ai-chat-send:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.ai-chat-send.is-loading {
    cursor: wait;
}

.ai-chat-send svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
}

.ai-chat-spinner {
    display: block;
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: public-widget-spin .7s linear infinite;
    opacity: .65;
}

@keyframes public-widget-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 1279px) {
    .analytics-consent {
        right: max(16px, env(safe-area-inset-right));
        left: max(16px, env(safe-area-inset-left));
        width: min(640px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    }
}

@media (max-width: 767px) {
    body.ai-chat-open {
        overflow: hidden;
    }

    .analytics-consent {
        right: max(12px, env(safe-area-inset-right));
        bottom: calc(12px + env(safe-area-inset-bottom));
        left: max(12px, env(safe-area-inset-left));
        width: auto;
        align-items: stretch;
        flex-direction: column;
        gap: 11px;
        padding: 13px;
        border-radius: 13px;
    }

    .analytics-consent strong,
    .analytics-consent p,
    .analytics-consent-actions button,
    .ai-chat-widget small,
    .ai-chat-widget label {
        font-size: 12px;
        line-height: 1.4;
    }

    .analytics-consent-actions button {
        flex: 1;
        min-height: 44px;
    }

    .ai-chat-widget {
        right: max(14px, env(safe-area-inset-right));
        bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .ai-chat-toggle {
        display: none;
    }

    .ai-chat-panel {
        position: fixed;
        inset: auto max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        width: auto;
        max-height: calc(100dvh - max(20px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
        border-radius: 18px;
    }

    .ai-chat-feed {
        min-height: 0;
        flex: 0 1 auto;
        max-height: 36dvh;
    }
}

@media (prefers-contrast: more) {
    .analytics-consent,
    .ai-chat-panel,
    .ai-chat-suggestions button,
    .ai-chat-input-wrap textarea {
        border-color: currentColor;
    }
}

@media (forced-colors: active) {
    .analytics-consent,
    .ai-chat-panel,
    .ai-chat-toggle,
    .ai-chat-send {
        border: 1px solid CanvasText;
        forced-color-adjust: auto;
    }
}

@media print {
    .analytics-consent,
    .ai-chat-widget,
    [data-runtime-widget] {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chat-widget,
    .ai-chat-panel,
    .analytics-consent {
        transition: none;
    }
}
