/* ============================================================
   İletişim kutusu (inc/whatsapp-chat.php)
   Koyu karşılama alanı + kanal seçimi (WhatsApp / canlı sohbet) + tek yazma alanı.
   ============================================================ */

/* Crisp yüklü kalır ama balonu gizli; yalnızca bilerek açıldığında (html.kt-crisp-on) görünür. */
html:not(.kt-crisp-on) .crisp-client { display: none !important; }
html.kt-crisp-on .ktwa { display: none; }

/* Crisp penceresinin başlığındaki "Geri" düğmesi (whatsapp-chat.js → injectBack). Crisp'in sıfırlama
   stillerini ezmek için kimlik seçicisi + !important. */
#crisp-chatbox .ktwa-crisp-back {
    position: absolute !important;
    top: 14px !important;
    left: 12px !important;
    z-index: 20 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    height: 30px !important;
    margin: 0 !important;
    padding: 0 11px 0 8px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: rgba(255, 255, 255, .18) !important;
    color: #fff !important;
    font: 600 12.5px/1 var(--kan-font-family, ui-sans-serif, system-ui, sans-serif) !important;
    letter-spacing: -.01em !important;
    cursor: pointer !important;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    transition: background-color .15s !important;
}
#crisp-chatbox .ktwa-crisp-back:hover { background: rgba(255, 255, 255, .3) !important; }
#crisp-chatbox .ktwa-crisp-back:focus-visible { outline: 2px solid #fff !important; outline-offset: 2px !important; }
#crisp-chatbox .ktwa-crisp-back svg { display: block !important; width: 16px !important; height: 16px !important; }
html:not(.kt-crisp-on) #crisp-chatbox .ktwa-crisp-back { display: none !important; }

.ktwa {
    --ktwa-bg: #fff;
    --ktwa-fg: #09090b;
    --ktwa-muted: #f4f4f5;
    --ktwa-muted-fg: #71717a;
    --ktwa-border: #e4e4e7;
    --ktwa-ink: #0c0c0f;
    --ktwa-ring: rgba(9, 9, 11, .14);
    --ktwa-brand: var(--primary, #d41818);
    --ktwa-wa: #25d366;
    --ktwa-wa-strong: #15803d;
    --ktwa-accent: var(--ktwa-wa-strong);
    --ktwa-accent-soft: rgba(37, 211, 102, .1);
    --ktwa-gap: 20px;
    position: fixed;
    right: var(--ktwa-gap);
    bottom: calc(var(--ktwa-gap) + env(safe-area-inset-bottom, 0px));
    z-index: 9995;
    color: var(--ktwa-fg);
    font-family: var(--kan-font-family, ui-sans-serif, system-ui, sans-serif);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: bottom .35s cubic-bezier(.2, .7, .2, 1);
}
.ktwa[data-channel="live"] {
    --ktwa-accent: var(--ktwa-ink);
    --ktwa-accent-soft: rgba(9, 9, 11, .05);
}
.ktwa *, .ktwa *::before, .ktwa *::after { box-sizing: border-box; }
.ktwa p, .ktwa h2 { margin: 0; }
.ktwa svg { display: block; }

/* Kanala göre değişen metin/ikonlar */
.ktwa[data-channel="wa"] .ktwa-only-live,
.ktwa[data-channel="live"] .ktwa-only-wa { display: none; }

/* Mobil/tablette alt sekme çubuğunun (58px, .site-mobile-tabbar) üstünde dur;
   ürün sayfasındaki alt satın alma çubuğu (.kt-appbar, ~92px) görünürken onun da üstüne çık. */
@media (max-width: 991.98px) {
    .ktwa { bottom: calc(58px + 14px + env(safe-area-inset-bottom, 0px)); }
    body:has(.kt-appbar.is-visible) .ktwa { bottom: calc(93px + 14px + env(safe-area-inset-bottom, 0px)); }
    body.site-mobile-menu-open .ktwa { display: none; }
}

/* ---------- Yüzen düğme: "Bize yazın" hapı ---------- */
.ktwa-fab {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    margin-left: auto;
    padding: 0 20px 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--ktwa-ink);
    color: #fff;
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -.01em;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .1), 0 10px 30px -8px rgba(0, 0, 0, .45);
    transition: transform .2s cubic-bezier(.2, .7, .2, 1), box-shadow .2s, padding .25s, gap .25s;
}
.ktwa-fab:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(0, 0, 0, .1), 0 16px 36px -10px rgba(0, 0, 0, .5); }
.ktwa-fab:active { transform: scale(.97); }
.ktwa-fab:focus-visible { outline: none; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ktwa-ink); }
.ktwa-fab-icons { position: relative; width: 22px; height: 22px; flex: none; }
.ktwa-fab-icon { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity .2s, transform .25s cubic-bezier(.2, .7, .2, 1); }
.ktwa-fab-icon svg { width: 22px; height: 22px; }
.ktwa-fab-icon--x { opacity: 0; transform: rotate(-90deg) scale(.6); }
.ktwa-fab-label { white-space: nowrap; }
/* Köşedeki küçük WhatsApp rozeti: kanalın orada olduğunu tanıdık bir işaretle söyler. */
.ktwa-fab-wa {
    position: absolute;
    top: -4px;
    right: -4px;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--ktwa-wa);
    color: #fff;
    transition: opacity .2s, transform .2s;
}
.ktwa-fab-wa svg { width: 12px; height: 12px; }
.ktwa.is-open .ktwa-fab { gap: 0; padding: 0 15px; }
.ktwa.is-open .ktwa-fab-label { display: none; }
.ktwa.is-open .ktwa-fab-wa { opacity: 0; transform: scale(.4); }
.ktwa.is-open .ktwa-fab-icon--chat { opacity: 0; transform: rotate(90deg) scale(.6); }
.ktwa.is-open .ktwa-fab-icon--x { opacity: 1; transform: none; }

/* Okunmamış yanıt rozeti (Crisp): WhatsApp rozetinin yerini alır. */
.ktwa-fab-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    display: none;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: var(--ktwa-brand);
    color: #fff;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.ktwa.has-unread .ktwa-fab-badge { display: block; animation: ktwa-pop .35s cubic-bezier(.2, .8, .2, 1.4); }
.ktwa.has-unread .ktwa-fab-wa,
.ktwa.has-live .ktwa-fab-wa { display: none; }
.ktwa.has-unread:not(.is-open) .ktwa-fab::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 0 0 rgba(212, 24, 24, .5);
    animation: ktwa-ping 1.8s ease-out infinite;
    pointer-events: none;
}
@keyframes ktwa-pop { from { transform: scale(.3); } to { transform: none; } }
@keyframes ktwa-ping { to { box-shadow: 0 0 0 14px rgba(212, 24, 24, 0); } }

/* Devam eden sohbet şeridi */
.ktwa-resume {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 8px 8px 8px 10px;
    border: 1px solid var(--ktwa-border);
    border-radius: 14px;
    background: linear-gradient(180deg, #fff, #fafafa);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.ktwa-resume[hidden] { display: none; }
.ktwa-resume-icon {
    position: relative;
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--ktwa-ink);
    color: #fff;
}
.ktwa-resume-icon svg { width: 16px; height: 16px; }
.ktwa-resume-dot {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--ktwa-wa);
}
.ktwa.has-unread .ktwa-resume-dot { background: var(--ktwa-brand); }
.ktwa-resume-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.ktwa .ktwa-resume-text strong { color: var(--ktwa-fg); font-size: 13px; font-weight: 600; }
.ktwa-resume-text small { overflow: hidden; font-size: 12px; color: var(--ktwa-muted-fg); white-space: nowrap; text-overflow: ellipsis; }
.ktwa.has-unread .ktwa-resume-text small { color: var(--ktwa-brand); font-weight: 600; }
.ktwa-resume-btn {
    flex: none;
    height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: 9px;
    background: var(--ktwa-ink);
    color: #fff;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s;
}
.ktwa-resume-btn:hover { background: #27272a; }
.ktwa-resume-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ktwa-ink); }

/* ---------- Kart ---------- */
.ktwa-panel {
    position: absolute;
    right: 0;
    bottom: 66px;
    width: 380px;
    max-width: calc(100vw - 2 * var(--ktwa-gap));
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 22px;
    background: var(--ktwa-bg);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 24px 64px -16px rgba(0, 0, 0, .35);
    transform-origin: bottom right;
    animation: ktwa-in .26s cubic-bezier(.2, .8, .2, 1);
}
.ktwa-panel[hidden] { display: none; }
@keyframes ktwa-in {
    from { opacity: 0; transform: translateY(12px) scale(.96); }
    to { opacity: 1; transform: none; }
}

/* Karşılama alanı */
.ktwa-hero {
    position: relative;
    flex: none;
    padding: 16px 18px 22px;
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(212, 24, 24, .45) 0%, rgba(212, 24, 24, 0) 55%),
        radial-gradient(80% 80% at 0% 100%, rgba(37, 211, 102, .14) 0%, rgba(37, 211, 102, 0) 60%),
        var(--ktwa-ink);
    color: #fff;
}
.ktwa-top { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.ktwa-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    padding: 2px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
}
.ktwa-avatar img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #fff; }
.ktwa-brand { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ktwa .ktwa-brand strong { color: #fff; font-size: 14px; font-weight: 600; }
.ktwa-brand small { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255, 255, 255, .62); }
.ktwa-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--ktwa-wa); box-shadow: 0 0 0 3px rgba(37, 211, 102, .2); }
.ktwa-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .08);
    color: rgba(255, 255, 255, .8);
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.ktwa-close svg { width: 16px; height: 16px; }
.ktwa-close:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.ktwa-close:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, .6); }
.ktwa-hello { font-size: 15px; color: rgba(255, 255, 255, .7); }
.ktwa .ktwa-title {
    margin-top: 2px;
    color: #fff;
    font-family: inherit;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -.025em;
}

/* Form */
.ktwa-form {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 16px 16px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Kanal seçimi: kayan seçicili iki parçalı düğme */
.ktwa-channels { min-width: 0; margin: 0; padding: 0; border: 0; }
.ktwa-seg {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    border-radius: 12px;
    background: var(--ktwa-muted);
}
.ktwa-seg-thumb {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc(50% - 4px);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .04);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.ktwa[data-channel="live"] .ktwa-seg-thumb { transform: translateX(100%); }
.ktwa-seg-item {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    margin: 0;
    border-radius: 9px;
    color: var(--ktwa-muted-fg);
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -.01em;
    cursor: pointer;
    user-select: none;
    transition: color .2s;
}
.ktwa-seg-item:hover { color: var(--ktwa-fg); }
.ktwa-seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.ktwa-seg-icon { display: grid; transition: color .2s; }
.ktwa-seg-icon svg { width: 17px; height: 17px; }
.ktwa-seg-item:has(input:checked) { color: var(--ktwa-fg); }
.ktwa-seg-item--wa:has(input:checked) .ktwa-seg-icon { color: #16a34a; }
.ktwa-seg-item:has(input:focus-visible) { box-shadow: 0 0 0 2px var(--ktwa-ring); }

/* Hazır konular: tek satır, sığmazsa yana kayar */
.ktwa-topics {
    display: flex;
    gap: 6px;
    margin: 12px -16px 12px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
}
.ktwa-topics::-webkit-scrollbar { display: none; }
.ktwa-topic {
    flex: none;
    padding: 6px 11px;
    border: 1px dashed #d4d4d8;
    border-radius: 999px;
    background: transparent;
    color: #3f3f46;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}
.ktwa-topic:hover { border-style: solid; background: var(--ktwa-muted); color: var(--ktwa-fg); }
.ktwa-topic.is-active { border: 1px solid var(--ktwa-ink); background: var(--ktwa-ink); color: #fff; }
.ktwa-topic:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ktwa-ring); }

/* Yazma alanı: metin + alt çubuk (ipucu ve gönder) tek kutuda */
.ktwa-field {
    border: 1px solid var(--ktwa-border);
    border-radius: 16px;
    background: var(--ktwa-bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    cursor: text;
    transition: border-color .15s, box-shadow .15s;
}
.ktwa-field:focus-within { border-color: #a1a1aa; box-shadow: 0 0 0 3px var(--ktwa-ring); }
.ktwa-sr {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
/* Temanın genel textarea stilleri (min-height: 118px vb.) burayı ezmesin diye seçici güçlü + !important. */
.ktwa .ktwa-form textarea.ktwa-input {
    display: block;
    width: 100%;
    height: 64px;
    min-height: 64px !important;
    max-height: 160px;
    margin: 0 !important;
    padding: 12px 14px 4px !important;
    border: 0 !important;
    border-radius: 16px 16px 0 0;
    background: transparent;
    color: var(--ktwa-fg);
    font: inherit;
    font-size: 15px; /* iOS'ta odaklanınca yakınlaşmasın diye ≥ 15px */
    line-height: 21px;
    resize: none;
    box-shadow: none !important;
    outline: none !important;
}
.ktwa .ktwa-form textarea.ktwa-input::placeholder { color: var(--ktwa-muted-fg); opacity: 1; }
.ktwa-field.is-empty { animation: ktwa-shake .3s; border-color: #f87171; }
@keyframes ktwa-shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
.ktwa-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 14px; }
.ktwa-hint { min-width: 0; overflow: hidden; font-size: 11.5px; color: var(--ktwa-muted-fg); white-space: nowrap; text-overflow: ellipsis; }

/* Gönder */
.ktwa-send {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px 0 14px;
    border: 0;
    border-radius: 10px;
    background: var(--ktwa-muted);
    color: #a1a1aa;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .2s, color .2s, transform .15s;
}
.ktwa-send svg { width: 15px; height: 15px; transition: transform .15s; }
.ktwa.has-text .ktwa-send { background: var(--ktwa-accent); color: #fff; }
.ktwa.has-text .ktwa-send:hover svg { transform: translateX(2px); }
.ktwa-send:active { transform: scale(.97); }
.ktwa-send:focus-visible { outline: none; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ktwa-accent); }

@media (max-width: 480px) {
    .ktwa { --ktwa-gap: 16px; }
    .ktwa-fab { width: 54px; height: 54px; padding: 0; justify-content: center; gap: 0; }
    .ktwa.is-open .ktwa-fab { padding: 0; }
    .ktwa-fab-label { display: none; }
    .ktwa-panel { bottom: 66px; width: calc(100vw - 32px); }
    .ktwa .ktwa-title { font-size: 20px; }
    .ktwa-resume-icon { display: none; }
    .ktwa-resume { padding-left: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .ktwa, .ktwa-panel, .ktwa-fab, .ktwa-fab-icon, .ktwa-fab-wa, .ktwa-fab-badge, .ktwa-fab::after, .ktwa-send, .ktwa-send svg, .ktwa-seg-thumb { animation: none; transition: none; }
}
@media print {
    .ktwa { display: none; }
}
