/* ============================================================
   MIRA CHAT WIDGET - Namespaced Styles
   All classes prefixed with .mira-chat to avoid conflicts
   ============================================================ */

/* Font face - same as main site */
@font-face {
    font-family: 'ITC Avant Garde Gothic';
    src: url('fonts/ITC Avant Garde Gothic CE Demi.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* CSS Custom Properties for easy theming */
.mira-chat-widget {
    --mira-sand: rgba(255, 250, 195, 0.35);
    --mira-sand-call: rgba(255, 250, 195, 0.15);
    --mira-sand-solid: #FFFAC3;
    --mira-burgundy: #721311;
    --mira-periwinkle: #5F28FF;
    --mira-periwinkle-mute: #CAC6FB;
    --mira-white: #FFFFFF;
    --mira-black: #231F20;
    --mira-text-dark: #231F20;
    --mira-shadow: rgba(0, 0, 0, 0.15);
    --mira-radius: 24px;
    --mira-font: 'ITC Avant Garde Gothic', 'Helvetica Neue', -apple-system, sans-serif;
}

/* ============================================================
   OVERLAY
   ============================================================ */
.mira-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    z-index: 9998;
    pointer-events: none;
    transition: background 0.4s ease;
}

.mira-chat-overlay.mira-chat-visible {
    background: rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

/* ============================================================
   MAIN CONTAINER
   ============================================================ */
.mira-chat-widget {
    position: fixed;
    z-index: 9999;
    font-family: var(--mira-font);
    -webkit-font-smoothing: antialiased;
    
    /* Desktop: bottom-right positioning */
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 680px;
    max-height: calc(100vh - 48px);
    
    /* Initial state - hidden and scaled to button origin */
    opacity: 0;
    transform: scale(0.1);
    transform-origin: bottom center;
    pointer-events: none;
    
    /* Appearance */
    background: var(--mira-sand);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-radius: var(--mira-radius);
    box-shadow: 
        0 25px 80px rgba(0, 0, 0, 0.25),
        0 10px 30px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    
    display: flex;
    flex-direction: column;
}

.mira-chat-widget.mira-chat-visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

/* Call mode - more transparent */
.mira-chat-widget.mira-chat-call-mode {
    background: var(--mira-sand-call);
    transition: background 0.5s ease;
}

/* ============================================================
   CALL MODE ORB CONTAINER
   ============================================================ */
.mira-chat-orb-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 5;
}

.mira-chat-orb-container.mira-chat-visible {
    opacity: 1;
    pointer-events: auto;
}

.mira-chat-orb-canvas {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* State indicator */
.mira-chat-state-indicator {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--mira-white);
    padding: 10px 20px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mira-chat-state-indicator.mira-chat-visible {
    opacity: 1;
}

/* Exit call mode hint */
.mira-chat-exit-hint {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s ease 0.5s;
}

.mira-chat-call-mode .mira-chat-exit-hint {
    opacity: 1;
}

/* ============================================================
   HEADER
   ============================================================ */
.mira-chat-header {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 16px 20px;
    /* Transparent header - messages scroll underneath */
    background: transparent;
    z-index: 10;
    pointer-events: none; /* Allow clicks to pass through to messages */
}

.mira-chat-close {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, transform 0.2s ease;
    color: var(--mira-text-dark);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: auto; /* Re-enable clicks on the button itself */
}

.mira-chat-close:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.1);
}

.mira-chat-close:active {
    transform: scale(0.95);
}

.mira-chat-close svg {
    width: 18px;
    height: 18px;
}

/* ============================================================
   MESSAGES AREA
   ============================================================ */
.mira-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 68px 20px 20px; /* Top padding accounts for floating header */
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: opacity 0.4s ease;
    
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Hide messages in call mode */
.mira-chat-call-mode .mira-chat-messages {
    opacity: 0;
    pointer-events: none;
}

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

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

.mira-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* Message bubbles */
.mira-chat-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.5;
    word-wrap: break-word;
    animation: mira-chat-message-in 0.3s ease;
}

@keyframes mira-chat-message-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* System messages (maroon) */
.mira-chat-message.mira-chat-system {
    align-self: flex-start;
    background: var(--mira-burgundy);
    color: var(--mira-white);
    border-bottom-left-radius: 6px;
}

/* User messages (periwinkle) */
.mira-chat-message.mira-chat-user {
    align-self: flex-end;
    background: var(--mira-periwinkle);
    color: var(--mira-white);
    border-bottom-right-radius: 6px;
}

/* ============================================================
   INPUT AREA
   ============================================================ */
.mira-chat-input-area {
    padding: 16px 20px 20px;
    background: transparent;
    flex-shrink: 0;
    transition: opacity 0.4s ease;
}

/* Hide input in call mode */
.mira-chat-call-mode .mira-chat-input-area {
    opacity: 0;
    pointer-events: none;
}

.mira-chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--mira-white);
    border-radius: 28px;
    padding: 8px 8px 8px 18px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.mira-chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-family: var(--mira-font);
    font-size: 17px;
    font-weight: 600;
    line-height: 1.4;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    padding: 6px 0;
    background: transparent;
    color: var(--mira-text-dark);
}

.mira-chat-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* Action buttons */
.mira-chat-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.mira-chat-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    background: rgba(0, 0, 0, 0.06);
}

.mira-chat-btn:hover {
    transform: scale(1.08);
    background: rgba(0, 0, 0, 0.1);
}

.mira-chat-btn:active {
    transform: scale(0.95);
}

.mira-chat-btn svg,
.mira-chat-btn img {
    width: 20px;
    height: 20px;
}

.mira-chat-btn-call {
    background: var(--mira-periwinkle);
}

.mira-chat-btn-call:hover {
    background: #4A1FCC;
}

.mira-chat-btn-call img {
    filter: brightness(0) invert(1);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.mira-chat-toast {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--mira-burgundy);
    color: var(--mira-white);
    padding: 12px 24px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.mira-chat-toast.mira-chat-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   MOBILE STYLES
   ============================================================ */
@media (max-width: 768px) {
    .mira-chat-widget {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        /* Use fixed positioning relative to visual viewport */
        position: fixed;
    }
    
    /* When keyboard is open, this class is added via JS */
    .mira-chat-widget.mira-chat-keyboard-open {
        height: 100%;
        bottom: 0;
    }
    
    .mira-chat-header {
        padding: 12px 16px;
        /* Safe area for notch */
        padding-top: max(12px, env(safe-area-inset-top));
    }
    
    .mira-chat-messages {
        /* Account for safe area in padding */
        padding: calc(56px + env(safe-area-inset-top, 0px)) 16px 16px;
        /* Ensure messages area takes available space */
        flex: 1;
        min-height: 0;
    }
    
    .mira-chat-input-area {
        padding: 12px 16px;
        /* Safe area for home indicator */
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        /* Ensure input stays at bottom */
        flex-shrink: 0;
        position: relative;
    }
    
    /* Mobile font sizes - slightly smaller than desktop */
    .mira-chat-message {
        font-size: 16px;
    }
    
    .mira-chat-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    .mira-chat-toast {
        bottom: 90px;
        left: 16px;
        right: 16px;
        transform: translateX(0) translateY(20px);
        text-align: center;
    }
    
    .mira-chat-toast.mira-chat-visible {
        transform: translateX(0) translateY(0);
    }
    
    .mira-chat-overlay.mira-chat-visible {
        background: rgba(0, 0, 0, 0);
    }
}

/* ============================================================
   ANIMATION CLASSES
   ============================================================ */
.mira-chat-widget.mira-chat-animating {
    transition: opacity 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mira-chat-widget.mira-chat-closing {
    transition: opacity 0.3s ease-out,
                transform 0.3s ease-out;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */
.mira-chat-typing {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    align-self: flex-start;
    background: var(--mira-burgundy);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
}

.mira-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: mira-chat-typing 1.4s ease-in-out infinite;
}

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

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

@keyframes mira-chat-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}
