/* =========================================================================
   Chatbot Widget — sol alt sabit, modern, mobil uyumlu
   Z-index 9998/9999; site içi overlay'lerle çakışmayı önlemek için sıkı namespace.
   ========================================================================= */

#cbw-root,
#cbw-root * {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

#cbw-root {
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #222;
}

/* ---------------- TOGGLE BUTTON ---------------- */
.cbw-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
    color: #fff;
    border: 0;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(30, 64, 175, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform .18s ease, box-shadow .18s ease;
    outline: none;
}
.cbw-toggle:hover  { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(30, 64, 175, 0.45); }
.cbw-toggle:focus  { box-shadow: 0 0 0 4px rgba(59,130,246,0.35); }
.cbw-toggle:active { transform: translateY(0); }

.cbw-toggle .cbw-icon-close { display: none; }
#cbw-root.cbw-open .cbw-toggle .cbw-icon-open  { display: none; }
#cbw-root.cbw-open .cbw-toggle .cbw-icon-close { display: block; }

.cbw-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #ef4444; color: #fff;
    font-size: 11px; font-weight: 700;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
    line-height: 1;
}

/* ---------------- WINDOW ---------------- */
.cbw-window {
    position: absolute;
    bottom: 70px;
    left: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom left;
    animation: cbw-pop .22s cubic-bezier(.4,1.4,.5,1);
}
@keyframes cbw-pop {
    from { opacity: 0; transform: translateY(10px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------------- HEADER ---------------- */
.cbw-header {
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.cbw-header-info { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.cbw-status-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(255,255,255,.25);
    animation: cbw-pulse 1.8s ease-in-out infinite;
}
@keyframes cbw-pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%     { opacity: .65; transform: scale(.85); }
}
.cbw-title { font-weight: 600; font-size: 15px; letter-spacing: .2px; }
.cbw-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: .85;
    transition: opacity .15s;
}
.cbw-close:hover { opacity: 1; }

/* ---------------- MESSAGES ---------------- */
.cbw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f3f5f9;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.cbw-messages::-webkit-scrollbar { width: 6px; }
.cbw-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.cbw-msg {
    max-width: 82%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: cbw-msg-in .18s ease;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
@keyframes cbw-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.cbw-msg-user   { align-self: flex-end;   background: #3b82f6; color: #fff; border-bottom-right-radius: 4px; }
.cbw-msg-bot    { align-self: flex-start; background: #fff;    color: #1f2937; border-bottom-left-radius: 4px; border:1px solid #e5e7eb; }
.cbw-msg-admin  { align-self: flex-start; background: #dcfce7; color: #14532d; border-bottom-left-radius: 4px; border:1px solid #bbf7d0; }
.cbw-msg-system { align-self: center; background: transparent; color: #64748b; font-size: 12px; font-style: italic; padding: 4px 8px; }
.cbw-msg-error  { align-self: center; background: #fef2f2; color: #991b1b; border:1px solid #fecaca; font-size:13px; }

.cbw-msg time {
    display: block;
    font-size: 10px;
    margin-top: 3px;
    opacity: .6;
}
.cbw-msg-user time { color: #e0e7ff; }

/* Mesaj içi linkler — baloncuk rengine göre kontrastlı */
.cbw-msg a {
    text-decoration: underline;
    word-break: break-all;
    font-weight: 500;
}
.cbw-msg-user  a { color: #ffffff; }
.cbw-msg-user  a:hover { color: #e0e7ff; }
.cbw-msg-bot   a,
.cbw-msg-admin a { color: #1e40af; }
.cbw-msg-bot   a:hover,
.cbw-msg-admin a:hover { color: #1e3a8a; }

/* ---------------- TYPING ---------------- */
.cbw-typing {
    display: flex;
    gap: 4px;
    padding: 0 18px 6px;
    background: #f3f5f9;
}
.cbw-typing span {
    width: 6px; height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: cbw-typing-bounce 1.2s infinite;
}
.cbw-typing span:nth-child(2) { animation-delay: .15s; }
.cbw-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes cbw-typing-bounce {
    0%,60%,100% { transform: translateY(0); opacity: .5; }
    30%         { transform: translateY(-4px); opacity: 1; }
}

/* ---------------- INPUT BAR ---------------- */
.cbw-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}
#cbw-input {
    flex: 1;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    border-radius: 18px;
    padding: 9px 14px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 38px;
    outline: none;
    font-family: inherit;
    transition: border-color .15s, background .15s;
}
#cbw-input:focus { border-color: #3b82f6; background: #fff; }

.cbw-send {
    width: 38px; height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    border: 0;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .12s;
}
.cbw-send:hover:not(:disabled)  { background: #1e40af; }
.cbw-send:active:not(:disabled) { transform: scale(.94); }
.cbw-send:disabled { background: #9ca3af; cursor: not-allowed; }

/* ---------------- MOBILE ---------------- */
@media (max-width: 480px) {
    #cbw-root { left: 10px; bottom: 10px; }
    .cbw-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 90px);
        max-height: calc(100vh - 90px);
        bottom: 70px;
    }
    .cbw-toggle { width: 52px; height: 52px; }
}

/* sayfanın scroll-to-top butonuyla çakışmasın diye kendi konumumuzu öne al */
#cbw-root { pointer-events: auto; }
