/* ============================================
   CHAT SIDEBAR - Unified History Panel
   Gemini-style sidebar inside the chat popup
   ============================================ */

/* Body wrapper: sidebar + main chat area, sits below header */
.modern-chat-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;
}

/* ── Sidebar ── */
.chat-sidebar {
    width: 280px;
    min-width: 280px;
    background: #f8f9fb;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, min-width 0.25s ease;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

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

.chat-sidebar-new-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #0e1369 0%, #06b8a0 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.chat-sidebar-new-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(6, 184, 160, 0.3);
}

.chat-sidebar-new-btn:active {
    transform: translateY(0);
}

.chat-sidebar-new-btn i {
    font-size: 12px;
}

/* ── Sidebar Search ── */
.chat-sidebar-search {
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chat-sidebar-search-wrap {
    position: relative;
}

.chat-sidebar-search-wrap i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #94a3b8;
    pointer-events: none;
}

.chat-sidebar-search-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    color: #1f2937;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-sidebar-search-input::placeholder {
    color: #94a3b8;
}

.chat-sidebar-search-input:focus {
    border-color: #06b8a0;
}

/* ── Sidebar Scrollable List ── */
.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

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

.chat-sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-sidebar-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.chat-sidebar-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ── Time Group Headers ── */
.chat-sidebar-group {
    padding: 0 8px;
}

.chat-sidebar-group-label {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 12px 4px;
    user-select: none;
}

/* ── Chat Item ── */
.chat-sidebar-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
    margin: 1px 0;
    position: relative;
    gap: 10px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.chat-sidebar-item:hover {
    background: #eef1f6;
}

.chat-sidebar-item.active {
    background: #e0e7f1;
}

.chat-sidebar-item.active .chat-sidebar-item-title {
    color: #0e1369;
    font-weight: 600;
}

/* Icon */
.chat-sidebar-item-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(14, 19, 105, 0.08) 0%, rgba(6, 184, 160, 0.08) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0e1369;
    font-size: 13px;
    flex-shrink: 0;
}

.chat-sidebar-item.active .chat-sidebar-item-icon {
    background: linear-gradient(135deg, #0e1369 0%, #06b8a0 100%);
    color: white;
}

/* Content */
.chat-sidebar-item-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-sidebar-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.chat-sidebar-item-snippet {
    font-size: 11px;
    color: #64748b;
    line-height: 1.4;
    margin-top: 2px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.chat-sidebar-item-snippet mark {
    background: rgba(6, 184, 160, 0.25);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.chat-sidebar-item-meta {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ··· Actions Button (visible on hover) */
.chat-sidebar-item-actions {
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.chat-sidebar-item:hover .chat-sidebar-item-actions {
    opacity: 1;
}

.chat-sidebar-actions-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s ease;
}

.chat-sidebar-actions-btn:hover {
    background: #dde2ea;
    color: #64748b;
}

/* ── Actions Dropdown ── */
.chat-sidebar-actions-menu {
    position: absolute;
    right: 8px;
    top: 100%;
    z-index: 200;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: 4px;
    min-width: 160px;
    display: none;
}

.chat-sidebar-actions-menu.open {
    display: block;
}

.chat-sidebar-action-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    font-family: inherit;
    transition: background 0.15s ease;
}

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

.chat-sidebar-action-item i {
    width: 16px;
    text-align: center;
    font-size: 12px;
    color: #64748b;
}

.chat-sidebar-action-item.danger {
    color: #dc2626;
}

.chat-sidebar-action-item.danger i {
    color: #dc2626;
}

.chat-sidebar-action-item.danger:hover {
    background: #fef2f2;
}

/* ── Inline Rename ── */
.chat-sidebar-item-title.editing {
    background: white;
    border: 1px solid #06b8a0;
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    cursor: text;
}

/* ── Folders Section ── */
.chat-sidebar-folders-section {
    border-top: 1px solid #e2e8f0;
    margin-top: 4px;
}

.chat-sidebar-folders-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 4px;
}

.chat-sidebar-folders-label {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-sidebar-folders-label i {
    font-size: 10px;
}

.chat-sidebar-add-folder-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s ease;
}

.chat-sidebar-add-folder-btn:hover {
    background: #e2e8f0;
    color: #64748b;
}

/* Folder Item */
.chat-sidebar-folder {
    padding: 0 8px;
}

.chat-sidebar-folder-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    user-select: none;
}

.chat-sidebar-folder-header:hover {
    background: #eef1f6;
}

.chat-sidebar-folder-header i.folder-icon {
    font-size: 13px;
    color: #64748b;
}

.chat-sidebar-folder-header i.chevron-icon {
    font-size: 10px;
    color: #9ca3af;
    transition: transform 0.2s ease;
}

.chat-sidebar-folder-header i.chevron-icon.expanded {
    transform: rotate(90deg);
}

.chat-sidebar-folder-name {
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
    flex: 1;
}

.chat-sidebar-folder-count {
    font-size: 11px;
    color: #9ca3af;
}

.chat-sidebar-folder-content {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.2s ease;
    padding-left: 8px;
}

.chat-sidebar-folder-content.expanded {
    max-height: 1000px;
}

/* ── Empty State ── */
.chat-sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
}

.chat-sidebar-empty i {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.chat-sidebar-empty p {
    font-size: 13px;
    margin: 0;
    line-height: 1.5;
}

/* ── No Search Results ── */
.chat-sidebar-no-results {
    padding: 24px 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

.chat-sidebar-no-results i {
    display: block;
    font-size: 24px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ── Resize Handle between Sidebar and Chat ── */
.chat-sidebar-resize-handle {
    width: 6px;
    min-width: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    z-index: 10;
    transition: background 0.15s ease;
}

.chat-sidebar-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 32px;
    border-radius: 2px;
    background: #d1d5db;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.chat-sidebar-resize-handle:hover::after,
.chat-sidebar-resize-handle.dragging::after {
    opacity: 1;
}

.chat-sidebar-resize-handle:hover {
    background: rgba(6, 184, 160, 0.06);
}

.chat-sidebar-resize-handle.dragging {
    background: rgba(6, 184, 160, 0.1);
}

.chat-sidebar-resize-handle.dragging::after {
    background: #06b8a0;
    opacity: 1;
}

/* Hide resize handle when sidebar is collapsed */
.chat-sidebar.collapsed + .chat-sidebar-resize-handle {
    display: none;
}

/* ── Main Chat Area Wrapper ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Persistent Sidebar Toggle Tab ── */
.chat-sidebar-toggle-tab {
    width: 20px;
    min-width: 20px;
    background: #f0f1f4;
    border: none;
    border-left: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #94a3b8;
    font-size: 12px;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
    z-index: 11;
}

.chat-sidebar-toggle-tab:hover {
    background: #e2e6eb;
    color: #06b8a0;
}

/* ── Mobile Overlay ── */
.chat-sidebar-mobile-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.chat-sidebar-mobile-backdrop.visible {
    opacity: 1;
}

/* ── Container Adjustment ── */
/* Increase max-width to accommodate sidebar */
.modern-chat-container {
    max-width: 1400px;
}

/* ── Responsive ── */

/* Tablet: narrower sidebar */
@media (max-width: 1024px) {
    .chat-sidebar {
        width: 240px;
        min-width: 240px;
    }
}

/* Mobile: sidebar as slide-over */
@media (max-width: 768px) {
    .modern-chat-body {
        position: relative;
    }

    .chat-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        width: 85vw;
        max-width: 320px;
        min-width: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
        background: #f8f9fb;
    }

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

    /* On mobile, collapsed means offscreen via transform, not width: 0 */
    .chat-sidebar.collapsed {
        width: 85vw;
        max-width: 320px;
        min-width: 0;
        opacity: 1;
        border-right: 1px solid #e2e8f0;
        transform: translateX(-100%);
    }

    .chat-sidebar-resize-handle {
        display: none;
    }

    .chat-sidebar-toggle-tab {
        position: absolute;
        left: 0;
        top: 8px;
        width: 24px;
        height: 36px;
        border-radius: 0 6px 6px 0;
        border: 1px solid #e2e8f0;
        border-left: none;
        background: white;
        box-shadow: 2px 1px 4px rgba(0,0,0,0.08);
        z-index: 98;
    }

    .chat-sidebar-mobile-backdrop {
        display: block;
        pointer-events: none;
    }

    .chat-sidebar-mobile-backdrop.visible {
        pointer-events: all;
    }

    /* Always show actions on mobile (no hover) */
    .chat-sidebar-item-actions {
        opacity: 1;
    }
}

/* ── Drop Zone Highlight for Folder Drag ── */
.chat-sidebar-folder.drag-over .chat-sidebar-folder-header {
    background: rgba(6, 184, 160, 0.1);
    outline: 2px dashed #06b8a0;
    outline-offset: -2px;
}

/* ── Shared Chats Section ── */
.chat-sidebar-shared-section {
    margin-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}

.chat-sidebar-shared-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: #64748b;
}

.chat-sidebar-shared-header:hover {
    background: #f3f0ff;
}

.chat-sidebar-shared-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #7c3aed;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-sidebar-shared-content {
    display: none;
    padding-left: 4px;
}

.chat-sidebar-shared-content.expanded {
    display: block;
}

.shared-chat-item {
    border-left: 2px solid #8b5cf6;
    margin-left: 8px;
}

.chat-sidebar-shared-header i.chevron-icon {
    font-size: 10px;
    color: #9ca3af;
    transition: transform 0.2s;
}

.chat-sidebar-shared-header i.chevron-icon.expanded {
    transform: rotate(90deg);
}
