/**
 * Aaron Services Chatbot - Erin
 * Main stylesheet with avatar emotion system support
 * 
 * @package AaronServices\Chatbot
 * @version 1.7.7
 */

/* ==========================================================================
   CSS Variables - Aaron Services Brand
   ========================================================================== */

:root {
    --erin-primary: #2c3580;
    --erin-primary-dark: #1e2560;
    --erin-secondary: #005B94;
    --erin-accent: #c82027;
    --erin-green: #27a965;
    --erin-yellow: #f0ad4e;
    --erin-bg: #ffffff;
    --erin-bg-dark: #f5f5f5;
    --erin-bg-message: #f0f2f5;
    --erin-text: #333333;
    --erin-text-light: #666666;
    --erin-text-muted: #999999;
    --erin-border: #e5e5e4;
    --erin-shadow: rgba(0, 0, 0, 0.1);
    --erin-shadow-strong: rgba(0, 0, 0, 0.2);
    --erin-radius: 16px;
    --erin-radius-small: 12px;
    --erin-radius-bubble: 18px;
    --erin-transition: 0.2s ease;
    --erin-transition-slow: 0.3s ease;
}

/* ==========================================================================
   Widget Container
   ========================================================================== */

.aaron-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Chat Bubble (Collapsed State)
   ========================================================================== */

.erin-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 16px 4px 4px;
    background: var(--erin-primary);
    border: none;
    border-radius: 32px;
    cursor: pointer;
    box-shadow: 
        0 4px 20px rgba(44, 53, 128, 0.4), 
        0 0 0 3px rgba(255, 255, 255, 0.9);
    transition: transform var(--erin-transition), box-shadow var(--erin-transition);
    position: relative;
}

.erin-bubble:hover {
    transform: scale(1.05);
    box-shadow: 
        0 6px 28px rgba(44, 53, 128, 0.5), 
        0 0 0 4px rgba(255, 255, 255, 1);
}

.erin-bubble:active {
    transform: scale(1.02);
}

.erin-bubble--hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

.erin-bubble__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    object-fit: cover;
    transition: opacity var(--erin-transition);
    flex-shrink: 0;
}

.erin-bubble__text {
    color: white;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: opacity 0.2s ease;
    padding-right: 4px;
}

/* Green "online" beacon - pulsating */
.erin-bubble__beacon {
    position: absolute;
    top: 0;
    left: 38px;
    width: 14px;
    height: 14px;
    background: var(--erin-green);
    border-radius: 50%;
    border: 2px solid white;
    animation: erin-pulse 2s infinite;
}

@keyframes erin-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 169, 101, 0.6);
    }
    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(39, 169, 101, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 169, 101, 0);
    }
}

/* ==========================================================================
   Chat Window
   ========================================================================== */

.erin-window {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 100px);
    background: var(--erin-bg);
    border-radius: var(--erin-radius);
    box-shadow: 0 8px 40px var(--erin-shadow-strong);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity var(--erin-transition-slow), transform var(--erin-transition-slow);
}

.erin-window--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ==========================================================================
   Header
   ========================================================================== */

.erin-header {
    background: var(--erin-primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.erin-header__info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.erin-header__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    object-fit: cover;
    transition: opacity 0.15s ease;
}

.erin-header__text {
    display: flex;
    flex-direction: column;
}

.erin-header__name {
    font-size: 16px;
    font-weight: 600;
}

.erin-header__status {
    font-size: 12px;
    opacity: 0.8;
}

.erin-header__close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    padding: 4px 8px;
    opacity: 0.8;
    transition: opacity var(--erin-transition);
}

.erin-header__close:hover {
    opacity: 1;
}

.erin-header__actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.erin-header__refresh {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    opacity: 0.7;
    transition: opacity var(--erin-transition), transform 0.3s ease;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.erin-header__refresh:hover {
    opacity: 1;
    transform: rotate(45deg);
}

.erin-header__refresh:focus {
    outline: none;
    background: none;
}

.erin-header__refresh:active {
    opacity: 0.5;
    background: none;
}

.erin-header__refresh svg {
    display: block;
}
.erin-window svg {
    height: inherit;
}
/* ==========================================================================
   Messages Area
   ========================================================================== */

.erin-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

.erin-messages__container {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================================================
   Message Bubbles
   ========================================================================== */

.erin-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 85%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.erin-message--visible {
    opacity: 1;
    transform: translateY(0);
}

.erin-message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.erin-message--assistant {
    align-self: flex-start;
}

.erin-message__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.erin-message__bubble {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.erin-message__content {
    padding: 12px 16px;
    border-radius: var(--erin-radius-bubble);
    line-height: 1.5;
    word-wrap: break-word;
}

.erin-message--user .erin-message__content {
    background: var(--erin-primary);
    color: white;
    border-bottom-right-radius: 6px;
}

.erin-message--assistant .erin-message__content {
    background: var(--erin-bg-message);
    color: var(--erin-text);
    border-bottom-left-radius: 6px;
}

/* Phone link styling */
.erin-phone-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.erin-message--user .erin-phone-link {
    color: white;
}

/* ==========================================================================
   Tool Links
   ========================================================================== */

.erin-tool-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.erin-tool-link {
    display: inline-block;
    background: linear-gradient(135deg, var(--erin-primary) 0%, #4a5bc9 100%);
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: transform var(--erin-transition), box-shadow var(--erin-transition);
}

.erin-tool-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(51, 65, 185, 0.3);
    color: white;
}

.erin-tool-link:active {
    transform: translateY(0);
}
a.erin-tool-link:visited {
    color: #fff;
}

/* ==========================================================================
   Quick Replies
   ========================================================================== */

.erin-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 40px; /* Align with message bubble */
    transition: opacity var(--erin-transition);
}

.erin-quick-reply {
    background: white;
    border: 1.5px solid var(--erin-primary);
    color: var(--erin-primary);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background var(--erin-transition), color var(--erin-transition), transform var(--erin-transition);
    text-decoration: none;
    display: inline-block;
}

.erin-quick-reply:hover {
    background: var(--erin-primary);
    color: white;
    transform: translateY(-1px);
}

.erin-quick-reply:active {
    transform: translateY(0);
}

.erin-quick-reply--call {
    background: var(--erin-green);
    border-color: var(--erin-green);
    color: white;
}

.erin-quick-reply--call:hover {
    background: #1e8f52;
    border-color: #1e8f52;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.erin-typing {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 0 16px 16px 16px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.erin-typing--visible {
    opacity: 1;
    transform: translateY(0);
}

.erin-typing__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.erin-typing__dots {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: var(--erin-bg-message);
    border-radius: var(--erin-radius-bubble);
    border-bottom-left-radius: 6px;
}

.erin-typing__dots span {
    width: 8px;
    height: 8px;
    background: var(--erin-text-muted);
    border-radius: 50%;
    animation: erin-typing 1.4s infinite ease-in-out;
}

.erin-typing__dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.erin-typing__dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes erin-typing {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ==========================================================================
   Input Area
   ========================================================================== */

.erin-input {
    padding: 12px 16px;
    border-top: 1px solid var(--erin-border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    background: var(--erin-bg);
}

.erin-input__field {
    flex: 1;
    border: 1px solid var(--erin-border);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--erin-transition), box-shadow var(--erin-transition);
}

.erin-input__field:focus {
    border-color: var(--erin-primary);
    box-shadow: 0 0 0 3px rgba(44, 53, 128, 0.1);
}

.erin-input__field::placeholder {
    color: var(--erin-text-muted);
}

.erin-input__send {
    background: var(--erin-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--erin-transition), transform var(--erin-transition);
}

.erin-input__send:hover {
    background: var(--erin-primary-dark);
    transform: scale(1.05);
}

.erin-input__send:active {
    transform: scale(0.98);
}

.erin-input__send svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Safety/Emergency Styling
   ========================================================================== */

.erin-message--safety .erin-message__content {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .aaron-chatbot-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .erin-bubble {
        padding: 4px 12px 4px 4px;
        gap: 8px;
    }
    
    .erin-bubble__avatar {
        width: 44px;
        height: 44px;
    }
    
    .erin-bubble__text {
        font-size: 13px;
    }
    
    .erin-bubble__beacon {
        left: 34px;
        width: 12px;
        height: 12px;
    }
    
    .erin-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .erin-messages__container {
        padding: 12px;
    }
    
    .erin-message {
        max-width: 90%;
    }
    
    .erin-quick-replies {
        padding-left: 0;
        justify-content: center;
    }
}

/* ==========================================================================
   Full Page Chatbot Mode (Shortcode / Landing Page)
   ========================================================================== */

/* Fullpage container - used by shortcode */
.aaron-chatbot-fullpage {
    width: 100%;
    max-width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Fullpage window - override fixed/absolute positioning */
.erin-window--fullpage {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    min-height: 500px;
    max-height: 600px;
    border-radius: 12px !important;
    box-shadow: 0 4px 20px -4px rgba(0, 0, 0, 0.08) !important;
    border: 1px solid var(--erin-border);
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    display: flex !important;
    flex-direction: column;
}

/* Always visible in fullpage mode */
.erin-window--fullpage.erin-window--open {
    transform: none !important;
}

/* Header adjustments for fullpage */
.erin-window--fullpage .erin-header {
    border-radius: 12px 12px 0 0;
}

/* Messages area fills available space */
.erin-window--fullpage .erin-messages {
    flex: 1;
    min-height: 300px;
}

/* Input area at bottom */
.erin-window--fullpage .erin-input {
    border-radius: 0 0 12px 12px;
}

/* Hide close button in fullpage mode */
.erin-window--fullpage .erin-header__close {
    display: none !important;
}

/* Mobile adjustments for fullpage */
@media (max-width: 782px) {
    .erin-window--fullpage {
        min-height: 420px;
        max-height: 500px;
        border-radius: 8px !important;
    }
    
    .erin-window--fullpage .erin-header {
        border-radius: 8px 8px 0 0;
    }
    
    .erin-window--fullpage .erin-input {
        border-radius: 0 0 8px 8px;
    }
    
    .erin-window--fullpage .erin-messages {
        min-height: 250px;
    }
}

/* Landing page specific container overrides */
.erin-fullpage-chat {
    min-height: 500px;
    max-height: 600px;
    border-radius: 12px;
    overflow: hidden;
}

.erin-fullpage-chat .erin-window--fullpage {
    height: 100%;
    min-height: inherit;
    max-height: inherit;
}

@media (max-width: 782px) {
    .erin-fullpage-chat {
        min-height: 420px;
        max-height: 500px;
    }
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

.erin-messages::-webkit-scrollbar,
.erin-messages__container::-webkit-scrollbar {
    width: 6px;
}

.erin-messages::-webkit-scrollbar-track,
.erin-messages__container::-webkit-scrollbar-track {
    background: transparent;
}

.erin-messages::-webkit-scrollbar-thumb,
.erin-messages__container::-webkit-scrollbar-thumb {
    background: var(--erin-border);
    border-radius: 3px;
}

.erin-messages::-webkit-scrollbar-thumb:hover,
.erin-messages__container::-webkit-scrollbar-thumb:hover {
    background: var(--erin-text-muted);
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.erin-bubble:focus,
.erin-quick-reply:focus,
.erin-input__send:focus,
.erin-header__close:focus {
    outline: 2px solid var(--erin-primary);
    outline-offset: 2px;
}

.erin-input__field:focus {
    outline: none; /* Uses box-shadow instead */
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .erin-bubble,
    .erin-window,
    .erin-message,
    .erin-typing,
    .erin-header__avatar,
    .erin-bubble__avatar,
    .erin-bubble__text {
        transition: none;
    }
    
    .erin-bubble__beacon,
    .erin-typing__dots span {
        animation: none;
    }
}

/* ==========================================================================
   GROUP 1: HANDOFF & RATE LIMIT STYLES
   ========================================================================== */

/* Handoff mode indicator - subtle border/glow */
.erin-window.erin-handoff-mode {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15),
                0 0 0 2px rgba(255, 152, 0, 0.5);
}

.erin-window.erin-handoff-mode .erin-header {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
}

.erin-window.erin-handoff-mode .erin-header__status {
    color: rgba(255, 255, 255, 0.9);
}

.erin-window.erin-handoff-mode .erin-header__status::before {
    content: "Connecting you to help...";
    display: inline;
}

.erin-window.erin-handoff-mode .erin-header__status span {
    display: none;
}

/* Disabled input state */
.erin-input__field.erin-input--disabled {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.erin-input__field.erin-input--disabled::placeholder {
    color: #999;
}

.erin-input__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Rate limit countdown display */
.erin-rate-limit-notice {
    background: #fff3e0;
    border: 1px solid #ffcc80;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 8px 16px;
    text-align: center;
    font-size: 14px;
    color: #e65100;
}

.erin-rate-limit-notice strong {
    display: block;
    margin-bottom: 4px;
}

/* Handoff message styling */
.erin-message--handoff .erin-message__bubble {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border: 1px solid #ffcc80;
}

/* Circuit breaker notice */
.erin-circuit-notice {
    background: #ffebee;
    border: 1px solid #ef9a9a;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 8px 16px;
    text-align: center;
    font-size: 14px;
    color: #c62828;
}

/* Pulse animation for handoff header */
@keyframes handoff-pulse {
    0%, 100% { 
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15),
                    0 0 0 2px rgba(255, 152, 0, 0.5);
    }
    50% { 
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15),
                    0 0 0 4px rgba(255, 152, 0, 0.3);
    }
}

.erin-window.erin-handoff-mode {
    animation: handoff-pulse 2s ease-in-out infinite;
}

/* Handoff quick reply styling - more prominent call button */
.erin-handoff-mode .erin-quick-reply--call {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: white;
    font-weight: 600;
    animation: call-pulse 1.5s ease-in-out infinite;
}

@keyframes call-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}