:root {
    --direct-purple: #5b4dd6;
    --direct-purple-dark: #493bc0;
    --direct-text: #1f2430;
    --direct-muted: #8b91a1;
    --direct-line: #e9eaf0;
    --direct-surface: #f7f7fa;
}

.direct-chat-panel {
    position: fixed;
    right: 24px;
    bottom: 92px;
    z-index: 1000;
    display: none;
    width: min(520px, calc(100vw - 32px));
    height: min(680px, calc(100vh - 130px));
    overflow: hidden;
    flex-direction: column;
    color: var(--direct-text);
    background: #fff;
    border: 1px solid #e3e4eb;
    border-radius: 16px;
    box-shadow: 0 20px 64px rgba(24, 27, 46, 0.2);
}

.direct-chat-header {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--direct-line);
}

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

.direct-chat-avatar,
.direct-chat-message__avatar {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(145deg, #48b8bd, #398d9d);
    font-weight: 800;
    letter-spacing: -0.04em;
}

.direct-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 12px;
    box-shadow: 0 4px 12px rgba(50, 143, 152, 0.22);
}

.direct-chat-header strong {
    display: block;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.direct-chat-header .direct-chat-title span {
    display: flex;
    margin-top: 3px;
    align-items: center;
    color: #7d8391;
    font-size: 11px;
}

.direct-chat-online-dot {
    width: 6px;
    height: 6px;
    margin-right: 5px;
    background: #24b47e;
    border-radius: 50%;
}

.direct-chat-provider-badge,
.dashboard-provider-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.dashboard-provider-badge {
    margin-left: 10px;
    color: #5142b8;
    background: #eeeaff;
}

.dashboard-provider-badge--direct {
    color: #087a56;
    background: #dcf8ec;
}

.direct-chat-icon-button,
.direct-chat-message__action,
.direct-chat-composer-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #6e7482;
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.direct-chat-icon-button {
    width: 38px;
    height: 38px;
}

.direct-chat-icon-button:hover,
.direct-chat-message__action:hover {
    color: var(--direct-purple);
    background: #f1efff;
}

.direct-chat-icon-button svg,
.direct-chat-message__action svg,
.direct-chat-composer-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.direct-chat-icon-button .icon-sound-off,
.direct-chat-icon-button.is-muted .icon-sound-on {
    display: none;
}

.direct-chat-icon-button.is-muted .icon-sound-off {
    display: block;
}

.direct-chat-messages {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 17px 12px;
    background: var(--direct-surface);
    scroll-behavior: smooth;
}

.direct-chat-message {
    display: flex;
    width: 100%;
    margin-bottom: 18px;
    align-items: flex-start;
    gap: 9px;
}

.direct-chat-message--user {
    justify-content: flex-end;
}

.direct-chat-message--system {
    justify-content: center;
}

.direct-chat-message__avatar {
    width: 30px;
    height: 30px;
    margin-top: 18px;
    border-radius: 50%;
    font-size: 9px;
}

.direct-chat-message__body {
    display: flex;
    max-width: calc(86% - 30px);
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
}

.direct-chat-message--user .direct-chat-message__body {
    align-items: flex-end;
}

.direct-chat-message--system .direct-chat-message__body {
    max-width: 90%;
    align-items: center;
}

.direct-chat-message__label {
    margin: 0 5px 5px;
    color: var(--direct-muted);
    font-size: 11px;
    line-height: 1.2;
}

.direct-chat-message__bubble {
    max-width: 100%;
    padding: 11px 13px;
    color: #303440;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #fff;
    border: 1px solid #ececf2;
    border-radius: 4px 14px 14px 14px;
    box-shadow: 0 2px 7px rgba(22, 26, 45, 0.04);
    font-size: 14px;
    line-height: 1.62;
}

.direct-chat-message--user .direct-chat-message__bubble {
    color: #fff;
    background: linear-gradient(135deg, #6657de, var(--direct-purple));
    border: 0;
    border-radius: 14px 4px 14px 14px;
    box-shadow: 0 5px 14px rgba(91, 77, 214, 0.2);
}

.direct-chat-message--system .direct-chat-message__bubble {
    color: #8c3d43;
    background: #fff1f2;
    border-color: #ffe0e2;
    border-radius: 10px;
    box-shadow: none;
    font-size: 12px;
}

.direct-chat-message__bubble a {
    color: #245bd8;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.direct-chat-message--user .direct-chat-message__bubble a {
    color: #fff;
}

.direct-chat-message__actions {
    display: flex;
    min-height: 28px;
    margin-top: 4px;
    align-items: center;
    gap: 2px;
}

.direct-chat-message__action {
    width: 30px;
    height: 28px;
}

.direct-chat-message__action svg {
    width: 17px;
    height: 17px;
}

.direct-chat-message__action.is-playing {
    color: var(--direct-purple);
    background: #ece9ff;
}

.direct-chat-message__action.is-success {
    color: #16865f;
    background: #e4f8ef;
}

.direct-chat-message--typing {
    align-items: center;
}

.direct-chat-typing {
    display: flex;
    min-width: 58px;
    height: 38px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: #fff;
    border: 1px solid #ececf2;
    border-radius: 4px 14px 14px 14px;
}

.direct-chat-typing i {
    width: 5px;
    height: 5px;
    background: #a8acb8;
    border-radius: 50%;
    animation: direct-chat-bounce 1.2s infinite ease-in-out;
}

.direct-chat-typing i:nth-child(2) {
    animation-delay: 0.15s;
}

.direct-chat-typing i:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes direct-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.direct-chat-voice-status {
    display: none;
    min-height: 0;
    padding: 7px 14px;
    color: #666d7c;
    background: #f7f7fa;
    border-top: 1px solid var(--direct-line);
    font-size: 12px;
    text-align: center;
}

.direct-chat-voice-status:not(:empty) {
    display: block;
}

.direct-chat-voice-status--listening {
    color: #a73d55;
    background: #fff1f4;
}

.direct-chat-voice-status--error {
    color: #9f3d43;
    background: #fff2f2;
}

.direct-chat-voice-status--success {
    color: #087a56;
    background: #ecfaf4;
}

.direct-chat-composer {
    display: flex;
    min-height: 62px;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px 8px;
    background: #fff;
    border-top: 1px solid var(--direct-line);
}

.direct-chat-composer textarea {
    min-height: 42px;
    max-height: 112px;
    flex: 1;
    padding: 10px 4px 8px;
    resize: none;
    color: var(--direct-text);
    background: transparent;
    border: 0;
    outline: none;
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
}

.direct-chat-composer textarea::placeholder {
    color: #a0a5b1;
}

.direct-chat-composer-button {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
}

.direct-chat-mic:hover {
    color: var(--direct-purple);
    background: #f1efff;
}

.direct-chat-mic.is-listening {
    color: #fff;
    background: #ef4f6b;
    animation: direct-chat-pulse 1.35s infinite;
}

.direct-chat-mic.is-unsupported {
    color: #a5a9b3;
}

@keyframes direct-chat-pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 79, 107, 0.36); }
    70% { box-shadow: 0 0 0 9px rgba(239, 79, 107, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 79, 107, 0); }
}

.direct-chat-send {
    color: #fff;
    background: var(--direct-purple);
}

.direct-chat-send:hover {
    color: #fff;
    background: var(--direct-purple-dark);
    transform: translateY(-1px);
}

.direct-chat-send:disabled {
    cursor: wait;
    opacity: 0.55;
    transform: none;
}

.direct-chat-send.is-sending svg {
    animation: direct-chat-send-spin 900ms linear infinite;
}

@keyframes direct-chat-send-spin {
    to { transform: rotate(360deg); }
}

.direct-chat-disclaimer {
    margin: 0;
    padding: 0 10px 8px;
    color: #a0a5b0;
    background: #fff;
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
}

@media (max-width: 640px) {
    .direct-chat-panel {
        top: max(12px, env(safe-area-inset-top));
        right: 10px;
        bottom: max(74px, calc(env(safe-area-inset-bottom) + 68px));
        left: 10px;
        width: auto;
        height: auto;
        border-radius: 14px;
    }

    .direct-chat-header {
        min-height: 58px;
        padding: 8px 12px;
    }

    .direct-chat-avatar {
        width: 34px;
        height: 34px;
    }

    .direct-chat-messages {
        padding: 16px 12px 8px;
    }

    .direct-chat-message__body {
        max-width: calc(90% - 28px);
    }

    .direct-chat-message__bubble {
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .direct-chat-messages {
        scroll-behavior: auto;
    }

    .direct-chat-typing i,
    .direct-chat-mic.is-listening,
    .direct-chat-send.is-sending svg {
        animation: none;
    }
}
