/* --- Responsive Toggle Size Variables --- */
:root {
    /* Mobile First Default */
    --n8n-cw-toggle-size: var(--n8n-cw-toggle-size-mobile, 50px);

    /* --- Global Theme Vars (set by JS via wp_localize_script) --- */
    --n8n-cw-header-bg: #f1f1f1;
    --n8n-cw-header-text-color: #000000;
    --n8n-cw-user-msg-bg: #0073aa;

    /* --- Send Button Vars (visual polish, set by JS) --- */
    --n8n-cw-send-btn-bg-idle: #cfcfcf;
    --n8n-cw-send-btn-bg-active: var(--n8n-cw-user-msg-bg);
    --n8n-cw-send-btn-bg-hover: rgba(0, 0, 0, 0.15);
    --n8n-cw-send-btn-icon-color: #ffffff;

    /* --- UI Vars --- */
    --n8n-cw-btn-radius: 50%;
}

@media (min-width: 768px) {
    :root { /* Tablet */
        --n8n-cw-toggle-size: var(--n8n-cw-toggle-size-tablet, 60px);
    }
}
@media (min-width: 992px) {
    :root { /* Desktop */
        --n8n-cw-toggle-size: var(--n8n-cw-toggle-size-desktop, 70px);
    }
}


/* --- General Container & Toggle Button --- */
#n8n-cw-container {
    /* This element is now only for JS to apply position classes */
}

/* Style for the SVG container button */
div#n8n-cw-toggle {
    position: fixed !important;
    bottom: var(--n8n-cw-bottom-spacing, 20px) !important;
    z-index: 99999 !important;
    background-color: var(--n8n-cw-user-msg-bg, #0073aa);
    color: white;
    width: var(--n8n-cw-toggle-size);
    height: var(--n8n-cw-toggle-size);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease-in-out;
}

/* Style for the Image-as-a-button */
img#n8n-cw-toggle {
    position: fixed !important;
    bottom: var(--n8n-cw-bottom-spacing, 20px) !important;
    z-index: 99999 !important;
    width: var(--n8n-cw-toggle-size);
    height: var(--n8n-cw-toggle-size);
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease-in-out;
}

#n8n-cw-container.n8n-cw-position-bottom-right #n8n-cw-toggle { right: var(--n8n-cw-side-spacing, 20px) !important; left: auto !important; }
#n8n-cw-container.n8n-cw-position-bottom-left #n8n-cw-toggle { left: var(--n8n-cw-side-spacing, 20px) !important; right: auto !important; }
#n8n-cw-container.n8n-cw-position-bottom-center #n8n-cw-toggle { left: 50% !important; transform: translateX(-50%) !important; right: auto !important; }

#n8n-cw-toggle:hover { transform: scale(1.1) !important; }
#n8n-cw-toggle.n8n-cw-hidden { display: none; }

#n8n-cw-toggle svg {
    width: calc(var(--n8n-cw-toggle-size) * 0.55);
    height: calc(var(--n8n-cw-toggle-size) * 0.55);
}


/* --- Chat Widget Window --- */
#n8n-cw-widget {
    z-index: 99999 !important;
    width: 350px;
    max-width: 90vw;
    height: 500px;
    max-height: 80vh;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s, transform 0.3s;
    position: fixed;
    bottom: calc(var(--n8n-cw-bottom-spacing, 20px) + var(--n8n-cw-toggle-size) + 20px);
}

#n8n-cw-container.n8n-cw-position-bottom-right #n8n-cw-widget { right: var(--n8n-cw-side-spacing, 20px); transform-origin: bottom right; }
#n8n-cw-container.n8n-cw-position-bottom-left #n8n-cw-widget { left: var(--n8n-cw-side-spacing, 20px); transform-origin: bottom left; }
#n8n-cw-container.n8n-cw-position-bottom-center #n8n-cw-widget { left: 50%; transform: translateX(-50%); transform-origin: bottom center; }

#n8n-cw-widget.n8n-cw-hidden { opacity: 0; transform: scale(0.5); pointer-events: none; }


/* --- Header --- */
.n8n-cw-header {
    background-color: var(--n8n-cw-header-bg, #f1f1f1);
    padding: 10px 15px;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    position: relative;
    z-index: 5;
    box-sizing: border-box;
}

.n8n-cw-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
}

.n8n-cw-header-avatar.n8n-cw-hidden {
    display: none;
}

.n8n-cw-header-title {
    margin: 0 !important;
    font-size: 16px;
    font-weight: 600;
    flex-grow: 1;
    color: var(--n8n-cw-header-text-color, #000000);
}

.n8n-cw-header-subtitle {
    font-size: 12px;
    line-height: 1.2;
    opacity: 0.8;
    color: var(--n8n-cw-header-text-color, #000000);
}

#n8n-cw-close {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: auto;
    padding: 5px;
    line-height: 0;
    flex-shrink: 0;
}

#n8n-cw-close svg {
    width: 24px;
    height: 24px;
    fill: var(--n8n-cw-header-text-color, #000000);
    transition: opacity 0.2s;
}

#n8n-cw-close:hover svg {
    opacity: 0.7;
}


/* --- Body / Messages Area --- */
.n8n-cw-chat-body {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f9f9f9;
}

.n8n-cw-message {
    display: flex;
    margin-bottom: 15px;
    align-items: flex-start;
    gap: 8px;
}

.n8n-cw-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}

.n8n-cw-message p {
    padding: 10px 15px 15px 15px;
    border-radius: 18px;
    max-width: 85%;
    margin: 0;
    line-height: 1.4;
    word-wrap: break-word;
}

.n8n-cw-message.n8n-cw-user { justify-content: flex-end; }
.n8n-cw-message.n8n-cw-user .n8n-cw-message-avatar { order: 2; }
.n8n-cw-message.n8n-cw-user p {
    background-color: var(--n8n-cw-user-msg-bg, #0073aa);
    color: white;
    border-bottom-right-radius: 4px;
}

.n8n-cw-message.n8n-cw-bot { justify-content: flex-start; }
.n8n-cw-message.n8n-cw-bot p {
    background-color: #e5e5ea;
    color: #000;
    border-bottom-left-radius: 4px;
}


/* --- Timestamp Styles --- */
.n8n-cw-timestamp {
    display: block;
    font-size: 11px;
    color: #999999;
    margin-top: 5px;
    text-align: right;
    clear: both;
}

.n8n-cw-message.n8n-cw-user .n8n-cw-timestamp {
    color: rgba(255, 255, 255, 0.75);
}


/* --- Typing Indicator --- */
.n8n-cw-message.n8n-cw-typing p {
    display: flex;
    align-items: center;
    padding: 12px 15px;
}

.n8n-cw-message.n8n-cw-typing span {
    height: 8px;
    width: 8px;
    background-color: #aaa;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: n8n-cw-bounce 1.2s infinite;
}

@keyframes n8n-cw-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}


/* --- Footer / Input Area --- */
.n8n-cw-chat-footer {
    padding: 10px;
    border-top: 1px solid #ddd;
    background-color: #fff;
    position: relative;
    z-index: 5;
}

#n8n-cw-chat-form {
    display: flex;
    align-items: center;
}

#n8n-cw-chat-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 14px;
    margin-right: 8px;
}

#n8n-cw-chat-input:focus {
    outline: none;
    border-color: var(--n8n-cw-user-msg-bg, #0073aa);
}

/* --- Send Button (Polished + Brandable) --- */
#n8n-cw-send-btn {
    background-color: var(--n8n-cw-send-btn-bg-idle);
    color: var(--n8n-cw-send-btn-icon-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--n8n-cw-btn-radius);
    width: 42px;
    height: 42px;
    cursor: not-allowed;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: transform 0.12s ease, opacity 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

#n8n-cw-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    opacity: 0.85;
}

#n8n-cw-send-btn.n8n-cw-active {
    background-color: var(--n8n-cw-send-btn-bg-active);
    cursor: pointer;
    border-color: rgba(0,0,0,0.06);
    box-shadow: 0 6px 14px rgba(0,0,0,0.14);
}

#n8n-cw-send-btn.n8n-cw-active svg {
    opacity: 1;
}

#n8n-cw-send-btn.n8n-cw-active:hover {
    background-color: var(--n8n-cw-send-btn-bg-hover);
    transform: translateY(-1px);
}

#n8n-cw-send-btn.n8n-cw-active:active {
    transform: translateY(0px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

#n8n-cw-send-btn:disabled {
    opacity: 0.75;
    box-shadow: none;
}


/* --- GDPR Consent Overlay Styles --- */
#n8n-cw-consent-overlay {
    position: absolute;
    top: 55px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    display: none;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    z-index: 10;
}

.n8n-cw-consent-content { max-width: 90%; }
.n8n-cw-consent-text { font-size: 14px; line-height: 1.5; color: #333; margin-bottom: 20px; }
.n8n-cw-consent-text p { margin: 0; }
.n8n-cw-consent-text a { color: var(--n8n-cw-user-msg-bg, #0073aa); text-decoration: underline; }

.n8n-cw-consent-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
}

#n8n-cw-consent-btn-accept,
#n8n-cw-consent-btn-deny {
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s;
}

#n8n-cw-consent-btn-accept { background-color: var(--n8n-cw-user-msg-bg, #0073aa); color: white; }
#n8n-cw-consent-btn-deny { background-color: #e5e5ea; color: #333; }
#n8n-cw-consent-btn-accept:hover,
#n8n-cw-consent-btn-deny:hover { opacity: 0.9; }


/* --- Embed Mode Overrides (shortcode output) --- */
/* The embed version is not fixed-position and should fill its container. */
.n8n-cw-embed #n8n-cw-toggle,
.n8n-cw-embed div#n8n-cw-toggle,
.n8n-cw-embed img#n8n-cw-toggle {
    display: none !important;
}

.n8n-cw-embed #n8n-cw-container {
    position: relative;
}

.n8n-cw-embed #n8n-cw-widget {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
    transform-origin: initial !important;

    width: 100% !important;
    max-width: none !important;

    /* Height is set inline by shortcode when provided */
    max-height: none !important;

    z-index: 1 !important;
}

/* If you want the embed to keep the same nice card look inside builders */
.n8n-cw-embed .n8n-cw-embed-widget {
    border-radius: 10px;
}


/* --- Device Visibility Rules --- */
@media (min-width: 992px) {
    .n8n-cw-hide-on-desktop #n8n-cw-container { display: none !important; }
}
@media (min-width: 768px) and (max-width: 991px) {
    .n8n-cw-hide-on-tablet #n8n-cw-container { display: none !important; }
}
@media (max-width: 767px) {
    .n8n-cw-hide-on-mobile #n8n-cw-container { display: none !important; }
}

