/* ==========================================================================
   AI MENTOR — Chat Design System
   Token-based stylesheet for the chat UI (home.html). Loaded after
   bootstrap.min.css, which is kept only for the modal/dialog mechanics
   (data-bs-toggle etc.) driven by bootstrap.bundle.min.js. Every visual rule
   for the app shell, sidebar, chat and composer lives here instead of in
   page-level <style> blocks.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root{
    /* Layout */
    --sidebar-w: 288px;
    --header-h: 64px;
    --content-max-w: 820px;

    /* Radius */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* Spacing (4px base) */
    --sp-1: .25rem;
    --sp-2: .5rem;
    --sp-3: .75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(15, 15, 20, .06);
    --shadow: 0 4px 16px rgba(15, 15, 20, .10);
    --shadow-lg: 0 16px 40px rgba(15, 15, 20, .20);

    /* Motion */
    --dur-fast: 120ms;
    --dur: 200ms;
    --ease: cubic-bezier(.4, 0, .2, 1);

    /* Font */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Sidebar (dark) */
    --sb-bg: #171717;
    --sb-hover: #232323;
    --sb-active: #2a2a2a;
    --sb-border: #2a2a2a;
    --sb-text: #ececec;
    --sb-text-muted: #9b9b9b;
    --sb-text-faint: #6b6b6b;

    /* Main (light) */
    --bg: #ffffff;
    --bg-alt: #f7f7f8;
    --bg-subtle: #eceef1;
    --border: #e5e5e8;
    --text: #101014;
    --text-muted: #6b6b76;
    --text-faint: #9a9aa5;

    /* Accent */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-light: #eef2ff;
    --accent-text: #ffffff;

    /* Semantic */
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fef2f2;
}

/* ---------- 2. Reset (scoped to what bootstrap.min.css doesn't already do sanely) ---------- */
*, *::before, *::after{ box-sizing: border-box; }
html, body{ height: 100%; }
/* Every font-size and spacing token in this file is rem-based, so this one
   line is what makes "reduce font sizes uniformly all over" a single-place
   fix: it scales every rem value (text AND padding/gaps) down together
   instead of needing per-rule tweaks. Default browser root is 16px. */
html{ font-size: 75%; }
body{
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
button{ font-family: inherit; }
img{ max-width: 100%; display: block; }

/* Custom scrollbar */
.app-sidebar ::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar{ width: 8px; }
.app-sidebar ::-webkit-scrollbar-track, .chat-scroll::-webkit-scrollbar-track{ background: transparent; }
.app-sidebar ::-webkit-scrollbar-thumb{ background: #3a3a3a; border-radius: var(--radius-pill); }
.chat-scroll::-webkit-scrollbar-thumb{ background: var(--bg-subtle); border-radius: var(--radius-pill); }
.app-sidebar ::-webkit-scrollbar-thumb:hover{ background: #4a4a4a; }
.chat-scroll::-webkit-scrollbar-thumb:hover{ background: #d7d9de; }

/* ---------- 3. App shell ---------- */
.app-shell{
    display: flex;
    height: 100dvh;
    width: 100%;
    background: var(--bg);
}

/* ---------- 4. Sidebar ---------- */
.app-sidebar{
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--sb-bg);
    color: var(--sb-text);
    transition: margin-left var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.app-sidebar.is-collapsed{ margin-left: calc(var(--sidebar-w) * -1); }

.sidebar-top{
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4);
    flex-shrink: 0;
}
.sidebar-brand{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex: 1 0 0%;
    min-width: 0;
    color: var(--sb-text);
    text-decoration: none;
}
.sidebar-brand img{ height: 32px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.sidebar-brand span{
    font-weight: 600;
    font-size: 1.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.icon-btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--sb-text-muted);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
    flex-shrink: 0;
}
.icon-btn:hover{ background: var(--sb-hover); color: var(--sb-text); }
.icon-btn.icon-btn-light{ color: var(--text-muted); }
.icon-btn.icon-btn-light:hover{ background: var(--bg-subtle); color: var(--text); }

.sidebar-section{ padding: 0 var(--sp-4) var(--sp-4); flex-shrink: 0; }
.sidebar-scroll{ flex: 1 1 auto; overflow-y: auto; min-height: 0; padding: 0 var(--sp-3); }

.new-chat-btn{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    border: 1px solid var(--sb-border);
    background: transparent;
    color: var(--sb-text);
    font-size: 1.15rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.new-chat-btn:hover{ background: var(--sb-hover); border-color: #3a3a3a; }
.new-chat-btn i{ color: var(--accent); }
.new-chat-btn:hover i{ color: #818cf8; }

.sidebar-heading{
    padding: var(--sp-4) var(--sp-3) var(--sp-2);
    font-size: .95rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--sb-text);
}

.sidebar-collapsible-toggle{
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color var(--dur-fast) var(--ease);
}
.sidebar-collapsible-toggle:hover{ color: var(--sb-text); }
.sidebar-collapsible-caret{
    font-size: .85rem;
    transition: transform var(--dur-fast) var(--ease);
}
.sidebar-collapsible-toggle.is-expanded .sidebar-collapsible-caret{ transform: rotate(90deg); }

.session-list{ list-style: none; margin: 0; padding: 0 0 var(--sp-2); }
.session-item{
    position: relative;
    display: flex;
    align-items: stretch;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
}
.session-item:hover, .session-item.active{ background: var(--sb-hover); }
.session-item.active{ background: var(--sb-active); }
.session-item-btn{
    flex: 1 0 0%;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    background: none;
    border: none;
    color: var(--sb-text);
    font-size: 1.15rem;
    text-align: left;
    cursor: pointer;
    border-radius: inherit;
}
.session-item-btn i{ color: var(--sb-text-faint); font-size: 1.05rem; flex-shrink: 0; }
.session-item-title{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-item-delete{
    display: none;
    align-items: center;
    justify-content: center;
    width: 30px;
    flex-shrink: 0;
    border: none;
    background: none;
    color: var(--sb-text-faint);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.session-item:hover .session-item-delete{ display: inline-flex; }
.session-item-delete:hover{ color: var(--danger); background: rgba(220, 38, 38, .15); }

/* Generic dark-sidebar text inputs (e.g. aeye's judges/parties filters) */
.sidebar-field{ margin-bottom: var(--sp-3); }
.sidebar-field label{
    display: block;
    font-size: 1rem;
    color: var(--sb-text-muted);
    margin-bottom: var(--sp-1);
}
.sidebar-input{
    width: 100%;
    height: 36px;
    border: 1px solid var(--sb-border);
    border-radius: var(--radius-sm);
    background: var(--sb-hover);
    color: var(--sb-text);
    font-size: 1.1rem;
    padding: 0 var(--sp-3);
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.sidebar-input::placeholder{ color: var(--sb-text-faint); }
.sidebar-input:focus{ outline: none; border-color: var(--accent); background: #262626; }

/* Files section */
.files-section{
    border-bottom: 1px solid var(--sb-border);
    padding-top: var(--sp-4);
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-2);
}
.upload-dropzone{
    border: 1.5px dashed #3a3a3a;
    border-radius: var(--radius);
    padding: var(--sp-4);
    text-align: center;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.upload-dropzone:hover{ border-color: var(--accent); background: rgba(79, 70, 229, .08); }
.upload-dropzone-label{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-1);
    cursor: pointer;
    color: var(--sb-text-muted);
}
.upload-dropzone-label i{ font-size: 1.8rem; color: var(--accent); margin-bottom: var(--sp-1); }
.upload-dropzone-label span{ font-size: 1.1rem; color: var(--sb-text); font-weight: 500; }
.upload-dropzone-label small{ font-size: .95rem; color: var(--sb-text-faint); }

.file-meta{ font-size: 1rem; color: var(--sb-text-faint); margin: var(--sp-2) 0; }
.file-chip-list{ display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-3); max-height: 160px; overflow-y: auto; }
.file-chip{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    background: var(--sb-hover);
    font-size: 1.05rem;
    color: var(--sb-text);
}
.file-chip i{ color: var(--sb-text-faint); flex-shrink: 0; }
.file-chip-name{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-block{
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-3);
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}
.btn-block:hover{ background: var(--accent-hover); }

.session-files{ margin-top: var(--sp-4); }
.session-files-header{ font-size: 1rem; color: var(--sb-text-faint); margin-bottom: var(--sp-2); }
.session-files-list{ display: flex; flex-direction: column; gap: var(--sp-1); max-height: 220px; overflow-y: auto; }

/* Sidebar footer / user menu */
.sidebar-footer{
    flex-shrink: 0;
    border-top: 1px solid var(--sb-border);
    padding: var(--sp-3);
    position: relative;
}
.user-menu-trigger{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-2);
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--sb-text);
    cursor: pointer;
    text-align: left;
}
.user-menu-trigger:hover{ background: var(--sb-hover); }
.user-avatar{
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 1.05rem;
}
.user-menu-email{
    flex: 1 0 0%;
    min-width: 0;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-menu-caret{ color: var(--sb-text-faint); font-size: .95rem; transition: transform var(--dur-fast) var(--ease); flex-shrink: 0; }
.user-menu-trigger.is-open .user-menu-caret{ transform: rotate(180deg); }

.user-menu-popover{
    position: absolute;
    left: var(--sp-3);
    right: var(--sp-3);
    bottom: calc(100% + 6px);
    background: #202020;
    border: 1px solid var(--sb-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility var(--dur-fast);
    z-index: 40;
}
.user-menu-popover.show{ opacity: 1; visibility: visible; transform: translateY(0); }
.user-menu-item{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--sb-text);
    font-size: 1.1rem;
    text-decoration: none;
    cursor: pointer;
}
.user-menu-item:hover{ background: var(--sb-hover); color: var(--sb-text); }
.user-menu-item i{ width: 16px; text-align: center; color: var(--sb-text-faint); }
.user-menu-item-danger:hover{ color: #f87171; background: rgba(220, 38, 38, .15); }
.user-menu-item-danger:hover i{ color: #f87171; }
.user-menu-divider{ height: 1px; background: var(--sb-border); margin: var(--sp-2) 0; }

/* ---------- 5. Main column ---------- */
.app-main{
    flex: 1 1 0%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg);
    position: relative;
}

.chat-header{
    flex-shrink: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.header-sidebar-toggle{ display: inline-flex; }
.chat-header-title{
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex: 1 1 0%;
    min-width: 0;
}
.chat-title{
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-title-input{
    font-size: 1.5rem;
    font-weight: 600;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: var(--sp-1) var(--sp-2);
    max-width: 420px;
    width: 100%;
    outline: none;
}
.chat-header-controls{ display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

/* Pill selects reuse Bootstrap's .form-select (already loaded) for the
   cross-browser caret + appearance handling instead of hand-rolling it -
   only the shape, color and left-icon spacing are overridden here. */
.pill-select-wrap{
    position: relative;
    display: flex;
    align-items: center;
}
.pill-select-wrap i{
    position: absolute;
    left: var(--sp-3);
    color: var(--text-faint);
    font-size: 1rem;
    pointer-events: none;
}
select.pill-select.form-select{
    width: auto;
    min-width: 130px;
    max-width: 210px;
    height: 32px;
    border: 1px solid var(--border);
    background-color: var(--bg-alt);
    color: var(--text);
    border-radius: var(--radius-pill);
    padding: 0 2.3rem 0 2.6rem;
    font-size: 1.05rem;
    line-height: 30px;
    cursor: pointer;
    box-shadow: none;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
select.pill-select.form-select:hover{ background-color: var(--bg-subtle); }
select.pill-select.form-select:focus{ outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

@media (max-width: 760px){
    select.pill-select.form-select{ min-width: 0; max-width: 130px; }
}

/* Header options menu - light-themed sibling of the sidebar user menu.
   Reuses .user-menu-trigger/.user-menu-popover/.user-menu-item for the
   toggle JS and shared structure, layering these classes on top for the
   light-on-white palette (the sidebar variant is dark-on-dark). */
.header-user-menu{ position: relative; flex-shrink: 0; }
.header-user-menu-trigger{
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 1.05rem;
    transition: background var(--dur-fast) var(--ease);
}
.header-user-menu-trigger:hover{ background: var(--accent-hover); }

.header-user-menu-popover{
    left: auto;
    right: 0;
    bottom: auto;
    top: calc(100% + 8px);
    width: 210px;
    background: var(--bg);
    border: 1px solid var(--border);
}
.header-user-menu-item{ color: var(--text); }
.header-user-menu-item:hover{ background: var(--bg-alt); color: var(--text); }
.header-user-menu-item i{ color: var(--text-faint); }
.header-user-menu-item.user-menu-item-danger:hover{ color: var(--danger); background: var(--danger-light); }
.header-user-menu-item.user-menu-item-danger:hover i{ color: var(--danger); }
.header-user-menu-divider{ background: var(--border); }

@media (max-width: 576px){
    .header-user-menu-popover{ width: 190px; }
}

/* Chat scroll area */
.chat-scroll{
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    padding: var(--sp-6) var(--sp-5);
}
.chat-scroll-inner{
    max-width: var(--content-max-w);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-6);
}

.chat-empty-state{
    max-width: 480px;
    margin: 10vh auto 0;
    text-align: center;
    color: var(--text-muted);
}
.chat-empty-icon{
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: grid;
    place-items: center;
    font-size: 1.9rem;
    margin: 0 auto var(--sp-4);
}
.chat-empty-state h2{ font-size: 1.6rem; color: var(--text); margin: 0 0 var(--sp-2); }
.chat-empty-state p{ font-size: 1.1rem; margin: 0; line-height: 1.6; }

/* Message rows */
.chat-list{ list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-6); }
.msg-row{ display: flex; gap: var(--sp-3); align-items: flex-start; }
.msg-row-user{ justify-content: flex-end; }
.msg-col{ display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.msg-row-user .msg-col{ align-items: flex-end; }

.msg-avatar{
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    font-size: 1.1rem;
    margin-top: 2px;
}

.msg-bubble{
    background: var(--accent-light);
    color: var(--text);
    border-radius: var(--radius-lg);
    padding: var(--sp-3) var(--sp-4);
    font-size: 1.2rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 620px;
}

.msg-content{
    font-size: 1.2rem;
    line-height: 1.65;
    color: var(--text);
    max-width: 100%;
}
.msg-content > :first-child{ margin-top: 0; }
.msg-content > :last-child{ margin-bottom: 0; }

.msg-time{
    font-size: .95rem;
    color: var(--text-faint);
    margin-top: var(--sp-1);
    padding: 0 var(--sp-1);
}

/* Query-processing progress status text (e.g. aeye's progress modal) */
.msg-processing-status{ font-size: .95rem; color: var(--text-faint); margin: 0 0 var(--sp-2); }
.msg-progress-track{ height: 8px; }

/* Generic Bootstrap .progress/.progress-bar restyle (recolored to the
   design system accent). #uploadProgressModal has its own more specific
   override for its indeterminate swirl, which still wins there. */
.progress{ background: var(--bg-subtle); border-radius: var(--radius-pill); overflow: hidden; height: 8px; }
.progress-bar{ background-color: var(--accent); font-size: .85rem; line-height: 8px; }

/* Markdown content rendering (assistant messages) */
.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6{
    margin: var(--sp-5) 0 var(--sp-2);
    font-weight: 600;
    line-height: 1.3;
}
.msg-content h1{ font-size: 1.6rem; }
.msg-content h2{ font-size: 1.45rem; }
.msg-content h3{ font-size: 1.35rem; }
.msg-content h4{ font-size: 1.25rem; }
.msg-content p{ margin: 0 0 var(--sp-3); }
.msg-content code{
    background: var(--bg-subtle);
    padding: .15em .4em;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .92em;
}
.msg-content pre{
    background: #17171b;
    color: #e6e6e6;
    padding: var(--sp-4);
    border-radius: var(--radius);
    overflow-x: auto;
    margin: var(--sp-3) 0;
}
.msg-content pre code{ background: transparent; padding: 0; color: inherit; }
.msg-content blockquote{
    border-left: 3px solid var(--accent);
    padding-left: var(--sp-4);
    margin: var(--sp-3) 0;
    color: var(--text-muted);
}
.msg-content ul, .msg-content ol{ margin: 0 0 var(--sp-3); padding-left: 1.8rem; }
.msg-content li{ margin: var(--sp-1) 0; }
.msg-content ul li{ list-style: disc; }
.msg-content ol li{ list-style: decimal; }
.msg-content table{ border-collapse: collapse; width: 100%; margin: var(--sp-3) 0; font-size: .95em; }
.msg-content table th, .msg-content table td{ border: 1px solid var(--border); padding: var(--sp-2) var(--sp-3); text-align: left; }
.msg-content table th{ background: var(--bg-alt); font-weight: 600; }
.msg-content a{ color: var(--accent); text-decoration: none; }
.msg-content a:hover{ text-decoration: underline; }
.msg-content img{ border-radius: var(--radius-sm); margin: var(--sp-2) 0; }
.msg-content hr{ border: none; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

/* Suggestions (related questions) */
.suggestions{ display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.suggestions-label{ font-size: 1rem; color: var(--text-muted); margin: 0 0 var(--sp-1); width: 100%; }
.suggestion-chip{
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius-pill);
    padding: var(--sp-2) var(--sp-4);
    font-size: 1.1rem;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
    text-align: left;
}
.suggestion-chip:hover{ border-color: var(--accent); background: var(--accent-light); }

/* Result images */
.result-images{ display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.result-image{ border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.result-image img{ height: 100px; width: auto; display: block; }

/* Composer */
.composer{
    flex-shrink: 0;
    padding: var(--sp-4) var(--sp-5) var(--sp-5);
}
.composer-inner{
    max-width: var(--content-max-w);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-5);
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.composer-inner:focus-within{ border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.composer-inner input{
    flex: 1 0 0%;
    border: none;
    outline: none;
    background: none;
    font-size: 1.2rem;
    color: var(--text);
    padding: var(--sp-2) 0;
}
.composer-inner input::placeholder{ color: var(--text-faint); }
.composer-send{
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 1.15rem;
    transition: background var(--dur-fast) var(--ease);
}
.composer-send:hover{ background: var(--accent-hover); }
.composer-hint{
    max-width: var(--content-max-w);
    margin: var(--sp-2) auto 0;
    text-align: center;
    font-size: .9rem;
    color: var(--text-faint);
}

/* ---------- 6. Overlay / backdrop ---------- */
.sidebar-backdrop{
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 20, .5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease), visibility var(--dur);
}
.sidebar-backdrop.active{ opacity: 1; visibility: visible; pointer-events: auto; }

/* Scroll to top */
.scroll-to-top-btn{
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur) var(--ease), visibility var(--dur), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.scroll-to-top-btn.show{ opacity: 1; visibility: visible; }
.scroll-to-top-btn:hover{ background: var(--accent-hover); transform: translateY(-2px); }

/* ---------- 7. Mermaid ---------- */
.mermaid-wrapper{
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: var(--sp-3) 0;
    overflow: hidden;
}
.mermaid-controls{
    background: var(--bg-subtle);
    padding: var(--sp-2) var(--sp-3);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
}
.mermaid-controls button{
    padding: var(--sp-1) var(--sp-3);
    font-size: 1rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--dur-fast) var(--ease);
}
.mermaid-controls button:hover{ background: var(--accent); color: #fff; border-color: var(--accent); }
.mermaid-controls button i{ margin-right: var(--sp-1); }
.msg-content .mermaid{ background: transparent; padding: var(--sp-4); margin: 0; overflow-x: auto; text-align: center; }
.msg-content .mermaid svg{ max-width: 100%; height: auto; }
.mermaid-code-block{
    display: none;
    background: #17171b;
    color: #d4d4d8;
    padding: var(--sp-4);
    margin: 0;
    overflow-x: auto;
    border-top: 1px solid var(--border);
    max-height: 400px;
    position: relative;
}
.mermaid-code-block.show{ display: block; }
.mermaid-code-block pre{ margin: 0; padding: 0; background: transparent; border: none; color: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; line-height: 1.5; }
.mermaid-code-block code{ color: inherit; background: transparent; padding: 0; }
.copy-code-btn{
    position: absolute;
    top: var(--sp-2);
    right: var(--sp-2);
    padding: var(--sp-1) var(--sp-2);
    font-size: .95rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}
.copy-code-btn:hover{ background: var(--accent-hover); }
.copy-code-btn.copied{ background: #16a34a; }

/* ---------- 8. Modals (bootstrap structure, restyled) ---------- */
.modal-content{
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.modal-header{ border-bottom: 1px solid var(--border); padding: var(--sp-4) var(--sp-5); }
.modal-header .modal-title{ font-size: 1.35rem; font-weight: 600; }
.modal-body{ padding: var(--sp-5); font-size: 1.1rem; color: var(--text); line-height: 1.7; }
.modal-body p{white-space: pre-line;}
.modal-footer{ border-top: 1px solid var(--border); padding: var(--sp-4) var(--sp-5); }
.btn-close{ background: none; color: var(--text-muted); opacity: 1; font-size: 1.3rem; border: none; cursor: pointer; }
.btn-close:hover{ color: var(--text); }

.btn-modal{
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-5);
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--dur-fast) var(--ease);
}
.btn-modal:hover{ background: var(--bg-alt); }
.btn-modal-primary{ background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-modal-primary:hover{ background: var(--accent-hover); }
.btn-modal-danger{ background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-modal-danger:hover{ background: var(--danger-hover); }

.help-steps{ margin: 0; padding-left: 1.8rem; }
.help-steps li{ margin-bottom: var(--sp-2); }

#uploadProgressModal .progress{ background: var(--bg-subtle); border-radius: var(--radius-pill); overflow: hidden; height: 8px; }
#uploadProgressModal .progress-bar{
    width: 50% !important;
    background: linear-gradient(90deg, rgba(79, 70, 229, .2) 0%, rgba(79, 70, 229, 1) 50%, rgba(79, 70, 229, .2) 100%);
    animation: progress-swing 2.5s ease-in-out infinite, progress-pulse 2.5s ease-in-out infinite;
}
@keyframes progress-swing{ 0%{ transform: translateX(-100%); } 50%{ transform: translateX(100%); } 100%{ transform: translateX(-100%); } }
@keyframes progress-pulse{ 0%, 100%{ opacity: .6; } 50%{ opacity: 1; } }

/* ---------- 9. Auth / login page ---------- */
.auth-shell{
    display: flex;
    height: 100dvh;
    width: 100%;
    background: var(--bg);
}

.auth-brand{
    width: 42%;
    min-width: 380px;
    max-width: 560px;
    flex-shrink: 0;
    background: var(--sb-bg);
    color: var(--sb-text);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--sp-8);
    padding: var(--sp-10);
}
.auth-brand-logo{ display: flex; align-items: center; gap: var(--sp-3); }
.auth-brand-logo img{ height: 68px; border-radius: var(--radius-sm); object-fit: cover; }
.auth-brand-logo span{ font-weight: 600; font-size: 2.6rem; }
.auth-brand-copy h1{ font-size: 2rem; font-weight: 600; line-height: 1.35; margin: 0 0 var(--sp-3); }
.auth-brand-copy p{ font-size: 1.15rem; color: var(--sb-text-muted); line-height: 1.7; margin: 0; }

.auth-feature-list{ list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-feature-list li{ display: flex; align-items: flex-start; gap: var(--sp-3); font-size: 1.1rem; color: var(--sb-text); }
.auth-feature-list i{ color: var(--accent); margin-top: 3px; flex-shrink: 0; }

.auth-main{
    flex: 1 1 0%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-6);
    overflow-y: auto;
}
.auth-card{ width: 100%; max-width: 380px; }
.auth-card h2{ font-size: 1.6rem; font-weight: 600; margin: 0 0 var(--sp-1); color: var(--text); }
.auth-card-subtitle{ color: var(--text-muted); font-size: 1.05rem; margin: 0 0 var(--sp-6); }

.auth-error{
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    background: var(--danger-light);
    color: var(--danger-hover);
    border: 1px solid rgba(220, 38, 38, .25);
    border-radius: var(--radius);
    padding: var(--sp-3) var(--sp-4);
    font-size: 1.05rem;
    margin-bottom: var(--sp-5);
}
.auth-error i{ margin-top: 2px; flex-shrink: 0; }

.auth-field{ margin-bottom: var(--sp-4); }
.auth-label{ display: block; font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: var(--sp-2); }
.auth-input-wrap{ position: relative; display: flex; align-items: center; }
.auth-input-icon{
    position: absolute;
    left: var(--sp-4);
    color: var(--text-faint);
    font-size: 1rem;
    pointer-events: none;
}
.auth-input{
    width: 100%;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-alt);
    color: var(--text);
    font-size: 1.1rem;
    padding: 0 var(--sp-4) 0 2.8rem;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.auth-input:focus{ outline: none; border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px var(--accent-light); }
.auth-input.auth-input-has-toggle{ padding-right: 2.8rem; }
.auth-toggle-visibility{
    position: absolute;
    right: var(--sp-3);
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    padding: var(--sp-1);
    display: flex;
}
.auth-toggle-visibility:hover{ color: var(--text); }

.auth-submit{
    width: 100%;
    height: 44px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
    margin-top: var(--sp-2);
}
.auth-submit:hover{ background: var(--accent-hover); }

.auth-footer{ margin-top: var(--sp-8); text-align: center; font-size: .95rem; color: var(--text-faint); }

@media (max-width: 900px){
    .auth-brand{ display: none; }
    .auth-main{ padding: var(--sp-4); }
}

/* ---------- 10. Responsive ---------- */
@media (max-width: 991px){
    .app-sidebar{
        position: fixed;
        left: 0;
        top: 0;
        z-index: 1050;
        height: 100dvh;
        transform: translateX(-100%);
        margin-left: 0;
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.is-open{ transform: translateX(0); }
}
@media (max-width: 576px){
    .chat-scroll{ padding: var(--sp-4) var(--sp-3); }
    .composer{ padding: var(--sp-3); }
    .chat-header{ padding: 0 var(--sp-3); }
    .msg-bubble{ max-width: 82vw; }
}
