/* ============================================
   Modern Sidebar - ChatGPT Style
   Floating Design with Shadow
   ============================================ */

/* ============================================
   iOS BACK-SWIPE GESTURE DEAKTIVIEREN
   Verhindert Konflikt mit Sidebar-Swipe
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* Nur für iOS Safari */
    html, body {
        overscroll-behavior-x: none;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Verhindere horizontale Overscroll-Bounce */
    body {
        overflow-x: hidden;
        position: fixed;
        width: 100%;
    }
}

/* iOS Back-Swipe auch für standalone PWA deaktivieren */
@media (display-mode: standalone) {
    html, body {
        overscroll-behavior-x: none;
    }
}


/* App Layout - Flexbox Container für Sidebar + Main Content */
.app-layout {
    display: flex;
    flex-direction: row;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    position: relative;
}

/* Main Content Area - Nimmt immer volle Breite ein */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 32px 40px;
    overflow-y: auto;
    background: #f5f5f7;
    display: flex;
    flex-direction: column;
}

/* Desktop: Content-Bereich verschiebt sich mit Sidebar */
@media (min-width: 769px) {
    .main-content {
        margin-left: 304px; /* Sidebar width (280px) + left margin (12px) + gap (12px) */
        transition: margin-left 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    }
    
    /* Wenn Sidebar geschlossen ist, Content ganz links */
    body:has(.sidebar.collapsed) .main-content {
        margin-left: 0;
    }
}

/* ============================================
   SIDEBAR - Floating Design
   ============================================ */
.sidebar {
    position: fixed;
    top: 12px;
    left: 12px;
    bottom: 12px;
    width: 280px;
    background: #F7F7F8;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    height: calc(100% - 24px);
    flex-shrink: 0;
    font-family: 'Söhne', -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
    z-index: 100;
    
    /* Elegant Shadow */
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 4px 8px rgba(0, 0, 0, 0.04),
        0 12px 24px rgba(0, 0, 0, 0.06),
        0 24px 48px rgba(0, 0, 0, 0.08);
    
    /* Smooth Transitions - 350ms mit optimierter Easing-Funktion */
    transition: transform 0.35s cubic-bezier(0.4, 0.0, 0.2, 1), 
                opacity 0.35s cubic-bezier(0.4, 0.0, 0.2, 1),
                box-shadow 0.25s ease;
    
    /* Initial state for animation */
    transform: translateX(0);
    opacity: 1;
}

/* Collapsed State - Desktop */
.sidebar.collapsed {
    transform: translateX(-300px);
    opacity: 0;
    pointer-events: none;
}

/* ============================================
   SIDEBAR HEADER
   ============================================ */
.sidebar-header {
    padding: 16px 16px 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* iOS Safe Area für Sidebar Header auf Mobile */
@media (max-width: 768px) {
    .sidebar-header {
        padding-top: calc(16px + env(safe-area-inset-top, 0));
    }
}

.brand-title {
    font-family: 'Söhne', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: #202123;
    text-decoration: none;
    letter-spacing: -0.3px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 0;
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: contain;
    /* Light Mode: dünner schwarzer Rahmen */
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Dark Mode: Rahmen entfernen */
body.dark-mode .brand-logo {
    border-color: transparent;
}

.brand-title:hover {
    color: #10a37f;
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: #6e6e80;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.sidebar-toggle-btn:hover {
    background: #f0f0f0;
    color: #202123;
}

/* ============================================
   SIDEBAR OPEN BUTTON (When Collapsed)
   ============================================ */
.sidebar-open-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 50;
    background: #FFFFFF;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 10px;
    color: #40414F;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.08),
        0 4px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.sidebar-open-btn:hover {
    background: #f7f7f8;
    transform: scale(1.05);
    box-shadow: 
        0 4px 8px rgba(0, 0, 0, 0.1),
        0 8px 16px rgba(0, 0, 0, 0.1);
}

/* iOS Touch Fix - Ensure button is clickable */
.sidebar-open-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.sidebar-open-btn .icon-desktop {
    display: block;
}

.sidebar-open-btn .icon-mobile {
    display: none;
}

/* ============================================
   SIDEBAR OVERLAY (Mobile only)
   ============================================ */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0.0, 0.2, 1),
                visibility 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    pointer-events: none;
}

/* Mobile: Overlay mit Blur aktiv */
@media (max-width: 768px) {
    .sidebar-overlay {
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

/* Desktop: Overlay komplett deaktiviert */
@media (min-width: 769px) {
    .sidebar-overlay {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    .sidebar-overlay.active {
        display: none !important;
    }
}

/* ============================================
   NAVIGATION
   ============================================ */
.sidebar-nav {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    color: #202123;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.new-chat-btn:hover {
    background: #EAEAEB;
}

.new-chat-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #202123;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: #353740;
    text-decoration: none;
    border-radius: 10px;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    background: #EAEAEB;
    color: #202123;
}

.nav-item.active {
    background: #E5E5E6;
    color: #202123;
    font-weight: 500;
}

.nav-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.nav-item svg {
    flex-shrink: 0;
    color: #6e6e80;
}

.nav-item:hover svg,
.nav-item.active svg {
    color: #202123;
}

/* ============================================
   DIVIDER & SECTION TITLE
   ============================================ */
.sidebar-divider {
    height: 1px;
    background: #e5e5e5;
    margin: 12px 16px;
}

.sidebar-section-title {
    font-size: 12px;
    font-weight: 700;
    color: #202123;
    padding: 8px 20px 6px 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   HISTORY LIST (Chat Sessions)
   ============================================ */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
    margin-bottom: 8px;
    
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #d1d1d1 transparent;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: #d1d1d1;
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

.history-item {
    position: relative;
    border-radius: 10px;
    margin-bottom: 2px;
    transition: background 0.15s;
}

.history-item:hover {
    background: #EAEAEB;
}

.history-item.active {
    background: #E5E5E6;
}

.history-link {
    display: block;
    padding: 10px 40px 10px 12px;
    color: #353740;
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s;
}

.history-item:hover .history-link,
.history-item.active .history-link {
    color: #202123;
}

/* ============================================
   THREE DOTS MENU BUTTON - Improved Visibility
   ============================================ */
.history-options-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6e6e80;
    cursor: pointer;
    border-radius: 6px;
    background: transparent;
    border: none;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

/* Always visible on touch devices */
@media (hover: none) {
    .history-options-btn {
        opacity: 0.7;
    }
}

/* Show on hover (Desktop) */
@media (hover: hover) {
    .history-item:hover .history-options-btn {
        opacity: 1;
    }
}

.history-options-btn:hover {
    background: #e0e0e0;
    color: #202123;
}

.history-options-btn.active {
    opacity: 1;
    background: #e0e0e0;
    color: #202123;
}

.history-options-btn svg {
    width: 18px;
    height: 18px;
}

/* ============================================
   OPTIONS DROPDOWN
   ============================================ */
.options-dropdown {
    position: fixed;
    background: #FFFFFF;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    min-width: 180px;
    display: none;
    padding: 6px;
    animation: dropdownFadeIn 0.15s ease;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.options-dropdown.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: #353740;
    text-decoration: none;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-item svg {
    flex-shrink: 0;
    color: #6e6e80;
}

.dropdown-item.danger {
    color: #ef4444;
}

.dropdown-item.danger svg {
    color: #ef4444;
}

.dropdown-item.danger:hover {
    background: #fef2f2;
}

/* ============================================
   USER PROFILE SECTION
   ============================================ */
.user-profile-container {
    position: relative;
    flex-shrink: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    padding: 12px 12px;
    margin: 0 8px 8px 8px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.15s;
    gap: 12px;
}

.user-profile:hover {
    background: #EAEAEB;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #10a37f 0%, #1a7f64 100%);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: #202123;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-dots {
    color: #8e8ea0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.user-profile:hover .user-menu-dots {
    color: #6e6e80;
}

/* ============================================
   USER POPUP MENU
   ============================================ */
.user-popup-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 8px;
    right: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 20px rgba(0, 0, 0, 0.1);
    padding: 6px;
    display: none;
    z-index: 1000;
    min-width: 220px;
}

.user-popup-menu.show {
    display: block;
    animation: popupSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popupSlideUp {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: #353740;
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.menu-item:hover {
    background: #f5f5f5;
}

/* Menu Item with Toggle - kein Hover auf der ganzen Zeile */
.menu-item.menu-item-toggle {
    cursor: default;
}

.menu-item.menu-item-toggle:hover {
    background: transparent;
}

.menu-item.danger {
    color: #ef4444;
}

.menu-item.danger:hover {
    background: #fef2f2;
}

.menu-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6e6e80;
    width: 20px;
}

.menu-item.danger .menu-icon {
    color: #ef4444;
}

.menu-divider {
    height: 1px;
    background: #e5e5e5;
    margin: 6px 0;
}

/* ============================================
   TOGGLE SWITCH (Dark Mode)
   ============================================ */
.toggle-switch {
    margin-left: auto;
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #d1d5db;
    transition: background-color 0.3s ease;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: transform 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background-color: #10a37f;
}

input:checked + .slider:before {
    transform: translateX(18px);
}

.slider.round {
    border-radius: 22px;
}

.slider.round:before {
    border-radius: 50%;
}

/* ============================================
   SESSION DROPDOWN (In Sidebar)
   ============================================ */
.session-dropdown {
    position: absolute;
    top: 100%;
    right: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e5e5;
    padding: 6px;
    display: none;
    z-index: 1000;
    min-width: 160px;
    margin-top: 4px;
}

.session-dropdown.active {
    display: block;
    animation: dropdownFadeIn 0.15s ease;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar-open-btn .icon-desktop {
        display: none;
    }
    
    .sidebar-open-btn .icon-mobile {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100%;
        width: 280px;
        border-radius: 0;
        border-top-right-radius: 16px;
        border-bottom-right-radius: 16px;
        transform: translateX(-100%);
        box-shadow: 
            4px 0 16px rgba(0, 0, 0, 0.1),
            8px 0 32px rgba(0, 0, 0, 0.08);
        /* Smooth transition - 400ms mit Apple-ähnlicher Easing-Funktion */
        transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
                    box-shadow 0.4s cubic-bezier(0.32, 0.72, 0, 1);
        /* Hardware-Beschleunigung für flüssigere Animation */
        will-change: transform;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 
            8px 0 24px rgba(0, 0, 0, 0.15),
            16px 0 48px rgba(0, 0, 0, 0.12);
    }
    
    /* Klasse für Swipe-Geste - deaktiviert Transition während des Ziehens */
    .sidebar.swiping {
        transition: none !important;
    }

    /* On Mobile, collapsed class doesn't apply width 0 */
    .sidebar.collapsed {
        width: 280px;
        transform: translateX(-100%);
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-open-btn {
        display: flex;
        top: 16px;
        left: 16px;
        padding: 12px;
        border-radius: 12px;
    }
    
    /* Three dots always visible on mobile */
    .history-options-btn {
        opacity: 0.7;
    }
    
    .history-item:hover .history-options-btn,
    .history-options-btn:active {
        opacity: 1;
    }
    
    /* Smooth overlay transition - 400ms mit Apple-ähnlicher Easing-Funktion */
    .sidebar-overlay {
        transition: opacity 0.4s cubic-bezier(0.32, 0.72, 0, 1),
                    visibility 0.4s cubic-bezier(0.32, 0.72, 0, 1);
        /* Hardware-Beschleunigung */
        will-change: opacity;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Klasse für Swipe-Geste - deaktiviert Transition während des Ziehens */
    .sidebar-overlay.swiping {
        transition: none !important;
    }
}

/* ============================================
   RENAME INLINE EDIT
   ============================================ */
.rename-edit-container {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 4px 12px;
    flex: 1;
    min-width: 0;
}

.rename-input {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #10a37f;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: #202123;
    background: #fff;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.rename-input:focus {
    border-color: #10a37f;
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.rename-input:disabled {
    background: #f5f5f5;
    color: #888;
}

.rename-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.rename-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    background: transparent;
    color: #6e6e80;
}

.rename-btn:hover {
    background: #e5e5e5;
    color: #202123;
}

.rename-btn.confirm {
    color: #10a37f;
}

.rename-btn.confirm:hover {
    background: rgba(16, 163, 127, 0.1);
    color: #0d8a6a;
}

.rename-btn.cancel {
    color: #6e6e80;
}

.rename-btn.cancel:hover {
    background: #fef2f2;
    color: #ef4444;
}

.rename-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* History item in rename mode */
.history-item:has(.rename-edit-container) {
    background: #f0f0f0;
}

.history-item:has(.rename-edit-container) .history-options-btn {
    display: none;
}

/* ============================================
   MOBILE RENAME ADJUSTMENTS
   ============================================ */
@media (max-width: 768px) {
    .rename-edit-container {
        padding: 6px 8px 6px 10px;
    }
    
    .rename-input {
        padding: 8px 10px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .rename-btn {
        width: 36px;
        height: 36px;
    }
    
    .rename-actions {
        gap: 4px;
    }
}

/* ============================================
   MOBILE RENAME POPUP MODAL
   ============================================ */
.mobile-rename-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.mobile-rename-modal.active {
    display: flex;
}

.mobile-rename-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mobile-rename-popup {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    width: calc(100% - 48px);
    max-width: 320px;
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 20px rgba(0, 0, 0, 0.1),
        0 20px 40px rgba(0, 0, 0, 0.15);
    animation: popupSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.mobile-rename-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px 16px;
    border-bottom: 1px solid #e5e5e5;
}

.mobile-rename-title {
    font-size: 16px;
    font-weight: 600;
    color: #202123;
}

.mobile-rename-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: #6e6e80;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.mobile-rename-close:hover {
    background: #f0f0f0;
    color: #202123;
}

.mobile-rename-body {
    padding: 16px;
}

.mobile-rename-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e5e5e5;
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    color: #202123;
    background: #fafafa;
    outline: none;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.mobile-rename-input:focus {
    border-color: #10a37f;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.15);
}

.mobile-rename-input:disabled {
    background: #f5f5f5;
    color: #888;
}

.mobile-rename-counter {
    text-align: right;
    font-size: 12px;
    color: #8e8ea0;
    margin-top: 6px;
    padding-right: 4px;
}

.mobile-rename-footer {
    display: flex;
    gap: 10px;
    padding: 12px 16px 16px 16px;
}

.mobile-rename-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.mobile-rename-btn:active {
    transform: scale(0.98);
}

.mobile-rename-btn.cancel {
    background: #f0f0f0;
    color: #353740;
}

.mobile-rename-btn.cancel:hover {
    background: #e5e5e5;
}

.mobile-rename-btn.confirm {
    background: #10a37f;
    color: #ffffff;
}

.mobile-rename-btn.confirm:hover {
    background: #0d8a6a;
}

.mobile-rename-btn.confirm:disabled {
    background: #a0d8c8;
    cursor: not-allowed;
}

/* Hide mobile rename modal on desktop */
@media (min-width: 769px) {
    .mobile-rename-modal {
        display: none !important;
    }
}

/* ============================================
   PAGE TOPBAR (Breadcrumb Navigation)
   ============================================ */
.page-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 80;
    border-bottom: 1px solid #E5E5E5;
    transition: left 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    
    /* iOS Safe Area - für Notch/Dynamic Island */
    padding-top: env(safe-area-inset-top, 0);
    height: calc(56px + env(safe-area-inset-top, 0));
}

/* Desktop: Page Topbar verschiebt sich wenn Sidebar offen ist */
@media (min-width: 769px) {
    .page-topbar {
        left: 304px; /* Sidebar width (280px) + left margin (12px) + gap (12px) */
    }
    
    /* Wenn Sidebar geschlossen ist, Topbar ganz links */
    .sidebar.collapsed ~ .page-topbar,
    body:has(.sidebar.collapsed) .page-topbar {
        left: 0;
    }
}

.page-topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-topbar-right {
    display: flex;
    align-items: center;
}

/* Sidebar Toggle Button in Topbar */
.sidebar-toggle-topbar {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    color: #6e6e80;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle-topbar:hover {
    background: #F0F0F0;
    color: #202123;
}

/* Sidebar Toggle Icon - Arrow Animation */
.sidebar-toggle-icon .toggle-arrow {
    transition: transform 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    transform-origin: center center;
}

/* Default: Sidebar ist offen, Pfeil zeigt nach links (zum Schließen) */
.sidebar-toggle-icon .toggle-arrow {
    transform: translateX(0);
}

/* Sidebar geschlossen: Pfeil zeigt nach rechts (zum Öffnen) */
.sidebar-toggle-topbar.sidebar-closed .toggle-arrow {
    transform: scaleX(-1);
}

/* Breadcrumb Navigation */
.page-breadcrumb {
    display: flex;
    align-items: center;
}

.breadcrumb-list {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 2px;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
}

.breadcrumb-link {
    display: flex;
    align-items: center;
    color: #6e6e80;
    text-decoration: none;
    font-size: 14px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.breadcrumb-link:hover {
    background: #F0F0F0;
    color: #202123;
}

.breadcrumb-home {
    padding: 8px;
}

.breadcrumb-home svg {
    display: block;
}

.breadcrumb-separator {
    display: flex;
    align-items: center;
    color: #C5C5C5;
    margin: 0 2px;
}

.breadcrumb-current {
    font-size: 14px;
    font-weight: 500;
    color: #202123;
    padding: 6px 8px;
}

/* Back Button */
.back-button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    color: #6e6e80;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.back-button:hover {
    background: #F0F0F0;
    color: #202123;
}

.back-button svg {
    flex-shrink: 0;
}

/* Adjust main content when page-topbar is present */
.has-page-topbar .overview-wrapper,
.has-page-topbar .main-content {
    padding-top: calc(56px + env(safe-area-inset-top, 0));
    /* iOS Safe Area für Home-Indikator am unteren Rand */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.has-page-topbar .overview-container {
    padding-top: 30px;
}

/* Hide the old sidebar-open-btn when using page-topbar */
.has-page-topbar .sidebar-open-btn {
    display: none !important;
}

/* Page Topbar Mobile Adjustments */
@media (max-width: 768px) {
    .page-topbar {
        padding: 0 12px;
        /* iOS Safe Area - für Notch/Dynamic Island auf Mobile */
        padding-top: env(safe-area-inset-top, 0);
        height: calc(52px + env(safe-area-inset-top, 0));
    }
    
    .sidebar-toggle-topbar {
        padding: 8px;
    }
    
    .breadcrumb-link {
        font-size: 13px;
        padding: 4px 6px;
    }
    
    .breadcrumb-current {
        font-size: 13px;
        padding: 4px 6px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .breadcrumb-home {
        padding: 6px;
    }
    
    .breadcrumb-home svg {
        width: 16px;
        height: 16px;
    }
    
    .breadcrumb-separator svg {
        width: 14px;
        height: 14px;
    }
    
    .back-button {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .back-button-text {
        display: none;
    }
    
    .has-page-topbar .overview-wrapper,
    .has-page-topbar .main-content {
        padding-top: calc(52px + env(safe-area-inset-top, 0));
        /* iOS Safe Area für Home-Indikator am unteren Rand */
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    .has-page-topbar .overview-container {
        padding-top: 20px;
        /* Zusätzliches Padding für iOS Home-Indikator */
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 20px));
    }
}

/* Very small screens - hide some breadcrumb items */
@media (max-width: 400px) {
    .breadcrumb-item:not(:first-child):not(:last-child) {
        display: none;
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */
body.dark-mode .sidebar {
    background: #202123;
    box-shadow: 
        0 0 0 1px rgba(255, 255, 255, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.2),
        0 12px 24px rgba(0, 0, 0, 0.3);
}

body.dark-mode .sidebar-header {
    background: transparent;
}

body.dark-mode .brand-title {
    color: #ececf1;
}

body.dark-mode .sidebar-toggle-btn {
    color: #8e8ea0;
}

body.dark-mode .sidebar-toggle-btn:hover {
    background: #3a3b42;
    color: #ececf1;
}

/* Dark Mode - Navigation Items */
body.dark-mode .sidebar-nav {
    background: transparent;
}

body.dark-mode .nav-item {
    color: #ececf1 !important;
    background: transparent;
}

body.dark-mode .nav-item:hover {
    background: #3a3b42 !important;
    color: #ffffff !important;
}

body.dark-mode .nav-item.active {
    background: #3a3b42 !important;
    color: #ffffff !important;
}

body.dark-mode .nav-item svg {
    color: #8e8ea0 !important;
}

body.dark-mode .nav-item:hover svg,
body.dark-mode .nav-item.active svg {
    color: #ececf1 !important;
}

/* Dark Mode - History List */
body.dark-mode .history-link {
    color: #ececf1;
}

body.dark-mode .history-item:hover {
    background: #3a3b42;
}

body.dark-mode .new-chat-btn {
    color: #ececf1;
}

body.dark-mode .new-chat-btn:hover {
    background: #3a3b42;
}

body.dark-mode .new-chat-icon {
    color: #ececf1;
}

body.dark-mode .sidebar-section-title {
    color: #8e8ea0;
}

body.dark-mode .sidebar-divider {
    background: #4d4d4f;
}

body.dark-mode .history-item.active {
    background: #3a3b42;
}

body.dark-mode .history-item.active .history-link {
    color: #ffffff;
}

body.dark-mode .history-item:hover .history-link {
    color: #ffffff;
}

body.dark-mode .history-options-btn {
    color: #8e8ea0;
}

body.dark-mode .history-options-btn:hover,
body.dark-mode .history-options-btn.active {
    background: #4d4d4f;
    color: #ececf1;
}

body.dark-mode .user-popup-menu,
body.dark-mode .session-dropdown,
body.dark-mode .options-dropdown {
    background: #2a2b32;
    border-color: #4d4d4f;
}

/* Dark Mode - User Profile */
body.dark-mode .user-profile:hover {
    background: #3a3b42;
}

body.dark-mode .user-name {
    color: #ececf1;
}

body.dark-mode .user-menu-dots {
    color: #8e8ea0;
}

body.dark-mode .user-profile:hover .user-menu-dots {
    color: #ececf1;
}

/* Dark Mode - Menu Items im Popup */
body.dark-mode .menu-item {
    color: #ececf1;
}

body.dark-mode .menu-item:hover {
    background: #3a3b42;
}

body.dark-mode .menu-item .menu-icon {
    color: #8e8ea0;
}

body.dark-mode .menu-item:hover .menu-icon {
    color: #ececf1;
}

body.dark-mode .menu-item.danger {
    color: #f87171;
}

body.dark-mode .menu-item.danger .menu-icon {
    color: #f87171;
}

body.dark-mode .menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

body.dark-mode .menu-divider {
    background: #4d4d4f;
}

/* Dark Mode - Dropdown Items */
body.dark-mode .dropdown-item {
    color: #ececf1;
}

body.dark-mode .dropdown-item:hover {
    background: #3a3b42;
}

body.dark-mode .dropdown-item svg {
    color: #8e8ea0;
}

body.dark-mode .dropdown-item:hover svg {
    color: #ececf1;
}

body.dark-mode .dropdown-item.danger {
    color: #f87171;
}

body.dark-mode .dropdown-item.danger svg {
    color: #f87171;
}

body.dark-mode .dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Dark Mode - Toggle Switch */
body.dark-mode .slider {
    background-color: #4d4d4f;
}

/* Dark Mode - Rename Input */
body.dark-mode .rename-input {
    background: #2a2b32;
    border-color: #10a37f;
    color: #ececf1;
}

body.dark-mode .rename-input:focus {
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.3);
}

body.dark-mode .rename-btn {
    color: #8e8ea0;
}

body.dark-mode .rename-btn:hover {
    background: #3a3b42;
    color: #ececf1;
}

body.dark-mode .rename-btn.confirm {
    color: #10a37f;
}

body.dark-mode .rename-btn.confirm:hover {
    background: rgba(16, 163, 127, 0.15);
}

body.dark-mode .rename-btn.cancel:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

body.dark-mode .history-item:has(.rename-edit-container) {
    background: #2a2b32;
}

/* Dark Mode - Sidebar Open Button */
body.dark-mode .sidebar-open-btn {
    background: #2a2b32;
    color: #ececf1;
}

body.dark-mode .sidebar-open-btn:hover {
    background: #3a3b42;
}

/* Dark Mode - Scrollbar in History List */
body.dark-mode .history-list {
    scrollbar-color: #4d4d4f transparent;
}

body.dark-mode .history-list::-webkit-scrollbar-thumb {
    background: #4d4d4f;
}

body.dark-mode .history-list::-webkit-scrollbar-thumb:hover {
    background: #5d5d5f;
}

/* Dark Mode - Mobile Rename Popup */
body.dark-mode .mobile-rename-popup {
    background: #2a2b32;
}

body.dark-mode .mobile-rename-header {
    border-bottom-color: #4d4d4f;
}

body.dark-mode .mobile-rename-title {
    color: #ececf1;
}

body.dark-mode .mobile-rename-close {
    color: #8e8ea0;
}

body.dark-mode .mobile-rename-close:hover {
    background: #3a3b42;
    color: #ececf1;
}

body.dark-mode .mobile-rename-input {
    background: #202123;
    border-color: #4d4d4f;
    color: #ececf1;
}

body.dark-mode .mobile-rename-input:focus {
    border-color: #10a37f;
    background: #2a2b32;
}

body.dark-mode .mobile-rename-counter {
    color: #6e6e80;
}

body.dark-mode .mobile-rename-btn.cancel {
    background: #3a3b42;
    color: #ececf1;
}

body.dark-mode .mobile-rename-btn.cancel:hover {
    background: #4a4b52;
}

/* Dark Mode - Page Topbar */
body.dark-mode .page-topbar {
    background: #202123;
    border-bottom-color: #4d4d4f;
}

body.dark-mode .sidebar-toggle-topbar {
    color: #8e8ea0;
}

body.dark-mode .sidebar-toggle-topbar:hover {
    background: #2a2b32;
    color: #ececf1;
}

body.dark-mode .breadcrumb-link {
    color: #8e8ea0;
}

body.dark-mode .breadcrumb-link:hover {
    background: #2a2b32;
    color: #ececf1;
}

body.dark-mode .breadcrumb-separator {
    color: #4d4d4f;
}

body.dark-mode .breadcrumb-current {
    color: #ececf1;
}

body.dark-mode .back-button {
    color: #8e8ea0;
}

body.dark-mode .back-button:hover {
    background: #2a2b32;
    color: #ececf1;
}
