/* === Sidebar === */

/* Action Buttons (New Chat / Folder) */
.sidebar-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 0;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.02em;
}

.sidebar-action-btn i {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.sidebar-action-btn:hover i {
    transform: scale(1.15);
}

.sidebar-action-btn:active {
    transform: scale(0.97);
}

.sidebar-action-primary {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.18) 0%, rgba(139, 92, 246, 0.12) 100%);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
}

.sidebar-action-primary:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3) 0%, rgba(139, 92, 246, 0.2) 100%);
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: #bfdbfe;
}

.sidebar-action-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 60%);
    pointer-events: none;
    transition: opacity 0.3s ease;
    opacity: 0;
}

.sidebar-action-primary:hover .sidebar-action-glow {
    opacity: 1;
}

.sidebar-action-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: #64748b;
    border-color: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(12px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.sidebar-action-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    color: #94a3b8;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.03), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.search-highlight {
    background: rgba(250, 204, 21, 0.4);
    color: #fff;
    border-radius: 2px;
    font-weight: 600;
}

.folder,
.chat-item {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    padding: 7px 10px;
    border-radius: 10px;
    transition: background 0.2s ease, border-color 0.2s ease;
    border: 1px solid transparent;
    margin-bottom: 2px;
    position: relative;
}

.folder:hover,
.chat-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.08);
}

.folder-content {
    display: none;
    margin-left: 16px;
    padding-left: 4px;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-item.dragging {
    opacity: 0.4;
    transform: scale(0.98);
}

.active-chat {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.22) 0%, rgba(139, 92, 246, 0.14) 100%);
    border-color: rgba(59, 130, 246, 0.35);
    font-weight: 600;
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(8px);
    color: #e0eaff;
}

.active-chat:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.28) 0%, rgba(139, 92, 246, 0.18) 100%);
    border-color: rgba(59, 130, 246, 0.45);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#sidebar {
    transition: transform 0.3s ease;
}

#sidebar.hidden {
    transform: translateX(-100%);
}

.hamburger {
    font-size: 1.75rem;
    margin-right: 0.5rem;
    cursor: pointer;
    position: absolute;
    right: 10px;
    top: 7px;
    color: #94a3b8;
    transition: transform 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

#clear-search {
    top: unset;
}

@media (max-width: 768px) {
    #clear-search {
        transform: translateY(-50%) !important;
    }
}

/* Sort controls */
.chat-sort-btn {
    color: #64748b;
    cursor: pointer;
    border: 1px solid transparent;
    background: none;
    transition: all 0.2s ease;
    border-radius: 6px;
    padding: 3px 7px;
}

.chat-sort-btn:hover {
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.05);
}

.chat-sort-btn.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}


/* Chat actions dropdown */
.chat-actions-dropdown {
    position: absolute;
    right: 0;
    background: rgb(15, 23, 42);
    min-width: 160px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.1);
    z-index: 50;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    overflow: hidden;
    padding: 4px;
}

.chat-actions-dropdown button {
    color: #cbd5e1;
    padding: 9px 14px;
    text-decoration: none;
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 7px;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.chat-actions-dropdown button:hover {
    background-color: #4a5568;
}

.chat-actions-dropdown.hidden {
    display: none;
}


[id^="chat-item-"] > div > div {
    width: 120px;
}

/* Resize handle */
#resize-handle {
    display: none;
    width: 25px;
    background: linear-gradient(to right, transparent, #4a5568 30%, #6b7280 50%, #4a5568 70%, transparent);
    position: relative;
    cursor: col-resize;
    transition: all 0.2s ease;
    border-radius: 3px;
}

#resize-handle:hover {
    background: linear-gradient(to right, transparent, #6b7280 20%, #9ca3af 50%, #6b7280 80%, transparent);
    width: 25px;
    box-shadow: 0 0 8px rgba(156, 163, 175, 0.3);
}

#resize-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 20px;
    background: repeating-linear-gradient(
        to bottom,
        #9ca3af 0px,
        #9ca3af 2px,
        transparent 2px,
        transparent 4px
    );
    border-radius: 1px;
    opacity: 0.7;
}

#resize-handle:hover::before {
    opacity: 1;
    background: repeating-linear-gradient(
        to bottom,
        #e5e7eb 0px,
        #e5e7eb 2px,
        transparent 2px,
        transparent 4px
    );
}

/* Sidebar scrollbar */
#sidebar::-webkit-scrollbar {
    width: 5px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

#sidebar {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* Sidebar responsive */
@media (min-width: 1200px) {
    #sidebar {
        transform: translateX(0);
    }

    .hamburger {
        display: none;
    }
}

@media (max-width: 1200px) {
    .w-64 {
        width: 30rem;
    }
}

@media (min-width: 600px) {
    #chat-list>div>div.folder-content>div.chat-drop-area {
        font-size: unset;
    }

    .w-64 {
        width: 22rem;
    }

    #chat-list {
        font-size: 15px;
    }

    [id^="chat-item-"]>button.text-left.flex-grow.hover\:bg-gray-700.p-2.rounded.bg-gray-800.text-white {
        padding: .3rem !important;
    }

    .folder,
    .chat-item {
        padding: 4px;
    }

    .space-y-2>:not([hidden])~:not([hidden]) {
        margin-top: 0px;
    }

    .py-2 {
        padding-top: .3rem !important;
        padding-bottom: .3rem !important;
    }

    .px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .mb-4 {
        margin-bottom: 0.5rem !important;
    }

    .mt-4 {
        margin-top: 0.5rem !important;
    }

    #sidebar {
        font-size: 14px;
    }

    #resize-handle {
        display: block;
    }
}

/* Credit Usage Widget */
/* Sidebar Footer — always visible at bottom */
#sidebar-footer {
    flex-shrink: 0;
    margin: 0 -16px -16px;
    padding: 12px 16px 14px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.6) 0%, rgba(15, 23, 42, 0.95) 30%);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(99, 102, 241, 0.12);
}

.sidebar-footer-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.sidebar-footer-btn {
    flex: 1;
    padding: 7px 0;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.sidebar-footer-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.15);
}

.sidebar-footer-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

.sidebar-footer-links {
    display: flex;
    gap: 12px;
}

.sidebar-footer-links a {
    color: #4b5563;
    font-size: 11px;
    text-decoration: none;
    transition: color 0.2s;
}

.sidebar-footer-links a:hover {
    color: #9ca3af;
}

.sidebar-footer-logout {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #4b5563;
    cursor: pointer;
    font-size: 13px;
    padding: 5px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-footer-logout:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

.credit-widget {
    padding: 8px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.credit-widget-bar-bg {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 99px;
    overflow: hidden;
}

.credit-widget-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: #22c55e;
    transition: width 0.6s ease, background 0.4s ease;
}

.credit-widget-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.credit-widget-info span {
    font-size: 12px;
    color: #9ca3af;
}

.sidebar-footer-manage-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    cursor: pointer;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-footer-manage-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.15);
}

.sidebar-footer-manage-btn.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
}

#credit-widget-btn {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(245, 158, 11, 0.06));
    border: 1px solid rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    cursor: pointer;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

#credit-widget-btn:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(245, 158, 11, 0.12));
    border-color: rgba(251, 191, 36, 0.4);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.1);
    color: #fde68a;
}

.credit-widget-reset {
    font-size: 11px;
    color: #6b7280;
}

/* === Aero-style search progress fill === */
.search-progress {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, rgba(59, 130, 246, .1), rgba(59, 130, 246, .18));
    border-radius: inherit;
    transition: width .3s ease, opacity .4s ease;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.search-progress::after {
    content: '';
    position: absolute;
    top: 0;
    right: -12px;
    bottom: 0;
    width: 28px;
    background: linear-gradient(90deg, rgba(59, 130, 246, .18), transparent);
    transform: skewX(-20deg);
}

.search-progress::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 30%, rgba(255, 255, 255, .1) 50%, transparent 70%);
    background-size: 200% 100%;
    animation: aero-wave 1.8s ease-in-out infinite;
}

.search-progress.done {
    opacity: 0;
}

@keyframes aero-wave {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* === Message search preview under chat title === */
[id^="chat-item-"] > button {
    overflow: hidden;
    min-width: 0;
}

.msg-preview {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.msg-preview i {
    font-size: 9px;
    margin-right: 5px;
    color: #6b7280;
}

.msg-preview .search-highlight {
    background: rgba(250, 204, 21, 0.5);
    font-weight: 600;
    border-radius: 2px;
    padding: 0 1px;
}

/* === Search term highlight inside message content === */
.search-highlight-msg {
    background: rgba(250, 204, 21, 0.45);
    color: #fff;
    border-radius: 2px;
    font-weight: 600;
    box-shadow: 0 0 8px rgba(250, 204, 21, 0.3);
}

/* === Target message highlight flash === */
.search-target-highlight {
    animation: search-target-flash 2.5s ease-out forwards;
    border-radius: 8px;
}

@keyframes search-target-flash {
    0%, 20% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.5), 0 0 20px rgba(250, 204, 21, 0.15); }
    100%    { box-shadow: 0 0 0 3px transparent, 0 0 20px transparent; }
}

/* === Streaming Indicator on Chat Items === */
.chat-stream-indicator {
    display: inline-block;
    margin-left: 6px;
    font-size: 11px;
    letter-spacing: 2px;
    color: #818cf8;
    vertical-align: middle;
}
.chat-stream-indicator::after {
    content: '···';
    animation: stream-dots 1.4s steps(4, end) infinite;
}
@keyframes stream-dots {
    0%   { content: '   '; }
    25%  { content: '·  '; }
    50%  { content: '·· '; }
    75%  { content: '···'; }
    100% { content: '   '; }
}

/* Glassmorphic wave glow on streaming chat item */
.chat-item.is-streaming {
    position: relative;
}
.chat-item.is-streaming::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(129, 140, 248, 0.15) 15%,
        rgba(99, 102, 241, 0.3) 50%,
        rgba(129, 140, 248, 0.15) 85%,
        transparent 100%
    );
    animation: stream-wave 1.8s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}
.chat-item.is-streaming > * {
    position: relative;
    z-index: 1;
}
@keyframes stream-wave {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
