:root {
    --accent: #2563ff;
    --accent-hover: #1d4ed8;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --bg: #020617;
    --card-bg: rgba(15, 23, 42, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --chat-bg: rgba(0, 0, 0, 0.2);
    --sidebar-width: 260px;
    --right-sidebar-width: 280px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header, nav, particles, and footer styles are handled globally by header.css via base.html */

/* Chat Layout Container */
.chat-container {
    display: flex;
    min-height: 100vh;
    padding-top: 80px;
    /* Account for fixed header */
}

/* Sidebars */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

.right-sidebar {
    width: var(--right-sidebar-width);
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    line-height: 1;
    box-shadow: none;
}

.sidebar-close-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
    transform: none;
}


.conversation-list,
.document-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

/* Main Chat Area */
.main-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-width: 0;
    height: calc(100vh - 80px);
    /* Full height minus header */
    overflow: hidden;
    /* Prevent main area from scrolling */
}

/* Mobile Header (hidden on desktop) */
.chat-header-mobile {
    display: none;
}

/* User Level Badge (3-tier progression) */
.level-badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 12px;
    color: #fff;
    font-weight: 500;
    margin-left: 8px;
}

.container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 120px 1rem 2rem;
    /* Added top padding for fixed header */
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    z-index: 1;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    align-self: flex-start;
    font-size: 0.95rem;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.back-link:hover {
    color: var(--accent);
}

.page-header {
    text-align: center;
    margin-bottom: 1rem;
    padding-top: 1rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, #fff, #bcd7ff);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-window {
    flex: 1;
    min-height: 0;
    /* Important: allows flex child to shrink below content size */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background-color: var(--chat-bg);
}

.message {
    max-width: 80%;
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    line-height: 1.6;
    font-size: 0.95rem;
}

.message.user {
    align-self: flex-end;
    background-color: var(--accent);
    color: white;
    border-bottom-right-radius: 0.25rem;
    box-shadow: 0 4px 12px rgba(37, 99, 255, 0.3);
}

.message.ai {
    align-self: flex-start;
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 0.25rem;
}

/* Typing indicator animation */
.typing-indicator {
    padding: 1rem 1.5rem;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

.input-area {
    display: flex;
    gap: 1rem;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    /* Don't shrink - stay at bottom */
}

.attach-btn {
    background-color: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-radius: 0.5rem;
}

.attach-btn:hover {
    color: var(--accent);
    background-color: rgba(37, 99, 255, 0.1);
}

/* Voice input button - universal */
.voice-btn {
    display: block;
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-radius: 0.5rem;
}

.voice-btn:hover {
    color: var(--accent);
    background-color: rgba(37, 99, 255, 0.1);
}

.voice-btn.recording {
    color: #ef4444;
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Microphone permission hint popup */
#micHintOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.mic-hint-popup {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

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

.mic-hint-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.mic-hint-popup h3 {
    margin: 0 0 0.75rem 0;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.mic-hint-popup p {
    margin: 0 0 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.mic-hint-note {
    font-size: 0.85rem !important;
    color: var(--text-muted) !important;
    margin-bottom: 1.25rem !important;
}

.mic-hint-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mic-hint-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.file-preview {
    padding: 0.5rem 0;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: var(--text);
}

.file-badge button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    display: flex;
    align-items: center;
}

.file-badge button:hover {
    color: #ef4444;
}

input[type="text"] {
    flex: 1;
    background-color: transparent;
    border: none;
    color: var(--text);
    padding: 0.5rem;
    font-size: 1rem;
    outline: none;
}

input[type="text"]::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

button {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(37, 99, 255, 0.3);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 255, 0.4);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* New Conversation Button */
.new-chat-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.chat-window {
    position: relative;
    /* For absolute positioning of button */
}

/* Conversation Item with Delete Button */
.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.conversation-item.active {
    background: rgba(37, 99, 255, 0.15);
}

.conversation-content {
    flex: 1;
    min-width: 0;
    padding: 0.5rem;
}

.conversation-title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
    color: var(--text);
}

.conversation-actions {
    display: none;
    flex-shrink: 0;
    gap: 2px;
}

.conversation-item:hover .conversation-actions {
    display: flex;
}

.rename-conversation-btn,
.delete-conversation-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.2s;
    box-shadow: none;
    line-height: 1;
}

.rename-conversation-btn:hover {
    opacity: 1;
    color: var(--accent, #2563ff);
    background: rgba(37, 99, 255, 0.1);
}

.delete-conversation-btn:hover {
    opacity: 1;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}


/* Document Item with Actions */
.document-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: background 0.2s;
}

.document-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.doc-icon {
    font-size: 1.5rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.document-info {
    flex: 1;
    min-width: 0;
}

.doc-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.85rem;
    color: var(--text);
}

.doc-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

.doc-actions {
    display: none;
    flex-shrink: 0;
    gap: 4px;
    margin-left: 0.5rem;
}

.document-item:hover .doc-actions {
    display: flex;
}

.doc-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.7;
    transition: all 0.2s;
    box-shadow: none;
    line-height: 1;
    text-decoration: none;
}

.doc-btn:hover {
    opacity: 1;
    transform: none;
}

.download-btn:hover {
    color: var(--accent);
    background: rgba(37, 99, 255, 0.1);
}

.delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}


/* ==================== MOBILE RESPONSIVE ==================== */

/* Sidebar overlay (dark background when sidebar is open) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {

    /* Hide sidebars by default on mobile */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        padding-top: 60px;
    }

    .left-sidebar {
        left: 0;
    }

    .right-sidebar {
        right: 0;
        transform: translateX(100%);
    }

    /* Show sidebars when active */
    .sidebar.active {
        transform: translateX(0);
    }

    /* Show close button on mobile */
    .sidebar-close-btn {
        display: block;
    }

    /* Always show action buttons on mobile (no hover on touch) */
    .conversation-actions {
        display: flex;
    }

    .rename-conversation-btn,
    .delete-conversation-btn {
        opacity: 0.6;
    }


    /* Show mobile header */
    .chat-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1rem;
        background: var(--card-bg);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        /* No gap below main header */
        z-index: 100;
        backdrop-filter: blur(10px);
    }

    .mobile-menu-btn {
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid var(--border-color);
        color: var(--text);
        padding: 0.5rem 0.75rem;
        border-radius: 8px;
        font-size: 1.2rem;
        cursor: pointer;
        box-shadow: none;
        min-width: 44px;
        min-height: 44px;
    }

    .mobile-menu-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: none;
    }

    .mobile-title {
        display: none;
        /* Hide duplicate title */
    }

    /* Make chat area full width */
    .chat-container {
        padding-top: 10px;
        /* Reduced gap between header and content */
        flex-direction: column;
    }

    .main-chat-area {
        padding: 0.5rem;
        min-height: calc(100vh - 120px);
    }

    /* Adjust chat window height */
    .chat-window {
        min-height: calc(100vh - 280px);
        max-height: calc(100vh - 280px);
        margin-top: 0.5rem;
        /* Space between ribbon and chat */
        margin-bottom: 0.5rem;
        padding-top: 50px;
        /* Push content below sticky mobile header (ribbon height ~50px) */
    }

    /* Make input area sticky at bottom */
    .input-area {
        position: sticky;
        bottom: 0;
        background: var(--bg);
        padding: 0.75rem 1rem;
        margin: 0;
        border-radius: 0;
        border-top: 1px solid var(--border-color);
        width: 100%;
        box-sizing: border-box;
    }


    /* Smaller messages */
    .message {
        max-width: 90%;
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }

    /* Adjust sidebar content spacing */
    .sidebar-header {
        padding: 0.75rem;
    }

    .conversation-list,
    .document-list {
        padding: 0.5rem;
    }

    /* Conversation item styles for mobile */
    .conversation-item {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.2s;
    }

    .conversation-item:hover,
    .conversation-item.active {
        background: rgba(255, 255, 255, 0.1);
    }

    .conversation-item .title {
        font-size: 0.9rem;
        color: var(--text);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .conversation-item .date {
        font-size: 0.75rem;
        color: var(--text-secondary);
        margin-top: 0.25rem;
    }

    /* Document item styles - always show actions on mobile */
    .document-item {
        padding: 0.6rem;
    }

    .doc-actions {
        display: flex;
    }

    .doc-btn {
        opacity: 0.6;
    }

    /* Auth promo styles */
    .auth-promo {
        padding: 1rem;
        text-align: center;
        border-top: 1px solid var(--border-color);
    }

    .auth-promo .btn-small {
        display: inline-block;
        margin-top: 0.5rem;
        padding: 0.5rem 1rem;
        background: var(--accent);
        color: white;
        text-decoration: none;
        border-radius: 6px;
        font-size: 0.85rem;
    }
}

/* Extra small screens (phones) */
@media (max-width: 480px) {
    .chat-window {
        min-height: calc(100vh - 260px);
        max-height: calc(100vh - 260px);
    }

    .message {
        max-width: 95%;
        font-size: 0.85rem;
    }

    /* Full-width sidebars on very small screens */
    .sidebar {
        width: 100%;
    }

    .mobile-menu-btn {
        padding: 0.4rem 0.6rem;
        font-size: 1.1rem;
    }

    .input-area {
        padding: 0.5rem 1rem;
        gap: 0.5rem;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .input-area input[type="text"] {
        font-size: 16px;
        /* Prevents zoom on iOS */
        flex: 1;
        min-width: 0;
    }

    .input-area button {
        flex-shrink: 0;
    }

    /* Adjust for smaller header (56px on phones) */
    .sidebar {
        padding-top: 56px;
    }

    .chat-header-mobile {
        top: 0;
        /* Ribbon sits right below main header */
    }

    .chat-container {
        padding-top: 56px;
        /* Match header height exactly */
    }
}


/* Landscape mode on phones */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        padding-top: 50px;
        /* Account for smaller header in landscape */
    }

    .chat-window {
        min-height: calc(100vh - 160px);
        max-height: calc(100vh - 160px);
        padding-top: 40px;
    }

    .chat-header-mobile {
        padding: 0.4rem 1rem;
        top: 0;
        /* Sit below main header, not on top */
    }
}