/* ============================================================
   StringMate Chat Widget
   ============================================================ */

/* Toggle knop */
#sm-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    background: #4a7c28;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(74, 124, 40, 0.45);
    z-index: 99999;
    transition: background 0.2s, transform 0.2s;
    padding: 0;
}
#sm-chat-toggle:hover {
    background: #3d6a22;
    transform: scale(1.05);
}
#sm-chat-toggle.actief {
    background: #3d6a22;
}

/* Pulsring rond de knop */
#sm-chat-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2.5px solid rgba(74,124,40,0.45);
    animation: sm-puls 2.4s ease-out infinite;
}
#sm-chat-toggle.actief::before { display: none; }
@keyframes sm-puls {
    0%   { transform: scale(1);   opacity: 0.8; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* Label naast de knop */
#sm-chat-label {
    position: fixed;
    bottom: 32px;
    right: 92px;
    background: white;
    color: #2d5016;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 20px;
    box-shadow: 0 3px 14px rgba(0,0,0,0.15);
    border: 1.5px solid #d4e8c2;
    z-index: 99998;
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.3s, transform 0.3s;
    animation: sm-label-in 0.5s ease-out 1.5s both;
}
#sm-chat-label::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    border: 7px solid transparent;
    border-left-color: white;
    border-right: 0;
    filter: drop-shadow(2px 0 1px rgba(0,0,0,0.06));
}
#sm-chat-label.verborgen {
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
}
@keyframes sm-label-in {
    from { opacity: 0; transform: translateX(10px); }
    to   { opacity: 1; transform: translateX(0); }
}
#sm-chat-toggle svg {
    width: 26px;
    height: 26px;
    fill: white;
    transition: opacity 0.2s;
}
#sm-chat-toggle .sm-icon-open  { display: block; }
#sm-chat-toggle .sm-icon-close { display: none; }
#sm-chat-toggle.actief .sm-icon-open  { display: none; }
#sm-chat-toggle.actief .sm-icon-close { display: block; }

/* Foto-variant van toggle knop */
#sm-chat-toggle.heeft-foto {
    padding: 0;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(74,124,40,0.5), 0 0 0 3px #4a7c28;
}
#sm-chat-toggle.heeft-foto .sm-toggle-foto {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    transition: opacity 0.2s;
}
#sm-chat-toggle.heeft-foto .sm-icon-close {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
#sm-chat-toggle.heeft-foto.actief .sm-toggle-foto { opacity: 0; }
#sm-chat-toggle.heeft-foto.actief .sm-icon-close  { display: block; }
/* Online status stipje */
#sm-chat-toggle.heeft-foto::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 13px;
    height: 13px;
    background: #2ecc71;
    border-radius: 50%;
    border: 2.5px solid white;
    z-index: 1;
}
#sm-chat-toggle.heeft-foto.actief::after { display: none; }

/* Chat venster */
#sm-chat-venster {
    position: fixed;
    bottom: 94px;
    right: 24px;
    width: 360px;
    max-height: 540px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    animation: sm-slide-up 0.22s ease-out;
}
#sm-chat-venster.zichtbaar {
    display: flex;
}
@keyframes sm-slide-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Header */
#sm-chat-header {
    background: #4a7c28;
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#sm-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
#sm-chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
#sm-chat-header-tekst strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
}
#sm-chat-header-tekst small {
    font-size: 11px;
    opacity: 0.85;
}
#sm-chat-sluiten {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}
#sm-chat-sluiten:hover { opacity: 1; }

/* Quick actions */
#sm-chat-acties {
    padding: 10px 12px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}
.sm-actie-knop {
    background: white;
    border: 1.5px solid #4a7c28;
    color: #4a7c28;
    border-radius: 20px;
    padding: 4px 11px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    font-family: inherit;
}
.sm-actie-knop:hover {
    background: #4a7c28;
    color: white;
}

/* Berichten */
#sm-chat-berichten {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
#sm-chat-berichten::-webkit-scrollbar { width: 4px; }
#sm-chat-berichten::-webkit-scrollbar-track { background: transparent; }
#sm-chat-berichten::-webkit-scrollbar-thumb { background: #dee2e6; border-radius: 4px; }

/* Berichten — opmaak */
.sm-bericht {
    display: flex;
    max-width: 88%;
}
.sm-bericht.sm-bericht-user {
    align-self: flex-end;
}
.sm-bericht.sm-bericht-assistant,
.sm-bericht.sm-bericht-error {
    align-self: flex-start;
}
.sm-bubbel {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}
.sm-bericht-user .sm-bubbel {
    background: #4a7c28;
    color: white;
    border-bottom-right-radius: 4px;
}
.sm-bericht-assistant .sm-bubbel {
    background: #f0f4f0;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}
.sm-bericht-error .sm-bubbel {
    background: #fff0f0;
    color: #c0392b;
    border: 1px solid #f5c6cb;
    border-bottom-left-radius: 4px;
    font-size: 13px;
}

/* Typing indicator */
#sm-bericht-typing .sm-bubbel {
    background: #f0f4f0;
    padding: 12px 16px;
}
#sm-bericht-typing .sm-bubbel span {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #adb5bd;
    border-radius: 50%;
    margin: 0 2px;
    animation: sm-stuit 1.3s infinite ease-in-out;
}
#sm-bericht-typing .sm-bubbel span:nth-child(2) { animation-delay: 0.18s; }
#sm-bericht-typing .sm-bubbel span:nth-child(3) { animation-delay: 0.36s; }
@keyframes sm-stuit {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* Invoer */
#sm-chat-invoer-blok {
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: white;
    flex-shrink: 0;
}
#sm-chat-invoer {
    flex: 1;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 16px; /* min. 16px voorkomt autozoom op iOS */
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.15s;
    min-height: 38px;
}
#sm-chat-invoer:focus {
    border-color: #4a7c28;
}
#sm-chat-verzenden {
    width: 38px;
    height: 38px;
    background: #4a7c28;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
    padding: 0;
}
#sm-chat-verzenden:hover  { background: #3d6a22; }
#sm-chat-verzenden:disabled { background: #adb5bd; cursor: default; }
#sm-chat-verzenden svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Mobiel: volledig scherm */
@media (max-width: 480px) {
    #sm-chat-venster {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 16px 16px 0 0;
        /* Invoerveld altijd zichtbaar boven toetsenbord */
        display: none;
        flex-direction: column;
    }
    #sm-chat-venster.zichtbaar {
        display: flex;
    }
    #sm-chat-berichten {
        flex: 1;
        min-height: 0; /* zorgt dat berichten scrollen en niet groeien */
    }
    #sm-chat-invoer-blok {
        /* Altijd boven toetsenbord op iOS/Android */
        position: sticky;
        bottom: 0;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        background: white;
    }
    /* Verberg toggle-knop als chat open is — sluit-knop in header is genoeg */
    #sm-chat-toggle.actief {
        display: none;
    }
    /* Label ook verbergen als chat open */
    #sm-chat-toggle.actief ~ #sm-chat-label,
    #sm-chat-label.verborgen {
        display: none;
    }
    #sm-chat-toggle {
        bottom: 16px;
        right: 16px;
    }
    /* Verificatieveld groter op mobiel */
    .sm-verify-invoer {
        font-size: 16px; /* voorkomt autozoom op iOS */
        padding: 11px 13px;
    }
    .sm-verify-knop {
        padding: 12px;
        font-size: 15px;
    }
}

/* ============================================================
   Verificatie UI
   ============================================================ */

.sm-verify-blok {
    background: #f8f9fa;
    border: 1.5px solid #4a7c28;
    border-radius: 12px;
    padding: 14px 16px;
    margin: 4px 0;
    font-size: 13.5px;
}
.sm-verify-titel {
    font-weight: 700;
    color: #4a7c28;
    margin-bottom: 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.sm-verify-tekst {
    margin: 0 0 10px;
    color: #333;
    line-height: 1.5;
}
.sm-verify-invoer {
    width: 100%;
    border: 1.5px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 13.5px;
    font-family: inherit;
    box-sizing: border-box;
    margin-bottom: 8px;
    outline: none;
    transition: border-color 0.15s;
}
.sm-verify-invoer:focus { border-color: #4a7c28; }
.sm-verify-code-invoer {
    letter-spacing: 6px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
}
.sm-verify-knop {
    width: 100%;
    background: #4a7c28;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
    margin-bottom: 6px;
}
.sm-verify-knop:hover:not(:disabled) { background: #3d6a22; }
.sm-verify-knop:disabled { background: #adb5bd; cursor: default; }
.sm-verify-link {
    background: none;
    border: none;
    color: #4a7c28;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    text-decoration: underline;
    padding: 2px 0;
    display: block;
    margin: 0 auto;
}
.sm-verify-fout {
    color: #dc3545;
    font-size: 12.5px;
    margin-top: 6px;
    min-height: 0;
    line-height: 1.4;
}
