/* ==================== Chat History Sidebar ==================== */

/* Backdrop (mobile only) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.visible {
    display: block;
    opacity: 1;
}

/* Sidebar panel */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
}

/* Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.sidebar-new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    color: #1e293b;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.sidebar-new-chat-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}

.sidebar-close-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Sessions list */
.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-sessions::-webkit-scrollbar {
    width: 4px;
}

.sidebar-sessions::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

/* Date group label */
.sidebar-date-group {
    padding: 12px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Session item */
.sidebar-session-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-session-item:hover {
    background: #f1f5f9;
}

.sidebar-session-item.active {
    background: #eff6ff;
    border-left-color: #3b82f6;
}

.sidebar-session-title {
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.sidebar-session-item.active .sidebar-session-title {
    color: #1d4ed8;
}

.sidebar-session-date {
    font-size: 11px;
    color: #94a3b8;
}

.sidebar-session-mode {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: middle;
}

.sidebar-session-mode.mode-quick { background: #eff6ff; color: #2563eb; }
.sidebar-session-mode.mode-research { background: #f5f3ff; color: #7c3aed; }
.sidebar-session-mode.mode-nearby { background: #ecfdf5; color: #059669; }

/* Empty state */
.sidebar-empty {
    padding: 32px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

/* Toggle button (injected into page headers) */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* ==================== Desktop Layout ==================== */

@media (min-width: 769px) {
    .sidebar-backdrop {
        display: none !important;
    }

    .sidebar {
        transform: translateX(0);
    }

    /* Push main content right when sidebar is open */
    body.sidebar-open #chat-screen,
    body.sidebar-open .nearby-screen {
        margin-left: 280px;
        width: calc(100% - 280px);
        transition: margin-left 0.3s ease, width 0.3s ease;
    }

    /* Collapsed state */
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-collapsed #chat-screen,
    body.sidebar-collapsed .nearby-screen {
        margin-left: 0;
        width: 100%;
    }

    /* Adjust scroll-to-bottom button position */
    body.sidebar-open:not(.sidebar-collapsed) .scroll-to-bottom-btn,
    body.sidebar-open:not(.sidebar-collapsed) .nearby-scroll-btn {
        left: calc(50% + 140px);
    }
}


/* Landing page: always use overlay-style sidebar (hidden by default, slide-in on toggle) */
body.landing-page .sidebar {
    transform: translateX(-100%);
}

body.landing-page .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
}

body.landing-page .sidebar-backdrop {
    display: block !important;
    pointer-events: none; /* Don't block clicks when invisible */
}

body.landing-page .sidebar-backdrop.visible {
    pointer-events: auto; /* Block clicks only when backdrop is shown */
}

/* ==================== Mobile Layout ==================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }
}
