/* Desktop navigation shares the existing sidebar, composer and learning tools. */
.desktop-chat-toolbar,
.desktop-shell-button { display:none; }

body[data-appearance-theme] :is(#desktopNewChatBtn,#mobileNewChatBtn) {
    --dm-icon-rest:var(--text-muted);
    --dm-icon-emphasis:var(--text-secondary);
}

@media(max-width:1100px) {
    .mobile-topbar { grid-template-columns:auto minmax(0,1fr) auto !important; }
    .mobile-topbar-start { gap:8px; }
    .mobile-topbar-actions { grid-column:3; }
    #mobileNewChatBtn { flex:none; }
    body.mobile-left-open #mobileNewChatBtn { display:none; }
}

@media(min-width:1101px) {
    body[data-appearance-theme] {
        --dmate-sidebar-width:280px;
        --dmate-reading-width:960px;
    }
    body[data-appearance-theme] > .layout {
        display:grid !important;
        grid-template-columns:var(--dmate-sidebar-width) minmax(0,1fr);
        width:100%; height:100vh; height:100dvh; min-height:0;
        overflow:hidden;
        transition:grid-template-columns .22s cubic-bezier(.2,.8,.2,1);
    }
    html[data-desktop-sidebar="collapsed"] body[data-appearance-theme] > .layout {
        grid-template-columns:0px minmax(0,1fr);
    }
    body[data-appearance-theme] #conversationSidebar {
        position:relative; inset:auto;
        display:flex !important; flex-direction:column;
        box-sizing:border-box; width:100% !important; min-width:0 !important;
        height:100%; min-height:0; max-height:100%;
        padding:12px !important; overflow:hidden !important;
        transition:padding .22s cubic-bezier(.2,.8,.2,1),opacity .16s ease;
    }
    body[data-appearance-theme] #conversationSidebar > :is(.btn,#sessions,.dmate-brand) {
        min-width:calc(var(--dmate-sidebar-width) - 24px);
    }
    body[data-appearance-theme] #conversationSidebar > .dmate-brand {
        min-height:50px; margin-bottom:14px; padding-right:34px;
    }
    body[data-appearance-theme] #conversationSidebar .dmate-brand-subtitle {
        overflow:hidden; text-overflow:ellipsis;
    }
    body[data-appearance-theme] #conversationSidebar > #sessions {
        min-height:0; flex:1 1 auto; overflow-y:auto; overflow-x:hidden;
    }
    html[data-desktop-sidebar="collapsed"] body[data-appearance-theme] #conversationSidebar {
        padding-inline:0 !important; opacity:0; pointer-events:none;
    }
    body[data-appearance-theme] .layout > .center {
        position:relative; inset:auto; display:flex !important;
        flex-direction:column; min-width:0 !important; min-height:0;
        width:100% !important; height:100%; overflow:hidden;
    }
    body[data-appearance-theme] .desktop-chat-toolbar {
        position:relative; z-index:12; display:flex;
        align-items:center; justify-content:space-between;
        flex:0 0 56px; min-height:56px; padding:8px 16px;
        gap:12px;
    }
    .desktop-chat-toolbar-start {
        display:flex; align-items:center; gap:10px;
        flex:1 1 auto; min-width:0;
    }
    .desktop-conversation-title {
        min-width:0; margin-left:8px;
        overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
        font-size:16px; font-weight:600; line-height:1.5;
        color:var(--text-primary);
    }
    html[data-desktop-sidebar="expanded"] .desktop-conversation-title {
        margin-left:0;
    }
    body[data-appearance-theme] .desktop-shell-button {
        display:inline-flex; align-items:center; justify-content:center; flex:none;
        box-sizing:border-box; width:36px !important; min-width:36px !important;
        height:36px !important; min-height:36px !important; margin:0 !important; padding:7px !important;
        border:0 !important; border-radius:10px !important;
        background:transparent !important; background-image:none !important; box-shadow:none !important;
        color:var(--text-secondary) !important; -webkit-text-fill-color:currentColor !important;
        cursor:pointer; transition:background-color .16s ease,color .16s ease;
    }
    body[data-appearance-theme] .desktop-shell-button:is(:hover,:focus-visible,[aria-expanded="true"]):not(#desktopSidebarToggle) {
        background:var(--surface-3) !important; color:var(--text-primary) !important;
    }
    body[data-appearance-theme] #desktopSidebarToggle:is(:hover,:focus-visible) { background:var(--surface-3) !important; }
    body[data-appearance-theme] .desktop-shell-button:focus-visible { outline:2px solid var(--accent) !important; outline-offset:-2px !important; }
    .desktop-shell-button svg {
        width:22px; height:22px; fill:none; stroke:currentColor;
        stroke-width:2; stroke-linecap:round; stroke-linejoin:round;
    }
    body[data-appearance-theme] #desktopSidebarToggle { position:absolute; top:15px; right:10px; }
    html[data-desktop-sidebar="expanded"] body[data-appearance-theme] :is(#desktopSidebarOpen,#desktopNewChatBtn) { display:none; }
    body[data-appearance-theme] #desktopToolsBtn { margin-left:auto !important; }

    body[data-appearance-theme] .center > #chat {
        flex:1 1 auto; min-width:0; min-height:0; overflow-y:auto;
        padding:16px max(24px,calc((100% - var(--dmate-reading-width)) / 2)) 20px;
    }
    body[data-appearance-theme] .center > #chat > .msg { max-width:85%; }
    body[data-appearance-theme] .center:not(.chat-empty) > .input-wrap:not([hidden]) {
        flex:0 0 auto; width:min(100%,calc(var(--dmate-reading-width) + 48px)) !important;
        margin:0 auto !important; padding:var(--dmate-mode-row-height) 24px 16px !important;
    }
    body[data-appearance-theme] .center:not(.chat-empty) > .input-wrap > .manual-question-mode { left:24px; }
    body[data-appearance-theme] .center.chat-empty > .input-wrap > .manual-question-mode { left:0; }
    body[data-appearance-theme] .center > #ocrUploadStage {
        width:calc(100% - 48px); max-width:var(--dmate-reading-width); margin-inline:auto;
    }

    body[data-appearance-theme] #learningToolsPanel {
        position:fixed !important; z-index:120; top:64px; right:16px; bottom:auto; left:auto;
        display:block !important; box-sizing:border-box;
        width:320px !important; min-width:0 !important; height:auto !important;
        min-height:0; max-height:calc(100dvh - 80px) !important;
        margin:0; padding:18px !important; overflow-x:hidden; overflow-y:auto;
        border:1px solid var(--border-strong) !important; border-radius:18px;
        background:var(--surface-2) !important; background-image:none !important;
        box-shadow:0 14px 44px rgb(0 0 0 / .2);
        opacity:0; visibility:hidden; pointer-events:none;
        transform:translateY(-6px) scale(.98); transform-origin:top right;
        transition:opacity .16s ease,transform .18s ease,visibility .18s;
    }
    body[data-appearance-theme].desktop-tools-open #learningToolsPanel {
        opacity:1; visibility:visible; pointer-events:auto; transform:translateY(0) scale(1);
    }
    body[data-appearance-theme] #learningToolsPanel .panel-heading-row { font-size:15px; }
    body[data-appearance-theme] #learningToolsPanel #info { margin:10px 0 0; font-size:13px; overflow-wrap:anywhere; }
    body[data-appearance-theme] #learningToolsPanel .learning-panel { margin-top:16px; padding-top:16px; }
    body[data-appearance-theme] #learningToolsPanel .learning-tools-secondary { margin-top:32px; }
    body[data-appearance-theme] #learningToolsPanel .learning-actions button { min-height:36px; font-size:14px; }
    body[data-appearance-theme].has-custom-background #learningToolsPanel {
        background:var(--dm-frost-panel-strong,var(--surface-2)) !important;
        backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px);
    }
}

@media(min-width:1101px) and (prefers-reduced-motion:reduce) {
    body[data-appearance-theme] > .layout,
    body[data-appearance-theme] #conversationSidebar,
    body[data-appearance-theme] #learningToolsPanel,
    body[data-appearance-theme] .desktop-shell-button { transition:none; }
}
