/*
 * Pipali Styles - Sidebar Layout
 * Includes: sidebar, navigation, user profile, conversation list, chat modal
 */

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    height: 100dvh;
    background: var(--color-bg-sidebar);
    border-right: 1px solid var(--color-border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition), width var(--transition);
    overflow: hidden;
}

.sidebar.closed {
    width: 0;
    transform: translateX(-100%);
    border-right: none;
}

/* Mobile backdrop - hidden on desktop */
.sidebar-backdrop {
    display: none;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.sidebar-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header-row .new-chat-btn {
    flex: 1;
}

/* Close button - hidden on desktop, shown on mobile */
.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.sidebar-close-btn:hover {
    background: var(--color-bg-muted);
    color: var(--color-text);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition);
}

.new-chat-btn:hover {
    background: var(--color-bg-muted);
    border-color: var(--color-text-muted);
}

/* Sidebar Navigation */
.sidebar-nav {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.sidebar-nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.sidebar-nav-btn:hover {
    background: var(--color-bg-muted);
    color: var(--color-text);
}

.sidebar-nav-btn.active {
    background: var(--color-bg-muted);
    color: var(--color-text);
    font-weight: 500;
}

/* User Profile Section */
.sidebar-user-section {
    padding: 12px;
    border-top: 1px solid var(--color-border-subtle);
    margin-top: auto;
}

.user-profile-container {
    position: relative;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
    text-align: left;
}

.user-profile-btn:hover {
    background: var(--color-bg-muted);
}

.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--color-bg-muted);
    border-radius: 50%;
    color: var(--color-text-secondary);
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-avatar-initial {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    text-transform: uppercase;
    user-select: none;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    overflow: hidden;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
    transition: background var(--transition);
    text-align: left;
}

.user-menu-item:hover {
    background: var(--color-bg-muted);
}

.user-menu-item.danger {
    color: var(--color-error);
}

.user-menu-item.danger:hover {
    background: var(--color-error-bg);
}

.user-menu-info {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: center;
}

.user-menu-version-badge {
    margin-left: auto;
    font-size: 11px;
    color: var(--color-text-muted);
}

/* What's New / Changelog Modal */
.changelog-modal {
    max-width: 480px;
}

.changelog-content {
    padding: 16px 20px;
    overflow-y: auto;
    max-height: 60vh;
    font-size: 13px;
    line-height: 1.6;
    color: var(--color-text);
}

.changelog-content h3 {
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 8px;
}

.changelog-content h3:first-child {
    margin-top: 0;
}

.changelog-content ul {
    margin: 0 0 4px;
    padding-left: 20px;
}

.changelog-content li {
    margin-bottom: 4px;
}

.changelog-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-border-subtle);
    font-size: 12px;
}

.changelog-footer a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.changelog-footer a:hover {
    color: var(--color-text);
}

/* Theme Toggle in User Menu */
.user-menu-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.user-menu-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.theme-toggle-group {
    display: flex;
    gap: 2px;
    background: var(--color-bg-muted);
    padding: 2px;
    border-radius: var(--radius-md);
}

.theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.theme-toggle-btn:hover {
    color: var(--color-text);
    background: var(--color-bg-elevated);
}

.theme-toggle-btn.active {
    color: var(--color-text);
    background: var(--color-bg-elevated);
    box-shadow: var(--shadow-sm);
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    position: relative;
}

.conversation-item:focus-visible {
    outline: 2px solid rgba(23, 23, 23, 0.25);
    outline-offset: 2px;
}

.conversation-item:hover {
    background: var(--color-bg-muted);
    color: var(--color-text);
}

.conversation-item.active {
    background: var(--color-bg-elevated);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

/* Conversation info wrapper for title + subtitle */
.conversation-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conversation-icon {
    flex-shrink: 0;
}

.conversation-icon.running {
    color: var(--color-info);
    animation: spin 1s linear infinite;
}

.conversation-icon.needs-attention {
    color: var(--color-warning);
}

.conversation-icon.completed {
    color: var(--color-success);
}

.conversation-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-subtitle {
    font-size: 11px;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
    opacity: 0.8;
}

.conversation-match-snippet {
    font-size: 11px;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-rename-input {
    width: 100%;
    padding: 2px 6px;
    font-size: 13px;
    font-family: inherit;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    outline: none;
}

.conversation-menu-container {
    position: relative;
    display: flex;
    align-items: center;
}

.menu-btn {
    opacity: 0;
    padding: 4px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.conversation-item:hover .menu-btn {
    opacity: 1;
}

.conversation-item:focus-within .menu-btn {
    opacity: 1;
}

.menu-btn:hover {
    background: var(--color-bg-elevated);
    color: var(--color-text);
}

.conversation-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    overflow: hidden;
}

.conversation-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
    transition: background var(--transition);
    text-align: left;
}

.conversation-menu-item:hover:not(:disabled) {
    background: var(--color-bg-muted);
}

.conversation-menu-item:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.conversation-menu-item.danger {
    color: var(--color-error);
}

.conversation-menu-item.danger:hover:not(:disabled) {
    background: var(--color-error-bg);
}

.conversation-menu-submenu-container > .conversation-menu-item .submenu-arrow {
    margin-left: auto;
    opacity: 0.5;
    transition: transform var(--transition);
}

.conversation-menu-submenu-container.open > .conversation-menu-item .submenu-arrow {
    transform: rotate(90deg);
}

.conversation-submenu {
    display: none;
}

.conversation-menu-submenu-container.open > .conversation-submenu {
    display: block;
}

.conversation-submenu .conversation-menu-item {
    padding-left: 24px;
}

.no-conversations {
    padding: 24px 12px;
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* See More Button */
.see-more-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    margin-top: 4px;
    background: transparent;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.see-more-btn:hover {
    background: var(--color-bg-muted);
    border-color: var(--color-text-muted);
    color: var(--color-text);
}

.see-more-btn:focus-visible {
    outline: 2px solid rgba(23, 23, 23, 0.25);
    outline-offset: 2px;
}

/* Chat Modal Overlay */
.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: fade-in 0.15s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Chat Modal */
.chat-modal {
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 480px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    animation: modal-slide-up 0.2s ease-out;
}

@keyframes modal-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.chat-modal-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.chat-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.chat-modal-close:hover {
    background: var(--color-bg-muted);
    color: var(--color-text);
}

/* Chat Modal Search */
.chat-modal-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg-muted);
}

.chat-modal-search .search-icon {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

.chat-modal-search input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--color-text);
    outline: none;
}

.chat-modal-search input::placeholder {
    color: var(--color-text-muted);
}

.search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--color-border);
    border: none;
    border-radius: 50%;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.search-clear:hover {
    background: var(--color-text-muted);
    color: var(--color-bg-elevated);
}

.search-spinner {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

/* Chat Modal List */
.chat-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    min-height: 200px;
    max-height: 400px;
}

.chat-modal-list .conversation-item {
    margin-bottom: 2px;
}

.chat-modal-list .conversation-item.keyboard-selected {
    background: var(--color-bg-muted);
    outline: 1px solid var(--color-accent);
    outline-offset: -1px;
}

.chat-modal-list .no-conversations {
    padding: 40px 12px;
}

/* Chat Modal Footer */
.chat-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border-subtle);
    background: var(--color-bg-muted);
    gap: 12px;
}

.chat-count {
    font-size: 12px;
    color: var(--color-text-muted);
}

.keyboard-hint {
    font-size: 11px;
    color: var(--color-text-muted);
}

.keyboard-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    font-size: 10px;
    font-family: inherit;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    box-shadow: 0 1px 0 var(--color-border);
    margin: 0 1px;
}
