body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f7f6;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Use dvh to account for mobile browser bars */
    height: 100dvh; 
    margin: 0;
    overflow: hidden;
}

.chat-container {
    width: 100%; 
    max-width: 450px;
    /* This ensures the container fits within the screen height */
    height: 100dvh; 
    background: white;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.chat-header {
    background: #007bff;
    color: white;
    padding: 20px 15px;
    text-align: center;
    flex-shrink: 0; /* Prevents header from squishing */
}

.chat-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    text-transform: uppercase;
}

.author-subtext {
    margin: 0;
    font-size: 13px;
    font-weight: 300;
    opacity: 0.85;
    font-style: italic;
}

.chat-box {
    /* MAGIC FIX: flex: 1 tells this box to take all available space */
    flex: 1; 
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #ffffff;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
}

.user-message {
    background: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ai-message {
    background: #f1f3f5;
    color: #212529;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.input-container {
    display: flex;
    border-top: 1px solid #eee;
    padding: 15px;
    background: #fff;
    flex-shrink: 0; /* Ensures the input bar stays visible */
}

input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    /* 16px prevents iOS from auto-zooming when you tap the box */
    font-size: 16px; 
}

button {
    background: #007bff;
    color: white;
    border: none;
    padding: 0 20px;
    margin-left: 10px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
}

/* Desktop-specific tweak: make it look like a floating box */
@media (min-width: 481px) {
    .chat-container {
        height: 85vh;
        border-radius: 15px;
        overflow: hidden;
    }
}