:root {
    /* Minimalist Indian Patriotic Palette - Saffron Dominant */
    --saffron: #FF8C00; 
    --saffron-light: #FFF5EB;
    --saffron-hover: #E67E00;
    --white: #FFFFFF;
    --green: #0A8F4E;
    --green-light: #E8F5EE;
    --navy: #1E293B; /* Kept only for deep text to maintain high contrast */
    
    /* UI Variables */
    --text-dark: #0F172A;
    --text-light: #64748B;
    --gray-soft: #F8FAFC;
    --gray-border: #E2E8F0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-glass: 0 10px 30px -5px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #F1F5F9;
    color: var(--text-dark);
    overflow: hidden; 
}

/* --- VISIBLE BACKGROUND TRICOLOR GLOW --- */
.bg-animation {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: -1; overflow: hidden;
    background: #F8FAFC; /* Clean base */
}

.orb {
    position: absolute; border-radius: 50%;
    filter: blur(80px); 
    opacity: 0.45; /* BOOSSTED: Makes the tricolor gradient much more visible */
    animation: floatOrb 20s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}

.orb-saffron {
    width: 60vw; height: 60vw; background: var(--saffron);
    top: -15%; left: -10%;
}

.orb-green {
    width: 60vw; height: 60vw; background: var(--green);
    bottom: -15%; right: -10%; animation-delay: -5s;
}

@keyframes floatOrb {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(40px, 60px) scale(1.1); }
}

/* --- CORE LAYOUT --- */
.screen {
    width: 100%; max-width: 650px; margin: 0 auto;
    height: 100dvh; display: flex; flex-direction: column;
    position: relative; background: var(--white);
    box-shadow: 0 0 40px rgba(0,0,0,0.03);
}

.transparent-screen { background: transparent; box-shadow: none; }
.hidden { display: none !important; }

/* Elegant Glassmorphism */
.glass-panel {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

/* --- WELCOME SCREEN --- */
#welcome-screen { justify-content: center; align-items: center; padding: 1.5rem; }

.welcome-container {
    width: 100%; max-width: 420px;
    border-radius: 24px; 
    padding: 2.5rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-glass);
}

.brand-logo {
    width: 64px; height: 64px; margin: 0 auto 1rem;
    border-radius: 16px; box-shadow: var(--shadow-md);
    object-fit: cover; background: #FFF;
}

.brand-title { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; color: var(--navy); }
.saffron-text { color: var(--saffron); }
.green-text { color: var(--green); }

.tricolor-line {
    height: 3px; width: 40px; margin: 0.8rem auto 0;
    background: linear-gradient(to right, var(--saffron) 33%, var(--gray-border) 33%, var(--gray-border) 66%, var(--green) 66%);
    border-radius: 2px;
}

.welcome-subtitle { color: var(--text-light); font-size: 0.95rem; margin: 1rem 0 2rem; font-weight: 400; }

/* Saffron Gender Cards */
.gender-selection { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 2rem; }
.gender-card input { display: none; }

.card-content {
    background: var(--white); border: 1px solid var(--gray-border);
    border-radius: 16px; padding: 1.2rem 1rem;
    cursor: pointer; transition: all 0.2s ease;
    display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
}

.gender-icon { width: 32px; height: 32px; color: var(--text-light); transition: all 0.2s ease; }
.gender-label { font-weight: 500; font-size: 0.95rem; color: var(--text-dark); }

.gender-card:hover .card-content { border-color: #CBD5E1; }

.gender-card input:checked + .card-content {
    border-color: var(--saffron); background: var(--saffron-light);
    box-shadow: 0 4px 15px rgba(255, 140, 0, 0.15); /* Boosted saffron shadow */
}

.gender-card input:checked + .card-content .gender-icon { color: var(--saffron); }
.gender-card input:checked + .card-content .gender-label { color: var(--saffron); font-weight: 700; }

/* Saffron Action Button */
.primary-btn {
    background: var(--saffron); color: var(--white);
    border: none; padding: 1rem; border-radius: 12px;
    font-size: 1rem; font-weight: 600;
    cursor: pointer; width: 100%;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(255, 140, 0, 0.25);
}

.primary-btn:hover { background: var(--saffron-hover); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { background: var(--text-light); cursor: not-allowed; transform: none; box-shadow: none; }

/* Disclaimer */
.disclaimer-box {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    margin-top: 1.5rem; color: var(--text-light);
    font-size: 0.8rem; font-weight: 400;
}
.disclaimer-box svg { opacity: 0.7; }

/* Loading State */
.loading-overlay { margin-top: 1.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.spinner-ring {
    width: 24px; height: 24px;
    border: 2px solid var(--saffron-light); border-top-color: var(--saffron);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
.pulse-text { color: var(--text-dark); font-size: 0.9rem; font-weight: 500; animation: pulseOpacity 1.5s infinite; }

/* --- CHAT UI --- */
.glass-header {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-border); 
    z-index: 50; /* Boosted to make sure nothing scrolls over it */
}

.chat-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 1rem 1.5rem; 
    
    /* 🔥 THIS IS THE FIX: Locks it to the top */
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.profile-info { display: flex; align-items: center; gap: 0.8rem; }

/* FIXED AVATAR: Saffron background, perfectly centered with line-height 0 */
.minimal-avatar {
    width: 42px; height: 42px; min-width: 42px;
    background: var(--saffron); color: var(--white);
    border-radius: 12px; font-size: 1.2rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    line-height: 0; text-transform: uppercase;
}

.user-details h3 { font-size: 1rem; font-weight: 600; color: var(--text-dark); }
.badge { font-size: 0.7rem; font-weight: 600; color: var(--green); background: var(--green-light); padding: 2px 6px; border-radius: 6px; }

.quit-btn {
    background: transparent; color: var(--text-light);
    border: 1px solid var(--gray-border); padding: 0.5rem; border-radius: 8px;
    cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.quit-btn:hover { background: #FFF1F2; color: #E11D48; border-color: #FECDD3; }

/* Chat Body Pattern */
.pattern-bg { position: relative; background-color: transparent; }
.pattern-bg::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 3.333c.92 0 1.667.746 1.667 1.667v10h10c.92 0 1.667.746 1.667 1.667s-.746 1.667-1.667 1.667h-10v10c0 .92-.746 1.667-1.667 1.667s-1.667-.746-1.667-1.667v-10h-10c-.92 0-1.667-.746-1.667-1.667s.746-1.667 1.667-1.667h10v-10c0-.92.746-1.667 1.667-1.667z' fill='%231E293B' fill-opacity='0.02' fill-rule='evenodd'/%3E%3C/svg%3E");
    z-index: 0; pointer-events: none;
}

#chat-body { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 0.8rem; }

/* Message Bubbles */
.message { display: flex; max-width: 80%; z-index: 1; animation: slideUp 0.2s ease-out forwards; }
.message.right { align-self: flex-end; }
.message.left { align-self: flex-start; }

.bubble {
    padding: 0.75rem 1rem 1.4rem 1rem; 
    border-radius: 14px; 
    font-size: 0.95rem; 
    line-height: 1.4; 
    font-weight: 400;
    position: relative; 
    box-shadow: var(--shadow-sm);
    min-width: 85px; /* 🔥 THE FIX: Forces a minimum width so short messages don't squash the time */
    
    /* 🔥 REPAIRED: Word wrap logic moved here to apply globally */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* User Messages */
.right .bubble { background: var(--navy); color: var(--white); border-bottom-right-radius: 4px; }
.left .bubble { background: var(--white); color: var(--text-dark); border-bottom-left-radius: 4px; border: 1px solid var(--gray-border); }

/* 🔥 REPAIRED: Fixed syntax error by removing the extra bracket */
.timestamp { 
    position: absolute; 
    bottom: 6px; 
    right: 12px; 
    font-size: 0.65rem; 
    opacity: 0.6; 
    font-weight: 500; 
    white-space: nowrap; /* 🔥 THE FIX: Prevents the PM/AM from ever dropping to a new line */
}

/* Chat Input Glass Footer */
.glass-footer {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--gray-border);
}

.chat-input-area { padding: 0.8rem 1.5rem; }

.input-wrapper {
    position: relative;
    display: flex; align-items: flex-end; /* Keeps button at the bottom as box grows */
    background: var(--white);
    border-radius: 20px; 
    border: 1px solid var(--gray-border); 
    transition: border-color 0.2s;
    padding: 0; /* Reset padding, we handle it inside elements */
}

.input-wrapper:focus-within { border-color: var(--saffron); box-shadow: 0 0 0 2px rgba(255, 140, 0, 0.1); }

#message-input { 
    flex: 1; 
    border: none; 
    background: transparent; 
    outline: none; 
    font-size: 0.95rem; 
    color: var(--text-dark);
    resize: none; /* Disables manual drag resizing */
    padding: 0.8rem 3rem 0.8rem 1.2rem; /* Right padding ensures text never hits the button */
    line-height: 1.4;
    min-height: 44px; /* 1 line height */
    max-height: 110px; /* ~4 lines height */
    overflow-y: hidden; /* Will be toggled to 'auto' by JS if it exceeds 4 lines */
    font-family: inherit;
}

#message-input::placeholder { color: #94A3B8; }

.send-btn {
    position: absolute;
    right: 6px;
    bottom: 4px; /* Locks button to the bottom right */
    background: var(--saffron); color: var(--white);
    border: none; border-radius: 50%; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.2s;
    box-shadow: 0 2px 8px rgba(255, 140, 0, 0.3);
}

.send-btn:hover { background: var(--saffron-hover); }

/* --- CUSTOM MODALS (Saffron Themed) --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 1rem;
    animation: fadeIn 0.2s ease-out;
}

.modal-card { width: 100%; max-width: 340px; border-radius: 20px; padding: 1.5rem; text-align: center; }
.modal-card h3 { color: var(--text-dark); margin-bottom: 0.5rem; font-size: 1.2rem; font-weight: 600; }
.modal-card p { color: var(--text-light); margin-bottom: 1.5rem; font-size: 0.95rem; line-height: 1.5; }

.modal-actions { display: flex; gap: 0.5rem; }
.modal-btn { flex: 1; padding: 0.8rem; border-radius: 10px; font-weight: 600; cursor: pointer; border: none; font-size: 0.95rem; transition: background 0.2s; }
.cancel-btn { background: var(--gray-soft); color: var(--text-dark); border: 1px solid var(--gray-border); }
.cancel-btn:hover { background: #E2E8F0; }

/* Saffron OK Button */
.ok-btn { background: var(--saffron); color: var(--white); }
.ok-btn:hover { background: var(--saffron-hover); }

/* Animations Keyframes */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { 0% { opacity: 0; transform: translateY(10px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes pulseOpacity { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Typing Indicator */
.typing { padding: 0.8rem 1.2rem; display: flex; gap: 4px; align-items: center; height: 40px; }
.typing span { display: block; width: 6px; height: 6px; background-color: var(--text-light); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* --- CUSTOM MOOD DROPDOWN --- */
.custom-select-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 1.5rem;
    text-align: left;
    user-select: none;
}

.custom-select-display {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--white); border: 1px solid var(--gray-border);
    padding: 1rem 1.2rem; border-radius: 12px;
    cursor: pointer; color: var(--text-dark); font-weight: 500;
    transition: all 0.2s ease;
}

.custom-select-display:hover { border-color: var(--saffron); }
.custom-select-display.active { border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(255,140,0,0.1); }

.custom-select-options {
    position: absolute; 
    bottom: 100%; /* 🔥 THE FIX: This forces the menu to open UPWARDS */
    left: 0; right: 0;
    margin-bottom: 8px; /* Space between the menu and the input box */
    background: var(--white);
    border: 1px solid var(--gray-border); 
    border-radius: 12px;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.1); /* Adjusted shadow for upward menu */
    z-index: 100;
    max-height: 220px; 
    overflow-y: auto;
}

.custom-option {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.8rem 1.2rem; cursor: pointer; border-bottom: 1px solid var(--gray-soft);
    transition: background 0.2s;
}
.custom-option:last-child { border-bottom: none; }
.custom-option:hover { background: var(--saffron-light); color: var(--saffron); font-weight: 600; }

.mood-pct { font-size: 0.8rem; color: var(--text-light); background: var(--gray-soft); padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.custom-option:hover .mood-pct { background: var(--white); color: var(--saffron); }

.mood-loading { padding: 1rem; text-align: center; color: var(--text-light); font-size: 0.9rem; }

/* --- STRANGER MOOD BADGE (Inside Chat) --- */
.mood-badge {
    align-self: center; background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--gray-border); color: var(--text-light);
    font-size: 0.8rem; font-weight: 600; padding: 6px 16px;
    border-radius: 20px; margin-bottom: 1rem; box-shadow: var(--shadow-sm);
    animation: fadeIn 0.5s ease-out;
}
.mood-badge span { color: var(--saffron); }

/* --- SEXY PROGRESS BAR --- */
.loading-overlay { margin-top: 1.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; width: 100%; }
.progress-bar-container { width: 100%; height: 6px; background: var(--gray-border); border-radius: 4px; overflow: hidden; margin-top: 5px; }
.progress-bar-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--saffron), #FFB84D, var(--saffron));
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear, loadProgress 8s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes loadProgress {
    0% { width: 0%; }
    40% { width: 60%; }
    80% { width: 85%; }
    100% { width: 95%; } /* Reaches 100% via JS when connected */
}

/* ========================================================= */
/* 📱 PROFESSIONAL MOBILE RESPONSIVENESS (Max Width: 600px)  */
/* ========================================================= */

@media screen and (max-width: 600px) {
    /* 1. Slim down the Welcome Screen container */
    #welcome-screen { padding: 1rem; }
    
    .welcome-container {
        padding: 2rem 1.5rem;
        border-radius: 20px;
    }

    /* 2. Scale down typography and logos */
    .brand-logo {
        width: 56px; height: 56px;
        margin-bottom: 0.8rem;
        border-radius: 14px;
    }

    .brand-title { font-size: 1.7rem; }
    .tricolor-line { width: 36px; margin-top: 0.6rem; }
    .welcome-subtitle { font-size: 0.85rem; margin: 0.8rem 0 1.5rem; }

    /* 3. Make Gender & Mood selection sleek, not chunky */
    .gender-selection { gap: 0.8rem; margin-bottom: 1.2rem; }
    .card-content { padding: 0.8rem 0.5rem; border-radius: 12px; gap: 0.5rem; }
    .gender-icon { width: 26px; height: 26px; }
    .gender-label { font-size: 0.85rem; }

    .custom-select-wrapper { margin-bottom: 1.2rem; }
    .custom-select-display { padding: 0.8rem 1rem; font-size: 0.9rem; border-radius: 10px; }
    .custom-option { padding: 0.7rem 1rem; font-size: 0.9rem; }

    /* 4. Streamline the main buttons */
    .primary-btn {
        padding: 0.85rem;
        font-size: 0.95rem;
        border-radius: 10px;
    }

    /* 5. Compact the Chat Header to save vertical space */
    .chat-header { padding: 0.8rem 1rem; }
    .minimal-avatar {
        width: 36px; height: 36px; min-width: 36px;
        font-size: 1rem; border-radius: 10px;
    }
    .user-details h3 { font-size: 0.95rem; }
    .badge { font-size: 0.65rem; padding: 2px 5px; }

    /* 6. Tighten the Chat Bubbles */
    #chat-body { padding: 1rem; gap: 0.6rem; }
    .mood-badge { font-size: 0.75rem; padding: 5px 12px; margin-bottom: 0.8rem; }
    
    /* 🔥 REPAIRED: Stripped word-wrap logic from here so it relies on the global .bubble class */
    .bubble {
        padding: 0.65rem 0.8rem 1.2rem 0.8rem; 
        font-size: 0.9rem;
        border-radius: 12px;
        min-width: 75px; 
    }
    .timestamp { font-size: 0.6rem; bottom: 4px; right: 8px; }

    /* 7. Shrink the Chat Input Bar */
    .chat-input-area { padding: 0.6rem 1rem; }
    .input-wrapper { padding: 0.2rem 0.2rem 0.2rem 1rem; border-radius: 20px; }
    #message-input { font-size: 0.9rem; padding: 0.4rem 0; }
    .send-btn { width: 34px; height: 34px; }

    /* 8. Scale down the Custom Modals */
    .modal-card { padding: 1.5rem; width: 90%; max-width: 300px; border-radius: 16px; }
    .modal-card h3 { font-size: 1.1rem; }
    .modal-card p { font-size: 0.85rem; margin-bottom: 1.2rem; }
    .modal-btn { padding: 0.7rem; font-size: 0.9rem; }
}

/* ========================================================= */
/* 📱 ULTRA-SMALL PHONES (e.g., iPhone SE) (Max Width: 380px)*/
/* ========================================================= */

@media screen and (max-width: 380px) {
    .brand-title { font-size: 1.5rem; }
    .welcome-container { padding: 1.5rem 1rem; }
    .card-content { padding: 0.6rem 0.4rem; }
    .gender-icon { width: 22px; height: 22px; }
    .gender-label { font-size: 0.75rem; }
    .bubble { font-size: 0.85rem; }
}
