:root {
    /* DocuSmart Brand Colors */
    --docusmart-blue: #A7D3E8;
    --docusmart-blue-dark: #7BB5D1;
    --docusmart-blue-light: #C5E4F3;
    --docusmart-black: #000000;
    --docusmart-dark-gray: #1a1a1a;
    --docusmart-medium-gray: #2a2a2a;
    --docusmart-light-gray: #3a3a3a;
    --docusmart-text-gray: #e0e0e0;
    --docusmart-white: #ffffff;
}

.light-mode {
    background-color: #f5f5f5;
    color: var(--docusmart-black);
}

.dark-mode {
    background-color: var(--docusmart-black);
    color: var(--docusmart-text-gray);
}

.light-mode #sidebar {
    background-color: var(--docusmart-white);
    border-right: 1px solid #e0e0e0;
}

.dark-mode #sidebar {
    background-color: var(--docusmart-dark-gray);
    border-right: 1px solid var(--docusmart-medium-gray);
}

.light-mode .email-btn span {
    color: var(--docusmart-blue-dark) !important;
}

.dark-mode .email-btn span {
    color: var(--docusmart-blue) !important;
}

.light-mode .share-btn img {
    filter: brightness(0) saturate(100%) invert(59%) sepia(23%) saturate(845%) hue-rotate(157deg) brightness(92%) contrast(87%);
}

.dark-mode .share-btn img {
    filter: brightness(0) saturate(100%) invert(79%) sepia(17%) saturate(745%) hue-rotate(157deg) brightness(95%) contrast(90%);
}

.light-mode .question-box {
    background-color: var(--docusmart-white);
    color: var(--docusmart-black);
    border: 2px solid #e0e0e0;
}

.dark-mode .question-box {
    background-color: var(--docusmart-medium-gray);
    color: var(--docusmart-text-gray);
    border: 2px solid var(--docusmart-light-gray);
}

.question-box:focus {
    border-color: var(--docusmart-blue) !important;
    box-shadow: 0 0 0 3px rgba(167, 211, 232, 0.1) !important;
}

.light-mode .docusmart-logo {
    color: var(--docusmart-black);
    font-weight: 700;
}

.dark-mode .docusmart-logo {
    color: var(--docusmart-white);
    font-weight: 700;
}

.docusmart-logo .ai-badge {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 4px;
    font-weight: 700;
}

.light-mode .docusmart-logo:hover {
    background-color: #f0f0f0;
}

.dark-mode .docusmart-logo:hover {
    background-color: var(--docusmart-medium-gray);
}

.light-mode .old-chat {
    background-color: #f5f5f5;
    border-left: 3px solid transparent;
}

.dark-mode .old-chat {
    background-color: var(--docusmart-medium-gray);
    border-left: 3px solid transparent;
}

.light-mode .old-chat:hover {
    background-color: #e8e8e8;
    border-left: 3px solid var(--docusmart-blue);
}

.dark-mode .old-chat:hover {
    background-color: var(--docusmart-light-gray);
    border-left: 3px solid var(--docusmart-blue);
}

.light-mode .bot {
    color: var(--docusmart-black);
}

.dark-mode .bot {
    color: var(--docusmart-text-gray);
}

.light-mode .user {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    font-weight: 500;
}

.dark-mode .user {
    background-color: var(--docusmart-blue-dark);
    color: var(--docusmart-black);
    font-weight: 500;
}

/* User messages aligned right */
.user {
    margin-left: auto !important;
    margin-right: 20px !important;
}

.input-container {
    position: relative;
    display: flex;
    align-items: center;
}

/* Desktop: 80% width, centered */
@media (min-width: 768px) {
    .input-container {
        width: 80%;
        max-width: 800px;
        margin: 0 auto;
    }
}

.action-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    padding: 12px;
    background-color: transparent;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.action-btn:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.action-btn:first-child {
    left: -40px;
}

.action-btn:last-child {
    right: -40px;
}

.share-btn {
    color: green;
}

/* Button Styling */
.btn-primary {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--docusmart-blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(167, 211, 232, 0.3);
}

.btn-secondary {
    background-color: transparent;
    color: var(--docusmart-blue);
    border: 2px solid var(--docusmart-blue);
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    transform: translateY(-1px);
}

.light-mode .btn-secondary {
    border-color: var(--docusmart-blue-dark);
    color: var(--docusmart-blue-dark);
}

.light-mode .btn-secondary:hover {
    background-color: var(--docusmart-blue-dark);
    color: var(--docusmart-white);
}

.btn-danger {
    background-color: #dc2626;
    color: white;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background-color: #b91c1c;
    transform: translateY(-1px);
}

/* Settings Dropdown */
.settings-container {
    position: relative;
}

.settings-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 8px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.dark-mode .settings-dropdown {
    background-color: var(--docusmart-medium-gray);
    border: 1px solid var(--docusmart-light-gray);
}

.light-mode .settings-dropdown {
    background-color: var(--docusmart-white);
    border: 1px solid #e0e0e0;
}

.settings-option {
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.9rem;
}

.dark-mode .settings-option {
    background-color: transparent;
    color: var(--docusmart-text-gray);
}

.light-mode .settings-option {
    background-color: transparent;
    color: var(--docusmart-black);
}

.dark-mode .settings-option:hover {
    background-color: var(--docusmart-light-gray);
}

.light-mode .settings-option:hover {
    background-color: #f0f0f0;
}

.settings-danger {
    color: #dc2626 !important;
}

.settings-danger:hover {
    background-color: rgba(220, 38, 38, 0.1) !important;
}

/* Connect Google Drive Link */
.connect-link {
    padding: 10px 16px;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.light-mode .connect-link {
    color: var(--docusmart-black);
    background-color: transparent;
}

.dark-mode .connect-link {
    color: var(--docusmart-text-gray);
    background-color: transparent;
}

.connect-link:hover {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    transform: translateX(4px);
}

/* Previous Chats Header */
.chats-header {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.light-mode .chats-header {
    color: #666;
}

.dark-mode .chats-header {
    color: #999;
}

/* Theme Toggle Icon Button */
.theme-toggle-icon {
    background-color: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
}

.theme-toggle-icon:hover {
    background-color: rgba(167, 211, 232, 0.2);
    transform: scale(1.1);
}

/* Send Button */
.send-btn {
    color: var(--docusmart-blue);
    transition: all 0.2s ease;
}

.send-btn:hover {
    color: var(--docusmart-blue-dark);
    transform: scale(1.1);
}

/* Bot Response Links */
.bot-response a {
    color: var(--docusmart-blue);
    text-decoration: none;
    border-bottom: 1px solid var(--docusmart-blue);
    transition: all 0.2s ease;
}

.bot-response a:hover {
    color: var(--docusmart-blue-dark);
    border-bottom: 2px solid var(--docusmart-blue-dark);
}

/* Sidebar layout - fixed header, scrollable chats, fixed footer */
#sidebar {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Desktop: sidebar always visible */
@media (min-width: 768px) {
    #sidebar {
        transform: none !important;
    }

    /* Constrain chat area to viewport so #chatbox can scroll */
    .main-chat {
        height: 100vh;
        min-height: 0;
    }

    .chat-wrapper {
        height: 100%;
        min-height: 0;
    }

    #chatbox {
        min-height: 0;
    }
}

#sidebar nav {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.sidebar-header {
    flex-shrink: 0;
    padding-bottom: 16px;
}

.light-mode .sidebar-header {
    border-bottom: 1px solid #e0e0e0;
}

.dark-mode .sidebar-header {
    border-bottom: 1px solid var(--docusmart-medium-gray);
}

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-top: 16px;
}

.sidebar-footer {
    flex-shrink: 0;
    padding-top: 1rem;
}

.light-mode .sidebar-footer {
    border-top: 1px solid #e0e0e0;
}

.dark-mode .sidebar-footer {
    border-top: 1px solid var(--docusmart-medium-gray);
}

/* Delete button styling */
.delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.delete-btn:hover {
    background-color: rgba(220, 38, 38, 0.1);
    transform: scale(1.1);
}

/* Email Modal */
.email-modal {
    backdrop-filter: blur(4px);
}

.light-mode .email-modal-content {
    background-color: white;
    color: var(--docusmart-black);
}

.dark-mode .email-modal-content {
    background-color: var(--docusmart-medium-gray);
    color: var(--docusmart-text-gray);
}

/* Integration Modal Items */
.integration-item {
    border: 1px solid transparent;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    background: none;
    font: inherit;
}

.dark-mode .integration-item {
    background-color: var(--docusmart-light-gray);
}

.light-mode .integration-item {
    background-color: #f5f5f5;
}

.dark-mode .integration-item:hover {
    border-color: var(--docusmart-blue);
    background-color: rgba(167, 211, 232, 0.1);
    transform: translateX(4px);
}

.light-mode .integration-item:hover {
    border-color: var(--docusmart-blue-dark);
    background-color: rgba(167, 211, 232, 0.2);
    transform: translateX(4px);
}

/* Sync progress bar scanning pulse */
@keyframes scan-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

#sync-progress-bar[style*="opacity: 0.4"] {
    animation: scan-pulse 1.5s ease-in-out infinite;
}

/* Loading Indicator */
.loading-dots {
    color: var(--docusmart-blue);
}

/* ============================================
   Mobile Header Bar
   ============================================ */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 50;
    border-bottom: 1px solid transparent;
}

.light-mode .mobile-header {
    background-color: var(--docusmart-white);
    border-bottom-color: #e0e0e0;
}

.dark-mode .mobile-header {
    background-color: var(--docusmart-dark-gray);
    border-bottom-color: var(--docusmart-medium-gray);
}

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.light-mode .hamburger-btn {
    color: var(--docusmart-black);
}

.dark-mode .hamburger-btn {
    color: var(--docusmart-text-gray);
}

.hamburger-btn:hover {
    background-color: rgba(167, 211, 232, 0.2);
}

.mobile-header-title {
    display: flex;
    align-items: center;
    font-size: 1.125rem;
    font-weight: 700;
}

.light-mode .mobile-header-title {
    color: var(--docusmart-black);
}

.dark-mode .mobile-header-title {
    color: var(--docusmart-white);
}

.mobile-header-title .ai-badge {
    background-color: var(--docusmart-blue);
    color: var(--docusmart-black);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
    font-size: 0.875rem;
}

.mobile-header-spacer {
    width: 40px; /* Same as hamburger to center the title */
}

/* ============================================
   Sidebar Overlay (Mobile)
   ============================================ */
.sidebar-overlay {
    display: none;
}

@media (max-width: 767px) {
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 45;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        cursor: pointer;
    }

    /* Sidebar - highest z-index when open */
    #sidebar {
        z-index: 50 !important;
        transform: translateX(-100%);
    }

    #sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Header stays below sidebar */
    .mobile-header {
        z-index: 40;
    }
}

/* ============================================
   Mobile Layout - ChatGPT Style
   ============================================ */
@media (max-width: 767px) {
    body {
        height: 100vh;
        height: 100dvh;
    }

    /* Main chat area - full screen below header */
    .main-chat {
        position: fixed;
        top: 56px; /* Below mobile header */
        left: 0;
        right: 0;
        bottom: 0;
        padding: 0 !important;
        margin: 0 !important;
    }

    .chat-wrapper {
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    /* Chatbox - full width, scrollable */
    #chatbox {
        flex: 1;
        overflow-y: auto;
        padding: 16px;
        padding-bottom: 8px;
    }

    /* Welcome message centered */
    .welcome-message {
        text-align: center;
        padding: 24px 16px;
        margin: 0;
    }

    /* Messages full width */
    #chatbox p {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Input container - fixed at bottom, full width */
    .input-container {
        flex-shrink: 0;
        width: 100% !important;
        padding: 12px;
        margin: 0;
    }

    .light-mode .input-container {
        background-color: var(--docusmart-white);
        border-top: 1px solid #e0e0e0;
    }

    .dark-mode .input-container {
        background-color: var(--docusmart-dark-gray);
        border-top: 1px solid var(--docusmart-medium-gray);
    }

    .input-wrapper {
        position: relative;
        width: 100%;
    }

    /* Hide desktop padding on mobile */
    .md\:p-6 {
        padding: 0 !important;
    }
}

/* Safe area padding for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 767px) {
        .input-container,
        .sidebar-footer {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
    }
}

@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 767px) {
        .mobile-header {
            padding-top: env(safe-area-inset-top);
            height: calc(56px + env(safe-area-inset-top));
        }
        .main-chat {
            top: calc(56px + env(safe-area-inset-top));
        }
    }
}