/* ========================================
   Chat Fullscreen - 側邊欄
   ======================================== */

.je-chat-sidebar {
    width: var(--je-space-70); /* 280px */
    min-width: var(--je-space-70); /* 280px */
    height: 100%;
    background: var(--je-bg-secondary);
    border-right: 1px solid var(--je-border-primary);
    display: flex;
    flex-direction: column;
    padding: var(--je-space-4) var(--je-space-4) 0;
    gap: var(--je-space-4);
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.2s ease;
}

/* 側邊欄收合狀態 */
body.je-sidebar-collapsed .je-chat-sidebar {
    width: 0;
    min-width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}

/* ========================================
   Agent 資料卡
   ======================================== */
.je-sidebar-agent {
    display: flex;
    align-items: center;
    gap: var(--je-space-3);
    padding: var(--je-space-3);
    background: var(--je-bg-primary);
    border-radius: var(--je-radius-lg);
    border: 1px solid var(--je-border-primary);
}

.je-agent-avatar {
    width: var(--je-space-12); /* 原始: 48px */
    height: var(--je-space-12); /* 原始: 48px */
    min-width: var(--je-space-12); /* 原始: 48px */
    background: var(--je-primary);
    color: var(--je-white);
    border-radius: var(--je-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--je-text-lg); /* 原始: 18px */
}

.je-agent-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--je-radius-full);
}

.je-agent-info {
    flex: 1;
    min-width: 0;
}

.je-agent-info h2 {
    font-size: var(--je-text-base);
    font-weight: var(--je-font-semibold);
    color: var(--je-text-primary);
    margin: 0 0 var(--je-space-0-5, 2px); /* 原始: 2px，無對應變數 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.je-agent-info p {
    font-size: var(--je-text-xs);
    color: var(--je-text-tertiary);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* 行數限制，非尺寸 */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ========================================
   新對話按鈕
   ======================================== */
.je-btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--je-space-2);
    width: 100%;
    height: var(--je-space-10, 40px); /* 原始: 40px */
    background: var(--je-primary);
    color: var(--je-white);
    border: none;
    border-radius: var(--je-radius-md);
    font-size: var(--je-text-sm);
    font-weight: var(--je-font-medium);
    cursor: pointer;
    transition: background 0.2s ease;
}

.je-btn-new-chat:hover {
    background: var(--je-primary-600, #ea580c);
}

.je-btn-new-chat:focus-visible {
    outline: 2px solid var(--je-primary); /* 固定尺寸，無對應變數 */
    outline-offset: var(--je-space-0-5, 2px); /* 原始: 2px，無對應變數 */
}

/* ========================================
   側邊欄搜尋
   ======================================== */
.je-sidebar-search {
    position: relative;
}

.je-sidebar-search i {
    position: absolute;
    left: var(--je-space-3); /* 原始: 12px */
    top: 50%;
    transform: translateY(-50%);
    color: var(--je-text-muted);
    font-size: var(--je-text-sm); /* 原始: 14px */
    pointer-events: none;
}

.je-sidebar-search input {
    width: 100%;
    height: var(--je-space-9, 36px); /* 原始: 36px */
    padding: 0 var(--je-space-3) 0 var(--je-space-9, 36px); /* 原始: 0 12px 0 36px */
    background: var(--je-bg-primary);
    border: 1px solid var(--je-border-primary);
    border-radius: var(--je-radius-md);
    font-size: var(--je-text-sm);
    color: var(--je-text-primary);
    transition: border-color 0.2s ease;
}

.je-sidebar-search input:focus {
    outline: none;
    border-color: var(--je-primary);
}

.je-sidebar-search input::placeholder {
    color: var(--je-text-muted);
}

/* ========================================
   歷史紀錄區塊
   ======================================== */
.je-sidebar-history {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 150px; /* 固定尺寸，無對應變數 */
    overflow: hidden;
}

.je-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--je-space-2) 0;
}

.je-history-header span {
    font-size: var(--je-text-xs);
    font-weight: var(--je-font-semibold);
    color: var(--je-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#historyBackIcon {
    display: none;
    cursor: pointer;
    color: var(--je-text-muted);
    transition: color 0.2s ease;
}

#historyBackIcon:hover {
    color: var(--je-text-primary);
}

.je-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--je-space-1);
    /* 重設 ul 預設樣式 */
    list-style: none;
    padding: 0;
    margin: 0;
}

.je-history-loading {
    display: none;
    padding: var(--je-space-3) var(--je-space-4);
    color: var(--je-text-muted);
    font-size: var(--je-text-xs);
    text-align: center;
}

/* ========================================
   歷史項目
   ======================================== */
.je-history-item {
    display: flex;
    align-items: center;
    gap: var(--je-space-2);
    padding: var(--je-space-3);
    border-radius: var(--je-radius-lg);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    margin-bottom: var(--je-space-1);
    overflow: hidden;
    flex-shrink: 0;
}

/* 歷史項目新增動畫 */
.je-history-item.je-animating-in {
    opacity: 0;
    transform: translateY(calc(-1 * var(--je-space-2-5, 10px))); /* 原始: -10px */
}

.je-history-item > .d-flex {
    flex: 1 1 0%;
    min-width: 0;
    gap: var(--je-space-2);
}

.je-history-item:hover {
    background: var(--je-bg-hover);
}

/* 當前對話 */
.je-history-item.active {
    background: var(--je-primary-alpha-8);
    border: 1px solid var(--je-primary-alpha-20);
}

.je-history-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px; /* 固定尺寸，無對應變數 */
    height: 70%; /* 百分比，非尺寸 */
    background: var(--je-primary);
    border-radius: 0 3px 3px 0; /* 固定圓角，無對應變數 */
}

/* 頭像 */
.je-history-avatar {
    width: var(--je-space-9, 36px); /* 原始: 36px */
    height: var(--je-space-9, 36px); /* 原始: 36px */
    min-width: var(--je-space-9, 36px); /* 原始: 36px */
    background: var(--je-primary);
    color: var(--je-white);
    border-radius: var(--je-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px; /* 固定尺寸，無對應變數 */
    font-weight: 600;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.je-history-item:hover .je-history-avatar {
    transform: scale(1.05); /* 比例，非尺寸 */
    box-shadow: 0 var(--je-space-0-5, 2px) var(--je-space-2) var(--je-primary-alpha-25); /* 原始: 0 2px 8px */
}

.je-history-item.active .je-history-avatar {
    box-shadow: 0 var(--je-space-0-5, 2px) var(--je-space-2) var(--je-primary-alpha-30); /* 原始: 0 2px 8px */
}

.je-history-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--je-radius-full);
}

/* 內容 */
.je-history-content {
    flex: 1 1 0%;
    min-width: 0;
    overflow: hidden;
}

/* 標題輸入框 - 單一元件控制 readonly/editable */
.je-title-input {
    width: 100%;
    padding: 0;
    margin: 0;
    font-size: var(--je-text-sm);
    font-weight: var(--je-font-medium);
    font-family: inherit;
    color: var(--je-text-primary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--je-radius-md);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    transition: all var(--je-transition-fast);
}

/* readonly 狀態 - 看起來像標題文字 */
.je-title-input:read-only {
    cursor: pointer;
    pointer-events: none;
}

/* 可編輯狀態 - 輸入框樣式 */
.je-title-input:not(:read-only) {
    padding: var(--je-space-1) var(--je-space-2); /* 原始: 4px 8px */
    background: var(--je-bg-primary);
    border-color: var(--je-primary);
    cursor: text;
    pointer-events: auto;
}

.je-title-input:not(:read-only):focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--je-primary-alpha-12); /* 固定尺寸，無對應變數 */
}

/* active 狀態下的標題顏色 */
.je-history-item.active .je-title-input:read-only {
    color: var(--je-primary);
    font-weight: var(--je-font-semibold);
}

.je-history-content p,
.je-history-content small {
    font-size: 11px; /* 固定尺寸，無對應變數 */
    color: var(--je-text-muted);
    margin: 3px 0 0; /* 固定間距，無對應變數 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.je-history-content small {
    display: block;
}

/* 操作按鈕 */
.je-history-item-actions {
    display: flex;
    align-items: center;
    gap: var(--je-space-1); /* 原始: 4px */
    opacity: 0;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

.je-history-item:hover .je-history-item-actions {
    opacity: 1;
}

/* 歷史項目按鈕位置（基礎樣式由 .je-btn 提供） */
.je-history-item > .je-edit-title-btn,
.je-history-item > .je-delete-thread-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
}

.je-history-item > .je-edit-title-btn {
    right: var(--je-space-10, 40px); /* 原始: 40px */
}

.je-history-item > .je-delete-thread-btn {
    right: var(--je-space-2); /* 原始: 8px */
}

.je-history-item:hover > .je-edit-title-btn,
.je-history-item:hover > .je-delete-thread-btn {
    opacity: 1;
}

/* 編輯按鈕 hover 主色 */
.je-history-item > .je-edit-title-btn:hover {
    color: var(--je-primary);
    border-color: var(--je-primary);
    background: var(--je-primary-light);
}

/* 刪除按鈕 hover 危險色 */
.je-history-item > .je-delete-thread-btn:hover {
    color: var(--je-error);
    border-color: var(--je-error);
    background: var(--je-error-bg);
}

/* 編輯時隱藏操作按鈕 */
.je-history-item.is-editing .je-history-item-actions,
.je-history-item.is-editing > .je-edit-title-btn,
.je-history-item.is-editing > .je-delete-thread-btn {
    display: none;
}

/* ========================================
   使用提示 - 可收合區塊
   ======================================== */
.je-sidebar-tips {
    border-top: 1px solid var(--je-border-secondary);
    flex-shrink: 0;
    padding-bottom: var(--je-space-4);
}

.je-sidebar-tips.je-collapsed {
    padding-bottom: 0;
}

.je-tips-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--je-space-3);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.je-tips-header:hover {
    background: var(--je-bg-hover);
}

.je-tips-header-left {
    display: flex;
    align-items: center;
    gap: var(--je-space-2);
}

.je-tips-header-left i {
    font-size: var(--je-text-sm); /* 原始: 14px */
    color: var(--je-primary);
}

.je-tips-header-left span {
    font-size: var(--je-text-xs);
    font-weight: var(--je-font-semibold);
    color: var(--je-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.je-tips-chevron {
    font-size: var(--je-text-xs); /* 原始: 12px */
    color: var(--je-text-muted);
    transition: transform 0.2s ease;
}

.je-sidebar-tips.je-collapsed .je-tips-chevron {
    transform: rotate(-90deg);
}

.je-tips-content {
    max-height: 200px; /* 固定尺寸，無對應變數 */
    overflow-y: auto;
    padding: 0 var(--je-space-3) var(--je-space-3);
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
}

.je-sidebar-tips.je-collapsed .je-tips-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    overflow: hidden;
}

.je-sidebar-tips ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--je-space-2);
}

.je-sidebar-tips li {
    list-style: none;
}

/* 使用提示按鈕 */
.je-tip-btn {
    display: flex;
    align-items: center;
    gap: var(--je-space-2);
    width: 100%;
    padding: var(--je-space-2) var(--je-space-3);
    background: var(--je-bg-primary);
    border: 1px solid var(--je-border-primary);
    border-radius: var(--je-radius-md);
    font-size: var(--je-text-xs);
    color: var(--je-text-secondary);
    line-height: 1.5;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.je-tip-btn:hover {
    border-color: var(--je-primary);
    background: var(--je-bg-hover);
}

.je-tip-btn:active {
    transform: scale(0.98);
}

.je-tip-btn i {
    font-size: var(--je-text-xs); /* 原始: 12px */
    color: var(--je-primary);
    flex-shrink: 0;
}

.je-tip-btn span {
    flex: 1;
}

/* 提示捲軸 */
.je-tips-content::-webkit-scrollbar {
    width: var(--je-space-1); /* 原始: 4px */
}

.je-tips-content::-webkit-scrollbar-track {
    background: transparent;
}

.je-tips-content::-webkit-scrollbar-thumb {
    background: var(--je-border-primary);
    border-radius: var(--je-space-0-5, 2px); /* 原始: 2px，無對應變數 */
}

.je-tips-content::-webkit-scrollbar-thumb:hover {
    background: var(--je-text-muted);
}

/* ========================================
   側邊欄切換按鈕
   ======================================== */
.je-sidebar-toggle {
    position: fixed;
    top: calc(var(--je-header-height, var(--je-space-20, 80px)) + var(--je-space-3)); /* 原始: 80px + 12px */
    left: var(--je-space-3); /* 原始: 12px */
    width: var(--je-space-9, 36px); /* 原始: 36px */
    height: var(--je-space-9, 36px); /* 原始: 36px */
    background: var(--je-bg-elevated);
    border: 1px solid var(--je-border-primary);
    border-radius: var(--je-radius-md);
    color: var(--je-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300; /* z-index，非尺寸 */
    transition: background 0.2s ease, color 0.2s ease, left 0.3s ease;
    box-shadow: var(--je-shadow-sm);
}

.je-sidebar-toggle:hover {
    background: var(--je-bg-hover);
    color: var(--je-text-primary);
}

.je-sidebar-toggle i {
    transition: transform 0.3s ease;
}

body:not(.je-sidebar-collapsed) .je-sidebar-toggle {
    left: 292px; /* 固定位置，無對應變數 */
}

body.je-sidebar-collapsed .je-sidebar-toggle i {
    transform: rotate(180deg);
}
