/* ============================================
   CHAT WIDGET - CSS
   Self-contained, themed via CSS variables.
   Theme colors are injected inline in site.blade.php
   based on the instance's active theme.
   ============================================ */

/* ----- Chat Widget Variables ----- */
:root {
    --chat-primary: #0d1b4c;           /* Overridden by inline style */
    --chat-primary-dark: #091236;
    --chat-accent: #d4a84b;
    --chat-accent-dark: #b8923f;
    --chat-accent-light: #e8c06a;
    --chat-bg: #ffffff;
    --chat-bg-secondary: #f5f5f5;
    --chat-text: #1a1a1a;
    --chat-text-secondary: #4a4a4a;
    --chat-text-muted: #888888;
    --chat-border: #e0e0e0;
    --chat-error: #c41e3a;
    --chat-success: #2e7d32;
}

/* ----- Floating Button ----- */
.chat-widget-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-primary);
    border: 3px solid var(--chat-primary);
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(0,0,0,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .3s ease;
    z-index: 99999999;
    padding: 0;
    font-size: 28px;
    line-height: 1;
}
.chat-widget-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 24px rgba(0,0,0,.25);
    background: var(--chat-accent-light);
}
.chat-widget-button .cw-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chat-error);
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* ----- Chat Window ----- */
.chat-window {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 400px;
    height: calc(100vh - 180px);
    max-height: 850px;
    min-height: 400px;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: 0 12px 24px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999998;
    transition: all .3s ease;
    opacity: 0;
    transform: translateY(20px) scale(.95);
    pointer-events: none;
    border: 3px solid var(--chat-primary);
}
.chat-window.cw-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

@media (max-height: 800px) {
    .chat-window {
        height: calc(100vh - 140px);
        max-height: none;
    }
}

/* ----- Chat Header ----- */
.chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 3px solid var(--chat-accent);
}
.chat-header-avatar {
    width: 45px;
    height: 45px;
    background: var(--chat-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chat-primary);
    font-size: 22px;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-info h3 { font-size: 1.1rem; margin: 0 0 3px; }
.chat-header-info .cw-status {
    font-size: .8rem;
    color: var(--chat-accent-light);
    display: flex;
    align-items: center;
    gap: 5px;
}
.cw-status-dot {
    width: 8px; height: 8px;
    background: #4caf50;
    border-radius: 50%;
    animation: cwPulse 2s infinite;
}
@keyframes cwPulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.chat-close-btn {
    background: rgba(212,168,75,.2);
    border: none;
    color: var(--chat-accent);
    width: 35px; height: 35px;
    border-radius: 50%;
    cursor: pointer;
    transition: background .2s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-close-btn:hover { background: rgba(212,168,75,.4); }

/* ----- Messages Area ----- */
.chat-messages {
    flex: 1;
    padding: 24px 20px 20px 20px;
    overflow-y: auto;
    background: var(--chat-bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 180px;
}
.cw-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: cwFadeIn .3s ease;
}
@keyframes cwFadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

.cw-msg.cw-user { align-self: flex-end; flex-direction: row-reverse; }
.cw-msg.cw-bot  { align-self: flex-start; }

.cw-msg-avatar {
    width: 35px; height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}
.cw-msg.cw-user .cw-msg-avatar { background: var(--chat-primary); color: #fff; }
.cw-msg.cw-bot  .cw-msg-avatar { background: var(--chat-accent);  color: var(--chat-primary); }

.cw-msg-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: .95rem;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}
.cw-msg.cw-user .cw-msg-content {
    background: var(--chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cw-msg.cw-bot .cw-msg-content {
    background: var(--chat-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    border-left: 3px solid var(--chat-accent);
}

/* Links in messages */
.cw-msg-content a {
    color: var(--chat-accent-dark);
    text-decoration: underline;
    font-weight: 500;
    transition: color .2s;
}
.cw-msg-content a:hover {
    color: var(--chat-accent);
}
.cw-msg.cw-user .cw-msg-content a {
    color: var(--chat-accent-light);
}
.cw-msg.cw-user .cw-msg-content a:hover {
    color: #fff;
}
.cw-msg-time {
    font-size: .7rem;
    color: var(--chat-text-muted);
    margin-top: 5px;
    text-align: right;
}
.cw-msg.cw-user .cw-msg-time { text-align: left; }

/* Welcome Message */
.cw-welcome {
    text-align: center;
    padding: 16px 20px 20px 20px;
    background: linear-gradient(135deg, rgba(13,27,76,.05) 0%, rgba(212,168,75,.1) 100%);
    border-radius: 12px;
    margin-bottom: 15px;
    border: 2px solid var(--chat-accent);
    box-sizing: border-box;
    width: 100%;
    overflow: visible;
}
.cw-welcome h4 { 
    color: var(--chat-primary); 
    margin: 0 0 8px 0; 
    font-size: 1rem; 
    line-height: 1.4;
    word-wrap: break-word;
}
.cw-welcome p  { 
    color: var(--chat-text-secondary); 
    font-size: .9rem; 
    margin: 0; 
    line-height: 1.5;
    word-wrap: break-word;
}

/* Typing Indicator */
.cw-typing {
    display: none;
    gap: 10px;
    align-items: center;
    padding: 12px 16px;
    background: var(--chat-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    border-left: 3px solid var(--chat-accent);
    width: fit-content;
}
.cw-typing.active { display: flex; }
.cw-typing-dots { display: flex; gap: 4px; }
.cw-typing-dots span {
    width: 8px; height: 8px;
    background: var(--chat-accent);
    border-radius: 50%;
    animation: cwTyping 1.4s infinite ease-in-out;
}
.cw-typing-dots span:nth-child(2) { animation-delay:.2s; }
.cw-typing-dots span:nth-child(3) { animation-delay:.4s; }
@keyframes cwTyping { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-8px)} }

/* Quick Actions */
.cw-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 15px;
    background: var(--chat-bg-secondary);
}
.cw-quick-btn {
    padding: 8px 14px;
    background: var(--chat-bg);
    border: 2px solid var(--chat-primary);
    border-radius: 20px;
    font-size: .8rem;
    color: var(--chat-primary);
    cursor: pointer;
    transition: all .2s;
}
.cw-quick-btn:hover { background: var(--chat-primary); color: #fff; }

/* ----- Input Area ----- */
.chat-input-area {
    padding: 15px 20px;
    background: var(--chat-bg);
    border-top: 2px solid var(--chat-border);
    display: flex;
    gap: 10px;
    align-items: center;
}
.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--chat-border);
    border-radius: 25px;
    font-size: .95rem;
    outline: none;
    transition: border-color .2s;
    font-family: inherit;
}
.chat-input:focus { border-color: var(--chat-primary); }
.chat-send-btn {
    width: 45px; height: 45px;
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    font-size: 16px;
    flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--chat-accent-dark); transform: scale(1.05); }
.chat-send-btn:disabled { background: var(--chat-text-muted); cursor: not-allowed; transform: none; }

/* ============================================
   MODALS (Registration + OTP)
   ============================================ */
.cw-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(13,27,76,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
}
.cw-modal-overlay.cw-open { opacity: 1; pointer-events: all; }

.cw-modal {
    background: var(--chat-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 12px 24px rgba(0,0,0,.25);
    transform: translateY(20px);
    transition: transform .3s ease;
    border: 3px solid var(--chat-primary);
    overflow: hidden;
    position: relative;
}
.cw-modal-overlay.cw-open .cw-modal { transform: translateY(0); }

.cw-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    z-index: 10;
}
.cw-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.cw-modal-header {
    padding: 25px 30px 15px;
    text-align: center;
    background: var(--chat-primary);
    border-bottom: 3px solid var(--chat-accent);
}
.cw-modal-header-icon {
    width: 60px; height: 60px;
    background: var(--chat-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    color: var(--chat-primary);
    font-size: 28px;
}
.cw-modal-header h2 { color: #fff; font-size: 1.4rem; margin: 0 0 5px; }
.cw-modal-header p  { color: var(--chat-accent-light); font-size: .9rem; margin: 0; }

.cw-modal-body { padding: 25px 30px; }

.cw-form-group { margin-bottom: 20px; }
.cw-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--chat-primary);
    font-size: .9rem;
}
.cw-form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--chat-border);
    border-radius: 10px;
    font-size: 1rem;
    transition: all .2s;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}
.cw-form-group input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(13,27,76,.1);
}
.cw-form-group input.cw-error { border-color: var(--chat-error); }
.cw-form-group .cw-error-msg {
    color: var(--chat-error);
    font-size: .8rem;
    margin-top: 5px;
    display: none;
}
.cw-input-icon { position: relative; }
.cw-input-icon input { padding-left: 45px; }
.cw-input-icon i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-primary);
}

/* OTP Inputs */
.cw-otp-inputs {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 25px 0;
}
.cw-otp-input {
    width: 55px; height: 60px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    outline: none;
    transition: all .2s;
    font-family: inherit;
}
.cw-otp-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(13,27,76,.1);
}
.cw-otp-input.cw-filled {
    border-color: var(--chat-accent);
    background: rgba(212,168,75,.1);
    color: var(--chat-primary);
}

.cw-resend-otp {
    text-align: center;
    margin-top: 20px;
    font-size: .9rem;
    color: var(--chat-text-secondary);
}
.cw-resend-otp a {
    color: var(--chat-primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}
.cw-resend-otp a:hover { text-decoration: underline; color: var(--chat-accent-dark); }
.cw-resend-otp .cw-timer { color: var(--chat-text-muted); }

/* Honeypot */
.cw-honeypot {
    position: absolute;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

/* Buttons */
.cw-btn {
    width: 100%;
    padding: 14px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}
.cw-btn-primary { background: var(--chat-accent); color: var(--chat-primary); }
.cw-btn-primary:hover { background: var(--chat-accent-dark); transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,.15); }
.cw-btn-primary:disabled { background: var(--chat-text-muted); cursor: not-allowed; transform: none; box-shadow: none; }
.cw-btn-secondary {
    background: var(--chat-bg-secondary);
    color: var(--chat-primary);
    border: 2px solid var(--chat-primary);
}
.cw-btn-secondary:hover { background: var(--chat-primary); color: #fff; }

/* reCAPTCHA badge mock */
.cw-recaptcha {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: var(--chat-bg-secondary);
    border-radius: 8px;
    margin-top: 15px;
    font-size: .75rem;
    color: var(--chat-text-muted);
}

/* General-purpose alert */
.cw-alert {
    padding: 10px 15px;
    border-radius: 8px;
    font-size: .85rem;
    margin-bottom: 15px;
    display: none;
}
.cw-alert-error { background: rgba(196,30,58,.1); color: var(--chat-error); display: block; }
.cw-alert-success { background: rgba(46,125,50,.1); color: var(--chat-success); display: block; }

/* ============================================
   MOBILE RESPONSIVENESS
   ============================================ */
@media (max-width: 768px) {
    .chat-window {
        width: calc(100% - 20px);
        right: 10px;
        bottom: 100px;
        height: calc(100vh - 130px);
        max-height: none;
    }
    .chat-widget-button {
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
    }
    .cw-modal { width: 95%; max-width: none; margin: 10px; }
    .cw-otp-inputs { gap: 8px; }
    .cw-otp-input { width: 45px; height: 50px; font-size: 1.2rem; }
}
