/* --- RESET & VARIABLES --- */
:root {
    --primary-color: #2563eb;       /* Royal Blue */
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;            /* Light Gray Background */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --user-msg-bg: #2563eb;
    --bot-msg-bg: #f1f5f9;
    --error-color: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    /* Fallback for older browsers */
    height: 100vh;
    /* Modern mobile viewport fix */
    height: 100dvh; 
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body scroll, handle internally */
}

/* --- UTILITY CLASSES --- */
.hidden {
    display: none !important;
}

/* --- HEADER --- */
header {
    padding: 0 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between; /* Space between logo and new chat button */
    height: 60px;
    flex-shrink: 0;
    z-index: 10;
}

.secondary-btn {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background-color: #eff6ff; /* Light blue tint */
    border-color: var(--primary-color);
}



.logo {
    font-weight: 600;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- MAIN CONTAINER --- */
#app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    height: 100%;
}

/* --- SECTION A: VIDEO INPUT --- */
#video-section {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-y: auto; 
}

.card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 500px;
    text-align: center;
}

.card h2 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.input-group input {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 1.5rem;
    appearance: none;
}

.input-group input:focus {
    border-color: var(--primary-color);
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    transition: background 0.2s, transform 0.1s;
    touch-action: manipulation;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.primary-btn:active {
    transform: scale(0.98);
}

.primary-btn:disabled {
    background-color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

/* --- SECTION B: STATUS & LOADER --- */
#status-section {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 20px;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#status-text {
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
}

#error-box {
    margin-top: 1.5rem;
    padding: 1rem;
    background-color: #fef2f2;
    border: 1px solid #fca5a5;
    color: var(--error-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 400px;
    text-align: center;
}

#retry-btn {
    background: white;
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

/* --- SECTION C: CHAT WORKSPACE --- */
#chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
    position: relative;
    /* DESKTOP FIX: Center the chat on large screens */
    width: 100%;
    max-width: 900px; 
    margin: 0 auto;
    border-left: 1px solid transparent; 
    border-right: 1px solid transparent;
}

/* Optional: Add subtle borders on desktop only for better definition */
@media (min-width: 901px) {
    #chat-section {
        border-color: var(--border-color);
        background-color: #ffffff; /* White background for chat area on desktop */
    }
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    min-height: 0; 
    -webkit-overflow-scrolling: touch;
}

/* Message Bubbles */
.message {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
    word-wrap: break-word;
}

.user-message {
    align-self: flex-end;
    background-color: var(--user-msg-bg);
    color: white;
    border-bottom-right-radius: 2px;
}

.bot-message {
    align-self: flex-start;
    background-color: var(--bot-msg-bg);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
    border: 1px solid var(--border-color);
}

/* Markdown Styles */
.bot-message code {
    background-color: rgba(0,0,0,0.06);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.bot-message pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    max-width: 100%;
}

.bot-message ul, .bot-message ol {
    margin-left: 20px;
    padding-left: 0;
    margin-top: 5px;
}

.bot-message strong {
    font-weight: 600;
}

/* Sticky Input Footer */
.input-area {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 20px;
    flex-shrink: 0;
    /* Mobile Safe Area */
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.input-wrapper {
    display: flex;
    gap: 10px;
    background: var(--bg-color);
    padding: 10px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    align-items: flex-end;
    transition: border 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
}

textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    max-height: 150px;
    line-height: 1.4;
}

#send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

#send-btn:disabled {
    background: var(--text-muted);
    cursor: default;
    opacity: 0.5;
}

/* --- MOBILE SPECIFIC OVERRIDES --- */
@media (max-width: 768px) {

    .secondary-btn .btn-text {
        display: none;
    }
    .secondary-btn {
        padding: 8px 12px;
        border-radius: 50%; /* Circle button on mobile */
    }

    /* Reset Max Width for Mobile to use full screen */
    #chat-section {
        max-width: 100%;
        border: none;
    }

    /* Reduce Header Padding */
    header {
        padding: 0 1rem;
        height: 56px;
    }
    
    .logo {
        font-size: 1.15rem;
    }

    /* Adjust Card */
    .card {
        padding: 2rem 1.5rem;
        margin: 0;
        box-shadow: none; /* Cleaner on mobile */
        background: transparent; /* Blend with background */
    }

    .card h2 {
        font-size: 1.35rem;
    }
    
    /* Input Area Tweak */
    .input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .input-wrapper {
        padding: 6px 12px;
    }

    #send-btn {
        width: 36px;
        height: 36px;
    }

    /* Messages */
    .message {
        max-width: 90%;
        font-size: 0.95rem;
        padding: 10px 14px;
    }

    /* Prevent iOS Zoom on Inputs */
    input[type="text"], 
    textarea {
        font-size: 16px !important;
    }
}