/* ============================================================
   chat.css — professional support chat (page + widget modal)
   - shared by the /chat page and the sticky robot widget
   - RTL-first, theme-aware via CSS variables with fallbacks
   - zero external assets; robot icon is inline SVG (chat-widget.js)
   ============================================================ */

/* ---------- sticky robot FAB (below the Bale icon) ---------- */
/* .floating-actions layout comes from main.css (fixed dock, column). */

.fab-btn.fab-bot {
    position: relative;
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(74, 108, 247, .38);
    border: 1px solid rgba(255, 255, 255, .25);
}

.fab-btn.fab-bot:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(74, 108, 247, .5); }

.fab-btn.fab-bot svg { width: 24px; height: 24px; display: block; }

.fab-btn.fab-bot .fab-bot-dot {
    position: absolute;
    top: 2px;
    inset-inline-end: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid #fff;
}

/* ---------- widget modal ---------- */
.chat-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    z-index: 3000;
    display: none;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px;
}

.chat-modal-backdrop.is-open { display: flex; }

/* compact modal — leaves the page visible; 110px guard reserves room
   for the dismiss pill + backdrop padding on short viewports */
.chat-modal {
    width: min(400px, calc(100vw - 32px));
    height: min(540px, calc(100vh - 110px));
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(2, 12, 27, .35);
    animation: chat-modal-in .25s ease;
}

@keyframes chat-modal-in {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-modal__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    flex: 0 0 auto;
}

.chat-modal__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.chat-modal__titles { flex: 1 1 auto; min-width: 0; }

.chat-modal__name { font-weight: 800; font-size: .95rem; line-height: 1.4; }

.chat-modal__status { font-size: .72rem; opacity: .92; }

.chat-modal__close {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.chat-modal__close:hover { background: rgba(255, 255, 255, .3); }

.chat-modal__close:active { transform: scale(.9); }

/* grab handle (mobile bottom sheet) — swipe it down to close */
.chat-modal__handle { display: none; }

/* labeled close pill under the modal — easiest way to dismiss */
.chat-modal__dismiss {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, .4);
    background: rgba(255, 255, 255, .16);
    color: #fff;
    border-radius: 999px;
    padding: 9px 20px;
    font-weight: 800;
    font-size: .84rem;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.chat-modal__dismiss:hover { background: rgba(255, 255, 255, .26); }

.chat-modal__dismiss:active { transform: scale(.96); }

.chat-modal__body { flex: 1 1 auto; min-height: 0; display: flex; }

.chat-modal__body .chat-app { flex: 1 1 auto; }

/* ---------- chat app (page + modal share) ---------- */
.chat-app {
    display: flex;
    flex-direction: column;
    background: #f6f8fc;
    min-height: 0;
    height: 100%;
}

.chat-app__log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    min-height: 0;
}

.chat-row { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; }

.chat-row--user { align-self: flex-end; flex-direction: row-reverse; }

.chat-row__avatar {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    font-size: 14px;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: .88rem;
    line-height: 1.9;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e8edf5;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .06);
}

.chat-row--bot .chat-bubble { border-start-start-radius: 4px; }

.chat-row--user .chat-bubble {
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    border: none;
    border-start-end-radius: 4px;
}

/* typing dots */
.chat-typing { display: inline-flex; gap: 4px; padding: 6px 2px; }

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #93a4c4;
    animation: chat-typing-blink 1.2s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes chat-typing-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* links + action chips */
.chat-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chat-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
    background: rgba(74, 108, 247, .1);
    color: #3450c8;
    border: 1px solid rgba(74, 108, 247, .25);
    cursor: pointer;
}

.chat-link:hover { background: rgba(74, 108, 247, .18); }

.chat-link--bale {
    background: rgba(0, 166, 81, .1);
    color: #067647;
    border-color: rgba(0, 166, 81, .3);
}

/* product cards */
.chat-products { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; width: 100%; }

.chat-product {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #e8edf5;
    border-radius: 12px;
    padding: 8px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s ease, transform .15s ease;
}

.chat-product:hover { box-shadow: 0 6px 16px rgba(16, 24, 40, .1); transform: translateY(-1px); }

.chat-product__img {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    object-fit: cover;
    background: #f1f5f9;
}

.chat-product__img--ph {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    background: linear-gradient(135deg, #eef2ff, #e0f2fe);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 18px;
}

.chat-product__info { flex: 1 1 auto; min-width: 0; }

.chat-product__name {
    font-size: .8rem;
    font-weight: 700;
    color: #1f2937;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.chat-product__price { font-size: .78rem; font-weight: 800; color: #e67e22; margin-top: 2px; }

.chat-product__stock { font-size: .7rem; margin-top: 2px; }

.chat-product__stock--in { color: #067647; }
.chat-product__stock--out { color: #b42318; }

/* quick replies */
.chat-quick {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 10px;
}

.chat-quick:empty { display: none; }

.chat-quick__chip {
    border: 1px solid #d7e0f0;
    background: #fff;
    color: #3450c8;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: .76rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s ease;
}

.chat-quick__chip:hover { background: #eef2ff; }

/* input row */
.chat-input-row {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e8edf5;
}

.chat-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid #d7e0f0;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: .86rem;
    outline: none;
    background: #f8fafc;
    color: #1f2937;
    font-family: inherit;
}

.chat-input:focus { border-color: #4a6cf7; background: #fff; }

.chat-send {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-send:disabled { opacity: .55; cursor: default; }

.chat-send svg { width: 20px; height: 20px; transform: scaleX(-1); }

/* escalation mini-form */
.chat-escalate {
    background: #fff;
    border: 1px solid #e8edf5;
    border-radius: 14px;
    padding: 12px;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-escalate__title { font-size: .82rem; font-weight: 800; color: #1f2937; }

.chat-escalate input,
.chat-escalate textarea {
    width: 100%;
    border: 1px solid #d7e0f0;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: .8rem;
    font-family: inherit;
    outline: none;
    background: #f8fafc;
    color: #1f2937;
    box-sizing: border-box;
}

.chat-escalate input:focus,
.chat-escalate textarea:focus { border-color: #4a6cf7; background: #fff; }

.chat-escalate textarea { resize: vertical; min-height: 64px; }

.chat-escalate__row { display: flex; gap: 8px; }

.chat-escalate__row > * { flex: 1 1 0; min-width: 0; }

.chat-escalate__submit {
    border: none;
    border-radius: 10px;
    padding: 9px 12px;
    background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
    color: #fff;
    font-weight: 800;
    font-size: .8rem;
    cursor: pointer;
    font-family: inherit;
}

.chat-escalate__cancel {
    border: 1px solid #d7e0f0;
    border-radius: 10px;
    padding: 9px 12px;
    background: #fff;
    color: #475569;
    font-weight: 700;
    font-size: .8rem;
    cursor: pointer;
    font-family: inherit;
}

/* /chat page shell */
.chat-page {
    min-height: calc(100vh - 320px);
    display: flex;
    flex-direction: column;
}

.chat-page .chat-app {
    border: 1px solid #e8edf5;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(16, 24, 40, .07);
    height: min(640px, 72vh);
}

.chat-page__note {
    margin-top: 12px;
    font-size: .8rem;
    color: #64748b;
    text-align: center;
}

/* mobile: compact bottom sheet — page stays visible around it,
   dvh shrinks with the on-screen keyboard so the input stays usable */
@media (max-width: 575.98px) {
    .chat-modal-backdrop {
        padding: 8px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        align-items: center;
        justify-content: flex-end;
    }

    .chat-modal {
        width: calc(100vw - 16px);
        height: min(62vh, 500px);
        height: min(62dvh, 500px);
        border-radius: 16px 16px 0 0;
    }

    .chat-modal__handle {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 9px 0 3px;
        background: linear-gradient(135deg, #4a6cf7 0%, #38b6ff 100%);
        flex: 0 0 auto;
        touch-action: none;
    }

    .chat-modal__handle::before {
        content: '';
        width: 46px;
        height: 4px;
        border-radius: 999px;
        background: rgba(255, 255, 255, .6);
    }

    .chat-modal__dismiss { align-self: center; }
}
