/* Germain Chatbot Widget Styles */
#germain-chatbot-widget {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: inline-block;           /* keep width to content */
    width: auto !important;          /* never full-width */
    left: auto !important;           /* pin to right */
    box-sizing: border-box;
    max-width: 100vw;                /* extra safety */
}

#germain-chat-button {
    background: linear-gradient(135deg, #1e40af, #dc2626);
    color: white;
    padding: 14px 16px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: inline-flex;            /* content-sized */
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    border: none;
    font-size: 14px;
    font-weight: 500;
    width: auto !important;          /* prevent full width from theme rules */
    min-height: 44px;                /* avoid looking like a line */
    white-space: nowrap;             /* keep text on one line */
    touch-action: manipulation;
}
#germain-chat-button:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }

.germain-avatar { position: relative; }
.germain-icon { font-size: 24px; background: white; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.pulse-ring { position: absolute; top: -3px; left: -3px; right: -3px; bottom: -3px; border: 2px solid rgba(255,255,255,0.7); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
.germain-text { font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,0.1); }

#germain-chat-window {
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;                /* prevent horizontal overflow */
    animation: slideUp 0.3s ease-out;
    position: relative;
    box-sizing: border-box;          /* include borders/padding in width calc */
    max-width: calc(100vw - 20px);   /* never wider than viewport */
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.chat-header { background: linear-gradient(135deg, #1e40af, #dc2626); color: white; padding: 15px; display: flex; justify-content: space-between; align-items: center; }
.header-info { display: flex; align-items: center; gap: 10px; }
.header-info .germain-icon { width: 35px; height: 35px; font-size: 20px; }
.name { font-weight: bold; font-size: 14px; margin-bottom: 2px; }
.status { font-size: 11px; opacity: 0.9; }
#germain-close {
    background: none; border: none; color: white; font-size: 20px; cursor: pointer; padding: 5px; border-radius: 50%; transition: background-color 0.2s ease; width: 30px; height: 30px; display: flex; align-items: center; 
    justify-content: center;
}
#germain-close:hover { background: rgba(255,255,255,0.2); }

/* Messages panel with extra padding for the watermark sticker and bottom counter */
.chat-messages { 
    position: relative;
    flex: 1; 
    padding: 15px 92px 96px 15px; /* right space for sticker, bottom space for counter */
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    background: linear-gradient(to bottom, #f8fafc, #ffffff);
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

.message { display: flex; animation: fadeInUp 0.3s ease-out; position: relative; z-index: 2; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.user-message { justify-content: flex-end; }
.germain-message { justify-content: flex-start; }
.message-content { max-width: 80%; padding: 12px 15px; border-radius: 18px; font-size: 13px; line-height: 1.4; word-wrap: break-word; position: relative; }
.user-message .message-content { background: #1e40af; color: white; border-bottom-right-radius: 4px; }
.germain-message .message-content { background: #f1f5f9; color: #334155; border-bottom-left-radius: 4px; border: 1px solid #e2e8f0; }

/* Watermark sticker: always visible, does not block interactions */
#germain-sticker {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 72px;
    height: auto;
    opacity: 0.95;
    pointer-events: none;
    user-select: none;
    z-index: 1; /* behind .message (z=2) */
}

.typing-indicator { font-style: italic; color: #64748b; font-size: 12px; padding: 8px 15px; background: #f1f5f9; border-radius: 15px; display: inline-block; animation: pulse 1.5s infinite; }

.chat-input {
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    background: white;
}
#germain-input {
    flex: 1 1 auto;
    min-width: 0;                    /* allow flex item to shrink on iOS */
    padding: 12px 15px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#germain-input:focus { border-color: #1e40af; box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1); }
#germain-input:disabled { background: #f9fafb; color: #6b7280; cursor: not-allowed; }

#germain-send {
    background: #1e40af;
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-width: 64px;
    flex: 0 0 auto;                  /* never shrink away */
}
#germain-send:hover:not(:disabled) { background: #1d4ed8; transform: translateY(-1px); }
#germain-send:disabled { background: #9ca3af; cursor: not-allowed; transform: none; }

/* High-contrast usage counter */
.usage-counter { 
    padding: 10px 15px; 
    background: rgba(15,23,42,0.92); 
    border-top: 1px solid rgba(255,255,255,0.12); 
    font-size: 11px; 
    color: #ffffff; 
    text-align: center; 
    font-weight: 600; 
    backdrop-filter: saturate(120%) blur(4px);
}
.usage-counter span { font-weight: 800; color: #ffed4a !important; }
.usage-counter, .usage-counter * { color: #ffffff !important; } /* ensure legible */
.usage-counter.warning { background: #7b5e00; } /* when JS adds .warning */

/* Mobile Responsive */
@media (max-width: 480px) {
    /* Keep the launcher in the bottom-right corner (no full-width container) */
    #germain-chatbot-widget {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        right: 10px;
        left: auto !important;
        width: auto !important;
        display: inline-block;
    }

    /* Make the opened chat window span the viewport width with margins and adapt to keyboard */
    #germain-chat-window { 
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        height: calc(var(--germain-vh, 1vh) * 80);      /* dynamic vh to avoid iOS keyboard jump */
        max-height: calc(var(--germain-vh, 1vh) * 90);
        margin: 0;
    }

    #germain-chat-button {
        padding: 12px 14px;
        font-size: 13px;
        min-height: 44px;
        width: auto !important;
        white-space: nowrap;
    }

    /* Avoid iOS zoom on focus */
    #germain-input, #germain-send { font-size: 16px; }

    /* tighter margins for small screens */
    .chat-messages { padding: 12px 76px 104px 12px; }
    #germain-sticker { width: 56px; bottom: 12px; right: 8px; }
}
@media (max-width: 768px) {
    #germain-chat-window { width: 320px; height: 450px; }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .message-content { border: 2px solid; }
    .user-message .message-content { border-color: white; }
    .germain-message .message-content { border-color: #000; }
}
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    .pulse-ring { animation: none; }
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #germain-chat-window { background: #1f2937; color: #f9fafb; }
    .chat-messages { background: linear-gradient(to bottom, #374151, #1f2937); }
    .germain-message .message-content { background: #374151; color: #f9fafb; border-color: #4b5563; }
    .chat-input { background: #1f2937; border-color: #4b5563; }
    #germain-input { background: #374151; color: #f9fafb; border-color: #4b5563; }
    .usage-counter { background: rgba(8,16,28,0.92); color: #ffffff; border-color: #4b5563; }
}

/* Hide deer icon and its holder everywhere (keep label visible) */
.germain-avatar, .germain-icon { display: none !important; }

/* Link/button styling inside bot messages */
.germain-message .message-content a.chat-btn,
.germain-message .message-content a.chat-link {
    display: inline-block;
    background: #1e40af;
    color: #ffffff;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    margin: 6px 6px 0 0;
    border: 1px solid rgba(0,0,0,0.05);
    max-width: 100%;
    line-height: 1.3;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.germain-message .message-content a.chat-btn:hover,
.germain-message .message-content a.chat-link:hover { background: #1d4ed8; color: #ffffff; }

/* Make inline anchors wrap nicely in narrow bubbles */
.germain-message .message-content a { word-break: break-word; }

/* Dark mode tweaks for buttons */
@media (prefers-color-scheme: dark) {
    .germain-message .message-content a.chat-btn,
    .germain-message .message-content a.chat-link { background: #2563eb; border-color: rgba(255,255,255,0.12); }
    .germain-message .message-content a.chat-btn:hover,
    .germain-message .message-content a.chat-link:hover { background: #3b82f6; }
}