/* ======================
   CHAT WIDGET
====================== */

.site-header,
.site-footer,
.mobile-bottom-nav,
.chat-fab {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.site-header {
    top: 0;
}

.mobile-bottom-nav {
    bottom: 0;
}

.site-footer {
    bottom: 0;
}

.temple-chat-modal,
.temple-chat-box,
.temple-chat-header,
.temple-chat-form,
.temple-chat-messages,
.temple-chat-title-wrap,
.temple-chat-close,
.chat-bubble {
    box-sizing: border-box;
}

.temple-chat-modal,
.temple-chat-box,
.temple-chat-header,
.temple-chat-form {
    max-width: 100%;
    overflow-x: hidden;
}

/* Desktop / default */
.temple-chat-modal {
    position: fixed;
    right: 20px;
    bottom: 90px;
    left: auto;
    top: auto;
    width: 520px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 120px);
    background: transparent;
    z-index: 99999;
    padding: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

.temple-chat-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.temple-chat-box {
    width: 100%;
    max-width: 520px;
    height: auto;
    max-height: calc(100vh - 120px);
    margin: 0;
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

.temple-chat-header {
    position: relative;
    background: linear-gradient(90deg, #8b0000, #b8860b);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    font-weight: 700;
    flex-shrink: 0;
    min-height: 72px;
    width: 100%;
}

.temple-chat-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
    padding-right: 100px;
}

.temple-chat-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.temple-chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
    font-weight: 500;
    line-height: 1.3;
    margin: 0;
}

.temple-chat-close {
    position: absolute;
    top: 12px;
    right: 12px;
    left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 86px;
    height: 42px;
    padding: 0 16px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,0.85);
    background: #8b0000;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    white-space: nowrap;
}

.temple-chat-close:hover {
    background: #6e0000;
}

.temple-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    background: #faf8f3;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.temple-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.temple-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.18);
    border-radius: 999px;
}

.temple-chat-form {
    display: flex;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
    width: 100%;
}

.temple-chat-form input[type="text"] {
    flex: 1 1 auto;
    margin-bottom: 0;
    border-radius: 14px;
    padding: 12px 14px;
    min-height: 46px;
    min-width: 0;
    width: 100%;
}

.temple-chat-form .btn {
    min-width: 82px;
    border-radius: 14px;
    padding: 12px 14px;
    flex-shrink: 0;
}

.chat-bubble {
    max-width: 84%;
    padding: 12px 14px;
    border-radius: 16px;
    margin-bottom: 12px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.04);
}

.chat-bubble.bot {
    background: #f3efe6;
    color: #333;
    border-top-left-radius: 6px;
    margin-right: auto;
}

.chat-bubble.user {
    background: #b8860b;
    color: #fff;
    border-top-right-radius: 6px;
    margin-left: auto;
}

.chat-bubble.bot ul {
    margin: 8px 0 0 18px;
}

.chat-bubble.bot li {
    margin-bottom: 4px;
}

.temple-chat-empty-tip {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
}

.chat-fab {
    position: fixed;
    right: 18px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    width: 58px;
    height: 58px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #b8860b, #8b0000);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0,0,0,0.22);
    z-index: 7000;
    padding: 0;
    margin: 0;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    appearance: none;
    -webkit-appearance: none;
}

.chat-fab i,
.chat-fab svg {
    pointer-events: none;
    line-height: 1;
    font-size: 24px;
}

.temple-chat-modal.active ~ .chat-fab,
html.chat-open .chat-fab,
body.chat-open .chat-fab {
    opacity: 0;
    pointer-events: none;
}

/* Tablet + mobile */
@media (max-width: 768px) {
    .temple-chat-modal {
        right: 10px;
        left: 10px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        top: auto;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        padding: 0;
    }

    .temple-chat-box {
        width: 100%;
        max-width: none;
        height: auto;
        max-height: calc(100vh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        border-radius: 16px;
    }

    .temple-chat-header {
        min-height: 76px;
        padding: 14px 14px;
    }

    .temple-chat-title-wrap {
        padding-right: 92px;
    }

    .temple-chat-title {
        font-size: 17px;
        line-height: 1.2;
    }

    .temple-chat-subtitle {
        font-size: 11px;
        line-height: 1.25;
    }

    .temple-chat-close {
        top: 10px;
        right: 10px;
        min-width: 78px;
        height: 40px;
        padding: 0 14px;
        font-size: 15px;
    }

    .temple-chat-messages {
        padding: 12px;
    }

    .temple-chat-form {
        gap: 8px;
        padding: 10px;
    }

    .temple-chat-form input[type="text"] {
        padding: 11px 12px;
        min-height: 44px;
    }

    .temple-chat-form .btn {
        min-width: 70px;
        padding: 11px 12px;
    }

    .chat-bubble {
        max-width: 90%;
        font-size: 15px;
        line-height: 1.5;
    }

    .chat-fab {
        right: 16px;
        bottom: calc(74px + env(safe-area-inset-bottom, 0px));
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .temple-chat-modal {
        right: 8px;
        left: 8px;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        max-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }

    .temple-chat-box {
        max-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        border-radius: 14px;
    }

    .temple-chat-header {
        min-height: 78px;
        padding: 12px 12px;
    }

    .temple-chat-title-wrap {
        padding-right: 84px;
    }

    .temple-chat-title {
        font-size: 16px;
    }

    .temple-chat-subtitle {
        font-size: 11px;
    }

    .temple-chat-close {
        top: 10px;
        right: 10px;
        min-width: 72px;
        height: 38px;
        padding: 0 12px;
        font-size: 14px;
    }

    .temple-chat-messages {
        padding: 10px;
    }

    .temple-chat-form {
        padding: 10px;
    }

    .temple-chat-form input[type="text"] {
        min-height: 42px;
        font-size: 14px;
    }

    .temple-chat-form .btn {
        min-width: 64px;
        font-size: 14px;
    }

    .chat-bubble {
        max-width: 92%;
        padding: 11px 12px;
        font-size: 14px;
    }
}