/* Frontend Chatbot Styles */

/* ── Launch Button ── */
.chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
    color: white;
    border: none;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 115, 170, 0.45);
    z-index: 99999;
    transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-button:hover {
    transform: scale(1.12);
    box-shadow: 0 6px 24px rgba(0, 115, 170, 0.55);
}

.chat-button:active {
    transform: scale(0.96);
}

/* Chat button — image mode (no circle, no background) */
.chat-button--image {
    background: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    width: auto !important;
    height: auto !important;
    padding: 0;
    overflow: visible;
}

.chat-button--image:hover {
    transform: scale(1.06);
}

.chat-btn-img {
    display: block;
    height: auto;
    /* width is set via inline CSS from admin settings */
}

/* Avatar image inside chat header */
.chat-header-avatar img {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* ── Chat Window ── */
.chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 360px;
    height: 520px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    z-index: 99998;
    overflow: hidden;
    animation: chatSlideIn 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes chatSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 20px);
        height: calc(100dvh - 100px);
        bottom: 84px;
        right: 10px;
        border-radius: 14px;
    }
}

/* ── Header ── */
.chat-header {
    background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
}

.chat-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.chat-header-status {
    font-size: 11px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.chat-header-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    flex-shrink: 0;
}

#chat-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

#chat-close:hover {
    background: rgba(255,255,255,0.3);
}

/* ── Messages Area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: #f4f6f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d0d7e2;
    border-radius: 4px;
}

/* ── Message Bubbles ── */
.message {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 82%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.55;
    animation: msgFadeIn 0.25s ease-out;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 115, 170, 0.25);
}

.bot-message {
    background: #ffffff;
    color: #2d3748;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0,0,0,0.07);
    max-width: min(88%, 760px);
    padding: 16px 20px;
    font-size: 13.5px;
    line-height: 1.68;
}

/* ── Typing Indicator ── */
.typing {
    background: #ffffff !important;
    border: 1px solid rgba(0,0,0,0.06) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08) !important;
    padding: 12px 16px !important;
    border-radius: 16px !important;
    border-bottom-left-radius: 4px !important;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 52px;
}

.typing::after {
    content: none;
}

.typing .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.2s infinite ease-in-out;
    display: inline-block;
}

.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); background: #94a3b8; }
    30%            { transform: translateY(-5px); background: #0073aa; }
}

/* ── Input Area ── */
.chat-input {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
    background: #ffffff;
    border-top: 1px solid #eaecf0;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 22px;
    font-size: 14px;
    background: #f8fafc;
    color: #2d3748;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    resize: none;
}

#user-input::placeholder {
    color: #a0aec0;
}

#user-input:focus {
    border-color: #0073aa;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.12);
}

#send-btn {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    box-shadow: 0 2px 8px rgba(0, 115, 170, 0.35);
}

#send-btn::after {
    content: '↑';
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
}

#send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.45);
}

#send-btn:active {
    transform: scale(0.94);
}

#send-btn:disabled {
    background: #cbd5e0;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* ── Formatted content inside bot messages ── */
.bot-message {
    overflow-wrap: break-word;
    word-break: break-word;
}

.bot-message ul {
    margin: 8px 0 12px 0;
    padding-left: 0;
    list-style: none;
}

.bot-message ul li {
    position: relative;
    padding-left: 20px;
    margin-bottom: 7px;
    line-height: 1.65;
}

.bot-message ul li::before {
    content: '•';
    position: absolute;
    left: 0;
    top: 0;
    color: #0073aa;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.5;
}

.bot-message ol {
    margin: 8px 0 12px 0;
    padding-left: 22px;
}

.bot-message ol li {
    margin-bottom: 7px;
    line-height: 1.65;
    padding-left: 4px;
}

.bot-message li:last-child {
    margin-bottom: 0;
}

.bot-message p {
    margin: 0 0 1.05em 0;
    max-width: 68ch;
}

.bot-message p:last-child {
    margin-bottom: 0;
}

.bot-message strong {
    font-weight: 600;
    color: #182538;
}

.bot-message h4 {
    margin: 0 0 9px;
    padding: 4px 0 4px 10px;
    border-bottom: none;
    border-left: 3px solid #0073aa;
    color: #0f5f8d;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.35;
    text-transform: none;
    background: #f4f9fd;
    border-radius: 0 4px 4px 0;
}

.bot-message h4:not(:first-child) {
    margin-top: 18px;
}

.bot-message .chatbot-numbered-heading {
    display: flex;
    align-items: baseline;
    gap: 9px;
    border: none;
    background: none;
    color: #182538;
    font-size: 14px;
    margin-top: 18px;
    padding: 0;
}

.bot-message .chatbot-numbered-heading span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #e8f4fb;
    color: #075985;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.chatbot-section-break {
    height: 1px;
    margin: 16px 0;
    background: #e7edf4;
}

.chatbot-quote-flow {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 14px;
    padding: 12px 14px;
    border-left: 3px solid #0f5f8d;
    border-radius: 8px;
    background: #f4f9fc;
}

.chatbot-quote-step,
.chatbot-quote-label {
    position: relative;
    padding-left: 24px;
    line-height: 1.55;
}

.chatbot-quote-step::before {
    content: '→';
    position: absolute;
    left: 0;
    top: 0;
    color: #0f5f8d;
    font-weight: 700;
}

.chatbot-quote-label {
    padding-left: 0;
    color: #0f5f8d;
    font-weight: 700;
}

/* ── Tables ── */
.chatbot-table-wrap {
    overflow-x: auto;
    margin: 10px 0 14px;
    border-radius: 8px;
    border: 1px solid #e2eaf3;
}

.chatbot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    min-width: 280px;
}

.chatbot-table thead tr {
    background: linear-gradient(135deg, #f0f6fb 0%, #e8f2f9 100%);
}

.chatbot-table th {
    color: #0f5f8d;
    font-weight: 700;
    padding: 9px 13px;
    text-align: left;
    border-bottom: 2px solid #b8d8ee;
    white-space: nowrap;
}

.chatbot-table td {
    padding: 8px 13px;
    border-bottom: 1px solid #edf2f7;
    color: #2d3748;
    vertical-align: top;
    line-height: 1.55;
}

.chatbot-table tbody tr:last-child td {
    border-bottom: none;
}

.chatbot-table tbody tr:nth-child(even) td {
    background: #f8fafc;
}

.chatbot-table tbody tr:hover td {
    background: #f0f6fb;
}

.chat-window .bot-message a,
.chat-window .bot-message a:link {
    color: #0000FF !important;
    text-decoration: underline !important;
}

.chat-window .bot-message a:visited {
    color: #0000FF !important;
}

.chat-window .bot-message a:hover {
    color: #0000FF !important;
}

.bot-message em {
    font-style: italic;
}

.bot-message code {
    background: #f0f4f8;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: monospace;
    font-size: 12px;
    color: #2d3748;
}

/* ── Lightbox Overlay ── */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99996;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.chat-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* Lightbox window — always flex, hidden via transform/opacity */
.chatbot-mode-lightbox .chat-window {
    position: fixed;
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    width: min(640px, 92vw);
    height: min(720px, 90vh);
    z-index: 99997;
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
    display: flex;
    /* Hidden state — scaled down, invisible, not interactive */
    transform: translate(-50%, -50%) scale(0.88);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease,
                transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* Open state — full size from dead center */
.chatbot-mode-lightbox .chat-window.is-open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* Lightbox chat header */
.chatbot-mode-lightbox .chat-header {
    padding: 16px 20px;
    border-radius: 20px 20px 0 0;
    flex-shrink: 0;
}

.chatbot-mode-lightbox .chat-header-avatar {
    width: 38px;
    height: 38px;
    font-size: 18px;
}

/* Prevent body scroll when lightbox is open */
body.chatbot-lightbox-open {
    overflow: hidden;
}

/* ── Lightbox Intro Panel ── */
.chat-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 24px 24px;
    text-align: center;
    flex-shrink: 0;
}

.chat-intro-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    font-size: 48px;
}

.chat-intro-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-intro-name {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 700;
    color: #1a202c;
}

.chat-intro-sub {
    margin: 0;
    font-size: 14px;
    color: #718096;
}

/* Lightbox messages area fills remaining space */
.chatbot-mode-lightbox .chat-messages {
    flex: 1;
}

/* Lightbox — when intro is hidden, messages get the full space */
.chatbot-mode-lightbox #chat-intro[style*="display: none"] + #chat-messages {
    flex: 1;
}

/* ── Typing cursor during word-by-word animation ── */
.bot-message--animating::after {
    content: '▍';
    display: inline-block;
    color: #94a3b8;
    font-size: 0.85em;
    margin-left: 2px;
    vertical-align: baseline;
    animation: cursorBlink 1.3s steps(1, end) infinite;
}

@keyframes cursorBlink {
    0%, 55% {
        opacity: 1;
    }
    56%, 100% {
        opacity: 0;
    }
}

/* ── Upgrade / Limit-Reached Button ── */
.chatbot-limit-msg a {
    color: #0073aa;
}

.chatbot-limit-msg a.chatbot-btn,
a.chatbot-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 8px 18px;
    background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
    color: #fff !important;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0, 115, 170, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}

.chatbot-limit-msg a.chatbot-btn:hover,
a.chatbot-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.45);
}

/* ── Bot message with avatar wrapper ── */
.bot-message-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-right: auto;
    max-width: min(92%, 760px);
}

.bot-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: rgba(0,0,0,0.07);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    align-self: flex-end;
}

.bot-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bot-message-wrap .bot-message {
    margin-right: 0;
    margin-left: 0;
    max-width: 100%;
}

/* ── New-chat icon button (header) ── */
#chat-new {
    background: rgba(255,255,255,0.15) !important;
    border: none !important;
    color: white !important;
    width: 28px !important;
    height: 28px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    font-size: 16px !important;
    line-height: 1 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.2s !important;
    flex-shrink: 0 !important;
    letter-spacing: 0 !important;
    font-weight: 400 !important;
}

#chat-new:hover {
    background: rgba(255,255,255,0.3) !important;
}

/* ── Error Messages ── */
.error-message {
    background: #fff5f5 !important;
    border: 1px solid #fed7d7 !important;
    color: #c53030 !important;
    max-width: 100% !important;
    border-radius: 12px !important;
    font-size: 13px !important;
}
