.agent-chat-root {
    --agent-primary: #7457f5;
    --agent-secondary: #16b8a6;
    --agent-accent: #f06f9b;
    --agent-ink: #29263c;
    color: var(--agent-ink);
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.agent-chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 3000;
    width: min(390px, calc(100vw - 32px));
    height: min(580px, calc(100vh - 100px));
    min-width: 330px;
    min-height: 420px;
    max-width: min(720px, calc(100vw - 16px));
    max-height: min(780px, calc(100vh - 84px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 18px;
    background: rgba(250, 249, 255, .94);
    box-shadow: 0 22px 70px rgba(63, 46, 120, .22);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    transition: width .22s ease, border-radius .22s ease, box-shadow .22s ease, transform .16s ease;
}

.agent-chat-page {
    max-width: 860px;
    margin: 105px auto 40px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 20px;
    background: rgba(251, 249, 255, .84);
    box-shadow: 0 16px 48px rgba(68, 48, 128, .16);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.agent-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid rgba(116, 87, 245, .13);
    background:
        linear-gradient(120deg, rgba(255,255,255,.9), rgba(239,233,255,.86) 52%, rgba(220,248,243,.8));
}

.agent-chat-widget .agent-chat-header {
    touch-action: none;
    user-select: none;
}

.agent-chat-orb-icon {
    display: none;
}

.agent-chat-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.agent-chat-heading strong,
.agent-chat-heading small {
    display: block;
}

.agent-chat-heading strong {
    font-size: .98rem;
    letter-spacing: .2px;
}

.agent-chat-heading small {
    margin-top: 1px;
    color: #6f8192;
    font-size: .72rem;
}

.agent-chat-status-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--agent-secondary);
    box-shadow: 0 0 0 5px rgba(22, 184, 166, .13);
}

.agent-chat-actions {
    display: flex;
    gap: 7px;
}

.agent-chat-actions button {
    min-width: 34px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid rgba(116, 87, 245, .22);
    border-radius: 10px;
    background: rgba(255,255,255,.72);
    color: #625b7b;
    font-size: .78rem;
    transition: background .2s ease, color .2s ease, transform .2s ease;
}

.agent-chat-actions button:hover {
    color: var(--agent-primary);
    background: white;
    transform: translateY(-1px);
}

.agent-chat-body {
    padding: 12px;
}

.agent-chat-widget .agent-chat-body {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
}

.agent-chat-messages {
    min-height: 280px;
    max-height: min(480px, calc(100vh - 260px));
    overflow-y: auto;
    padding: 4px 3px 10px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
}

.agent-chat-page .agent-chat-messages {
    min-height: 420px;
    max-height: 62vh;
}

.agent-chat-widget .agent-chat-messages {
    min-height: 0;
    max-height: none;
    flex: 1;
}

.agent-chat-message {
    max-width: 88%;
    margin: 10px 0;
    padding: 10px 13px;
    border-radius: 13px;
    overflow-wrap: anywhere;
    line-height: 1.55;
    font-size: .91rem;
}

.agent-chat-message.user {
    margin-left: auto;
    color: white;
    background: linear-gradient(135deg, var(--agent-primary), #9a55e8 58%, var(--agent-accent));
    box-shadow: 0 6px 18px rgba(116, 87, 245, .2);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.agent-chat-message.assistant {
    color: var(--agent-ink);
    background: linear-gradient(135deg, rgba(237,233,255,.94), rgba(226,248,244,.88));
    border-bottom-left-radius: 4px;
}

.agent-chat-message.system {
    max-width: 100%;
    color: #6d7f90;
    background: rgba(235, 241, 247, .72);
    text-align: center;
    font-size: .82rem;
}

.agent-chat-guest-notice {
    margin: 10px 0;
    padding: 10px 12px;
    border: 1px solid rgba(116, 87, 245, .2);
    border-radius: 12px;
    color: #596b7c;
    background: rgba(245, 242, 255, .82);
    font-size: .82rem;
    line-height: 1.55;
}

.agent-chat-guest-notice a {
    color: var(--agent-primary);
    font-weight: 700;
    text-decoration: none;
}

.agent-chat-root button:disabled,
.agent-chat-root textarea:disabled {
    cursor: not-allowed;
    opacity: .58;
}

.agent-chat-message p:last-child {
    margin-bottom: 0;
}

.agent-chat-message pre {
    overflow-x: auto;
    margin: 8px 0;
    padding: 10px;
    border-radius: 8px;
    color: #d8e2ec;
    background: #1f2933;
    font-size: .82rem;
}

.agent-chat-message code {
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(31, 41, 51, .08);
}

.agent-chat-message pre code {
    padding: 0;
    background: transparent;
}

.agent-chat-message table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

.agent-chat-message th,
.agent-chat-message td {
    padding: 5px 8px;
    border: 1px solid #bdccda;
}

.agent-chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(116, 87, 245, .13);
}

.agent-chat-form textarea {
    width: 100%;
    min-height: 44px;
    max-height: 130px;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid rgba(116, 87, 245, .24);
    border-radius: 12px;
    outline: none;
    background: rgba(255,255,255,.8);
    color: var(--agent-ink);
    font-size: .9rem;
}

.agent-chat-form textarea:focus {
    border-color: var(--agent-primary);
    box-shadow: 0 0 0 3px rgba(116, 87, 245, .12);
}

.agent-chat-form button {
    min-width: 62px;
    border: 0;
    border-radius: 12px;
    color: white;
    background: linear-gradient(135deg, var(--agent-primary), #6654d9 55%, var(--agent-secondary));
    font-weight: 600;
}

.agent-chat-form button:disabled,
.agent-chat-actions button:disabled {
    cursor: wait;
    opacity: .55;
}

.agent-chat-hint {
    margin-top: 7px;
    color: #8291a0;
    text-align: center;
    font-size: .69rem;
}

.agent-chat-typing::after {
    content: "▋";
    margin-left: 3px;
    animation: agent-blink 1s step-end infinite;
}

@keyframes agent-blink {
    50% { opacity: 0; }
}

.agent-chat-widget.is-collapsed {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    max-width: 56px;
    max-height: 56px;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 12px 34px rgba(48, 116, 190, .28);
}

.agent-chat-widget.is-collapsed .agent-chat-header {
    width: 100%;
    min-height: 56px;
    height: 56px;
    justify-content: center;
    padding: 0;
    border-bottom: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(255,255,255,.97), rgba(237,229,255,.95));
}

.agent-chat-widget.is-collapsed .agent-chat-body {
    display: none;
}

.agent-chat-widget.is-collapsed .agent-chat-heading,
.agent-chat-widget.is-collapsed .agent-chat-actions {
    display: none;
}

.agent-chat-widget.is-collapsed .agent-chat-orb-icon {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 50%;
    color: white;
    background: conic-gradient(from 210deg, var(--agent-primary), var(--agent-accent), var(--agent-secondary), var(--agent-primary));
    box-shadow: 0 5px 18px rgba(116, 87, 245, .38);
    font-size: 1.18rem;
}

.agent-chat-widget.is-collapsed:not(.is-dragging):hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 16px 42px rgba(116, 87, 245, .36);
}

.agent-chat-widget.is-dragging,
.agent-chat-widget.is-resizing {
    transform: scale(1.015);
    border-color: rgba(116, 87, 245, .62);
    box-shadow: 0 24px 76px rgba(91, 62, 173, .34), 0 0 0 5px rgba(22, 184, 166, .12);
    transition: none;
}

.agent-chat-widget.is-dragging .agent-chat-header,
.agent-chat-widget.is-resizing .agent-chat-header {
    background: linear-gradient(135deg, rgba(249,247,255,.97), rgba(231,222,255,.94), rgba(214,247,241,.9));
}

.agent-drag-trail-dot {
    position: fixed;
    z-index: 2998;
    width: 11px;
    height: 11px;
    pointer-events: none;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.98) 0 18%, rgba(139,101,246,.84) 35%, rgba(22,184,166,0) 72%);
    box-shadow: 0 0 12px rgba(116, 87, 245, .62);
    animation: agent-trail-fade .58s ease-out forwards;
    will-change: transform, opacity;
}

@keyframes agent-trail-fade {
    from {
        opacity: .9;
        transform: translate(-50%, -50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(.15);
    }
}

.agent-chat-resize-handle {
    position: absolute;
    right: 5px;
    bottom: 5px;
    z-index: 3;
    width: 22px;
    height: 22px;
    cursor: nwse-resize;
    touch-action: none;
    opacity: .6;
}

.agent-chat-resize-handle::before,
.agent-chat-resize-handle::after {
    content: "";
    position: absolute;
    right: 2px;
    bottom: 2px;
    border-right: 2px solid rgba(116, 87, 245, .72);
    border-bottom: 2px solid rgba(22, 184, 166, .72);
    border-radius: 0 0 3px;
}

.agent-chat-resize-handle::before {
    width: 15px;
    height: 15px;
}

.agent-chat-resize-handle::after {
    width: 9px;
    height: 9px;
}

.agent-chat-widget.is-collapsed .agent-chat-resize-handle {
    display: none;
}

@media (max-width: 600px) {
    .agent-chat-widget {
        right: 10px;
        bottom: 10px;
        width: calc(100vw - 20px);
        max-height: calc(100vh - 84px);
        min-width: min(330px, calc(100vw - 20px));
    }

    .agent-chat-page {
        margin: 88px 10px 20px;
    }

    .agent-chat-widget.is-collapsed {
        width: 54px;
        height: 54px;
    }

    .agent-chat-messages {
        max-height: calc(100vh - 270px);
    }
}
