/* ===========================================
   MedOrbit v2 - Conversation Sidebar
   JWT-gated conversation list (history, rename, delete, search)
   =========================================== */

.sidebar-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border);
    overflow: hidden;
}

[dir="rtl"] .sidebar-panel {
    border-left: none;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-new-btn {
    width: 100%;
}

.sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-search i {
    color: var(--text-mute);
    font-size: 12px;
}

.sidebar-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 13px;
    color: var(--text);
}

.sidebar-search input::placeholder {
    color: var(--text-faint);
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 10px;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background var(--t-fast);
}

.sidebar-item:hover {
    background: var(--bg-soft);
}

.sidebar-item.active {
    background: var(--primary-50);
}

[data-theme="dark"] .sidebar-item.active {
    background: rgba(37, 99, 235, 0.15);
}

.sidebar-item-main {
    flex: 1;
    min-width: 0;
}

.sidebar-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-item.active .sidebar-item-title {
    color: var(--primary);
}

.sidebar-item-meta {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}

.sidebar-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--t-fast);
    flex-shrink: 0;
}

.sidebar-item:hover .sidebar-item-actions {
    opacity: 1;
}

.sidebar-item-btn {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    color: var(--text-mute);
    font-size: 11px;
    transition: all var(--t-fast);
}

.sidebar-item-btn:hover {
    background: var(--bg-card);
    color: var(--text);
}

.sidebar-rename-input {
    width: 100%;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-card);
    border: 1.5px solid var(--primary);
    border-radius: var(--r-sm);
    padding: 3px 6px;
    outline: none;
}

.sidebar-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-faint);
}

.sidebar-empty i {
    font-size: 22px;
    margin-bottom: 8px;
    display: block;
}

.sidebar-empty p {
    font-size: 12.5px;
}

/* === Grid integration: reserve a column only when the sidebar is enabled === */
#app.sidebar-enabled .app-main {
    grid-template-columns: 260px 440px 1fr;
}

#app.sidebar-enabled.sidebar-collapsed .app-main {
    grid-template-columns: 440px 1fr;
}

#app.sidebar-enabled.sidebar-collapsed .sidebar-panel {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

/* === Mobile: sidebar becomes a slide-in drawer instead of a grid column === */
@media (max-width: 768px) {
    #app.sidebar-enabled .app-main {
        grid-template-columns: 1fr;
    }

    /* Mobile uses the slide-in drawer (.sidebar-open on the panel itself)
       instead of the desktop collapse mechanism — always keep it in the
       DOM/flex flow here so the transform-based drawer can show it. */
    #app.sidebar-enabled.sidebar-collapsed .sidebar-panel {
        display: flex;
    }

    .sidebar-panel {
        position: fixed;
        inset-inline-start: 0;
        top: var(--header-h);
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: var(--z-modal);
        transform: translateX(-100%);
        transition: transform var(--t-base);
        box-shadow: var(--shadow-xl);
    }

    [dir="rtl"] .sidebar-panel {
        transform: translateX(100%);
    }

    .sidebar-panel.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-backdrop.visible {
        display: block;
        position: fixed;
        inset: 0;
        top: var(--header-h);
        background: var(--bg-overlay);
        z-index: calc(var(--z-modal) - 1);
    }
}
