/* ============================================================
   SnapGPT — App shell sidebar
   The left sidebar + phone navbar shared by the app pages
   (/notes, /study). Mirrors the /chat sidebar (chat/styles.css):
   a 52px rail when collapsed, a top bar, "New …" + search rows,
   a foldable Apps section, a foldable per-page history section
   and the account row with its usage popover.
   Colours are scoped to the shell so a page's own variables never
   leak in; layout variables live on :root for .main-container.
   Behaviour: /js/app-sidebar.js
   ============================================================ */
:root {
    --sidebar-w: 260px;
    --sidebar-collapsed-w: 52px;
    --sidebar-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --navbar-h: 52px;
}

.sidebar-wrapper, .mobile-navbar {
    --bg: #0f0f11;
    --sidebar-bg: #0a0a0c;
    --text-1: rgba(255, 255, 255, 0.95);
    --text-2: rgba(255, 255, 255, 0.55);
    --text-3: rgba(255, 255, 255, 0.4);
    --primary: #ff4a36;
    --secondary: rgba(255, 255, 255, 0.1);
    --tertiary: rgba(255, 255, 255, 0.05);
    --hover: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.07);
    --border-2: rgba(255, 255, 255, 0.14);
    --panel: #1a1a1e;
    --green: #22c55e;
    --radius-sm: 8px;
    --radius-md: 12px;
    /* Every row (New, search, app links, history rows) shares these
       "menu item" metrics, like /chat */
    --menu-item-h: 36px;
    --menu-item-radius: 10px;
    --menu-item-px: 10px;
    --menu-item-hover: rgba(255, 255, 255, 0.06);
    --sidebar-px: 0.5rem;
    --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    letter-spacing: -0.01em;
    line-height: 1.5;
    color: var(--text-1);
    -webkit-font-smoothing: antialiased;
}
/* Element resets at zero specificity (:where) so the component classes below always win */
:where(.sidebar-wrapper, .mobile-navbar) :where(*) { box-sizing: border-box; }
:where(.sidebar-wrapper, .mobile-navbar) :where(button) { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; padding: 0; margin: 0; cursor: pointer; }
:where(.sidebar-wrapper, .mobile-navbar) :where(a) { color: inherit; text-decoration: none; }
:where(.sidebar-wrapper, .mobile-navbar) :where(svg) { flex-shrink: 0; display: block; }
:where(.sidebar-wrapper, .mobile-navbar) :where(h1, h2, h3, p) { margin: 0; }
.sidebar-wrapper [hidden], .mobile-navbar [hidden] { display: none !important; }
:where(.sidebar-wrapper, .mobile-navbar) :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============================================================
   App sidebar
   ============================================================ */
.sidebar-wrapper {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 30;
    transition: width 0.28s var(--sidebar-ease);
}

.sidebar {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
}

/* ---- Top bar: icon-only home link + collapse button ---- */
.sidebar-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-home-btn,
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-home-btn:hover,
.sidebar-collapse-btn:hover { background: var(--hover); color: var(--text-1); }
.sidebar-home-btn img { width: 20px; height: 20px; display: block; }
.sidebar-collapse-btn svg { width: 20px; height: 20px; }

/* ---- Header: the "New …" row and the search row ---- */
.sidebar-header {
    display: flex;
    flex-direction: column;
    padding: 0.35rem var(--sidebar-px) 0;
}

.sidebar-new-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: var(--menu-item-h);
    padding: 0 var(--menu-item-px);
    border-radius: var(--menu-item-radius);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.875rem;
    font-weight: 400;
    text-align: left;
    transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-new-btn:hover { background: var(--menu-item-hover); color: var(--text-1); }
.sidebar-new-content { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sidebar-new-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: rgba(255, 255, 255, 0.85);
}
.sidebar-new-btn:hover .sidebar-new-icon { color: var(--text-1); }
.sidebar-new-icon svg { width: 20px; height: 20px; }
.sidebar-new-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-search {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: var(--menu-item-h);
    padding: 0 var(--menu-item-px);
    border-radius: var(--menu-item-radius);
    background: transparent;
    cursor: text;
    transition: background 0.12s ease;
}
.sidebar-search:hover,
.sidebar-search:focus-within { background: var(--menu-item-hover); }
.sidebar-search svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    padding: 1px;
    color: rgba(255, 255, 255, 0.85);
}
.sidebar-search input {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-1);
    font-family: inherit;
    font-size: 0.875rem;
    letter-spacing: inherit;
}
.sidebar-search input::placeholder { color: rgba(255, 255, 255, 0.85); user-select: none; transition: color 0.12s ease; }
.sidebar-search:hover input::placeholder { color: var(--text-1); }
.sidebar-search input:focus::placeholder { color: rgba(255, 255, 255, 0.35); }
.sidebar-search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

/* ---- Foldable sections (Apps, history) ----
   A small tertiary label with a chevron that shows on hover (always when
   folded) and folds the section body. */
.sidebar-section { display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-section-header { display: flex; align-items: center; justify-content: space-between; padding-right: 6px; }
.sidebar-section-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    width: 100%;
    padding: 6px calc(var(--sidebar-px) + var(--menu-item-px));
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: left;
    user-select: none;
    -webkit-user-select: none;
    transition: color 0.12s ease;
}
.sidebar-section-toggle:hover,
.sidebar-section-toggle:focus-visible { color: rgba(255, 255, 255, 0.7); }
.sidebar-section-toggle:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.25); outline-offset: -2px; }
.sidebar-section-chevron {
    width: 12px;
    height: 12px;
    visibility: hidden;
    transition: transform 0.15s ease;
}
.sidebar-section:hover .sidebar-section-chevron,
.sidebar-section-toggle:focus-visible .sidebar-section-chevron,
.sidebar-section.is-folded .sidebar-section-chevron { visibility: visible; }
.sidebar-section.is-folded .sidebar-section-chevron { transform: rotate(-90deg); }
.sidebar-section.is-folded .sidebar-section-body { display: none; }
@media (pointer: coarse) { .sidebar-section-chevron { visibility: visible; } }

/* Apps section: links to the other SnapGPT apps */
.sidebar-apps { padding-top: 0.35rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0; padding: 0 var(--sidebar-px); flex-shrink: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: var(--menu-item-h);
    padding: 0 var(--menu-item-px);
    border-radius: var(--menu-item-radius);
    font-size: 0.875rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--menu-item-hover); color: var(--text-1); }
.nav-item.active { background: rgba(255, 74, 54, 0.1); color: var(--text-1); font-weight: 500; }
.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.85);
    transition: color 0.12s ease;
}
.nav-icon svg { width: 20px; height: 20px; }
.nav-item:hover .nav-icon { color: var(--text-1); }
.nav-item.active .nav-icon { color: var(--primary); }

/* ---- History: the page's list (notes on /notes, sets on /study) ----
   Scrolls under a sticky section header, like /chat's thread list. */
.sidebar-history {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 var(--sidebar-px) 0.65rem;
}
.sidebar-history .sidebar-section-header {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 calc(-1 * var(--sidebar-px));
    padding: 4px calc(var(--sidebar-px) + 6px) 0 var(--sidebar-px);
    background: var(--sidebar-bg);
}
.sidebar-history .sidebar-section-toggle { padding-left: var(--menu-item-px); padding-right: var(--menu-item-px); }
.sidebar-history::-webkit-scrollbar { width: 3px; }
.sidebar-history::-webkit-scrollbar-track { background: transparent; }
.sidebar-history::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 999px; }

.sidebar-history-section { margin-bottom: 0.5rem; }
.sidebar-history-label {
    padding: 0.45rem var(--menu-item-px) 0.2rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.42);
}
.sidebar-history-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--menu-item-h);
    padding: 0 var(--menu-item-px);
    border-radius: var(--menu-item-radius);
    cursor: pointer;
    user-select: none;
    transition: background 0.12s ease;
}
.sidebar-history-item:hover { background: var(--menu-item-hover); }
.sidebar-history-item.active { background: rgba(255, 74, 54, 0.1); }
.sidebar-history-item:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.25); outline-offset: -2px; }
.sidebar-history-title {
    flex: 1;
    min-width: 0;
    padding-right: 0.5rem;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-history-item.active .sidebar-history-title { color: var(--text-1); font-weight: 500; }
.sidebar-history-actions {
    display: flex;
    gap: 0.15rem;
    min-width: 2rem;
    justify-content: flex-end;
    margin-right: -0.25rem;
    opacity: 0;
    pointer-events: none;
    transform: translateX(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.sidebar-history-item:hover .sidebar-history-actions,
.sidebar-history-item:focus-within .sidebar-history-actions { opacity: 1; pointer-events: auto; transform: translateX(0); }
.sidebar-history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem;
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.35);
    transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-history-btn:hover { background: var(--hover); color: var(--text-2); }
.sidebar-history-btn.delete:hover { background: rgba(239, 68, 68, 0.08); color: #f87171; }
.sidebar-history-btn svg { width: 15px; height: 15px; }
/* No hover on touch (e.g. an iPad wide enough to show the sidebar): keep the
   per-row actions visible and tappable, like /chat's thread list */
@media (pointer: coarse) {
    .sidebar-history-actions { opacity: 1; pointer-events: auto; transform: none; }
    .sidebar-history-btn { padding: 0.3rem; }
}

.sidebar-history-empty { padding: 2rem 1rem; font-size: 0.85rem; line-height: 1.45; text-align: center; color: var(--text-2); }
.sidebar-history-skeleton { display: flex; flex-direction: column; }
.sidebar-history-skeleton span {
    display: flex;
    align-items: center;
    min-height: var(--menu-item-h);
    padding: 0 var(--menu-item-px);
}
.sidebar-history-skeleton span::before {
    content: '';
    display: block;
    width: var(--w, 70%);
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.07) 50%, rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
    animation: sidebar-skeleton 1.5s ease-in-out infinite;
}
@keyframes sidebar-skeleton { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
/* First paint restores the remembered width without animating it */
.app.no-anim .sidebar-wrapper, .app.no-anim .main-container { transition: none !important; }

/* ---- Footer: Upgrade + account ---- */
.sidebar-footer { flex-shrink: 0; }

/* Upgrade: the same gold button as /chat's quota banner */
.upgrade-btn {
    margin: 0 0.75rem 0.65rem;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-sm);
    background: linear-gradient(110deg, #d4af37 0%, #e5e4e2 50%, #d4af37 100%);
    background-size: 200% auto;
    color: #000;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
    animation: shine 3s linear infinite;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.upgrade-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3); color: #000; }
.upgrade-btn svg { width: 18px; height: 18px; }
@keyframes shine { to { background-position: 200% center; } }

/* Account row (same as /chat's sidebar user section) */
.sidebar-user-section:not(.is-ready),
.sidebar-rail-profile:not(.is-ready) { visibility: hidden; }

.sidebar-user-section {
    position: relative;
    padding: 0.6rem 0.75rem 0.75rem;
    border-top: 1px solid var(--border);
}

.sidebar-user-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    color: var(--text-1);
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.sidebar-user-button:hover,
.sidebar-user-button:focus-visible,
.sidebar-user-button[aria-expanded="true"] { background: rgba(255, 255, 255, 0.04); border-color: var(--border); }
.sidebar-user-button:focus-visible { outline: none; }

.user-avatar, .navbar-avatar {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--secondary);
    color: rgba(255, 255, 255, 0.7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.user-avatar img, .navbar-avatar img, .sidebar-rail-avatar img { width: 100%; height: 100%; flex-shrink: 0; object-fit: cover; display: block; }
.avatar-initial { font-size: 0.75rem; font-weight: 600; line-height: 1; color: rgba(255, 255, 255, 0.7); text-transform: uppercase; }
.avatar-icon { width: 16px; height: 16px; }

.sidebar-user-email {
    flex: 1;
    min-width: 0;
    font-size: 0.8rem;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-chevron { width: 16px; height: 16px; color: var(--text-2); transition: transform 0.2s ease; }
.sidebar-user-button[aria-expanded="true"] .sidebar-user-chevron { transform: rotate(180deg); }

/* Signed out: the row becomes a centered "Sign In" button */
.sidebar-user-button.sign-in-mode { justify-content: center; border-color: var(--border); padding: 0.5rem 0.75rem; }
.sidebar-user-button.sign-in-mode:hover { background: var(--hover); border-color: var(--border-2); }
.sidebar-user-button.sign-in-mode .user-avatar,
.sidebar-user-button.sign-in-mode .sidebar-user-chevron { display: none; }
.sidebar-user-button.sign-in-mode .sidebar-user-email { flex: 0 1 auto; text-align: center; font-weight: 500; }

/* Popover: usage, Manage Account, Log out */
.sidebar-quota-popover {
    position: absolute;
    left: 0.75rem;
    bottom: calc(100% + 0.65rem);
    width: calc(100% - 1.5rem);
    padding: 0.85rem;
    border-radius: var(--radius-md);
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 20;
}
.sidebar-quota-popover.show { opacity: 1; transform: translateY(0); pointer-events: auto; }

.quota-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.quota-name { font-size: 0.8rem; font-weight: 600; }
.quota-value { font-size: 0.8rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.quota-bar { height: 4px; background: rgba(255, 255, 255, 0.08); border-radius: 999px; overflow: hidden; margin-bottom: 0.5rem; }
.quota-progress { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.premium-progress {
    background: linear-gradient(90deg, #ff4a36 0%, #dd98ff 100%);
    background-size: 200% 100%;
    animation: gradientShift 3s linear infinite;
}
.quota-detail { font-size: 0.75rem; color: var(--text-2); line-height: 1.45; }
.quota-unlimited { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--green); font-weight: 500; }
.quota-unlimited svg { fill: var(--green); stroke: none; }

.sidebar-manage-account-btn,
.sidebar-logout-btn {
    margin-top: 0.65rem;
    width: 100%;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 500;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sidebar-manage-account-btn:hover { border-color: rgba(255, 74, 54, 0.4); background: rgba(255, 74, 54, 0.08); color: #ff9d91; }
.sidebar-logout-btn:hover { border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); color: #fca5a5; }

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ---- Collapsed: a 52px rail of 36px buttons, like /chat ----
   Logo (opens the sidebar on hover/focus it swaps to the panel icon),
   gap, New, Search, the other apps, then Upgrade and the avatar. */
.sidebar-rail {
    display: none;
    flex-direction: column;
    align-items: center;
    height: 100%;
    padding: 0.45rem 0 0.4rem;
    overflow: visible;
}
.sidebar-rail-logo-btn { position: relative; }
.sidebar-rail-logo { width: 22px; height: 22px; display: block; transition: opacity 0.15s ease; }
.sidebar-rail-open-icon {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 20px;
    height: 20px;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.sidebar-rail-logo-btn:hover .sidebar-rail-logo,
.sidebar-rail-logo-btn:focus-visible .sidebar-rail-logo { opacity: 0; }
.sidebar-rail-logo-btn:hover .sidebar-rail-open-icon,
.sidebar-rail-logo-btn:focus-visible .sidebar-rail-open-icon { opacity: 1; }
.sidebar-rail-gap { height: 14px; flex-shrink: 0; }

.sidebar-rail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-bottom: 0.35rem;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-rail-btn:hover { background: var(--hover); color: var(--text-1); }
.sidebar-rail-btn svg { width: 20px; height: 20px; }
.sidebar-rail-spacer { flex: 1; }

.sidebar-rail-upgrade {
    background: linear-gradient(110deg, #d4af37 0%, #e5e4e2 50%, #d4af37 100%);
    background-size: 200% auto;
    color: #000;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
    animation: shine 3s linear infinite;
}
.sidebar-rail-upgrade:hover { background: linear-gradient(110deg, #d4af37 0%, #e5e4e2 50%, #d4af37 100%); background-size: 200% auto; color: #000; }
.sidebar-rail-upgrade svg { width: 18px; height: 18px; }

.sidebar-rail-profile {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 0.35rem;
}
.sidebar-rail-profile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.sidebar-rail-profile-btn:hover,
.sidebar-rail-profile-btn:focus-visible,
.sidebar-rail-profile-btn[aria-expanded="true"] { background: var(--hover); border-color: var(--border); }
.sidebar-rail-profile-btn:focus-visible { outline: none; }
.sidebar-rail-profile-btn.sign-in-mode { border-color: var(--border); }
.sidebar-rail-profile-btn.sign-in-mode:hover { border-color: var(--border-2); }
.sidebar-rail-avatar {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--secondary);
    color: rgba(255, 255, 255, 0.7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.sidebar-rail-avatar .avatar-initial { font-size: 0.7rem; }
.sidebar-rail-avatar .avatar-icon { width: 14px; height: 14px; }
/* The one popover is moved into the rail while collapsed and opens to the right */
.sidebar-quota-popover-rail { left: calc(100% + 0.6rem); bottom: 0; width: 240px; }

.sidebar-wrapper.is-collapsed { width: var(--sidebar-collapsed-w); }
.sidebar-wrapper.is-collapsed .sidebar { overflow: visible; }
.sidebar-wrapper.is-collapsed .sidebar-top-bar,
.sidebar-wrapper.is-collapsed .sidebar-header,
.sidebar-wrapper.is-collapsed .sidebar-section,
.sidebar-wrapper.is-collapsed .sidebar-footer { display: none; }
.sidebar-wrapper.is-collapsed .sidebar-rail { display: flex; }

/* ---- Resize handle (desktop): copied from /chat ---- */
/* The hit area starts on the sidebar's 1px border and extends 8px into the
   page, so it never covers the history list's scrollbar that hugs the
   sidebar's inner edge. The wrapper is position: fixed, so the handle
   hangs off its right edge instead of being a flex sibling like in /chat. */
.sidebar-wrapper.resizing { transition: none; }
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(100% - 1px);
    width: 9px;
    cursor: col-resize;
    z-index: 10;
    touch-action: none;
}
.sidebar-resize-handle::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 3px;
    border-radius: 2px;
    background: transparent;
    transition: background 0.15s ease;
}
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.dragging::after,
.sidebar-resize-handle:focus-visible::after {
    background: rgba(255, 255, 255, 0.25);
}
.sidebar-resize-handle:focus-visible { outline: none; }
.sidebar-resize-handle:focus-visible::after {
    width: 3px;
    background: rgba(255, 255, 255, 0.5);
}
.sidebar-wrapper.is-collapsed .sidebar-resize-handle { display: none; }
body.sidebar-resizing {
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
}
/* The page offset follows the drag frame by frame instead of easing after it */
body.sidebar-resizing .main-container { transition: none !important; }


/* ============================================================
   Mobile navbar (phones)
   ============================================================ */
.mobile-navbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-h);
    z-index: 40;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.navbar-logo-icon { width: 30px; height: 30px; }
.navbar-menu { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; font-size: 15px; font-weight: 600; }
.navbar-menu:hover { background: var(--hover); }
.navbar-menu-chevron { color: var(--text-3); }
.navbar-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.navbar-user-name { font-size: 13px; font-weight: 500; max-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.navbar-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.8);
}
.navbar-dropdown a { display: block; padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.navbar-dropdown a:hover { background: var(--hover); }
.navbar-dropdown a.is-active { background: var(--tertiary); color: var(--primary); }


/* ============================================================
   Page offset for the sidebar
   ============================================================ */
.main-container {
    height: 100%;
    padding-left: var(--sidebar-w);
    transition: padding-left 0.2s ease;
}
.app.sidebar-collapsed .main-container { padding-left: var(--sidebar-collapsed-w); }

@media (max-width: 900px) {
    .mobile-navbar { display: flex; }
    .sidebar-wrapper { display: none; }
    .main-container, .app.sidebar-collapsed .main-container { padding-left: 0; padding-top: var(--navbar-h); }
}
