:root {
    --ai-navy: var(--ordnt-v2-navy, #0B1F3B);
    --ai-blue: var(--ordnt-v2-blue, #2563FF);
    --ai-card: #FFFFFF;
    --ai-border: var(--ordnt-v2-border, #E3EBF4);
    --ai-muted: var(--ordnt-v2-muted, #667085);
    --ai-soft-blue: #EDF5FF;
    --ai-warning: #9A6700;
    --ai-warning-bg: #FFF8E7;
    --ai-danger: #B42318;
    --ai-danger-bg: #FEF3F2;
}

.ai-assistant-drawer,
.ai-assistant-drawer *,
.ai-assistant-backdrop {
    box-sizing: border-box;
}

.ai-assistant-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1690;
    visibility: hidden;
    background: rgba(11, 31, 59, .04);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
}

.ai-assistant-backdrop.open {
    visibility: visible;
    opacity: 1;
}

.ai-assistant-drawer {
    position: fixed;
    top: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 1700;
    width: min(448px, 100vw);
    max-width: calc(100vw - 32px);
    height: auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    visibility: hidden;
    overflow: hidden;
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    background: var(--ai-card);
    color: #172033;
    box-shadow: 0 24px 70px rgba(20, 43, 74, .22);
    opacity: 0;
    transform: translateY(10px) scale(.985);
    transition:
        transform .2s ease,
        opacity .2s ease,
        visibility .2s ease;
}

.ai-assistant-drawer.open {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.ai-assistant-drawer button,
.ai-assistant-drawer textarea {
    font: inherit;
}

.ai-assistant-drawer button {
    cursor: pointer;
}

.ai-assistant-drawer .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ai-chat-header {
    min-height: 68px;
    padding: 12px 14px 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--ai-border);
    background: rgba(255, 255, 255, .96);
}

.ai-chat-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--ai-soft-blue);
    color: var(--ai-blue);
}

.ai-chat-mark svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-chat-title-group {
    min-width: 0;
}

.ai-chat-title-group h2 {
    margin: 0;
    color: var(--ai-navy);
    font-size: 16px;
    line-height: 1.2;
    letter-spacing: -.015em;
}

.ai-chat-business {
    margin: 3px 0 0;
    overflow: hidden;
    color: var(--ai-muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-assistant-close {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    line-height: 0;
    border-radius: 10px;
    background: transparent;
    color: #607086;
}

.ai-assistant-close:hover,
.ai-assistant-close:focus-visible {
    background: #F0F5FA;
    color: var(--ai-navy);
    outline: none;
}

.ai-assistant-close svg {
    width: 20px;
    height: 20px;
    display: block;
    margin: 0;
    place-self: center;
    transform: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.ai-chat-messages {
    min-height: 0;
    padding: 18px 16px 10px;
    overflow-y: auto;
    background: #F8FAFD;
    scroll-behavior: smooth;
}

.ai-chat-welcome {
    margin: 20px auto;
    text-align: center;
}

.ai-chat-welcome-icon {
    width: 38px;
    height: 38px;
    margin: 0 auto 10px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--ai-soft-blue);
    color: var(--ai-blue);
    font-size: 18px;
}

.ai-chat-welcome h3 {
    margin: 0 0 6px;
    color: var(--ai-navy);
    font-size: 18px;
    letter-spacing: -.02em;
}

.ai-chat-welcome p {
    max-width: 340px;
    margin: 0 auto;
    color: var(--ai-muted);
    font-size: 12px;
    line-height: 1.5;
}

.ai-chat-suggestions {
    margin-top: 15px;
    display: grid;
    gap: 7px;
}

.ai-chat-suggestions button {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--ai-border);
    border-radius: 9px;
    background: #FFFFFF;
    color: #40566F;
    font-size: 11px;
    font-weight: 700;
    text-align: left;
}

.ai-chat-suggestions button:hover,
.ai-chat-suggestions button:focus-visible {
    border-color: #AACBFA;
    color: var(--ai-blue);
    outline: none;
}

.ai-message-row {
    margin: 0 0 12px;
    display: flex;
}

.ai-message-row.user {
    justify-content: flex-end;
}

.ai-message {
    width: fit-content;
    max-width: 86%;
    padding: 10px 12px;
    border: 1px solid var(--ai-border);
    border-radius: 5px 13px 13px 13px;
    background: #FFFFFF;
    color: #26374B;
    font-size: 12px;
    line-height: 1.48;
    box-shadow: 0 2px 7px rgba(25, 49, 78, .03);
}

.ai-message-row.user .ai-message {
    border-color: var(--ai-blue);
    border-radius: 13px 13px 5px 13px;
    background: var(--ai-blue);
    color: #FFFFFF;
    box-shadow: none;
}

.ai-message.need_clarification {
    border-color: #F2D28A;
    background: var(--ai-warning-bg);
}

.ai-message.confirmation_required {
    border-color: #BBD4FA;
    background: #F2F7FF;
}

.ai-message.error {
    border-color: #F5C7C2;
    background: var(--ai-danger-bg);
    color: var(--ai-danger);
}

.ai-message.out_of_scope {
    color: #53657A;
    background: #F8FAFC;
}

.ai-message-badge {
    margin-bottom: 5px;
    color: var(--ai-blue);
    font-size: 9px;
    font-weight: 850;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.ai-message.need_clarification .ai-message-badge {
    color: var(--ai-warning);
}

.ai-message.error .ai-message-badge {
    color: var(--ai-danger);
}

.ai-action-card {
    margin-top: 8px;
    padding: 9px 10px;
    border: 1px solid rgba(37, 99, 255, .16);
    border-radius: 8px;
    background: rgba(255, 255, 255, .74);
}

.ai-action-title {
    margin-bottom: 6px;
    color: var(--ai-navy);
    font-size: 11px;
    font-weight: 800;
}

.ai-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 10px;
}

.ai-action-item {
    min-width: 0;
}

.ai-action-key {
    display: block;
    color: var(--ai-muted);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
}

.ai-action-value {
    display: block;
    overflow-wrap: anywhere;
    color: #26374B;
    font-size: 11px;
}

.ai-writing-note {
    margin: 7px 0 0;
    color: #426890;
    font-size: 10px;
    font-weight: 700;
}

.ai-interaction-feedback {
    margin-top: 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--ai-muted);
    font-size: 9px;
}

.ai-interaction-feedback-label {
    font-weight: 700;
}

.ai-interaction-feedback-actions {
    display: inline-flex;
    gap: 4px;
}

.ai-interaction-feedback button {
    min-height: 24px;
    padding: 3px 7px;
    border: 1px solid var(--ai-border);
    border-radius: 7px;
    background: rgba(255, 255, 255, .82);
    color: #52657B;
    font-size: 9px;
    font-weight: 750;
}

.ai-interaction-feedback button:hover:not(:disabled),
.ai-interaction-feedback button:focus-visible {
    border-color: #AACBFA;
    color: var(--ai-blue);
    outline: none;
}

.ai-interaction-feedback button:disabled {
    cursor: default;
    opacity: .52;
}

.ai-interaction-feedback.submitted
.ai-interaction-feedback-actions {
    display: none;
}

.ai-interaction-feedback-status {
    color: #5D7188;
    font-weight: 700;
}

.ai-loading-dots {
    display: inline-flex;
    gap: 4px;
}

.ai-loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #7990A8;
    animation: ai-pulse 1.1s infinite ease-in-out;
}

.ai-loading-dots span:nth-child(2) {
    animation-delay: .15s;
}

.ai-loading-dots span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes ai-pulse {
    0%, 70%, 100% { opacity: .35; transform: translateY(0); }
    35% { opacity: 1; transform: translateY(-2px); }
}

.ai-chat-composer {
    margin: 10px 12px 0;
    padding: 6px 6px 6px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border: 1px solid #CEDAEA;
    border-radius: 12px;
    background: #FFFFFF;
    box-shadow: 0 5px 16px rgba(25, 54, 88, .07);
}

.ai-chat-composer:focus-within {
    border-color: #83AFF8;
    box-shadow: 0 0 0 3px rgba(37, 99, 255, .1);
}

.ai-chat-composer textarea {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 8px 0 6px;
    resize: none;
    overflow-y: auto;
    border: 0;
    outline: 0;
    background: transparent;
    color: #172033;
    font-size: 13px;
    line-height: 1.45;
}

.ai-chat-composer textarea::placeholder {
    color: #8A9AAF;
}

.ai-chat-composer button {
    width: 38px;
    min-width: 38px;
    max-width: 38px;
    height: 38px;
    min-height: 38px;
    max-height: 38px;
    padding: 0;
    flex: 0 0 38px;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: var(--ai-blue);
    color: #FFFFFF;
}

.ai-chat-composer button:hover:not(:disabled) {
    background: #174FD1;
}

.ai-chat-composer button:focus-visible {
    outline: 3px solid rgba(37, 99, 255, .28);
    outline-offset: 2px;
}

.ai-chat-composer button:disabled {
    cursor: wait;
    opacity: .5;
}

.ai-chat-composer button svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-chat-footnote {
    margin: 7px 14px max(10px, env(safe-area-inset-bottom));
    color: #8493A6;
    font-size: 9px;
    text-align: center;
}

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

    .ai-assistant-backdrop {
        background: transparent;
    }

    .ai-assistant-drawer {
        top: var(--ai-mobile-viewport-top, 0px);
        right: 0;
        bottom: auto;
        width: 100vw;
        max-width: none;
        height: 100vh;
        height: var(--ai-mobile-viewport-height, 100dvh);
        border: 0;
        border-radius: 0;
    }

    .ai-chat-header {
        min-height: calc(62px + env(safe-area-inset-top));
        padding:
            max(10px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            10px
            max(14px, env(safe-area-inset-left));
    }

    .ai-chat-messages {
        padding: 14px 12px 8px;
    }

    .ai-chat-welcome {
        margin: 16px auto;
    }

    .ai-message {
        max-width: 90%;
    }

    .ai-action-grid {
        grid-template-columns: 1fr;
    }

    .ai-chat-composer {
        margin:
            8px
            max(10px, env(safe-area-inset-right))
            0
            max(10px, env(safe-area-inset-left));
    }

    .ai-chat-composer textarea {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-assistant-backdrop,
    .ai-assistant-drawer {
        transition: none;
    }

    .ai-chat-messages {
        scroll-behavior: auto;
    }

    .ai-loading-dots span {
        animation: none;
    }
}
