:root {
    --n8n-primary: var(--neon-blue, #00ffea);
    --n8n-secondary: var(--dashboard-bg, #0b0c10);
    --n8n-accent: var(--neon-orange, #ff4d1d);
    --n8n-text: var(--text-main, #c5c6c7);
    --n8n-bg-dark: var(--surface-2, #1f2833);
    --n8n-user-bubble: var(--neon-blue, #00ffea);
    --n8n-bot-bubble: var(--surface-1, #2c3e50);
    --n8n-shadow: rgba(0, 255, 234, 0.4);
    --n8n-shadow-warm: rgba(255, 77, 29, 0.35);
    --n8n-card-radius: 14px;
    --n8n-card-border: var(--border-strong, rgba(0, 255, 234, 0.25));
    --n8n-glass-border: rgba(255, 255, 255, 0.16);
    --n8n-chat-clip: var(--clip-btn, polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px));
    --n8n-muted: var(--text-muted, #8fa2b0);
    --n8n-surface-glass: linear-gradient(160deg, rgba(6, 12, 18, 0.85), rgba(12, 17, 23, 0.84));
    --n8n-glass-bg: rgba(0, 255, 234, 0.09);
    --n8n-card-clip: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
}

/* Floating Button */
.n8n-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 10000;
    width: 148px;
    min-width: 148px;
    height: 116px;
    padding: 0;
    border-radius: 12px;
    clip-path: none;
    transition: transform 0.22s ease, box-shadow 0.22s ease, opacity 0.22s ease;
    box-shadow: none;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.42px;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: "Orbitron", sans-serif;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.n8n-chat-brand {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    flex: 0 0 54px;
    padding: 2px;
    background: linear-gradient(160deg, rgba(255, 77, 29, 0.22), rgba(255, 77, 29, 0.05));
    border: 1.5px solid var(--neon-orange);
    overflow: visible;
    clip-path: var(--n8n-chat-clip);
    box-shadow: 0 0 12px rgba(255, 77, 29, 0.27);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: n8n-chat-brand-callout 1.5s ease-in-out infinite;
}

.n8n-chat-brand::after {
    content: "";
    position: absolute;
    inset: 3px;
    border: 1px solid rgba(255, 77, 29, 0.25);
    clip-path: inherit;
    pointer-events: none;
}

.n8n-chat-brand::before {
    content: "";
    position: absolute;
    inset: -10px;
    border: 1px solid rgba(255, 77, 29, 0.45);
    clip-path: var(--n8n-chat-clip);
    border-radius: inherit;
    pointer-events: none;
    animation: n8n-attention-ring 2.6s ease-in-out infinite;
    opacity: 0;
}

.n8n-chat-btn.is-open .n8n-chat-brand::before {
    animation: none;
    opacity: 0;
}

.n8n-chat-brand__svg,
.n8n-chat-brand__icon {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 0 6px rgba(0, 255, 234, 0.32));
    transform-origin: 50% 50%;
    position: relative;
    z-index: 1;
}

.n8n-chat-brand__svg path,
.n8n-chat-brand__icon::before {
    transform-origin: 50% 50%;
    line-height: 1;
}

.n8n-chat-brand__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #ecfdff;
    width: 100%;
    height: 100%;
    line-height: 1;
    animation: n8n-chat-icon-wave 1.6s ease-in-out infinite;
}

.n8n-chat-btn:not(.is-open) .n8n-chat-brand {
    animation: n8n-chat-brand-callout 1.5s ease-in-out infinite;
}

.n8n-chat-btn.is-open .n8n-chat-brand {
    animation: none;
}

.n8n-chat-btn:hover .n8n-chat-brand__icon {
    animation: none;
}

.n8n-chat-btn:hover .n8n-chat-brand__svg {
    animation: none;
}

.n8n-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: none;
}

.n8n-chat-btn:hover .n8n-chat-brand {
    transform: scale(1.06);
    box-shadow: 0 0 16px rgba(255, 77, 29, 0.42);
}

.n8n-chat-btn:active {
    transform: scale(0.98);
}

@media (max-width: 480px) {
    .n8n-chat-btn {
        bottom: calc(15px + env(safe-area-inset-bottom, 0px));
        right: calc(15px + env(safe-area-inset-right, 0px));
        width: 132px;
        min-width: 132px;
        height: 102px;
        padding: 0;
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .n8n-chat-brand {
        width: 48px;
        height: 48px;
        flex: 0 0 48px;
    }

    .n8n-chat-brand__icon {
        font-size: 1.45rem;
    }
}

.n8n-chat-btn::before {
    display: none;
    content: none;
}

.n8n-chat-btn::after {
    display: none;
    content: none;
}

.n8n-chat-btn.is-open {
    box-shadow: none;
}

.n8n-chat-btn.is-open::before {
    animation: none;
    opacity: 0;
}

.n8n-chat-btn:focus-visible {
    outline: none;
    box-shadow: none;
}

.n8n-chat-btn:focus {
    outline: none;
    box-shadow: none;
}

@keyframes n8n-chat-brand-breathe {
    0%,
    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 6px rgba(0, 255, 234, 0.22));
    }
    50% {
        transform: scale(1.04) translateY(-1px);
        filter: drop-shadow(0 0 12px rgba(0, 255, 234, 0.44));
    }
}

@keyframes n8n-chat-icon-wave {
    0% {
        transform: scale(1) rotate(0deg);
    }
    25% {
        transform: scale(1.07) rotate(-4deg);
    }
    50% {
        transform: scale(1) rotate(0deg);
    }
    75% {
        transform: scale(1.07) rotate(4deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes n8n-chat-brand-boost {
    0% {
        transform: scale(1);
    }
    55% {
        transform: scale(1.08) rotate(-2deg);
        filter: drop-shadow(0 0 16px rgba(255, 77, 29, 0.45));
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes n8n-chat-brand-callout {
    0% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(255, 77, 29, 0.25), 0 0 0 0 rgba(255, 77, 29, 0.2);
    }
    50% {
        transform: scale(1.09);
        box-shadow: 0 0 20px rgba(255, 77, 29, 0.45), 0 0 0 8px rgba(255, 77, 29, 0.12);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(255, 77, 29, 0.25), 0 0 0 0 rgba(255, 77, 29, 0.2);
    }
}

.n8n-chat-btn .n8n-chat-brand__icon {
    font-size: 1.6rem !important;
    line-height: 1;
}

.n8n-chat-btn i:not(.n8n-chat-brand__icon) {
    font-size: 1rem;
    line-height: 1;
}

.n8n-chat-btn-label {
    font-weight: 700;
    text-wrap: nowrap;
}

@keyframes n8n-attention-ring {
    0% {
        transform: scale(0.9);
        opacity: 0.75;
    }
    55% {
        transform: scale(1.08);
        opacity: 0.25;
    }
    100% {
        transform: scale(0.9);
        opacity: 0.75;
    }
}

@keyframes n8n-attention-glass {
    0%,
    100% {
        opacity: 0.18;
        transform: scale(0.93);
    }
    50% {
        opacity: 0.4;
        transform: scale(1.15);
    }
}

/* Chat Container */
.n8n-chat-container {
    position: fixed;
    bottom: 92px;
    right: 20px;
    width: min(380px, calc(100vw - 32px));
    height: min(560px, 82vh);
    max-height: min(82vh, calc(100vh - 120px));
    z-index: 9999;
    font-family: "Barlow", "Roboto", Arial, sans-serif;
    animation: slideIn 0.3s ease-out;
    background-color: transparent;
    margin-right: env(safe-area-inset-right, 0px);
    margin-bottom: env(safe-area-inset-bottom, 0px);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.n8n-chat-card {
    width: 100%;
    height: 100%;
    background: var(--n8n-surface-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--n8n-glass-border);
    border-radius: var(--n8n-card-radius);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px var(--n8n-shadow), 0 0 28px var(--n8n-shadow-warm), inset 0 0 24px rgba(255, 255, 255, 0.04);
    overflow: hidden;
    clip-path: var(--n8n-card-clip);
}

/* Header */
.n8n-chat-header {
    padding: 15px;
    background: linear-gradient(135deg, rgba(0, 255, 234, 0.14), rgba(255, 77, 29, 0.12));
    border-bottom: 1px solid var(--n8n-glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.n8n-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.n8n-avatar {
    width: 32px;
    height: 32px;
    background: var(--n8n-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-weight: bold;
}

.n8n-title {
    display: flex;
    flex-direction: column;
}

.n8n-agent-name {
    color: #fff;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.n8n-status {
    color: color-mix(in oklab, var(--n8n-accent), #fff 35%);
    font-size: 0.7rem;
}

.n8n-header-actions button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 5px;
    transition: color 0.2s;
}

.n8n-header-actions button:hover {
    color: #fff;
}

/* Chat Body */
.n8n-chat-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
}

.n8n-msg {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.n8n-msg-content {
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.typing-dots .dot {
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    animation: n8n-dot-bounce 1s infinite ease-in-out;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes n8n-dot-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

.n8n-msg-bot {
    align-self: flex-start;
}

.n8n-msg-bot .n8n-msg-content {
    background: rgba(19, 35, 50, 0.86);
    color: #fff;
    border-top-left-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 12px rgba(0, 255, 234, 0.1);
}

.n8n-msg-user {
    align-self: flex-end;
}

.n8n-msg-user .n8n-msg-content {
    background: var(--n8n-user-bubble);
    color: #000;
    border-top-right-radius: 2px;
    font-weight: 500;
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.45);
}

.n8n-msg-time {
    font-size: 0.65rem;
    color: var(--n8n-muted);
    margin-top: 4px;
    align-self: flex-end;
}

.n8n-msg-bot .n8n-msg-time {
    align-self: flex-start;
}

/* Footer & Input */
.n8n-chat-footer {
    padding: 15px;
    background: var(--n8n-bg-dark);
    border-top: 1px solid var(--n8n-glass-border);
}

.n8n-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(0, 243, 255, 0.2);
}

.n8n-input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    resize: none;
    font-family: inherit;
    font-size: 0.9rem;
    max-height: 100px;
    outline: none;
    line-height: 1.35;
}

.n8n-input-wrapper button {
    background: linear-gradient(155deg, rgba(255, 77, 29, 0.94), rgba(255, 77, 29, 0.78));
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #0f0f13;
    transition: opacity 0.2s;
    box-shadow: 0 0 14px rgba(255, 77, 29, 0.35);
}

.n8n-input-wrapper button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.n8n-input-wrapper button:hover:not(:disabled) {
    filter: brightness(1.08);
}

.n8n-input-wrapper button[aria-busy="true"] {
    opacity: 0.75;
}

.n8n-footer-branding {
    text-align: center;
    font-size: 0.6rem;
    color: var(--n8n-muted);
    margin-top: 5px;
}

.n8n-empty-state {
    color: var(--n8n-muted);
    font-size: 0.82rem;
    text-align: center;
    border: 1px dashed var(--n8n-glass-border);
    border-radius: 10px;
    padding: 10px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .n8n-chat-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        max-height: 100%;
        border-radius: 0;
        margin-right: env(safe-area-inset-right, 0px);
        margin-bottom: env(safe-area-inset-bottom, 0px);
    }

    .n8n-chat-card {
        border-radius: 0;
        border: none;
    }
}

@media (max-width: 991px) {
    body.dashboard-body .n8n-chat-btn,
    body.dashboard-body .n8n-chat-container {
        display: none !important;
    }
}
