:root {
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --bg-light: #F9FAFB;
    --bg-white: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    /* Kept for reference but utilized less */
    --sidebar-w: 260px;
    --header-h: 60px;
    --input-h: 80px;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px rgba(59, 130, 246, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-white);
    color: var(--text-main);
    height: 100dvh;
    overflow: hidden;
}

/* --- LAYOUT --- */
.app-layout {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-w);
    background-color: var(--bg-light);
    /* border-right: 1px solid var(--border); REMOVED BORDER */
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    z-index: 20;
}

.sidebar.active {
    transform: translateX(0);
}

@media (min-width: 768px) {
    .sidebar {
        position: relative;
        transform: translateX(0);
    }
}

.sidebar-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    /* border-bottom: 1px solid var(--border); REMOVED BORDER */
}

.brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand i {
    font-size: 1.4rem;
    color: var(--primary);
}

.close-sidebar-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

@media (min-width: 768px) {
    .close-sidebar-btn {
        display: none;
    }
}

.sidebar-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

/* New Chat Button - Matched with Landing 'Start Learning' style */
.new-chat-btn {
    width: 100%;
    padding: 0.8rem 1.5rem;
    background-color: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    /* Subtle border */
    border-radius: 12px;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Aligned left usually better for menu */
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
}

.new-chat-btn:hover {
    background-color: white;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
    color: var(--primary);
}

.new-chat-btn i {
    color: var(--primary);
}

.conversations-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.convo-item {
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s;
    position: relative;
    overflow: hidden;
}

.convo-item:hover {
    background-color: #E5E7EB;
}

.convo-item.active {
    background-color: #DBEAFE;
    color: var(--primary-dark);
}

.convo-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.convo-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    margin-left: 8px;
}

.convo-item:hover .convo-actions {
    opacity: 1;
}

.convo-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.convo-action-btn:hover {
    color: var(--primary);
    background-color: rgba(0, 0, 0, 0.05);
}

.convo-action-btn.delete:hover {
    color: #ef4444;
}

.convo-search-container {
    margin-bottom: 1rem;
    position: relative;
}

.convo-search-input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.2rem;
    background-color: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.convo-search-icon {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.guest-alert-box {
    background: #FFF9E6;
    border-radius: 12px;
    padding: 24px 16px;
    color: #856404;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    margin-bottom: 2rem;
    line-height: 1.4;
}

.sidebar-footer {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
}

.user-profile:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info .name {
    font-size: 0.9rem;
    font-weight: 500;
}

.user-info .logout {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
}

.user-info .logout:hover,
.user-info .upgrade-link:hover {
    text-decoration: underline;
}

.upgrade-btn-sidebar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white !important;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    margin-top: 5px;
}

.upgrade-btn-sidebar:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
}

.upgrade-btn-sidebar i {
    font-size: 0.9rem;
}

.footer-legal {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 1rem;
}

.footer-legal p {
    margin-bottom: 0.2rem;
}

.socials {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.socials a {
    color: var(--text-muted);
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

/* Matching Landing Page Buttons */
.btn-signup {
    display: block;
    text-align: center;
    padding: 10px 24px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    transition: all 0.2s;
}

.btn-signup:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-login {
    display: block;
    text-align: center;
    padding: 10px 24px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    background-color: white;
    /* Changed to white for visibility */
    color: var(--text-main);
    transition: all 0.2s;
    border: 1px solid rgba(0, 0, 0, 0.05);
    /* Subtle border for visibility */
}

.btn-login:hover {
    background-color: #F9FAFB;
}

/* --- MAIN CHAT --- */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-white);
    position: relative;
    width: 100%;
}

.chat-header {
    height: var(--header-h);
    /* border-bottom: 1px solid var(--border); REMOVED BORDER */
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    flex-shrink: 0;
}

.menu-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

@media (min-width: 768px) {
    .menu-btn {
        display: none;
    }
}

.header-title {
    font-weight: 700;
    font-size: 1.02rem;
    color: #1e293b;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-signup {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    margin-right: 1rem;
}

.lang-select {
    border: none;
    background: none;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
}

/* CHAT CONTAINER */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    max-width: 900px;
    /* Constrain width of chat area too */
    margin: 0 auto;
    width: 100%;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-main);
    text-align: center;
    padding-bottom: 5%;
    /* Push it up slightly (visual center shift) */
}

/* Wrapper to control size and position of the main welcome text/icon group */
.welcome-content-wrapper {
    margin-bottom: 2rem;
}

.welcome-screen h2 {
    font-size: 2.76rem;
    font-weight: 800;
    margin-bottom: 0.79rem;
    color: #1a202c;
    letter-spacing: -0.5px;
}

.welcome-icon {
    width: 117px;
    height: 117px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 21px;
    color: var(--primary);
    font-size: 4.93rem;
}

/* Suggestion Chips */
.suggestions-container {
    display: flex;
    flex-wrap: nowrap;
    /* Prevent wrapping */
    overflow-x: auto;
    /* Horizontal scroll */
    gap: 12px;
    padding: 10px 20px;
    /* Add padding for safe area */
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    /* Center the container block */
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on mobile */
    scrollbar-width: none;
    /* Hide scrollbar Firefox */

    /* Essential for scrolling: items start at left */
    justify-content: flex-start;
}

/* Custom Scrollbar Styling */
.suggestions-container::-webkit-scrollbar {
    height: 6px;
    /* Visible thin scrollbar */
    display: block;
}

.suggestions-container::-webkit-scrollbar-track {
    background: transparent;
}

.suggestions-container::-webkit-scrollbar-thumb {
    background-color: #E5E7EB;
    /* Light gray */
    border-radius: 20px;
}

.suggestions-container::-webkit-scrollbar-thumb:hover {
    background-color: #D1D5DB;
    /* Darker on hover */
}

.suggestion-chip {
    flex: 0 0 auto;
    background-color: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    /* Pill shape */
    padding: 10.1px 20.2px;
    font-size: 0.89rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.suggestion-chip i {
    color: var(--primary);
}

.suggestion-chip:hover {
    background-color: #F9FAFB;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.message-row {
    display: flex;
    width: 100%;
    margin-bottom: 1rem;
}

.message-row.user-msg {
    justify-content: flex-end;
}

.message-row.ai-msg {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 1rem;
    border-radius: 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
}

.user-msg .message-bubble {
    background-color: #E0F2FE;
    color: var(--text-main);
    border-bottom-right-radius: 0.2rem;
}

.ai-msg .message-bubble {
    background-color: transparent;
    color: var(--text-main);
    border: none;
    box-shadow: none;
    padding: 0.5rem 0;
    border-bottom-left-radius: 0;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.8rem;
    user-select: none;
    animation: fadeInFooter 0.4s ease-out forwards;
}

@keyframes fadeInFooter {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.message-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover,
.action-btn.active {
    background-color: #F3F4F6;
    color: var(--primary);
}

.action-btn i {
    pointer-events: none;
}

@media (min-width: 768px) {
    .message-bubble {
        max-width: 70%;
    }
}

/* INPUT AREA - RESIZED AND CENTRALIZED */
.input-area {
    padding: 1rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    background: var(--bg-white);
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.8rem;
    background: #F3F4F6;
    /* Slightly darker than white for input box background, like Gemini */
    border-radius: 2rem;
    /* Fully rounded Pill shape */
    padding: 0.8rem 1.2rem;
    max-width: 800px;
    /* Constrain width as requested */
    margin: 0 auto;
    /* Center */
    /* border: 1px solid var(--border); REMOVED BORDER explicitly */
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    max-height: 150px;
    outline: none;
    color: var(--text-main);
    min-height: 24px;
}

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    /* Circle button */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#send-btn:disabled {
    background: #D1D5DB;
    cursor: default;
}

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

.upload-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
}

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

.image-preview-container {
    position: relative;
    width: 100px;
    height: 100px;
    margin-bottom: 10px;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--primary);
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.image-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    z-index: 10;
}

.message-bubble img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 8px;
    display: block;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-bubble img:hover {
    transform: scale(1.02);
}

.learn-mini-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: #6366f1;
    /* Novalearn indigo */
    color: white;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.learn-mini-btn:hover {
    background-color: #4f46e5;
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.disclaimer {
    text-align: center;
    font-size: 0.70rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding-bottom: 0.2rem;
}

/* OVERLAY */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10;
    display: none;
}

.overlay.active {
    display: block;
}

@media (min-width: 768px) {
    .overlay.active {
        display: none;
    }
}

/* --- UPGRADE POPUP --- */
.upgrade-popup {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: white;
    border: 1px solid var(--primary);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
    margin-bottom: 10px;
}

.upgrade-link {
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    color: white !important;
    padding: 6px 12px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
    transition: all 0.2s;
    margin-top: 4px;
}

.upgrade-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(59, 130, 246, 0.4);
    text-decoration: none !important;
}

.popup-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
}

.popup-content i {
    font-size: 1.5rem;
    color: var(--primary);
}

.popup-content p {
    font-size: 0.9rem;
    font-weight: 500;
}

.btn-upgrade {
    background: var(--primary);
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

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

.close-popup {
    position: absolute;
    top: 5px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
}