/* ======================================================================
   MODULE — AI LIVE CHAT WIDGET
   Prefix: .m-chat
   ====================================================================== */

/* ─────────── Floating Action Button (FAB) ─────────── */

.m-chat-fab {
    position: fixed;
    bottom: var(--sp-5, 20px);
    inset-inline-end: var(--sp-5, 20px);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary, #e85d04);
    color: #fff;
    border: 0;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(232, 93, 4, 0.35);
    z-index: var(--z-sticky, 200);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--t-fast, 0.15s), box-shadow var(--t-fast, 0.15s);
}

.m-chat-fab[hidden] { display: none; }

.m-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(232, 93, 4, 0.45);
}

.m-chat-fab:focus-visible {
    outline: 2px solid var(--primary, #e85d04);
    outline-offset: 4px;
}

.m-chat-fab-icon { display: inline-flex; align-items: center; justify-content: center; }
.m-chat-fab-icon[hidden] { display: none; }
.m-chat-fab-icon svg { width: 24px; height: 24px; }

/* Pulse ring — yumuşak dikkat çekme animasyonu */
.m-chat-fab-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--primary, #e85d04);
    opacity: 0;
    animation: m-chat-pulse 2.4s ease-out infinite;
    pointer-events: none;
}

.m-chat-fab.is-open .m-chat-fab-pulse { display: none; }

/* Full-page panel açıkken FAB gizlensin — panel kendi close butonu var,
   FAB'in z-index'i panel'in altında kalmasın diye gizliyoruz. */
.m-chat-fab.is-open { display: none; }

/* Full-page chat açıkken body scroll lock (modal pattern) */
body.m-chat-open { overflow: hidden; }

@keyframes m-chat-pulse {
    0%   { opacity: 0.6; transform: scale(1);   }
    100% { opacity: 0;   transform: scale(1.7); }
}

/* ════════════════════════════════════════════════════════════
   CHAT — Mobile full-page beyaz, Desktop center modal
   Backdrop ayrı div YOK — overlay'in kendisi koyu (desktop)
   ════════════════════════════════════════════════════════════ */

/* Overlay container — mobile: full viewport beyaz; desktop: koyu + center */
.m-chat-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 400);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    animation: m-chat-fade 200ms ease-out;
}
.m-chat-overlay[hidden] { display: none; }

@keyframes m-chat-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Inner panel — mobile: full viewport */
.m-chat-panel-inner {
    position: relative;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: m-chat-slide 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes m-chat-slide {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Desktop (≥640px) — center modal ─── */
@media (min-width: 640px) {
    .m-chat-overlay {
        background: rgba(15, 23, 42, 0.55);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        align-items: center;
        justify-content: center;
        padding: 4vh 16px;
    }
    .m-chat-panel-inner {
        width: min(92vw, 720px);
        max-width: 720px;
        height: auto;
        max-height: 86vh;
        border-radius: 16px;
        box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
        animation: m-chat-slide-desktop 280ms cubic-bezier(0.16, 1, 0.3, 1);
    }
    @keyframes m-chat-slide-desktop {
        from { opacity: 0; transform: translateY(-16px) scale(0.98); }
        to   { opacity: 1; transform: translateY(0) scale(1); }
    }
}

/* Header */
.m-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: linear-gradient(135deg,
        var(--primary, #e85d04) 0%,
        color-mix(in srgb, var(--primary, #e85d04) 85%, black) 100%);
    color: #fff;
    flex-shrink: 0;
}

.m-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.m-chat-header-avatar svg { width: 22px; height: 22px; }

.m-chat-header-text { flex: 1; min-width: 0; line-height: 1.25; }

.m-chat-bot-name {
    display: block;
    font-size: 15px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.m-chat-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    opacity: 0.9;
}

.m-chat-status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.25);
}

.m-chat-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.12);
    border: 0;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--t-fast, 0.15s);
}
.m-chat-close:hover { background: rgba(255, 255, 255, 0.22); }
.m-chat-close svg { width: 16px; height: 16px; }

/* Messages container — center column, geniş ekranda darda kalmasın */
.m-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px clamp(16px, 4vw, 32px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-page, #f7f7f8);
    scroll-behavior: smooth;
}
.m-chat-messages > * {
    max-width: 720px;
    width: 100%;
    margin-inline: auto;
}

/* Message bubble — center column içinde */
.m-chat-msg {
    max-width: 80% !important;  /* width:100% override */
    width: auto !important;
    margin-inline: 0 !important;
}
.m-chat-msg-user {
    margin-inline-start: auto !important;
}
.m-chat-msg-bot {
    margin-inline-end: auto !important;
}

/* Message bubble */
.m-chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: m-chat-msg-in 200ms ease-out;
}

@keyframes m-chat-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.m-chat-msg-bot {
    align-self: flex-start;
    background: var(--bg-card, #fff);
    color: var(--text, #111827);
    border: 1px solid var(--border, #e5e7eb);
    border-top-left-radius: 4px;
}

.m-chat-msg-user {
    align-self: flex-end;
    background: var(--primary, #e85d04);
    color: #fff;
    border-top-right-radius: 4px;
}

/* ─── Markdown inside bot messages ─── */

.m-chat-msg-bot p {
    margin: 0 0 8px 0;
}
.m-chat-msg-bot p:last-child { margin-bottom: 0; }

.m-chat-msg-bot strong {
    font-weight: 700;
    color: var(--text, #111827);
}

.m-chat-msg-bot em {
    font-style: italic;
}

.m-chat-msg-bot code {
    background: var(--bg-soft, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.9em;
    color: var(--primary, #e85d04);
}

.m-chat-msg-bot a {
    color: var(--primary, #e85d04);
    text-decoration: underline;
    word-break: break-all;
}
.m-chat-msg-bot a:hover {
    text-decoration: none;
}

.m-chat-msg-bot ul,
.m-chat-msg-bot ol {
    margin: 6px 0 8px 0;
    padding-left: 22px;
}
.m-chat-msg-bot ul:last-child,
.m-chat-msg-bot ol:last-child { margin-bottom: 0; }

.m-chat-msg-bot li {
    margin: 2px 0;
    line-height: 1.45;
}

.m-chat-msg-bot li::marker {
    color: var(--primary, #e85d04);
}

/* User mesajında markdown'a izin yok — düz text */

/* Typing indicator (3 bouncing dots) */
.m-chat-typing {
    align-self: flex-start;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    padding: 12px 16px;
    border-radius: 16px;
    border-top-left-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.m-chat-typing[hidden] { display: none; }

.m-chat-typing-dot {
    width: 7px;
    height: 7px;
    background: var(--text-soft, #9ca3af);
    border-radius: 50%;
    animation: m-chat-bounce 1.2s ease-in-out infinite;
}
.m-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.m-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes m-chat-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
    30%            { transform: translateY(-5px); opacity: 1;   }
}

/* Quick reply chips — center'da toplanır, full page'de doğal yerleşim */
.m-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px clamp(16px, 4vw, 32px) 0;
    background: var(--bg-page, #f7f7f8);
    flex-shrink: 0;
    justify-content: center;
}
.m-chat-quick-replies[hidden] { display: none; }

.m-chat-quick {
    background: var(--bg-card, #fff);
    border: 1px solid var(--primary, #e85d04);
    color: var(--primary, #e85d04);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast, 0.15s);
    min-height: 40px;
}
.m-chat-quick:hover {
    background: color-mix(in srgb, var(--primary, #e85d04) 10%, var(--bg-card, #fff));
}

/* Composer — STICKY BOTTOM, full-width input alanı */
.m-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px clamp(16px, 4vw, 32px);
    background: var(--bg-card, #fff);
    border-top: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
}

.m-chat-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text, #111827);
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    transition: border-color var(--t-fast, 0.15s);
}

.m-chat-input:focus {
    border-color: var(--primary, #e85d04);
}

.m-chat-send {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: 0;
    background: var(--primary, #e85d04);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t-fast, 0.15s), opacity var(--t-fast, 0.15s);
}
.m-chat-send:hover:not(:disabled) {
    background: color-mix(in srgb, var(--primary, #e85d04) 90%, black);
}
.m-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.m-chat-send svg { width: 16px; height: 16px; }

/* Error banner */
.m-chat-error {
    margin: 0 14px 8px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--danger, #dc2626) 12%, var(--bg-card, #fff));
    color: var(--danger, #dc2626);
    border: 1px solid color-mix(in srgb, var(--danger, #dc2626) 35%, transparent);
    border-radius: 8px;
    font-size: 12.5px;
    line-height: 1.4;
}
.m-chat-error[hidden] { display: none; }

/* ─────────── Mobile ─────────── */

@media (max-width: 480px) {
    .m-chat-fab {
        width: 52px;
        height: 52px;
        bottom: 16px;
        inset-inline-end: 16px;
    }
    /* Panel her ekranda full-page — mobile için ek bir şey gerekmez */
}

/* ─────────── RTL ─────────── */

[dir="rtl"] .m-chat-msg-bot { border-top-left-radius: 16px; border-top-right-radius: 4px; }
[dir="rtl"] .m-chat-msg-user { border-top-right-radius: 16px; border-top-left-radius: 4px; }
[dir="rtl"] .m-chat-send svg { transform: scaleX(-1); }
