/**
 * n8n Chatbot Integrator - Frontend Styles v2.1 (UI/UX Polish)
 *
 * This stylesheet provides the styles for the floating chat widget.
 * It uses CSS variables for customization and includes animations for a polished feel.
 */

/* --- Main Widget Container --- */
#n8n-chat-widget {
    position: fixed;
    bottom: var(--n8n-widget-bottom-spacing, 20px);
    right: var(--n8n-widget-right-spacing, 20px);
    z-index: 2147483647; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

/* --- Chat Bubble --- */
.n8n-chat-bubble {
    width: var(--n8n-bubble-size, 60px);
    height: var(--n8n-bubble-size, 60px);
    background-color: var(--n8n-primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--n8n-shadow-color, rgba(0, 0, 0, 0.15));
    transition: transform var(--n8n-transition-speed, 0.3s) ease, box-shadow var(--n8n-transition-speed, 0.3s) ease;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.n8n-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px var(--n8n-shadow-color, rgba(0, 0, 0, 0.15));
}

/* --- Bubble Icons --- */
.n8n-chat-bubble-icon {
    position: absolute;
    width: 60%;
    height: 60%;
    transition: transform var(--n8n-transition-speed, 0.3s) ease, opacity var(--n8n-transition-speed, 0.3s) ease;
}

.n8n-bubble-icon-open { object-fit: contain; transform: scale(1); opacity: 1; }
.n8n-bubble-icon-close {
    /* Pozicioniranje cez cel krog */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    /* Flexbox centriranje - to bo sedaj delovalo perfektno za SVG */
    display: flex;
    justify-content: center;
    align-items: center;

    /* Barva ikone */
    color: var(--n8n-user-message-text-color);

    /* Animacija - zacetno stanje (zaprto) */
    transform: scale(0.5) rotate(-90deg);
    opacity: 0;
    
    /* Preprecimo vpliv pisav */
    line-height: normal;
    padding: 0;
}

/* Prisilno zmanjsanje SVG ikone za X */
.n8n-bubble-icon-close svg {
    width: 22px !important;
    height: 22px !important;
}

/* --- Chat Window --- */
.n8n-chat-window {
    position: absolute;
    bottom: calc(var(--n8n-bubble-size, 60px) + 15px);
    right: 0;
    width: 370px;
    height: 70vh;
    max-height: 580px;
    background-color: var(--n8n-background-color);
    border-radius: 12px;
    box-shadow: 0 5px 40px var(--n8n-shadow-color, rgba(0, 0, 0, 0.15));
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity var(--n8n-transition-speed, 0.3s) ease, visibility var(--n8n-transition-speed, 0.3s) ease, transform var(--n8n-transition-speed, 0.3s) ease;
    display: flex;
    flex-direction: column;
}

/* --- Open/Visible State Logic --- */
#n8n-chat-widget.is-open .n8n-chat-window { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
#n8n-chat-widget.is-open .n8n-chat-bubble { transform: rotate(180deg); }
#n8n-chat-widget.is-open .n8n-bubble-icon-open { transform: scale(0.5) rotate(-90deg); opacity: 0; }
#n8n-chat-widget.is-open .n8n-bubble-icon-close { transform: scale(1) rotate(0deg); opacity: 1; }

/* --- Header --- */
.n8n-chat-header {
    position: relative; /* Required for alignment options */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--n8n-header-background);
    border-bottom: 1px solid var(--n8n-border-color, #e0e0e0);
    flex-shrink: 0;
}
.n8n-chat-header-logo { max-width: 150px; object-fit: contain; }
.n8n-chat-close-button { width: 32px; height: 32px; border: none; background: none; cursor: pointer; padding: 0; border-radius: 50%; display: flex; justify-content: center; align-items: center; transition: background-color 0.2s ease; font-size: 24px; font-weight: 300; color: #555; line-height: 1; }
.n8n-chat-close-button:hover { background-color: rgba(0, 0, 0, 0.08); }

/* --- Header Alignment Options --- */
.n8n-header-align-center {
    justify-content: center;
}
.n8n-header-align-center .n8n-chat-close-button {
    position: absolute;
    right: 12px;
}
.n8n-header-align-right {
    flex-direction: row-reverse;
}

/* --- Body & Messages --- */
.n8n-chat-body { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; }
.n8n-chat-messages { flex-grow: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }

.n8n-chat-message {
    padding: 10px 14px;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.5;
    word-wrap: break-word;
    animation: slideIn 0.3s ease-out forwards;
}

.n8n-chat-message--bot { background-color: var(--n8n-bot-message-bg-color); color: var(--n8n-bot-message-text-color); align-self: flex-start; border-bottom-left-radius: 4px; }
.n8n-chat-message--user { background-color: var(--n8n-primary-color); color: var(--n8n-user-message-text-color); align-self: flex-end; border-bottom-right-radius: 4px; }

/* --- Footer & Input --- */
.n8n-chat-footer { padding: 12px 16px; border-top: 1px solid var(--n8n-border-color, #e0e0e0); background-color: var(--n8n-header-background); }
.n8n-chat-form { display: flex; align-items: center; gap: 10px; }
.n8n-chat-input { flex-grow: 1; border: 1px solid #ccc; border-radius: 20px; padding: 10px 15px; font-size: 15px; line-height: 1.4; transition: border-color 0.2s ease; }
.n8n-chat-input:focus { outline: none; border-color: var(--n8n-primary-color); box-shadow: 0 0 0 2px color-mix(in srgb, var(--n8n-primary-color) 20%, transparent); }

/* --- Send Button --- */
.n8n-chat-send-btn {
    flex-shrink: 0;
    border: none;
    border-radius: 8px;
    background-color: var(--n8n-primary-color);
    color: var(--n8n-user-message-text-color);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center; /* Add this for good measure */
    padding: 0 16px;
    height: 42px;
    font-size: 15px;
    font-weight: 600;
    transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.1s ease;
}
.n8n-chat-send-btn:hover:not(:disabled) { opacity: 0.85; }
.n8n-chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.n8n-chat-send-btn:not(:disabled):active { transform: scale(0.92); }


/* --- Typing Indicator --- */
.n8n-typing-indicator span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background-color: #999; animation: n8n-typing-bounce 1.3s infinite; margin: 0 1px; }
.n8n-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.n8n-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* --- Animations --- */
@keyframes n8n-typing-bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- Responsive Design & Mobile Optimizations --- */
@media (max-width: 768px) {
    #n8n-chat-widget {
        --n8n-widget-bottom-spacing: 15px;
        --n8n-widget-right-spacing: 15px;
    }
    .n8n-chat-window {
        width: 100vw;
        height: 100dvh; /* Use dynamic viewport height to adapt to virtual keyboard */
        max-height: 100dvh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        box-shadow: none;
        position: fixed;
    }
    #n8n-chat-widget.is-open .n8n-chat-bubble {
        display: none; /* Hide bubble in fullscreen mobile view */
    }
    .n8n-chat-close-button {
        width: 40px; /* Increase tap target size */
        height: 40px;
        font-size: 28px;
    }
}

/* --- Header Buttons --- */
.n8n-chat-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- New Chat Button --- */
.n8n-chat-new-chat-button {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
    color: #555;
}

.n8n-chat-new-chat-button:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.n8n-new-chat-icon {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}
