/* --- Responsive Toggle Size Variables --- */
:root {
    /* Mobile First Default */
    --n8n-cw-toggle-size: var(--n8n-cw-toggle-size-mobile, 50px);
}
@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-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); }
#n8n-cw-send-btn { background-color: #ccc; color: white; border: none; border-radius: 50%; width: 40px; height: 40px; cursor: not-allowed; display: flex; justify-content: center; align-items: center; padding: 0; transition: background-color 0.2s ease; }
#n8n-cw-send-btn svg {
    /* No margin needed, flexbox handles centering */
}
#n8n-cw-send-btn.n8n-cw-active { background-color: var(--n8n-cw-user-msg-bg, #0073aa); cursor: pointer; }
#n8n-cw-send-btn.n8n-cw-active:hover { opacity: 0.9; }

/* --- 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; }

/* --- 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; }
}