@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@700&family=Poppins:wght@400;600&family=Montserrat:wght@400&display=swap');

:root {
    --red-light: #f8d7da;
    --red-medium: #dc3545;
    --red-dark: #c82333;
    --pink-medium: #e83e8c;
    --pink-dark: #d63384;
    --purple-medium: #6f42c1;
    --purple-dark: #5a1da6;
    --red-pink-purple-gradient: linear-gradient(135deg, #f8d7da, #e83e8c, #6f42c1);
    --bot-bubble-bg: #E5E5EA;
    --bot-bubble-color: #000;
    --user-bubble-bg: #007AFF;
    --user-bubble-color: #FFF;
    --bubble-gap: 20px;
    --bubble-tail-size: 8px;
    
    /* Responsive sizing variables */
    --base-font-size: clamp(14px, 4vw, 16px);
    --header-height: clamp(40px, 10vw, 44px);
    --input-height: clamp(40px, 11vw, 44px);
    --button-padding-y: clamp(10px, 3vw, 12px);
    --button-padding-x: clamp(14px, 4vw, 18px);
    --bubble-padding-y: clamp(10px, 3vw, 12px);
    --bubble-padding-x: clamp(14px, 4vw, 18px);
}

* {
    box-sizing: border-box;
}

body, html {
    background-image: url('https://starsignharmony.com/static/picslow/lmbg2.jpg');
    background-size: cover;
    background-repeat: repeat;
    background-attachment: scroll;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    will-change: background-position;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    background-color: #f0f0f0;
    font-size: var(--base-font-size);
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(6px, 2vw, 8px) clamp(12px, 4vw, 16px);
    background: #f6f6f6;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: var(--header-height);
    box-sizing: border-box;
    width: 100%;
}

.header-left {
    position: absolute;
    left: clamp(12px, 4vw, 16px);
    top: 50%;
    transform: translateY(-50%);
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

#back-btn {
    all: unset;
    color: #007AFF;
    font-size: clamp(14px, 4vw, 16px);
    display: flex;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    white-space: nowrap;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.2;
}

#back-btn::before {
    content: '‹';
    font-size: 1.5em;
    font-weight: 300;
    line-height: inherit;
    vertical-align: middle;
    transform: translateY(-2px);
}

#back-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.avatar {
    width: clamp(24px, 7vw, 28px);
    height: clamp(24px, 7vw, 28px);
    border-radius: 50%;
    margin: 0;
    padding: 0;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

.chat-header h1 {
    all: unset;
    font-size: clamp(13px, 3.5vw, 14px);
    font-weight: 600;
    margin: 0;
    padding: 0;
    color: #000;
    text-align: center;
    line-height: 1;
    display: block;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: clamp(8px, 2.5vw, 10px);
    padding-bottom: calc(var(--input-height) + 30px);
    overflow-y: auto;
    gap: 0;
    min-height: 0;
    /* Smooth scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    /* Allow scrolling to reveal footer */
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.chat-window.location-active {
    padding-bottom: calc(var(--input-height) * 3 + 40px);
}

.chat-window.first-question .footer-section {
    position: fixed;
    bottom: -500px;
    left: 0;
    right: 0;
    margin: 0;
}

#messages-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--bubble-gap);
    flex: 0 0 auto;
    /* Ensure footer stays hidden by default */
    /* This creates enough space so footer is pushed below viewport */
    padding-bottom: 50px;
}

/* General Bubble Styles */
.bubble {
    max-width: min(90%, 320px); /* Limit max width on larger screens */
    padding: var(--bubble-padding-y) var(--bubble-padding-x) calc(var(--bubble-padding-y) + 8px);
    border-radius: clamp(16px, 5vw, 20px);
    font-size: var(--base-font-size);
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
}

/* Bot Bubble */
.bot-bubble {
    background: var(--bot-bubble-bg);
    color: var(--bot-bubble-color);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    margin-bottom: 20px;
}


/* User Bubble */
.user-bubble {
    background: var(--user-bubble-bg);
    color: var(--user-bubble-color);
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}


/* Options Bubble */
.options-bubble {
    background: rgba(255, 255, 255, 0.8);
    color: var(--purple-dark);
    align-self: center;
    text-align: center;
    border-radius: clamp(12px, 4vw, 15px);
    padding: clamp(12px, 4vw, 15px);
}

/* Question Label Bubble */
.question-label-bubble {
    background: #f0f0f0;
    color: #666;
    font-size: clamp(11px, 3vw, 12px);
    font-weight: bold;
    text-transform: uppercase;
    padding: clamp(4px, 1.5vw, 5px) clamp(8px, 2.5vw, 10px);
    border-radius: clamp(12px, 4vw, 15px);
    align-self: center;
    margin: clamp(16px, 5vw, 20px) 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Input Area */
.input-area {
    display: flex;
    align-items: center;
    padding: clamp(6px, 2vw, 8px);
    background: #f0f0f0;
    border-top: 1px solid #ccc;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    gap: clamp(8px, 2.5vw, 10px);
    flex-wrap: wrap;
    max-width: 100%;
    min-height: var(--input-height);
}

#user-input {
    flex: 1;
    padding: var(--button-padding-y);
    border: 1px solid var(--purple-medium);
    border-radius: clamp(16px, 5vw, 20px);
    font-size: var(--base-font-size);
    min-height: var(--input-height);
    min-width: 0; /* Allow shrinking */
}

#send-button, #submitCountryButton, #submitCityButton {
    background: var(--purple-medium);
    color: white;
    border: none;
    border-radius: clamp(16px, 5vw, 20px);
    padding: var(--button-padding-y) var(--button-padding-x);
    cursor: pointer;
    min-width: clamp(70px, 20vw, 80px);
    font-size: var(--base-font-size);
}

/* Button Grids */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(70px, 20vw, 80px), 1fr));
    gap: clamp(8px, 2.5vw, 10px);
    margin-top: clamp(8px, 2.5vw, 10px);
    width: 100%;
}

.options-grid button {
    background: linear-gradient(135deg, var(--pink-medium), var(--purple-dark));
    color: white;
    border: none;
    border-radius: clamp(12px, 4vw, 15px);
    padding: clamp(12px, 3.5vw, 15px);
    cursor: pointer;
    font-size: var(--base-font-size);
    min-height: clamp(44px, 12vw, 50px);
    transition: transform 0.2s;
}

.options-grid button:active {
    transform: scale(0.95);
    background: linear-gradient(135deg, var(--pink-dark), var(--purple-medium));
}

/* Date Selection Container */
.date-selection-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: clamp(4px, 1.5vw, 5px);
    padding: 0;
}

#end-month-label, #start-month-label {
    font-size: clamp(12px, 3.5vw, 13px);
    color: var(--purple-dark);
    font-weight: 600;
    margin: clamp(4px, 1.5vw, 5px) 0 clamp(2px, 1vw, 3px) 0;
}

/* Responsive Date Grid */
.date-grid {
    display: grid;
    /* Dynamic columns based on screen width */
    grid-template-columns: repeat(
        clamp(4, calc(100vw / 80), 5),
        1fr
    );
    gap: clamp(4px, 1.5vw, 6px);
    width: 100%;
    max-width: 100%;
    padding: 0 clamp(3px, 1vw, 5px);
}

.date-grid button {
    background: linear-gradient(135deg, var(--pink-medium), var(--purple-dark));
    color: white;
    border: none;
    border-radius: clamp(8px, 2.5vw, 10px);
    padding: clamp(6px, 2vw, 8px) clamp(2px, 0.5vw, 2px);
    cursor: pointer;
    font-size: clamp(11px, 3vw, 13px);
    min-height: clamp(30px, 9vw, 35px);
    height: clamp(30px, 9vw, 35px);
    transition: transform 0.2s;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1.2;
}

.date-grid button:active {
    transform: scale(0.95);
    background: linear-gradient(135deg, var(--pink-dark), var(--purple-medium));
}

/* Decade and Year Grids */
.decade-grid, .year-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(55px, 16vw, 60px), 1fr));
    gap: clamp(8px, 2.5vw, 10px);
    width: 100%;
}

.decade-grid button, .year-grid button {
    background: linear-gradient(135deg, var(--pink-medium), var(--purple-dark));
    color: white;
    border: none;
    border-radius: clamp(12px, 4vw, 15px);
    padding: clamp(12px, 3.5vw, 15px);
    cursor: pointer;
    font-size: var(--base-font-size);
    min-height: clamp(44px, 12vw, 50px);
    transition: transform 0.2s;
}

.decade-grid button:active, .year-grid button:active {
    transform: scale(0.95);
    background: linear-gradient(135deg, var(--pink-dark), var(--purple-medium));
}

/* 
 * Footer Section
 * Intentionally hidden below viewport with large margin-top
 * User must scroll past all messages to see it
 */
.footer-section {
    background: rgba(0, 0, 0, 0.5);
    padding: clamp(6px, 2vw, 8px);
    text-align: center;
    font-size: clamp(0.5em, 2vw, 0.6em);
    color: #fff;
    line-height: 1.3em;
    border-top: 1px solid #eaeaea;
    width: 100%;
    box-sizing: border-box;
    margin-top: 450px; /* Fixed large margin to keep footer hidden */
    margin-bottom: calc(var(--input-height) + 30px);
    flex-shrink: 0;
    /* Ensure footer stays below viewport on smaller screens */
    min-height: 50px;
    transition: opacity 0.3s ease;
    opacity: 0.7;
}

/* Optional: Add visual feedback when footer becomes visible */
.footer-section.visible {
    opacity: 1;
}

/* Location Input Special Styling */
.input-area.location-input {
    min-height: calc(var(--input-height) * 3);
    flex-direction: row;
    align-items: flex-start;
    padding: clamp(12px, 4vw, 15px) clamp(8px, 2.5vw, 10px) clamp(80px, 20vw, 100px) clamp(8px, 2.5vw, 10px);
    position: relative;
    overflow: visible;
    gap: clamp(6px, 2vw, 8px);
}

.input-area.location-input #country,
.input-area.location-input #city {
    flex: 1;
    padding: var(--button-padding-y) clamp(12px, 3.5vw, 14px);
    font-size: clamp(14px, 4vw, 15px);
    border: 2px solid var(--purple-medium);
    border-radius: clamp(8px, 2.5vw, 10px);
    margin-bottom: 0;
    background-color: #fff;
    position: relative;
    z-index: 1002;
    height: var(--input-height);
}

.input-area.location-input button {
    width: auto;
    padding: clamp(8px, 2.5vw, 10px) clamp(14px, 4vw, 16px);
    margin-top: 0;
    font-size: clamp(13px, 3.5vw, 14px);
    min-height: var(--input-height);
    height: var(--input-height);
    flex-shrink: 0;
    white-space: nowrap;
}

.input-area button.disabled-btn {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
}

/* Small phones (iPhone SE, etc.) */
@media (max-width: 374px) and (max-height: 700px) {
    .footer-section {
        margin-top: 350px; /* Slightly less on very small screens */
    }
    
    .date-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .bubble {
        max-width: 85%;
    }
    
    .options-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Standard phones */
@media (min-width: 375px) and (max-width: 413px) {
    .date-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* Large phones */
@media (min-width: 414px) {
    :root {
        --base-font-size: 16px;
    }
    
    .date-grid {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .options-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --header-height: 36px;
        --input-height: 36px;
        --base-font-size: 14px;
    }
    
    .chat-window {
        padding-bottom: calc(var(--input-height) + 20px);
    }
    
    .bubble {
        padding: 8px 14px 10px;
    }
    
    .options-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .date-grid button,
    .decade-grid button,
    .year-grid button {
        min-height: 32px;
        height: 32px;
    }
    
    /* Keep footer hidden even in landscape */
    .footer-section {
        margin-top: 350px; /* Slightly less in landscape due to limited height */
    }
}

/* Animations */
@keyframes fade-in {
    from { 
        opacity: 0; 
        transform: translateY(10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* Accessibility: Ensure touch targets meet minimum size */
@media (pointer: coarse) {
    button, input, a {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Prevent horizontal scroll on all devices */
@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden;
    }
    
    * {
        max-width: 100vw;
    }
}

/* Google Autocomplete dropdown adjustments */
.pac-container {
    z-index: 2000 !important;
    font-size: var(--base-font-size);
}

.pac-item {
    padding: clamp(8px, 2.5vw, 10px);
    font-size: var(--base-font-size);
}

/* Ensure inputs don't zoom on iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    input[type="text"],
    input[type="email"],
    input[type="time"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}
