/* ===== RESET AND BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f0f0f1 0%, #fdfaff 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* ===== CHAT CONTAINER ===== */
.chat-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    background: white;
    border-radius: 24px;
    box-shadow: 0 32px 64px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ===== CHAT HEADER ===== */
.chat-header {
    background: linear-gradient(135deg, #a4d2ea 0%, #6363f5 100%);
    color: white;
    padding: 24px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="40" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="40" cy="80" r="1.5" fill="rgba(255,255,255,0.1)"/></svg>');
    opacity: 0.6;
}

.chat-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.chat-header p {
    opacity: 0.9;
    font-size: 16px;
    font-weight: 400;
    position: relative;
    z-index: 1;
}

.security-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

.security-icon {
    width: 16px;
    height: 16px;
}

/* ===== CHAT MESSAGES ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: linear-gradient(to bottom, #f8fafc 0%, #f1f5f9 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    align-items: flex-start;
    animation: messageSlide 0.3s ease-out;
}

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

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

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

.message-content {
    padding: 16px 20px;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 15px;
    position: relative;
}

.message.user .message-content {
    background: linear-gradient(135deg, #a4d2ea 0%, #6363f5 100%);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.message.bot .message-content {
    background: white;
    color: #334155;
    border-bottom-left-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
}

/* ===== SECURITY VERIFICATION ===== */
.security-verification {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 2px solid #cbd5e1;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.security-verification::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s ease;
}

.security-verification.verified {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-color: #22c55e;
    animation: verifiedPulse 0.6s ease-out;
}

.security-verification.error {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border-color: #ef4444;
    animation: errorShake 0.5s ease-out;
}

@keyframes verifiedPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.verification-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.verification-icon {
    width: 24px;
    height: 24px;
    padding: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f0f0f1 0%, #fdfaff 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.security-verification.verified .verification-icon {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    animation: successBounce 0.6s ease-out;
}

.security-verification.error .verification-icon {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    animation: errorBounce 0.6s ease-out;
}

@keyframes successBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes errorBounce {
    0%, 100% { transform: scale(1); }
    25%, 75% { transform: scale(1.1); }
    50% { transform: scale(0.95); }
}

.verification-title {
    font-size: 18px;
    font-weight: 600;
    color: #334155;
    margin: 0;
}

.security-verification.verified .verification-title {
    color: #16a34a;
}

.security-verification.error .verification-title {
    color: #dc2626;
}

.verification-description {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 20px;
    line-height: 1.4;
}

.security-verification.verified .verification-description {
    color: #22c55e;
}

.security-verification.error .verification-description {
    color: #ef4444;
}

.recaptcha-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.security-verification.verified .recaptcha-container {
    opacity: 0.5;
    pointer-events: none;
}

/* ===== STATUS INDICATORS ===== */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 12px;
    transition: all 0.3s ease;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

.status-verified {
    background: #dcfce7;
    color: #16a34a;
    border: 1px solid #22c55e;
}

.status-error {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #ef4444;
}

.status-icon {
    width: 14px;
    height: 14px;
}

/* ===== IMPROVED INPUT SECTION ===== */
.chat-input {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 16px;
    z-index: 10;
    /* Ensure input stays above keyboard on mobile */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.input-section {
    position: relative;
    width: 100%;
}

.input-group {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
}

/* ===== IMPROVED TEXTAREA ===== */
#messageInput {
    flex: 1;
    width: 100%;
    min-width: 0; /* Prevents flex item from overflowing */
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    font-size: 16px; /* Prevents zoom on iOS */
    line-height: 1.4;
    font-family: inherit;
    resize: none;
    outline: none;
    background: #f8fafc;
    transition: all 0.3s ease;

    /* Improved mobile handling */
    min-height: 48px; /* Better touch target */
    max-height: 140px; /* Allow more text on mobile */
    overflow-y: auto;
    word-wrap: break-word;

    /* iOS specific fixes */
    -webkit-appearance: none;
    -webkit-border-radius: 20px;
}

#messageInput:focus {
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#messageInput:disabled {
    background-color: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
    border-color: #cbd5e1;
}

#messageInput::placeholder {
    color: #94a3b8;
}

/* ===== SEND BUTTON ===== */
#sendButton {
    flex-shrink: 0; /* Prevent button from shrinking */
    padding: 14px 20px;
    min-width: 60px;
    height: 48px; /* Match input height */
    background: linear-gradient(135deg, #a4d2ea 0%, #6363f5 100%);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#sendButton:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

#sendButton:active:not(:disabled) {
    transform: translateY(0);
}

#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== NOTIFICATIONS ===== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 400px;
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    backdrop-filter: blur(10px);
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    color: #16a34a;
    border: 1px solid #22c55e;
}

.notification.error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
    border: 1px solid #ef4444;
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: none;
    margin-bottom: 16px;
}

.typing-indicator .message-content {
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

/* ===== INPUT HELPERS ===== */
.input-helpers {
    position: absolute;
    bottom: -24px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #94a3b8;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.input-section:focus-within .input-helpers {
    opacity: 1;
}

.char-counter {
    font-size: 11px;
    color: #94a3b8;
}

.char-counter.warning {
    color: #ef4444;
}

.shortcut-hint {
    font-size: 11px;
    color: #94a3b8;
}

/* ===== ANIMATIONS ===== */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== MOBILE RESPONSIVE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    body {
        padding: 8px;
        align-items: stretch; /* Use full height on mobile */
    }

    .chat-container {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0; /* Remove border radius on very small screens */
    }

    .chat-header {
        padding: 16px;
    }

    .chat-header h1 {
        font-size: 22px;
    }

    .chat-messages {
        padding: 16px;
        gap: 12px;
    }

    .message-content {
        max-width: 85%;
        padding: 12px 16px;
        font-size: 14px;
    }

    .chat-input {
        padding: 12px;
        /* Prevent input from being covered by keyboard */
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .input-group {
        gap: 8px;
    }

    #messageInput {
        min-height: 44px;
        max-height: 120px;
        font-size: 16px; /* Prevent zoom on focus */
        padding: 12px 16px;
    }

    #sendButton {
        height: 44px;
        min-width: 56px;
        padding: 10px 16px;
        font-size: 14px;
    }

    .security-verification {
        padding: 16px;
        margin-bottom: 16px;
    }

    .recaptcha-container {
        transform: scale(0.9);
        transform-origin: center;
    }

    .notification {
        top: 8px;
        right: 8px;
        left: 8px;
        max-width: none;
        transform: translateY(-100px);
    }

    .notification.show {
        transform: translateY(0);
    }

    .input-helpers {
        bottom: -20px;
        font-size: 10px;
    }

    .shortcut-hint {
        display: none; /* Hide on mobile to save space */
    }
}

@media (max-width: 480px) {
    .chat-container {
        border-radius: 0;
        height: 100vh;
    }

    .chat-input {
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .input-group {
        gap: 6px;
    }

    #messageInput {
        font-size: 16px; /* Critical for preventing zoom on iOS */
        min-height: 42px;
        padding: 10px 14px;
    }

    #sendButton {
        height: 42px;
        min-width: 50px;
        padding: 8px 12px;
    }

    /* Ensure textarea uses full available width */
    .input-section {
        width: 100%;
        max-width: 100%;
    }
}

/* ===== iOS SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    #messageInput {
        -webkit-appearance: none;
        border-radius: 20px;
    }

    .chat-input {
        /* Account for iOS keyboard and safe areas */
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    /* Prevent zoom on input focus */
    #messageInput {
        font-size: max(16px, 1em);
    }
}

/* ===== KEYBOARD HANDLING STYLES ===== */
.keyboard-open .chat-container {
    height: 100vh;
}

.keyboard-open .chat-input {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}