html, body {
    height: 100%;
    min-height: 100%;
}

body {
    background: #f4f7fa;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    height: 100vh;
    display: flex;
    align-items: center;   /* Center vertically */
    justify-content: center; /* Center horizontally */
    overscroll-behavior-y: none; /* Prevents pull-to-refresh on the body */
}

.flex-row.w-full.max-w-5xl {
    height: 100vh;
    min-height: 100vh;
    width: 100vw;
    max-width: 100vw;
    display: flex;
    flex-direction: row;
    gap: 2rem;
}

.bg-white.rounded-xl.shadow-2xl.flex-1.flex.flex-col {
    height: 90vh;
    min-height: 0;
    max-height: 90vh;
    width: 60vw;
    max-width: 60vw;
    flex: none;
}

#sourcesArea {
    height: 90vh;
    min-height: 0;
    max-height: 90vh;
    width: 30vw;
    max-width: 30vw;
    flex: none;
    margin-top: 0;
    padding: 12px 0 0 0;
}

/* Ensure chatMessages area scrolls within the available space */
#chatMessages, .chat-messages,
#sourcesArea {
    flex: 1 1 0%;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    overscroll-behavior: contain;      /* Prevents scroll chaining to body */
}

.chat-container {
    max-width: 480px;
    margin: 40px auto;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 4px 32px rgba(0,0,0,0.08);
    padding: 0 0 16px 0;
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

.chat-header {
    background: #2563eb;
    color: #fff;
    padding: 24px 32px;
    border-radius: 18px 18px 0 0;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 1px;
}

.chat-messages {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.chat-bubble {
    max-width: 80%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 4px;
    word-break: break-word;
}

.chat-bubble.user {
    background: #e0e7ff;
    align-self: flex-end;
    color: #1e293b;
}

.chat-bubble.bot {
    background: #f1f5f9;
    align-self: flex-start;
    color: #334155;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 16px 32px 0 32px;
    border-top: 1px solid #e5e7eb;
}

#queryInput {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    outline: none;
    transition: border 0.2s;
}

#queryInput:focus {
    border: 1.5px solid #2563eb;
}

#submitQuery {
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0 22px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

#submitQuery:hover {
    background: #1d4ed8;
}

#loadingIndicator {
    margin: 0 auto;
    color: #2563eb;
    font-size: 1.1rem;
}

#sourcesArea {
    margin-top: 12px;
    padding: 12px 0 0 0;
}

#playlistUrl {
    margin-bottom: 8px;
}

#sourceList {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sourceList li {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 0.97rem;
}

.loader {
    border: 4px solid #e0e7ff;
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    display: inline-block;
}
@keyframes spin {
    0% { transform: rotate(0deg);}
    100% { transform: rotate(360deg);}
}

@media (max-width: 768px) {
    .flex-row.w-full.max-w-5xl {
        flex-direction: column;
        gap: 1rem;
        height: auto;
        min-height: 100vh;
        width: 100vw;
        max-width: 100vw;
        align-items: stretch;
    }
    .bg-white.rounded-xl.shadow-2xl.flex-1.flex.flex-col,
    #sourcesArea {
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: none !important;
    }
    #chatMessages, .chat-messages {
        padding-left: 8px;
        padding-right: 8px;
    }
}