/**
 * N8N Chatbot - Stylesheet v2.0
 *
 * CSS variabelen worden gezet via JavaScript:
 * --n8n-primary-color       : legacy fallback
 * --n8n-header-color        : header achtergrond
 * --n8n-button-color        : toggle (FAB) + verzend knop achtergrond
 * --n8n-user-bubble-color   : gebruikers berichtkleur
 * --n8n-toggle-icon-color   : SVG-icoon kleur in de FAB-knop
 * --n8n-send-icon-color     : pijl-icoon kleur in de verzendknop
 * --n8n-send-border-color   : rand van de verzendknop
 * --n8n-quick-border-color  : rand van de snelle-keuze knoppen
 * --n8n-quick-text-color    : tekstkleur van de snelle-keuze knoppen
 * --n8n-prompt-bg-color     : achtergrond van het prompt-ballonnetje
 * --n8n-prompt-text-color   : tekstkleur van het prompt-ballonnetje
 * --n8n-prompt-border-color : rand + pijltje van het prompt-ballonnetje
 */

/* ============================================
   CONTAINER & POSITIONERING
   ============================================ */

#n8n-chatbot-container {
    position: fixed;
    bottom: 22px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

#n8n-chatbot-container.n8n-chatbot-right {
    right: 20px;
}

#n8n-chatbot-container.n8n-chatbot-left {
    left: 20px;
}

/* Reset voor elementen binnen de chatbot.
   Houd deze laag-specifiek, zodat component-styling padding/marges kan bepalen. */
#n8n-chatbot-container,
#n8n-chatbot-container :where(*) {
    box-sizing: border-box;
}

#n8n-chatbot-container :where(button, input) {
    font: inherit;
}

/* ============================================
   TOGGLE KNOP
   ============================================ */

.n8n-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--n8n-button-color, var(--n8n-primary-color, #0073aa));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 14px 32px rgba(79, 70, 229, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: var(--n8n-toggle-icon-color, #ffffff);
}

.n8n-chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.n8n-chatbot-toggle:active {
    transform: scale(0.95);
}

.n8n-chatbot-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.n8n-chatbot-prompt {
    position: absolute;
    bottom: 8px;
    width: max-content;
    min-width: 190px;
    max-width: 260px;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--n8n-prompt-border-color, #e2e8f0);
    border-radius: 12px;
    background: var(--n8n-prompt-bg-color, #ffffff);
    color: var(--n8n-prompt-text-color, #1f2937);
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.16);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    white-space: normal;
    animation: n8n-chatbot-prompt-appear 0.22s ease;
}

.n8n-chatbot-right .n8n-chatbot-prompt {
    right: 72px;
}

.n8n-chatbot-left .n8n-chatbot-prompt {
    left: 72px;
}

.n8n-chatbot-prompt::after {
    content: '';
    position: absolute;
    bottom: 14px;
    width: 12px;
    height: 12px;
    background: var(--n8n-prompt-bg-color, #ffffff);
    border-top: 1px solid var(--n8n-prompt-border-color, #e2e8f0);
    border-right: 1px solid var(--n8n-prompt-border-color, #e2e8f0);
}

.n8n-chatbot-right .n8n-chatbot-prompt::after {
    right: -7px;
    transform: rotate(45deg);
}

.n8n-chatbot-left .n8n-chatbot-prompt::after {
    left: -7px;
    transform: rotate(225deg);
}

@keyframes n8n-chatbot-prompt-appear {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   CHAT WINDOW
   ============================================ */

.n8n-chatbot-window {
    position: absolute;
    bottom: 78px;
    width: 440px;
    max-width: calc(100vw - 28px);
    height: 550px;
    max-height: calc(100vh - 112px);
    background: white;
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 14px;
    box-shadow: 0 22px 54px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: n8n-chatbot-slide-up 0.3s ease;
}

.n8n-chatbot-right .n8n-chatbot-window {
    right: 0;
}

.n8n-chatbot-left .n8n-chatbot-window {
    left: 0;
}

@keyframes n8n-chatbot-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   HEADER
   ============================================ */

.n8n-chatbot-header {
    background: var(--n8n-header-color, var(--n8n-primary-color, #1E1B4B));
    color: white;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    position: relative;
}

/* Gradient-overlay voor dieptewerking bovenop de basiskleur */
.n8n-chatbot-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 55%);
    pointer-events: none;
    border-radius: inherit;
}

/* Zorg dat alle directe header-kinderen boven de gradient-overlay liggen */
.n8n-chatbot-header > * {
    position: relative;
    z-index: 1;
}

.n8n-chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
}

.n8n-chatbot-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.n8n-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.n8n-chatbot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.n8n-chatbot-avatar img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    border-radius: 7px;
}

.n8n-chatbot-avatar-emoji {
    font-size: 18px;
    line-height: 1;
}

.n8n-chatbot-name {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.n8n-chatbot-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    opacity: 0.9;
}

.n8n-chatbot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffc107;
}

.n8n-chatbot-status-online .n8n-chatbot-status-dot {
    background: #4caf50;
}

.n8n-chatbot-status-offline .n8n-chatbot-status-dot {
    background: #f44336;
}

.n8n-chatbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
    display: none;
}

.n8n-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Reset Chat knop in header */
.n8n-chatbot-reset {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.n8n-chatbot-reset:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   BERICHTEN GEBIED
   ============================================ */

.n8n-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 36px 36px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8fafc;
}

/* Scrollbar styling */
.n8n-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.n8n-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.n8n-chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.n8n-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ============================================
   BERICHTEN
   ============================================ */

.n8n-chatbot-message {
    display: flex;
    max-width: 82%;
    align-items: flex-start;
    gap: 14px;
    animation: n8n-chatbot-message-appear 0.2s ease;
}

@keyframes n8n-chatbot-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.n8n-chatbot-message-user {
    align-self: flex-end;
    margin-left: 64px;
    max-width: 74%;
}

.n8n-chatbot-message-bot {
    align-self: flex-start;
    max-width: 100%;
    margin-right: 18px;
}

.n8n-chatbot-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--n8n-button-color, var(--n8n-primary-color, #4F46E5));
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    margin-top: 0;
    overflow: hidden;
}

.n8n-chatbot-message-avatar img {
    width: 76%;
    height: 76%;
    object-fit: contain;
    border-radius: 6px;
}

.n8n-chatbot-message-avatar .n8n-chatbot-avatar-emoji {
    font-size: 16px;
}

.n8n-chatbot-message-content {
    padding: 14px 17px;
    border-radius: 10px;
    word-wrap: break-word;
    line-height: 1.55;
}

.n8n-chatbot-message-user .n8n-chatbot-message-content {
    background: var(--n8n-user-bubble-color, var(--n8n-primary-color, #0073aa));
    color: white;
    border-bottom-right-radius: 4px;
}

.n8n-chatbot-message-bot .n8n-chatbot-message-content {
    background: #ffffff;
    color: #1a1a2e;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 4px;
    box-shadow: none;
}

.n8n-chatbot-message-error .n8n-chatbot-message-content {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

/* Links in berichten */
.n8n-chatbot-message-content a {
    color: inherit;
    text-decoration: underline;
}

.n8n-chatbot-message-user .n8n-chatbot-message-content a {
    color: white;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.n8n-chatbot-typing .n8n-chatbot-message-content {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
}

.n8n-chatbot-typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: n8n-chatbot-typing-bounce 1.4s infinite ease-in-out;
}

.n8n-chatbot-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes n8n-chatbot-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   INPUT FORM
   ============================================ */

.n8n-chatbot-form {
    display: flex;
    margin: 22px 36px 0;
    padding: 12px;
    background: white;
    border: 1.5px solid var(--n8n-button-color, var(--n8n-primary-color, #4F46E5));
    border-radius: 14px;
    gap: 12px;
    flex-shrink: 0;
    align-items: flex-end;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}

.n8n-chatbot-input {
    flex: 1;
    padding: 4px 5px;
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    min-width: 0;
    min-height: 40px;
    max-height: 132px;
    line-height: 1.45;
    resize: none;
    overflow-y: auto;
    white-space: pre-wrap;
}

.n8n-chatbot-input:focus {
    box-shadow: none;
}

.n8n-chatbot-input::placeholder {
    color: #999;
}

.n8n-chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--n8n-button-color, var(--n8n-primary-color, #4F46E5));
    border: 1px solid var(--n8n-send-border-color, transparent);
    color: var(--n8n-send-icon-color, #ffffff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
    box-shadow: none;
}

.n8n-chatbot-send:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}

.n8n-chatbot-send:active {
    transform: scale(0.95);
}

.n8n-chatbot-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.n8n-chatbot-quick-actions {
    display: flex;
    gap: 8px;
    padding: 12px 36px 18px;
    background: #ffffff;
    flex-shrink: 0;
}

.n8n-chatbot-quick-action {
    border: 1px solid var(--n8n-quick-border-color, #e2e8f0);
    border-radius: 7px;
    background: #ffffff;
    color: var(--n8n-quick-text-color, #334155);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    padding: 10px 16px;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.n8n-chatbot-quick-action:hover {
    border-color: var(--n8n-button-color, var(--n8n-primary-color, #4F46E5));
    color: var(--n8n-button-color, var(--n8n-primary-color, #4F46E5));
    background: #f8fafc;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
    #n8n-chatbot-container {
        bottom: 12px;
    }

    #n8n-chatbot-container.n8n-chatbot-right {
        right: 14px;
    }

    #n8n-chatbot-container.n8n-chatbot-left {
        left: 14px;
    }

    .n8n-chatbot-toggle {
        width: 54px;
        height: 54px;
    }

    .n8n-chatbot-prompt {
        bottom: 6px;
        min-width: 0;
        max-width: min(230px, calc(100vw - 96px));
        font-size: 13px;
    }

    .n8n-chatbot-right .n8n-chatbot-prompt {
        right: 66px;
    }

    .n8n-chatbot-left .n8n-chatbot-prompt {
        left: 66px;
    }

    .n8n-chatbot-window {
        bottom: 66px;
        width: calc(100vw - 28px);
        height: calc(100vh - 86px);
        border-radius: 12px;
    }

    .n8n-chatbot-header {
        padding: 18px 22px;
        gap: 12px;
    }

    .n8n-chatbot-messages {
        padding: 34px 32px 26px;
    }

    .n8n-chatbot-form {
        margin: 20px 32px 0;
    }

    .n8n-chatbot-quick-actions {
        padding: 12px 32px 18px;
        overflow-x: auto;
    }

    .n8n-chatbot-message {
        max-width: 100%;
    }

    .n8n-chatbot-message-user {
        max-width: 72%;
        margin-left: 72px;
    }

    .n8n-chatbot-message-bot {
        margin-right: 8px;
    }

    .n8n-chatbot-right .n8n-chatbot-window,
    .n8n-chatbot-left .n8n-chatbot-window {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .n8n-chatbot-window {
        background: #1a1a1a;
    }

    .n8n-chatbot-messages {
        background: #2d2d2d;
    }

    .n8n-chatbot-message-bot .n8n-chatbot-message-content {
        background: #3d3d3d;
        color: #eee;
    }

    .n8n-chatbot-form {
        background: #1a1a1a;
        border-color: var(--n8n-button-color, var(--n8n-primary-color, #0073aa));
    }

    .n8n-chatbot-input {
        background: #2d2d2d;
        color: #eee;
    }

    .n8n-chatbot-quick-actions {
        background: #1a1a1a;
    }

    .n8n-chatbot-quick-action {
        background: #262626;
        border-color: #3f3f46;
        color: #e5e7eb;
    }

    .n8n-chatbot-input:focus {
        border-color: var(--n8n-button-color, var(--n8n-primary-color, #0073aa));
    }
}

/* ============================================
   PRINT
   ============================================ */

@media print {
    #n8n-chatbot-container {
        display: none !important;
    }
}
