/* RESET & BASE */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { background-color: #f8fafc; color: #111827; height: 100vh; overflow: hidden; }
.screen { width: 100vw; height: 100vh; display: flex; flex-direction: column; }

/* =========================================
   LOGIN SCREEN
   ========================================= */
#login-screen { background-color: #f2f6f8; justify-content: center; align-items: center; }
.login-container { position: relative; }
.login-card { background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); width: 380px; max-width: calc(100vw - 32px); overflow: hidden; border: 1px solid #e1e4e8; }
.login-header { background-color: #1b4b60; padding: 25px 22px 20px; text-align: center; }
.login-header img { width: 160px; }
.login-header h2 { color: #00c3a5; margin: 12px 0 0; font-size: 16px; font-weight: 600; }
.login-header .login-slogan { color: #cbd5e1; font-size: 12px; line-height: 1.45; margin: 10px 0 0; font-weight: 400; }
.login-body { padding: 24px; }
.login-body p { text-align: center; color: #6b7280; font-size: 14px; margin: 0 0 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: #6b7280; margin-bottom: 6px; }
.form-group input { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; color: #111827; font-weight: 500; outline: none; transition: 0.2s; }
.form-group input:focus { border-color: #0d8a73; box-shadow: 0 0 0 2px rgba(13,138,115,0.2); }
.login-button { width: 100%; background-color: #0d8a73; color: white; border: none; padding: 10px; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; margin-top: 8px; }
.login-button:hover { background-color: #0a6b59; }
.forgot-password { display: block; text-align: center; color: #0d8a73; font-size: 12px; margin-top: 16px; text-decoration: none; }
.mockup-text { position: absolute; bottom: -40px; left: 0; width: 100%; text-align: center; font-size: 11px; color: #6b7280; font-family: monospace; }

/* =========================================
   APP HEADER
   ========================================= */
.app-header { height: 52px; background: white; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; }
.header-left, .header-right { display: flex; align-items: center; gap: 12px; }
.app-logo { background-color: #1b4b60; color: white; width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; }
.app-title { font-size: 14px; font-weight: 600; }
.app-nav { display: flex; gap: 4px; margin-left: 10px; }
.app-nav a { padding: 6px 14px; border-radius: 6px; color: #6b7280; font-size: 13px; font-weight: 500; text-decoration: none; }
.app-nav a.active { background-color: #d1f4ee; color: #0d8a73; }
.app-nav a:hover:not(.active) { background-color: #f3f4f6; }

.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px; }
.user-avatar { background-color: #d1f4ee; color: #0d8a73; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: bold; }
.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 10px; color: #6b7280; }
.sign-out-btn { border: 1px solid #d1d5db; background: white; padding: 6px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; color: #374151; }

/* =========================================
   APP BODY & SIDEBAR
   ========================================= */
.app-body { display: flex; flex: 1; overflow: hidden; }
.app-sidebar { width: 280px; background: white; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; padding: 20px 16px; }
.sidebar-section-title { font-size: 10px; text-transform: uppercase; color: #9ca3af; font-weight: bold; letter-spacing: 0.5px; margin-bottom: 12px; }

.indexed-card { background-color: #f3f4f6; border-radius: 8px; padding: 15px; border: 1px solid #e5e7eb; }
.indexed-card h3 { font-size: 13px; margin: 0 0 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; display: block; }
.metadata-row { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 6px; font-family: monospace; color: #6b7280; }
.metadata-row .val { color: #374151; font-weight: 500; }
.view-doc-btn { width: 100%; background-color: white; border: 1px solid #d1d5db; padding: 8px; border-radius: 6px; margin-top: 12px; font-size: 12px; color: #374151; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }

.conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conversation-item { position: relative; padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.conversation-item.active { background-color: #d1f4ee; }
.conv-title { font-size: 13px; font-weight: 600; color: #111827; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 24px; }
.conv-date { font-size: 11px; color: #6b7280; }

.delete-conv-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    display: none;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.conversation-item:hover .delete-conv-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-conv-btn:hover {
    background-color: #fee2e2;
}

.sidebar-bottom { padding-top: 16px; margin-top: auto; border-top: 1px solid #e5e7eb; }
.new-conv-btn { width: 100%; background: white; border: 1px solid #d1d5db; padding: 10px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; transition: 0.2s; }
.new-conv-btn:hover { background: #f9fafb; border-color: #9ca3af; }

.sidebar-slogan-card { margin-top: 14px; background: #f0fbf8; border: 1px solid #c8ede6; border-radius: 8px; padding: 12px 14px; }
.sidebar-slogan-title { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #0d8a73; margin-bottom: 6px; }
.sidebar-slogan-text { font-size: 11px; color: #4b7a70; line-height: 1.5; margin: 0; }

/* =========================================
   MODAL
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
}
.modal-content {
    background: white; padding: 24px; border-radius: 12px;
    width: 100%; max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}
.modal-btn-cancel {
    background: white; border: 1px solid #d1d5db; padding: 8px 16px;
    border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer;
    color: #374151; transition: 0.2s;
}
.modal-btn-cancel:hover { background: #f3f4f6; }

.modal-btn-delete {
    background: #ef4444; border: 1px solid #dc2626; padding: 8px 16px;
    border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer;
    color: white; transition: 0.2s;
}
.modal-btn-delete:hover { background: #dc2626; }

/* =========================================
   MAIN CHAT
   ========================================= */
.app-chat { flex: 1; display: flex; flex-direction: column; background: #f8fafc; position: relative; }
.chat-messages { flex: 1; overflow-y: auto; padding: 40px 10%; display: flex; flex-direction: column; gap: 30px; scroll-behavior: smooth; }

.message { display: flex; gap: 16px; max-width: 800px; width: 100%; margin: 0 auto; }
.avatar { width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: bold; flex-shrink: 0; }
.system-avatar { background-color: #1b4b60; color: white; }
.user-msg-avatar { background-color: #d1f4ee; color: #0d8a73; }

.message-content { flex: 1; font-size: 15px; line-height: 1.6; color: #374151; }
.pill { display: inline-block; background: #e0f4f0; color: #0d8a73; padding: 2px 8px; border-radius: 12px; font-size: 11px; margin-right: 8px; font-weight: bold; }
.subtext { color: #6b7280; font-size: 14px; margin-top: 12px; }

/* WELCOME MESSAGE */
.welcome-message .welcome-title { font-weight: 600; font-size: 15px; color: #111827; margin-bottom: 4px; }
.welcome-message .welcome-slogan { color: #4b5563; font-size: 13.5px; line-height: 1.5; margin: 4px 0 12px; }
.welcome-message .welcome-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: #6b7280; border-top: 1px solid #f3f4f6; padding-top: 8px; margin-bottom: 8px; }

/* CHAT INPUT */
.chat-input-area { padding: 20px 10% 30px; background: linear-gradient(to top, #f8fafc 80%, rgba(248,250,252,0)); }
.starters { display: flex; gap: 10px; flex-wrap: wrap; max-width: 800px; margin: 0 auto 16px; }
.starters button { background: white; border: 1px solid #d1d5db; padding: 8px 14px; border-radius: 20px; font-size: 13px; color: #4b5563; cursor: pointer; transition: 0.2s; }
.starters button:hover { border-color: #0d8a73; color: #0d8a73; }

.chat-form { max-width: 800px; margin: 0 auto; position: relative; display: flex; align-items: center; background: white; border: 1px solid #d1d5db; border-radius: 24px; padding: 4px 4px 4px 20px; box-shadow: 0 2px 6px rgba(0,0,0,0.02); }
.chat-form:focus-within { border-color: #0d8a73; box-shadow: 0 0 0 2px rgba(13,138,115,0.1); }
#chat-input { flex: 1; border: none; outline: none; font-size: 15px; padding: 10px 0; background: transparent; }
.send-btn { background: #0d8a73; color: white; border: none; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; }
.send-btn:hover { background: #0a6b59; }

.chat-footer { text-align: center; font-size: 11px; color: #9ca3af; margin-top: 12px; }

/* Markdown styling in messages */
.message-content p { margin-bottom: 1em; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { color: #111827; }

/* =========================================
   NEW: USER MESSAGES
   ========================================= */
.message.user-message {
    flex-direction: row-reverse;
    margin-left: auto;
    margin-right: 0;
}
.message.user-message .message-content {
    background-color: #0d8a73;
    padding: 12px 16px;
    border-radius: 16px 16px 4px 16px;
    color: white;
    flex: none;
    max-width: 80%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.message.user-message .message-content p { color: white; }
.message.user-message .message-content strong { color: white; }
.message.user-message .avatar { display: none; }

.message.system-message .message-content {
    background-color: white;
    padding: 16px;
    border-radius: 16px 16px 16px 4px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* =========================================
   NEW: BOT MESSAGE ELEMENTS
   ========================================= */
.stated-box {
    background-color: #eaf7f4;
    border-left: 2px solid #0d8a73;
    padding: 14px 16px;
    margin: 16px 0;
    border-radius: 0 4px 4px 0;
}
.stated-title {
    font-size: 10px;
    text-transform: uppercase;
    color: #6b7280;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stated-content {
    font-size: 14px;
    color: #374151;
    line-height: 1.5;
    white-space: pre-wrap;
}
.sources-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}
.sources-title {
    font-size: 12px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.source-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.source-pill {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: white;
    color: #6b7280;
    text-transform: uppercase;
}
.source-pill:hover { border-color: #9ca3af; }
.source-pill.active {
    background-color: #d1f4ee;
    color: #0d8a73;
    border-color: #d1f4ee;
}
.msg-actions {
    display: flex;
    gap: 12px;
    color: #9ca3af;
}
.msg-actions svg {
    width: 14px; height: 14px;
    cursor: pointer;
}
.msg-actions svg:hover { color: #4b5563; }

/* =========================================
   RIGHT SIDEBAR (PDF VIEWER)
   ========================================= */
.app-right-sidebar {
    width: 380px;
    background: #f8fafc;
    border-left: 1px solid #e5e7eb;
    display: none; /* hidden by default */
    flex-direction: column;
}
.pdf-header {
    height: 60px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}
.pdf-close-btn {
    background: none; border: none; cursor: pointer; color: #6b7280;
    display: flex; align-items: center; justify-content: center;
}
.pdf-header-info { flex: 1; min-width: 0; }
.pdf-page-title { font-size: 14px; font-weight: 700; color: #111827; }
.pdf-page-sub { font-size: 11px; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-badge {
    background-color: #d1f4ee;
    color: #0d8a73;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid #0d8a73;
}

.pdf-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.pdf-page-render {
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    min-height: 500px;
    padding: 24px;
    position: relative;
}

/* FAKE PDF STYLES */
.pdf-title-bar {
    background-color: #00938f;
    color: white;
    text-align: center;
    padding: 12px;
    border-radius: 16px;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 20px;
}
.pdf-section-title {
    background-color: #d1f4ee;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 4px 8px;
    margin-bottom: 12px;
    display: inline-block;
    color: #00938f;
    width: 100%;
}
.pdf-list {
    margin-left: 16px;
    font-size: 11px;
    color: #374151;
    margin-bottom: 20px;
    line-height: 1.4;
}
.pdf-list li { margin-bottom: 8px; }
.pdf-highlight {
    background-color: #fef08a;
    padding: 0 2px;
}
.pdf-box {
    border: 1px solid #00938f;
    padding: 10px;
    font-size: 11px;
    line-height: 1.4;
}
.pdf-footer-text {
    position: absolute;
    bottom: 24px;
    left: 24px;
    right: 24px;
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #6b7280;
    font-style: italic;
    border-top: 1px solid #e5e7eb;
    padding-top: 8px;
}

.pdf-controls {
    height: 60px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}
.pdf-btn {
    background: white;
    border: 1px solid #d1d5db;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.pdf-btn:hover { background: #f9fafb; }
.pdf-page-count {
    font-size: 11px;
    color: #6b7280;
}

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

#chat-input:disabled { background: #f3f4f6; cursor: not-allowed; }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.collapsable-context {
    max-height: 85px; /* ~4 lines */
    overflow: hidden;
    position: relative;
    transition: max-height 0.3s ease;
}
.collapsable-context::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: linear-gradient(transparent, #eaf7f4);
    pointer-events: none;
}
.collapsable-context.expanded {
    max-height: 5000px;
    overflow: visible;
}
.collapsable-context.expanded::after {
    display: none;
}

.edit-conv-btn {
    position: absolute;
    right: 36px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #4b5563;
    cursor: pointer;
    display: none;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}
.conversation-item:hover .edit-conv-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}
.edit-conv-btn:hover {
    background-color: #e5e7eb;
}

/* Toggle Switch Styles */
.switch input:checked + .slider {
    background-color: #0d8a73;
}
.switch input:focus + .slider {
    box-shadow: 0 0 1px #0d8a73;
}
.switch input:checked + .slider:before {
    transform: translateX(16px);
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.slider {
    background-color: #d1d5db;
    transition: .4s;
    border-radius: 20px;
}

/* Dark Mode (Invert Method) */
html.dark-mode {
    filter: invert(0.92) hue-rotate(180deg) brightness(1.1) contrast(0.95);
    background: #111827; /* Dark slate */
}
html.dark-mode img,
html.dark-mode .user-avatar,
html.dark-mode .avatar {
    /* Reverse the inversion for images and avatars so they look natural */
    filter: invert(1) hue-rotate(-180deg) brightness(0.9) contrast(1.05);
}
.admin-tab {
    color: #6b7280;
    border-bottom: 2px solid transparent;
}
.admin-tab.active {
    color: #111827;
    border-bottom: 2px solid #0d8a73;
}
html.dark-mode .admin-tab {
    color: #9ca3af;
}
html.dark-mode .admin-tab.active {
    color: #f9fafb;
    border-bottom: 2px solid #34d399; /* Lighter green for dark mode */
}

/* File Input Styles */
input[type="file"] {
    font-size: 13px;
    color: #6b7280;
}
input[type="file"]::file-selector-button {
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
    cursor: pointer;
    margin-right: 12px;
    transition: background 0.2s;
}
input[type="file"]::file-selector-button:hover {
    background: #f9fafb;
}
html.dark-mode input[type="file"]::file-selector-button {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}
html.dark-mode input[type="file"]::file-selector-button:hover {
    background: #4b5563;
}


/* =========================================
   RESPONSIVE DESIGN (TABLET)
   ========================================= */
@media screen and (max-width: 1024px) {
    .app-sidebar { width: 240px; }
    .chat-messages { padding: 30px 5%; }
    .chat-input-area { padding: 16px 5% 24px; }
    
    #admin-area, #profile-area { padding: 24px 20px; }
    #admin-area > div > div:nth-child(2) { flex-wrap: wrap; }
    #tab-content-usage > div:last-child { flex-direction: column; }
    #tab-content-usage > div:last-child > div { width: 100%; flex: none; }
}

/* =========================================
   RESPONSIVE DESIGN (MOBILE)
   ========================================= */
@media screen and (max-width: 768px) {
    /* Login & Setup screens */
    .login-container { width: 90% !important; margin: 20px auto !important; padding: 0 !important; }
    .login-card { padding: 24px 16px !important; }
    #setup-account-screen > div { width: 90% !important; margin: 20px auto !important; padding: 24px 16px !important; box-sizing: border-box; }

    /* Fixed top header (closed menu) */
    .app-header {
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important;
        height: 60px !important;
        padding: 0 16px !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        background: white !important;
        border-bottom: 1px solid #e5e7eb !important;
        z-index: 2000 !important;
    }
    .header-left { flex-direction: row !important; align-items: center !important; flex: 1 !important; width: auto !important; gap: 0 !important; }
    .mobile-menu-icon { display: flex !important; align-items: center; margin-right: 12px; cursor: pointer; color: #4b5563; }
    .app-logo { margin: 0 8px 0 0 !important; }
    .app-title { font-size: 16px !important; white-space: nowrap !important; }

    /* Hide items by default */
    .app-nav, .header-right { display: none !important; }
    .app-sidebar { display: none !important; }
    .starters { display: none !important; } /* Hide suggested questions */

    /* Push body down due to fixed header */
    .app-body, #admin-area, #profile-area, #full-pdf-screen {
        margin-top: 60px !important;
        height: calc(100vh - 60px) !important;
        box-sizing: border-box !important;
        overflow-y: auto !important;
    }
    
    /* =======================================
       MENU OPEN STATE (display: contents hack)
       ======================================= */
    #app-screen:has(#mobile-menu-toggle:checked) {
        position: fixed !important;
        top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important;
        overflow-y: auto !important;
        z-index: 2000 !important;
        background: transparent !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-body {
        display: contents !important;
    }

    #mobile-menu-toggle:checked ~ .app-header {
        position: relative !important;
        width: 85% !important;
        max-width: 320px !important;
        height: auto !important;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 24px 20px 0 20px !important;
        background: white !important;
        border-right: 1px solid #e5e7eb !important;
        border-bottom: none !important;
        z-index: 3 !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-header .header-left {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 12px !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-header .app-nav {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        margin-top: 16px !important;
        border-top: 1px solid #e5e7eb !important;
        padding-top: 16px !important;
        gap: 8px !important;
    }
    #mobile-menu-toggle:checked ~ .app-header .app-nav a { padding: 12px !important; border-radius: 6px !important; text-align: left !important; }
    
    #mobile-menu-toggle:checked ~ .app-header .header-right {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        border-top: 1px solid #e5e7eb !important;
        margin-top: 16px !important;
        padding-top: 16px !important;
        gap: 16px !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-body .app-sidebar {
        display: flex !important;
        position: relative !important;
        width: 85% !important;
        max-width: 320px !important;
        height: auto !important;
        flex: 1 !important; /* visually fill the rest of the height */
        padding: 16px 20px 40px 20px !important;
        background: white !important;
        border-right: 1px solid #e5e7eb !important;
        border-bottom: none !important;
        z-index: 3 !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-body .mobile-backdrop {
        display: block !important;
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
        background: rgba(0,0,0,0.5) !important;
        z-index: 2 !important;
    }
    
    #mobile-menu-toggle:checked ~ .app-body .app-chat {
        position: fixed !important;
        top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important;
        z-index: 1 !important;
        overflow: hidden !important;
    }

    /* Main App Body (Chat layout) */
    .app-body { flex-direction: column !important; }
    .app-chat { 
        width: 100% !important; 
        flex: 1 !important; 
        overflow-y: auto !important;
    }
    
    /* Fix horizontal scroll in chat */
    .chat-messages { 
        padding: 20px 16px !important; 
        gap: 16px !important; 
        overflow-x: hidden !important; 
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .chat-input-area { padding: 12px 16px 20px !important; }
    .message { max-width: 100% !important; width: 100% !important; }
    .message.user-message .message-content { max-width: 90% !important; }
    .message-content {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        box-sizing: border-box !important;
    }
    
    /* PDF Sidebar Overlay */
    .app-right-sidebar {
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
        width: 100vw !important; height: 100vh !important;
        z-index: 3000 !important;
        border-left: none !important;
    }

    /* Admin & Profile Main Areas */
    #admin-area, #profile-area { padding: 20px 16px !important; }
    
    /* Profile Layout */
    #profile-area > div > div:nth-child(2) { flex-direction: column !important; }
    #profile-area > div > div:nth-child(2) > div { flex: none !important; width: 100% !important; }
    div[style*="justify-content: space-between; align-items: flex-start"] { 
        flex-direction: column !important; gap: 16px !important; align-items: stretch !important;
    }
    div[style*="justify-content: space-between; align-items: flex-start"] > div { flex-wrap: wrap; }

    /* Manage User Sidebar (Photo 2 fix) */
    #manage-sidebar { width: 100vw !important; z-index: 3000 !important; }
    #manage-sidebar[style*="-400px"] { width: 400px !important; }

    /* Admin Layouts */
    #admin-area > div > div:first-child { flex-direction: column !important; gap: 16px !important; }
    #admin-area > div > div:first-child > div:last-child { flex-wrap: wrap !important; width: 100% !important; justify-content: stretch !important; }
    #admin-area > div > div:first-child > div:last-child button { flex: 1 !important; text-align: center !important; }

    #admin-area .admin-tab { padding-bottom: 8px !important; font-size: 13px !important; flex: 1; text-align: center; }
    #admin-area > div > div:nth-child(2) { flex-wrap: wrap !important; gap: 8px !important; margin-bottom: 24px !important; }
    
    div[style*="background: white; border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 24px;"] { flex-direction: column !important; }
    div[style*="background: white; border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 24px;"] > div { border-right: none !important; border-bottom: 1px solid #e5e7eb !important; padding: 16px !important; }
    div[style*="background: white; border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 24px;"] > div:last-child { border-bottom: none !important; }

    div[style*="display: flex; justify-content: space-between; align-items: center"] { flex-direction: column !important; align-items: flex-start !important; gap: 12px !important; }
    div[style*="display: flex; justify-content: space-between; align-items: center"] > div { width: 100% !important; flex-wrap: wrap !important; }
    
    #tab-content-usage > div:last-child { flex-direction: column !important; }
    #tab-content-usage > div:last-child > div { width: 100% !important; flex: none !important; }

    div[style*="overflow: hidden"] > table, .table-container > table, #admin-users-table, #admin-docs-table, #admin-audit-table { 
        display: block !important; width: 100% !important; overflow-x: auto !important; white-space: nowrap !important; -webkit-overflow-scrolling: touch;
    }
    table { min-width: 600px !important; }
    
    #full-pdf-screen { padding: 0 !important; }
    #full-pdf-screen .full-pdf-toolbar { 
        height: auto !important; 
        padding: 10px !important; 
        flex-direction: column !important; 
        align-items: flex-start !important; 
        gap: 12px !important; 
    }
    #full-pdf-screen .full-pdf-toolbar > div {
        width: 100% !important;
        justify-content: space-between !important;
    }
    #main-pdf-iframe { width: 100% !important; }
    
    .modal-content, #invite-user-modal .modal-content, #setup-account-screen > div {
        width: 90% !important; max-width: none !important; padding: 20px !important; box-sizing: border-box !important;
    }
}

/* Profile Email fix */
#profile-email {
    word-break: break-all;
}

button { transition: opacity 0.2s ease; }
button:hover { opacity: 0.85; }

