/* Full-height flex layout for contact page body */
body:has(.chat-main) {
    height: 100vh;
    /* Fallback for older browsers */
    height: 100dvh;
    /* Dynamic viewport height - accounts for mobile browser UI */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat page main - fills remaining viewport after header */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: 1.5rem;
    /* Desktop margin below header */
}

/* Chat container - the key flex container */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
    overflow: hidden;
}

/* Scrollable chat history area - height controlled by JS on desktop */
.chat-history {
    flex: 0 0 auto;
    overflow-y: auto;
    padding: 1rem;
    border-radius: 0.5rem;
    background-color: var(--bg-color);
    transition: height 0.3s linear;
    /* Default height to roughly center input on desktop (matches JS calculation) */
    height: calc(50% - 5.5rem);
}

/* Input area */
.chat-input {
    flex: 0 0 auto;
    padding: 1rem 0 2rem 0;
    /* Extra bottom padding on desktop */
    background: var(--bg-color);
}

/* Input wrapper - positions button inside textarea bubble */
.input-wrapper {
    position: relative;
    width: 100%;
}

.input-wrapper textarea {
    width: 100%;
    padding: 0.75rem;
    padding-right: 3rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background-color: var(--card-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    min-height: 120px;
    max-height: 250px;
}

.input-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Send button - positioned inside textarea, vertically centered */
.send-btn {
    position: absolute;
    right: 0.6rem;
    top: 70%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--accent-color);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Stop button - positioned inside textarea, vertically centered */
.stop-btn {
    position: absolute;
    right: 0.6rem;
    top: 70%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background-color: #dc3545;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.stop-btn:hover {
    background-color: #c82333;
}

/* Dark mode */
body.dark-mode .input-wrapper textarea {
    background-color: var(--input-bg);
    border-color: var(--input-border);
}

body.dark-mode .input-wrapper textarea:focus {
    border-color: var(--primary-color);
}

/* Mobile adjustments - chat-history fills space naturally */
@media (max-width: 768px) {
    .chat-main {
        padding-top: 0.5rem;
    }

    .chat-container {
        padding: 0 0.5rem;
    }

    .chat-history {
        flex: 1;
        height: auto !important;
        /* Override JS on mobile */
    }

    .chat-input {
        padding: 0.75rem 0;
    }
}