/* 
 * Realtor Chat - Premium Design System (SDUI 2.0)
 * Aesthetics: Glassmorphism, Brutalist-leaning refined, Mobile-First.
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600&family=Inter:wght@400;500;700&display=swap');

:root {
    /* Branding Hierarchy */
    --brand-primary: #4b38b3;
    --brand-secondary: #6366f1;
    --brand-surface: #0f172a;
    --brand-accent: #06b6d4;

    /* Text Contrast Hierarchy */
    --text-on-primary: #ffffff;
    --text-on-secondary: #ffffff;
    --text-on-surface: #f8fafc;
    --text-muted: #94a3b8;

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    /* Aesthetics */
    --border-radius: 24px;
    --box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);

    /* Semantic Mappings */
    --header-bg: var(--brand-primary);
    --header-text: var(--text-on-primary);
    --chat-bg: var(--brand-surface);
    --chat-text: var(--text-on-surface);
    --bot-bubble-bg: var(--brand-primary);
    --bot-bubble-text: var(--text-on-primary);
    --cta-bg: var(--brand-secondary);
    --cta-text: var(--text-on-secondary);

    /* Glass Effects (Retained for depth) */
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-highlight: rgba(255, 255, 255, 0.05);

    /* Transitions */
    --spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--chat-bg);
    color: var(--chat-text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

/* --- Floating Launcher --- */
#chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--brand-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(75, 56, 179, 0.2);
    z-index: 9999;
    transition: transform 0.3s var(--spring), box-shadow 0.3s var(--smooth);
}

#chat-launcher:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4), 0 0 0 6px rgba(75, 56, 179, 0.3);
}

#chat-launcher:active {
    transform: scale(0.95);
}

#chat-launcher svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.3s var(--spring);
}

#chat-launcher:hover svg {
    transform: rotate(-10deg) scale(1.1);
}

#chat-launcher.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* --- Widget Window --- */
#chat-widget {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 420px;
    height: 700px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    box-shadow: var(--box-shadow);
    z-index: 9998;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.4s var(--smooth), transform 0.4s var(--spring);
}

#chat-widget.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.widget-header {
    padding: 24px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.brand-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(45deg, var(--brand-accent), var(--brand-secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
}

.header-info h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0;
    /* Adjusted for image alignment */
    color: var(--header-text);
    display: flex;
    align-items: center;
    min-height: 32px;
    /* Ensure consistent height */
}

.brand-wordmark {
    max-height: 80px;
    max-width: 320px;
    object-fit: contain;
    display: block;
    transition: opacity 0.3s ease;
}

/* Close Button */
.close-button {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.close-button svg {
    width: 16px;
    height: 16px;
    fill: var(--header-text);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 10px #10b981;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        opacity: 1;
    }
}

/* Messages Area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--brand-surface);
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

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

#chat-messages::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

/* Input Area */
.widget-input-area {
    padding: 20px 24px;
    background: var(--glass-highlight);
    border-top: 1px solid var(--glass-border);
}

.input-wrapper {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.3s var(--smooth), box-shadow 0.3s var(--smooth);
}

.input-wrapper:focus-within {
    border-color: var(--brand-secondary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--chat-text);
    padding: 12px 0;
    font-family: var(--font-body);
    font-size: 1.1rem;
    outline: none;
}

.send-button {
    width: 40px;
    height: 40px;
    background: var(--brand-secondary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s var(--smooth);
}

.send-button:hover {
    transform: scale(1.05);
}

.send-button svg {
    width: 20px;
    height: 20px;
    fill: var(--text-on-secondary, white);
}

/* --- Message Bubbles --- */
.message-wrapper {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.4s var(--smooth);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-wrapper.user {
    align-items: flex-end;
}

.message-wrapper.bot {
    align-items: flex-start;
}

.sender-name {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 1.1rem;
    line-height: 1.5;
    max-width: 85%;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s var(--smooth);
}

.message-bubble:hover {
    transform: translateY(-2px);
}

.bot .message-bubble {
    background: var(--bot-bubble-bg);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    color: var(--bot-bubble-text);
}

.user .message-bubble {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(75, 56, 179, 0.3);
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--glass-highlight);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 24px;
    animation: fadeIn 0.3s var(--smooth);
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1s infinite;
}

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

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

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
        opacity: 0.5;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Skeleton Loading (for later) */
.skeleton {
    background: linear-gradient(90deg, var(--glass-highlight) 25%, var(--glass-border) 50%, var(--glass-highlight) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 8px;
}

@keyframes loading {
    from {
        background-position: 200% 0;
    }

    to {
        background-position: -200% 0;
    }
}

/* ============================================
   RESPONSIVE DESIGN - MOBILE OPTIMIZATION
   ============================================ */

/* Tablets and smaller (max-width: 768px) */
@media (max-width: 768px) {
    #chat-widget {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 80px;
        max-height: calc(100vh - 120px);
    }

    .widget-header {
        padding: 16px;
    }

    #chat-messages {
        padding: 16px;
    }

    .widget-input-area {
        padding: 12px 16px;
    }
}

/* Mobile devices (max-width: 480px) */
@media (max-width: 480px) {
    #chat-widget {
        width: calc(100vw - 16px);
        right: 8px;
        left: 8px;
        bottom: 16px;
        /* Fallback para navegadores viejos */
        height: calc(100vh - 40px);
        max-height: calc(100vh - 40px);
        /* Unidades modernas que respetan la barra de direcciones */
        height: calc(100dvh - 32px);
        max-height: calc(100dvh - 32px);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    .widget-header {
        padding: 12px 16px;
        gap: 12px;
    }

    .brand-wordmark {
        max-height: 60px;
        max-width: 200px;
    }


    #chat-messages {
        padding: 12px;
        gap: 12px;
    }

    #chat-messages::-webkit-scrollbar {
        width: 4px;
    }

    .message-bubble {
        max-width: 90%;
        padding: 10px 14px;
    }

    .widget-input-area {
        padding: 10px 12px;
    }

    .input-wrapper {
        padding: 3px 3px 3px 12px;
    }

    #user-input {
        padding: 10px 0;
    }

    .send-button {
        width: 36px;
        height: 36px;
    }

    #chat-fab {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }
}