/* Reset y Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #D32F2F;
    --primary-dark: #B71C1C;
    --secondary: #E8DACB;
    --bg-main: #FAF7F2;
    --bg-chat: #ffffff;
    --bg-user: #D32F2F;
    --bg-bot: #E8DACB;
    --text-dark: #2d3748;
    --text-light: #718096;
    --text-white: #ffffff;
    --border: #E8DACB;
    --shadow: rgba(211, 47, 47, 0.1);
    --success: #48bb78;
    --error: #f56565;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    /* Soporte para safe area en iPhone */
    padding-bottom: env(safe-area-inset-bottom);
}

/* Container Principal */
.chat-container {
    width: 100%;
    max-width: 800px;
    height: 90vh;
    max-height: 900px;
    background: var(--bg-main);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--text-white);
    padding: 20px 24px;
    box-shadow: 0 2px 10px var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-container {
    display: flex;
    align-items: center;
}

.chat-logo {
    height: 50px;
    width: auto;
    object-fit: contain;
}

.avatar {
    position: relative;
}

.avatar-circle {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    border: 3px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: var(--success);
    border: 3px solid var(--primary);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.header-info h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 2px;
}

.header-info .status {
    font-size: 13px;
    opacity: 0.9;
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-main);
    scroll-behavior: smooth;
}

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

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

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

.messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    max-width: 500px;
    margin: 40px auto;
    animation: fadeIn 0.6s ease-out;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    color: var(--text-dark);
    font-size: 28px;
    margin-bottom: 12px;
}

.welcome-message p {
    color: var(--text-light);
    font-size: 16px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.welcome-message ul {
    list-style: none;
    text-align: left;
    margin: 24px auto;
    max-width: 300px;
}

.welcome-message li {
    padding: 12px 0;
    color: var(--text-dark);
    font-size: 15px;
    border-bottom: 1px solid var(--border);
}

.welcome-message li:last-child {
    border-bottom: none;
}

.start-prompt {
    font-weight: 600;
    color: var(--primary) !important;
    margin-top: 24px !important;
    font-size: 17px !important;
}

/* Message Bubble */
.message {
    display: flex;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease-out;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.message.user {
    justify-content: flex-end;
}

.message.bot {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    white-space: pre-wrap; /* Preservar saltos de línea */
}

.message.user .message-bubble {
    background: var(--bg-user);
    color: var(--text-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.3);
}

.message.bot .message-bubble {
    background: var(--bg-bot);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px var(--shadow);
}

.message-time {
    display: block;
    font-size: 11px;
    margin-top: 6px;
    opacity: 0.7;
}

.message.user .message-time {
    text-align: right;
}

.message.bot .message-time {
    text-align: left;
    color: var(--text-light);
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    gap: 6px;
    width: fit-content;
    padding: 14px 20px;
    background: var(--bg-bot);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    margin-left: 24px;
    box-shadow: 0 2px 8px var(--shadow);
    margin-bottom: 16px;
}

.typing-indicator.active {
    display: flex;
    animation: fadeIn 0.3s;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    background: var(--bg-chat);
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    /* Soporte para safe area en iPhone */
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-main);
    border-radius: 24px;
    padding: 8px 8px 8px 12px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 16px; /* 16px o más para evitar zoom en iOS */
    color: var(--text-dark);
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 8px 0;
}

#messageInput::placeholder {
    color: var(--text-light);
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--text-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.4);
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.input-footer {
    text-align: center;
    margin-top: 8px;
}

.input-footer small {
    color: var(--text-light);
    font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
        min-height: auto !important;
    }

    .chat-container {
        max-width: 100%;
        height: 100vh;
        height: 100svh;
        border-radius: 0;
    }

    .messages-area {
        padding: 16px;
    }

    .message-bubble {
        max-width: 85%;
    }

    .welcome-message {
        margin: 20px auto;
    }

    .welcome-icon {
        font-size: 48px;
    }

    .welcome-message h2 {
        font-size: 24px;
    }

    .input-footer {
        display: none;
    }
}

/* Estados especiales */
.error-message {
    background: var(--error) !important;
    color: var(--text-white) !important;
}

.message-bubble a {
    color: inherit;
    text-decoration: underline;
}

.message.user .message-bubble a {
    color: var(--text-white);
}

.message.bot .message-bubble a {
    color: var(--primary);
    font-weight: 500;
}

/* Waiting Screen / Preloader */
.waiting-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-chat);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.waiting-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.waiting-content {
    text-align: center;
    padding: 40px;
    max-width: 500px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    margin: 0 auto 30px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.waiting-content h2 {
    font-size: 22px;
    color: var(--text-dark);
    margin-bottom: 12px;
    font-weight: 600;
}

.waiting-content p {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 8px;
    line-height: 1.6;
}

.waiting-content .wait-time {
    font-weight: 500;
    color: var(--text-dark);
    margin-top: 16px;
}

.waiting-content .wait-time span {
    color: var(--primary);
    font-weight: 700;
}

.waiting-content .hang-tight {
    font-size: 15px;
    color: var(--text-light);
    margin-top: 8px;
}

/* Attach Button */
.attach-button {
    background: transparent;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.attach-button:hover {
    background: rgba(211, 47, 47, 0.1);
    color: var(--primary);
}

.attach-button:active {
    transform: scale(0.95);
}

/* Photo Preview Container */
.photo-preview-container {
    background: var(--bg-main);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.photo-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-dark);
    font-weight: 600;
}

.clear-photos-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-photos-btn:hover {
    background: var(--primary);
    color: white;
}

.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

.photo-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--border);
    background: white;
}

.photo-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-preview-item .remove-photo {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(211, 47, 47, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.photo-preview-item:hover .remove-photo {
    opacity: 1;
}

.photo-preview-item .uploading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-preview-item .uploading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Chat Closed Banner */
.chat-closed-banner {
    background: linear-gradient(135deg, #D32F2F 0%, #B71C1C 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    margin: 20px 24px 24px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.3);
    animation: fadeInBanner 0.5s ease-in-out;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.closed-icon {
    font-size: 24px;
    flex-shrink: 0;
    animation: lockPulse 2s ease-in-out infinite;
}

.closed-text {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
}

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

@keyframes lockPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

