/* Modern Premium Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 10000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chat-widget-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f4c81 0%, #1e3a5f 100%);
    color: white;
    border: none;
    box-shadow: 0 10px 25px rgba(15, 76, 129, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-widget-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 35px rgba(15, 76, 129, 0.5);
}

.chat-widget-window {
    display: none;
    position: absolute;
    bottom: 85px;
    left: 0;
    width: min(380px, calc(100vw - 60px));
    height: min(550px, calc(100vh - 135px));
    height: min(550px, calc(100dvh - 135px));
    box-sizing: border-box;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.2);
    border: 1px solid rgba(0,0,0,0.05);
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom left;
    animation: chatPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

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

.chat-widget-window.open {
    display: flex;
}

.chat-header {
    flex-shrink: 0;
    background: linear-gradient(135deg, #0f4c81 0%, #1a5c9a 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header h3::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}

.chat-close-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-close-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: rotate(90deg);
}

.chat-messages {
    min-height: 0;
    min-width: 0;
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8fafc;
}

.chat-message {
    flex-shrink: 0;
    overflow-wrap: anywhere;
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    animation: slideIn 0.3s ease-out forwards;
}

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

.chat-message.bot {
    background: #ffffff;
    color: #1e293b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.chat-message.user {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.admin {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-scripts {
    max-height: 25%;
    overflow-y: auto;
    flex-shrink: 0;
    padding: 12px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: #ffffff;
    border-top: 1px solid #f1f5f9;
}

.chat-script-btn {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #0284c7;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-script-btn:hover {
    background: #0ea5e9;
    color: white;
    border-color: #0ea5e9;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(14, 165, 233, 0.15);
}

.chat-input-area {
    flex-shrink: 0;
    min-width: 0;
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #f1f5f9;
    display: flex;
    gap: 12px;
}

.chat-input-area input {
    min-width: 0;
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    background: #f8fafc;
    transition: all 0.2s ease;
}

.chat-input-area input:focus {
    border-color: #0ea5e9;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.chat-input-area button {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(14, 165, 233, 0.2);
}

.chat-input-area button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(14, 165, 233, 0.3);
}

.chat-input-area button svg {
    margin-left: -2px; /* slight visual offset for the send icon */
}

@media (max-width: 480px), (max-height: 600px) {
    .chat-widget { left: 12px; bottom: 12px; }
    .chat-widget-window {
        bottom: 76px;
        width: min(380px, calc(100vw - 24px));
        height: min(550px, calc(100vh - 100px));
        height: min(550px, calc(100dvh - 100px));
    }
    .chat-header { padding: 10px 14px; }
    .chat-input-area { padding: 10px; gap: 8px; }
    .chat-messages { padding: 12px; }
}

/* Guided help stays separate from the live conversation. */
.chat-widget .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.chat-widget-window { width: min(410px, calc(100vw - 60px)); height: min(680px, calc(100dvh - 135px)); }
.chat-widget-btn { background: linear-gradient(135deg, #ffd600, #e6a800); color: #171717; box-shadow: 0 8px 26px #d9a90040; }
.chat-header { background: linear-gradient(125deg, #252525, #111); border-bottom-color: #ffd60040; }
.chat-header h3::before { background: #ffd600; box-shadow: 0 0 0 3px #ffd60025; }
.chat-messages { min-height: 76px; }
.chat-guide { flex-shrink: 1; min-height: 0; max-height: 41%; overflow-y: auto; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 7px; background: #fffdf4; border-top: 1px solid #eae3c6; }
.chat-guide-title { flex-basis: 100%; color: #27251b; font-size: 14px; }
.chat-guide p { flex-basis: 100%; margin: 0 0 3px; color: #57513c; font-size: 12px; line-height: 1.5; }
.chat-guide .chat-script-btn { color: #403717; border-color: #e7d783; background: #fff; text-align: left; padding: 7px 10px; }
.chat-guide .chat-script-btn:hover { background: #ffd600; border-color: #e5be00; color: #171717; box-shadow: none; }
.chat-guide-link { color: #675000; font-size: 13px; font-weight: 650; padding: 6px 2px; margin-right: 7px; text-decoration: underline; text-underline-offset: 3px; }
.chat-feedback { flex-shrink: 0; margin: 0; padding: 0 14px; background: #fff; color: #754c12; font-size: 12px; line-height: 1.45; }
.chat-feedback:not(:empty) { padding-top: 7px; padding-bottom: 7px; }
.chat-widget button:focus-visible, .chat-widget a:focus-visible { outline: 3px solid #917000; outline-offset: 2px; }
.chat-widget button:disabled { opacity: .55; cursor: wait; transform: none; }
.chat-widget .chat-input-area button { background: #ffd600; color: #171717; box-shadow: 0 4px 10px #b99b0025; }
.chat-message.user { background: #ffdc36; color: #242011; }
.chat-message.admin { background: #174d3c; }
.chat-widget .chat-header h3 { color: #fff; }
@media (max-width: 480px), (max-height: 600px) {
    .chat-widget-window { width: min(410px, calc(100vw - 24px)); height: min(680px, calc(100dvh - 100px)); }
    .chat-guide { padding: 9px 12px; gap: 6px; max-height: 40%; }
    .chat-guide .chat-script-btn { padding: 6px 8px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .chat-widget *, .chat-widget *::before, .chat-widget *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Scripted bot replies: a short warm typing cue followed by a readable type-on effect. */
.chat-message.bot {
    background: linear-gradient(145deg, #fff 0%, #fffdf5 100%);
    border-color: #e9dfb5;
    box-shadow: 0 5px 16px rgba(54, 45, 16, .07);
}
.chat-message.bot.is-typing {
    border-color: #dfc760;
    box-shadow: 0 7px 20px rgba(166, 132, 25, .12);
}
.chat-message-body { white-space: pre-wrap; }
.chat-message.bot.is-typing .chat-message-body::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: -.15em;
    border-radius: 2px;
    background: #9b7900;
    animation: chatTypingCaret .8s steps(2, end) infinite;
}
.chat-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 1.4em;
    padding: 0 2px;
}
.chat-typing-indicator i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b99a25;
    animation: chatTypingDot .9s ease-in-out infinite;
}
.chat-typing-indicator i:nth-child(2) { animation-delay: 120ms; }
.chat-typing-indicator i:nth-child(3) { animation-delay: 240ms; }
@keyframes chatTypingDot {
    0%, 60%, 100% { opacity: .42; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}
@keyframes chatTypingCaret {
    0%, 48% { opacity: 1; }
    49%, 100% { opacity: 0; }
}
