/* ═══════════════════════════════════════════════
   Chat History Sidebar
   ═══════════════════════════════════════════════ */

/* ── Toggle button in nav ── */
.history-toggle-btn {
    display: flex;               /* always visible */
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    background: transparent;
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.history-toggle-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
}
.history-toggle-btn.active {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.25);
    color: #fff;
}

/* ── Backdrop ── */
.history-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}
.history-backdrop.open {
    opacity: 1;
    pointer-events: all;
}

/* ── Sidebar panel ── */
.history-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 272px;
    height: 100vh;
    background: rgba(13,13,20,0.97);
    border-right: 1px solid rgba(255,255,255,0.07);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 40px rgba(0,0,0,0.5);
}
.history-sidebar.open {
    transform: translateX(0);
}

/* ── Sidebar header ── */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.history-header-title {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
    letter-spacing: 0.3px;
}
.history-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.4);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.history-close-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* ── New chat button ── */
.history-new-btn {
    margin: 12px 14px 8px;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
    flex-shrink: 0;
}
.history-new-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
}
.history-new-btn svg { flex-shrink: 0; }

/* ── Scrollable list ── */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Date group label ── */
.history-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 14px 8px 5px;
}

/* ── Individual chat item ── */
.history-item {
    width: 100%;
    text-align: left;
    padding: 9px 10px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.history-item:hover {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.9);
}
.history-item.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
.history-item-icon {
    flex-shrink: 0;
    opacity: 0.4;
}
.history-item-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* ── State messages ── */
.history-loading,
.history-empty {
    font-size: 12px;
    color: rgba(255,255,255,0.28);
    text-align: center;
    padding: 32px 16px;
    line-height: 1.6;
}

/* ── Auth / upgrade gate ── */
.history-gate {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px 24px;
    gap: 8px;
}
.history-gate-icon {
    font-size: 28px;
    margin-bottom: 4px;
    opacity: 0.6;
}
.history-gate-title {
    font-size: 14px;
    font-weight: 700;
    color: rgba(255,255,255,0.8);
    margin: 0;
}
.history-gate-sub {
    font-size: 12px;
    color: rgba(255,255,255,0.35);
    margin: 0 0 10px;
    line-height: 1.5;
}
.history-gate-btn {
    padding: 9px 22px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.8);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
}
.history-gate-btn:hover { background: rgba(255,255,255,0.13); color: #fff; }
.history-gate-btn-upgrade {
    background: linear-gradient(135deg, #6d28d9, #a78bfa);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 3px 14px rgba(124,58,237,0.35);
}
.history-gate-btn-upgrade:hover { opacity: 0.88; }

/* ── Light theme ── */
[data-theme="light"] .history-toggle-btn,
[data-theme="system"] .history-toggle-btn {
    border-color: rgba(0,0,0,0.1);
    color: rgba(0,0,0,0.5);
}
[data-theme="light"] .history-toggle-btn:hover,
[data-theme="system"] .history-toggle-btn:hover {
    background: rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.18);
    color: #000;
}
[data-theme="light"] .history-toggle-btn.active,
[data-theme="system"] .history-toggle-btn.active {
    background: rgba(0,0,0,0.08);
    color: #000;
}
[data-theme="light"] .history-sidebar,
[data-theme="system"] .history-sidebar {
    background: rgba(248,248,250,0.98);
    border-color: rgba(0,0,0,0.08);
    box-shadow: 4px 0 40px rgba(0,0,0,0.12);
}
[data-theme="light"] .history-backdrop,
[data-theme="system"] .history-backdrop {
    background: rgba(0,0,0,0.25);
}
[data-theme="light"] .history-header,
[data-theme="system"] .history-header { border-color: rgba(0,0,0,0.07); }
[data-theme="light"] .history-header-title,
[data-theme="system"] .history-header-title { color: rgba(0,0,0,0.65); }
[data-theme="light"] .history-close-btn,
[data-theme="system"] .history-close-btn { color: rgba(0,0,0,0.4); }
[data-theme="light"] .history-close-btn:hover,
[data-theme="system"] .history-close-btn:hover { background: rgba(0,0,0,0.06); color: #000; }
[data-theme="light"] .history-new-btn,
[data-theme="system"] .history-new-btn {
    border-color: rgba(0,0,0,0.1);
    background: rgba(0,0,0,0.025);
    color: rgba(0,0,0,0.65);
}
[data-theme="light"] .history-new-btn:hover,
[data-theme="system"] .history-new-btn:hover {
    background: rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.18);
    color: #000;
}
[data-theme="light"] .history-group-label,
[data-theme="system"] .history-group-label { color: rgba(0,0,0,0.28); }
[data-theme="light"] .history-item,
[data-theme="system"] .history-item { color: rgba(0,0,0,0.6); }
[data-theme="light"] .history-item:hover,
[data-theme="system"] .history-item:hover { background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.9); }
[data-theme="light"] .history-item.active,
[data-theme="system"] .history-item.active { background: rgba(0,0,0,0.08); color: #000; }
[data-theme="light"] .history-loading,
[data-theme="light"] .history-empty,
[data-theme="system"] .history-loading,
[data-theme="system"] .history-empty { color: rgba(0,0,0,0.3); }
[data-theme="light"] .history-gate-title,
[data-theme="system"] .history-gate-title { color: rgba(0,0,0,0.75); }
[data-theme="light"] .history-gate-sub,
[data-theme="system"] .history-gate-sub { color: rgba(0,0,0,0.4); }
[data-theme="light"] .history-gate-btn,
[data-theme="system"] .history-gate-btn {
    border-color: rgba(0,0,0,0.12);
    background: rgba(0,0,0,0.05);
    color: rgba(0,0,0,0.7);
}
[data-theme="light"] .history-gate-btn:hover,
[data-theme="system"] .history-gate-btn:hover { background: rgba(0,0,0,0.09); color: #000; }

/* ── Mobile ── */
@media (max-width: 600px) {
    .history-sidebar { width: 80vw; max-width: 300px; }
}
