/* ============================================================
   RTG AI Chat Widget — Stylesheet v1.1.0
   ============================================================ */

/* Reset & isolatie */
#rtg-chat-widget {
    all: initial;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1a1a1a;

    /* CSS-variabelen — worden overschreven via inline style vanuit PHP */
    --rtg-primary:      #0073aa;
    --rtg-primary-dark: color-mix(in srgb, var(--rtg-primary) 80%, black);
    --rtg-radius:       12px;
    --rtg-shadow:       0 10px 40px rgba(0, 0, 0, 0.18);
    --rtg-transition:   0.2s ease;

    /* Positie */
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 999999 !important;
    pointer-events: auto !important;
}

#rtg-chat-widget * {
    box-sizing: border-box;
    pointer-events: auto;
}

/* ============================================================
   Chat knop
   ============================================================ */

#rtg-chat-button {
    width: 60px;
    height: 60px;
    background: var(--rtg-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    box-shadow: var(--rtg-shadow);
    transition: transform var(--rtg-transition), background var(--rtg-transition);
    position: relative;
    margin-left: auto; /* Houdt de knop rechts als window erboven staat */
}

#rtg-chat-button:hover {
    transform: scale(1.08);
    background: var(--rtg-primary-dark);
}

#rtg-chat-button:focus-visible {
    outline: 3px solid var(--rtg-primary);
    outline-offset: 3px;
}

/* Icoon wisseling open/close */
.rtg-chat-icon           { transition: opacity var(--rtg-transition), transform var(--rtg-transition); }
.rtg-icon-close          { position: absolute; opacity: 0; transform: rotate(-90deg); font-style: normal; }
.rtg-chat-open .rtg-icon-open  { opacity: 0; transform: rotate(90deg); }
.rtg-chat-open .rtg-icon-close { opacity: 1; transform: rotate(0); }

/* ============================================================
   Chat venster
   ============================================================ */

#rtg-chat-window {
    width: 360px;
    height: 520px;
    background: #fff;
    border-radius: var(--rtg-radius);
    box-shadow: var(--rtg-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: 72px;
    right: 0;

    /* Animatie open/dicht */
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.22s ease, transform 0.22s ease;
    pointer-events: none;
}

#rtg-chat-window:not([hidden]) {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* [hidden] override — verberg het venster volledig */
#rtg-chat-window[hidden] {
    display: flex !important; /* Behoud flex voor animatie, maar pointer-events: none bovenin */
    visibility: hidden;
}

/* ============================================================
   Header
   ============================================================ */

#rtg-chat-header {
    background: var(--rtg-primary);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.rtg-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rtg-chat-logo {
    max-height: 32px;
    width: auto;
    display: block;
    border-radius: 4px;
    flex-shrink: 0;
}

.rtg-chat-title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rtg-chat-status {
    font-size: 11px;
    opacity: 0.8;
    white-space: nowrap;
}

#rtg-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: background var(--rtg-transition);
}

#rtg-chat-close:hover       { background: rgba(255,255,255,0.2); }
#rtg-chat-close:focus-visible { outline: 2px solid #fff; }

/* ============================================================
   Berichtenlijst
   ============================================================ */

#rtg-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #f5f7fa;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#rtg-chat-messages::-webkit-scrollbar       { width: 5px; }
#rtg-chat-messages::-webkit-scrollbar-track { background: transparent; }
#rtg-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* Berichten */
.rtg-message {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    animation: rtgFadeIn 0.18s ease;
}

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

.rtg-user {
    background: var(--rtg-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.rtg-ai {
    background: #e8eaed;
    color: #1a1a1a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.rtg-ai a {
    color: var(--rtg-primary);
    text-decoration: underline;
}

.rtg-ai ul, .rtg-ai ol {
    margin: 6px 0 0 16px;
    padding: 0;
}

.rtg-ai p { margin: 0 0 6px; }
.rtg-ai p:last-child { margin-bottom: 0; }

/* Typeelindicator */
.rtg-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
}

.rtg-typing span {
    width: 7px;
    height: 7px;
    background: #aaa;
    border-radius: 50%;
    animation: rtgBounce 1.2s infinite ease-in-out;
}

.rtg-typing span:nth-child(2) { animation-delay: 0.2s; }
.rtg-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes rtgBounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: 0.5; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

/* Productkaartjes */
.rtg-product-cards {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.rtg-product-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12.5px;
}

.rtg-product-card strong { display: block; margin-bottom: 2px; }
.rtg-product-card .rtg-product-meta { color: #555; }
.rtg-product-card a {
    display: inline-block;
    margin-top: 6px;
    color: var(--rtg-primary);
    font-weight: 600;
    text-decoration: none;
    font-size: 12px;
}
.rtg-product-card a:hover { text-decoration: underline; }

/* Foutmelding */
.rtg-error {
    background: #fff0f0;
    color: #c0392b;
    border: 1px solid #f5c6cb;
}

/* ============================================================
   Input
   ============================================================ */

#rtg-chat-input-wrapper {
    display: flex;
    align-items: center;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
    position: relative;
    background: #fff;
}

#rtg-chat-input {
    flex: 1;
    border: none;
    padding: 13px 14px;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    background: transparent;
    color: #1a1a1a;
    resize: none;
}

#rtg-chat-input::placeholder { color: #999; }

.rtg-char-count {
    font-size: 11px;
    color: #bbb;
    white-space: nowrap;
    padding: 0 4px;
    transition: color 0.2s;
}

.rtg-char-count.rtg-near-limit  { color: #e67e22; }
.rtg-char-count.rtg-at-limit    { color: #e74c3c; }

#rtg-chat-send {
    background: var(--rtg-primary);
    color: #fff;
    border: none;
    padding: 0 18px;
    height: 100%;
    min-height: 46px;
    cursor: pointer;
    font-size: 16px;
    transition: background var(--rtg-transition);
    flex-shrink: 0;
}

#rtg-chat-send:hover       { background: var(--rtg-primary-dark); }
#rtg-chat-send:disabled    { opacity: 0.5; cursor: not-allowed; }
#rtg-chat-send:focus-visible { outline: 2px solid var(--rtg-primary); outline-offset: -2px; }

/* ============================================================
   Intro-animatie
   Zelfde aanpak als origineel: .rtg-intro overschrijft de positie
   naar bovenin gecentreerd, animatie eindigt op translate(0,0)
   waarna de class verwijderd wordt en fixed bottom/right geldt.
   ============================================================ */

#rtg-chat-widget.rtg-intro {
    top:    20px !important;
    left:   50%  !important;
    right:  auto !important;
    bottom: auto !important;
    transform: translate(-50%, 0) scale(1.3);
    opacity: 0;
    animation: rtgIntroAnimation 1.8s ease forwards;
}

@keyframes rtgIntroAnimation {
    0% {
        opacity: 0;
        transform: translate(-50%, 0) scale(1.3);
    }
    40% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1.3);
    }
    100% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 480px) {
    #rtg-chat-window {
        width:  calc(100vw - 16px);
        height: 75vh;
        right:  -16px; /* Zorg dat het precies op de rechterkant sluit */
        bottom: 72px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #rtg-chat-widget.rtg-intro    { animation: none; opacity: 1; }
    .rtg-message                   { animation: none; }
    .rtg-typing span               { animation: none; opacity: 1; }
    #rtg-chat-window               { transition: none; }
    #rtg-chat-button               { transition: none; }
}
