.cm-ai-assistant {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1300;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.cm-ai-assistant *,
.cm-ai-assistant *::before,
.cm-ai-assistant *::after {
    box-sizing: border-box;
}

.cm-ai-launcher {
    position: relative;
    width: 86px;
    height: 86px;
    border: 0;
    border-radius: 999px;
    background: radial-gradient(circle at 30% 22%, #fff8c7, #f5c542 48%, #d4a017 102%);
    box-shadow: 0 22px 50px rgba(120, 80, 10, .28);
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 6px;
    animation: cm-ai-float 4.6s ease-in-out infinite;
}

.cm-ai-launcher img {
    width: 82px;
    height: 82px;
    object-fit: contain;
    transform: translateY(-7px);
    transform-origin: 50% 82%;
    animation: cm-ai-mascot-idle 3.8s ease-in-out infinite;
    pointer-events: none;
}

.cm-ai-launcher:focus-visible,
.cm-ai-icon-button:focus-visible,
.cm-ai-send:focus-visible,
.cm-ai-secondary:focus-visible,
.cm-ai-action:focus-visible {
    outline: 3px solid #f5c542;
    outline-offset: 3px;
}

.cm-ai-notification {
    position: absolute;
    top: 0;
    right: 2px;
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    border-radius: 999px;
    background: #d97706;
    color: #111827;
    border: 2px solid #fff;
    font-size: 12px;
    font-weight: 900;
    line-height: 20px;
    z-index: 2;
}

.cm-ai-sparkle {
    position: absolute;
    inset: -6px;
    border-radius: 999px;
    background: conic-gradient(from 90deg, transparent, rgba(245, 197, 66, .55), transparent 34%);
    opacity: 0;
    pointer-events: none;
}

.cm-ai-bubble {
    position: absolute;
    right: 82px;
    bottom: 55px;
    width: 228px;
    padding: 10px 12px;
    border: 1px solid rgba(245, 197, 66, .8);
    border-radius: 16px 16px 4px 16px;
    background: linear-gradient(135deg, #f5c542, #fff7db);
    color: #111827;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .25);
    font-size: 13px;
    font-weight: 800;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .25s ease, transform .25s ease;
    pointer-events: none;
}

.cm-ai-assistant[data-state="greeting"] .cm-ai-bubble,
.cm-ai-assistant[data-state="speaking"] .cm-ai-bubble,
.cm-ai-assistant[data-state="error"] .cm-ai-bubble,
.cm-ai-assistant[data-state="notification"] .cm-ai-bubble {
    opacity: 1;
    transform: translateY(0);
}

.cm-ai-panel {
    position: absolute;
    right: 0;
    bottom: 96px;
    width: min(420px, calc(100vw - 32px));
    max-height: 70vh;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
    border-radius: 18px;
    border: 1px solid rgba(212, 160, 23, .42);
    background: #fffaf0;
    box-shadow: 0 28px 80px rgba(120, 80, 10, .24);
}

.cm-ai-panel[hidden] {
    display: none !important;
}

.cm-ai-header {
    display: grid;
    grid-template-columns: 44px 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: linear-gradient(135deg, #fff7db, #f5c542 55%, #d4a017);
    color: #111827;
}

.cm-ai-header img {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    object-fit: contain;
    background: #fff7db;
    border: 1px solid rgba(17, 24, 39, .12);
}

.cm-ai-header strong,
.cm-ai-header span {
    display: block;
    color: #111827;
    text-shadow: none;
}

.cm-ai-header strong {
    font-size: 15px;
    line-height: 1.1;
}

.cm-ai-header span {
    color: #1f2937;
    font-size: 12px;
    font-weight: 700;
}

.cm-ai-icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(17, 24, 39, .16);
    background: #0f2f5f;
    color: #fff;
    font-weight: 900;
    position: relative;
    z-index: 2;
    cursor: pointer;
}

.cm-ai-body {
    min-height: 280px;
    overflow: auto;
    padding: 14px;
}

.cm-ai-messages {
    display: grid;
    gap: 10px;
}

.cm-ai-message {
    max-width: 92%;
    display: grid;
    gap: 4px;
    padding: 11px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.42;
}

.cm-ai-message.assistant {
    justify-self: start;
    background: #ffffff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
}

.cm-ai-message.user {
    justify-self: end;
    background: #1e3a5f;
    color: #ffffff;
}

.cm-ai-message strong,
.cm-ai-message span {
    color: inherit;
}

.cm-ai-source {
    display: inline-flex;
    width: max-content;
    max-width: 100%;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1e3a5f;
    font-size: 11px;
    font-weight: 900;
}

.cm-ai-source.source-live_system {
    background: #ecfdf5;
    color: #166534;
}

.cm-ai-source.source-faq {
    background: #fffbeb;
    color: #92400e;
}

.cm-ai-source.source-openai {
    background: #eef2ff;
    color: #3730a3;
}

.cm-ai-result-cards {
    display: grid;
    gap: 8px;
    margin-top: 4px;
}

.cm-ai-result-card {
    display: grid;
    gap: 3px;
    padding: 10px;
    border: 1px solid #dbeafe;
    border-left: 4px solid #16a34a;
    border-radius: 12px;
    background: #f8fafc;
    color: #1f2937;
}

.cm-ai-result-card strong {
    font-size: 13px;
    line-height: 1.25;
}

.cm-ai-card-subtitle,
.cm-ai-card-meta,
.cm-ai-card-status {
    display: block;
    color: #4b5563;
    font-size: 12px;
    line-height: 1.35;
}

.cm-ai-card-status {
    color: #166534;
    font-weight: 900;
}

.cm-ai-result-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
}

.cm-ai-result-card-actions .cm-ai-action {
    padding: 7px 9px;
    font-size: 12px;
}

.cm-ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.cm-ai-action,
.cm-ai-secondary,
.cm-ai-send {
    border-radius: 999px;
    border: 1px solid #d4a017;
    background: #ffffff;
    color: #111827;
    font-weight: 900;
    padding: 9px 12px;
    text-decoration: none;
    cursor: pointer;
}

.cm-ai-action:hover,
.cm-ai-secondary:hover {
    background: #fff7db;
}

.cm-ai-error,
.cm-ai-ticket-notice {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    background: #fef2f2;
    color: #991b1b;
    font-weight: 800;
}

.cm-ai-ticket-notice {
    background: #ecfdf5;
    color: #166534;
}

.cm-ai-ticket-notice a {
    display: block;
    color: #14532d;
    margin-top: 4px;
}

.cm-ai-support-drawer {
    margin-top: 14px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #ffffff;
    overflow: hidden;
}

.cm-ai-support-drawer summary {
    cursor: pointer;
    padding: 11px 12px;
    color: #1f2937;
    font-weight: 900;
    list-style: none;
}

.cm-ai-support-drawer summary::-webkit-details-marker {
    display: none;
}

.cm-ai-support-drawer summary::after {
    content: "+";
    float: right;
    color: #d4a017;
}

.cm-ai-support-drawer[open] summary::after {
    content: "-";
}

.cm-ai-support-form,
.cm-ai-ticket-form {
    display: grid;
    gap: 10px;
    padding: 0 12px 12px;
}

.cm-ai-support-form label,
.cm-ai-ticket-form label {
    display: grid;
    gap: 5px;
    color: #1f2937;
    font-size: 12px;
    font-weight: 900;
}

.cm-ai-support-form input,
.cm-ai-support-form textarea,
.cm-ai-ticket-form input {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    color: #111827;
    padding: 9px 10px;
}

.cm-ai-ticket-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.cm-ai-ticket-row button {
    border: 1px solid #d4a017;
    border-radius: 12px;
    background: #fff;
    color: #111827;
    font-weight: 900;
    padding: 0 12px;
}

.cm-ai-support-links,
.cm-ai-support-history {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: #1e3a5f;
    font-size: 12px;
    font-weight: 900;
}

.cm-ai-support-links a,
.cm-ai-support-history {
    color: #1e3a5f;
}

.cm-ai-form {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.cm-ai-form textarea {
    width: 100%;
    min-height: 54px;
    resize: vertical;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 10px 12px;
    color: #111827;
    background: #fff;
}

.cm-ai-form-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.cm-ai-send {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.cm-ai-assistant[data-state="listening"] .cm-ai-launcher {
    box-shadow: 0 0 0 6px rgba(245, 197, 66, .18), 0 22px 50px rgba(15, 23, 42, .28);
}

.cm-ai-assistant[data-state="thinking"] .cm-ai-launcher img,
.cm-ai-assistant[data-state="typing"] .cm-ai-launcher img {
    animation: cm-ai-think 1.2s ease-in-out infinite;
}

.cm-ai-assistant[data-state="success"] .cm-ai-sparkle,
.cm-ai-assistant[data-state="notification"] .cm-ai-sparkle {
    opacity: 1;
    animation: cm-ai-spin .9s ease-out;
}

.cm-ai-assistant[data-state="error"] .cm-ai-launcher {
    background: radial-gradient(circle at 30% 22%, #fff, #f59e0b 48%, #dc2626 102%);
}

.cm-ai-assistant[data-state="sleeping"] .cm-ai-launcher {
    filter: saturate(.72);
    animation-duration: 7s;
}

@keyframes cm-ai-float {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-8px) rotate(1deg); }
}

@keyframes cm-ai-mascot-idle {
    0%, 100% { transform: translateY(-7px) rotate(-2deg) scale(1); }
    24% { transform: translateY(-10px) rotate(2deg) scale(1.015); }
    48% { transform: translateY(-6px) rotate(-1deg) scale(1); }
    72% { transform: translateY(-9px) rotate(2.5deg) scale(1.012); }
}

@keyframes cm-ai-think {
    0%, 100% { transform: translateY(-7px) rotate(-4deg) scale(1); }
    35% { transform: translateY(-13px) rotate(5deg) scale(1.04); }
    70% { transform: translateY(-8px) rotate(-2deg) scale(1.02); }
}

@keyframes cm-ai-spin {
    from { transform: rotate(0deg) scale(.9); }
    to { transform: rotate(180deg) scale(1.08); }
}

@media (max-width: 760px) {
    .cm-ai-assistant {
        right: 14px;
        bottom: calc(92px + env(safe-area-inset-bottom));
    }

    .cm-ai-launcher {
        width: 68px;
        height: 68px;
    }

    .cm-ai-launcher img {
        width: 66px;
        height: 66px;
    }

    .cm-ai-bubble {
        right: 64px;
        bottom: 44px;
        width: min(220px, calc(100vw - 104px));
    }

    .cm-ai-panel {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(86px + env(safe-area-inset-bottom));
        width: auto;
        max-height: min(74vh, 640px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cm-ai-launcher,
    .cm-ai-launcher img,
    .cm-ai-sparkle {
        animation: none !important;
    }
}
