/* ===== Sidebar Overrides for Chat Layout ===== */
.sidebar-new-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0.5rem 0.75rem;
    color: var(--sidebar-text);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .sidebar-new-btn:hover {
        color: #ffffff;
        background: #000000;
    }

    .sidebar-new-btn i {
        font-size: 1.1rem;
        width: 20px;
        text-align: center;
    }

/* ===== Sidebar History ===== */
.sidebar-history {
    padding: 0 0.75rem;
    overflow-y: auto;
    max-height: calc(100vh - 360px);
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

    .sidebar-history:hover {
        scrollbar-color: rgba(139, 149, 176, 0.3) transparent;
    }

    .sidebar-history::-webkit-scrollbar {
        width: 6px;
    }

    .sidebar-history::-webkit-scrollbar-track {
        background: transparent;
    }

    .sidebar-history::-webkit-scrollbar-thumb {
        background: transparent;
        border-radius: 3px;
        transition: background 0.3s ease;
    }

    .sidebar-history:hover::-webkit-scrollbar-thumb {
        background: rgba(139, 149, 176, 0.3);
    }

        .sidebar-history:hover::-webkit-scrollbar-thumb:hover {
            background: rgba(139, 149, 176, 0.5);
        }

.sidebar-history-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.5rem 0 0.25rem;
    margin: 0;
}

.sidebar-history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 0.5rem;
}

.sidebar-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.5rem 0.75rem;
    color: var(--sidebar-text);
    font-size: 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .sidebar-history-item:hover {
        color: var(--sidebar-text-hover);
        background: var(--sidebar-bg-hover);
    }

    .sidebar-history-item.active {
        color: var(--sidebar-text-active);
        background: var(--sidebar-bg-active);
        font-weight: 500;
    }

    .sidebar-history-item i {
        font-size: 0.95rem;
        width: 18px;
        text-align: center;
        flex-shrink: 0;
    }

    .sidebar-history-item span {
        overflow: hidden;
        text-overflow: ellipsis;
    }

/* ===== Sidebar Footer Profile ===== */
.sidebar-footer-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .sidebar-footer-profile:hover {
        color: var(--sidebar-text-hover);
        background: var(--sidebar-bg-hover);
    }

.sidebar-footer .user-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.85rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.sidebar-footer .user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-footer .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .user-profile-more {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ===== Context Menu ===== */
.user-context-menu {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    min-width: 180px;
    padding: 0.5rem 0;
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

    .user-context-menu.show {
        opacity: 1;
        transform: translateY(0) scale(1);
        pointer-events: auto;
    }

    .user-context-menu ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .user-context-menu li a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 0.55rem 1rem;
        color: var(--text-primary);
        font-size: 0.88rem;
        text-decoration: none;
        transition: background 0.15s ease;
    }

        .user-context-menu li a:hover {
            background: var(--bg-secondary);
        }

    .user-context-menu li a i {
        font-size: 1rem;
        color: var(--text-secondary);
        width: 18px;
        text-align: center;
    }

    .user-context-menu .menu-divider {
        height: 1px;
        background: var(--border);
        margin: 0.4rem 0;
    }

    .user-context-menu .logout-link {
        color: #ef4444;
    }

        .user-context-menu .logout-link i {
            color: #ef4444;
        }

/* ===== Chat Main ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem 1.5rem;
}

/* ===== Welcome ===== */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 0;
}

.chat-welcome-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 1.5rem;
}

    .chat-welcome-icon i {
        font-size: 1.8rem;
        color: var(--accent);
    }

.chat-welcome-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.chat-welcome-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.6;
}

.chat-welcome-login-btn {
    display: inline-block;
    margin-top: 1.5rem;
    padding: 0.75rem 2.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    background: linear-gradient(135deg, #1a1a1a 0%, #000 100%);
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chat-welcome-login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.20);
    color: #ffffff;
}

/* ===== Messages ===== */
.chat-messages {
    flex: 1 0 auto;
    padding: 1rem 0 160px 0;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.chat-message {
    margin-bottom: 1.25rem;
    display: flex;
}

.chat-message-user {
    justify-content: flex-end;
}

.chat-message-ai {
    justify-content: flex-start;
}

.chat-message-bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.chat-message-user .chat-message-bubble {
    background: var(--accent);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-message-ai .chat-message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* ===== Input Area ===== */
.chat-input-area {
    position: fixed;
    bottom: 0;
    left: var(--new-sidebar-width);
    right: 0;
    background: var(--bg-primary);
    z-index: 10;
    padding: 1rem 1.5rem;
    margin: 0px 10px;
}

.chat-input-area-inner {
    max-width: 800px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .chat-input-area {
        left: 0;
        padding: 0.75rem 1rem;
    }
}

/* ===== Model Selector Inline ===== */
.chat-model-selector-inline {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.chat-model-btn-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.4rem 0.7rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

    .chat-model-btn-inline:hover {
        background: var(--bg-secondary);
        border-color: var(--border);
        color: var(--text-primary);
    }

    .chat-model-btn-inline i:first-child {
        color: var(--accent);
        font-size: 0.95rem;
    }

.chat-model-arrow-inline {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.chat-model-btn-inline[aria-expanded="true"] .chat-model-arrow-inline {
    transform: rotate(180deg);
}

.chat-model-btn-inline[aria-expanded="true"] {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.chat-model-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    min-width: 320px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

    .chat-model-dropdown.show {
        display: block;
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

    .chat-model-dropdown::-webkit-scrollbar {
        width: 6px;
    }

    .chat-model-dropdown::-webkit-scrollbar-track {
        background: transparent;
    }

    .chat-model-dropdown::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 3px;
    }

    .chat-model-dropdown::-webkit-scrollbar-thumb:hover {
        background: var(--text-muted);
    }

.chat-model-loading {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.chat-model-group {
    padding: 0.5rem 0;
}

    .chat-model-group:not(:last-child) {
        border-bottom: 1px solid var(--border);
    }

.chat-model-group-title {
    padding: 0.4rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

    .chat-model-option:hover {
        background: var(--bg-secondary);
    }

    .chat-model-option.active {
        background: var(--accent-light);
    }

.chat-model-option-info {
    flex: 1;
    min-width: 0;
}

.chat-model-option-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.chat-model-option-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.chat-model-badge {
    padding: 0.2rem 0.5rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-model-badge-primary {
    background: var(--accent);
    color: #ffffff;
}

.chat-model-badge-pro {
    background: linear-gradient(135deg, #333333 0%, #555555 100%);
    color: #ffffff;
}

.chat-model-badge-ultra {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: #ffffff;
}

/* 模型厂商标识颜色 */
.chat-model-group:nth-child(1) .chat-model-group-title {
    color: #10a37f; /* OpenAI 绿色 */
}

.chat-model-group:nth-child(2) .chat-model-group-title {
    color: #4285f4; /* Google 蓝色 */
}

.chat-model-group:nth-child(3) .chat-model-group-title {
    color: #d97706; /* Anthropic 橙色 */
}

.chat-model-group:nth-child(4) .chat-model-group-title {
    color: #4f46e5; /* DeepSeek 靛蓝 */
}

.chat-input-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

    .chat-input-box:focus-within {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
    }

.chat-input-textarea {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 2.6;
    font-family: inherit;
    min-height: 24px;
    max-height: 150px;
}

    .chat-input-textarea::placeholder {
        color: var(--text-muted);
    }

.chat-input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.chat-input-tools {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .chat-tool-btn:hover {
        background: var(--bg-secondary);
        color: var(--accent);
    }

.chat-send-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .chat-send-btn:hover {
        background: #000000;
        transform: scale(1.05);
    }

    .chat-send-btn:active {
        transform: scale(0.98);
    }

.chat-input-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.5rem 0 0;
}

/* ===== Scrollbar ===== */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


/* ===== Message Layout ===== */
.chat-message-row {
    display: flex;
    margin-bottom: 1.25rem;
}

.chat-message-row.user {
    justify-content: flex-end;
}

    .chat-message-row.user .chat-message-body {
        max-width: 75%;
    }

    .chat-message-row.assistant {
        flex-direction: column;
        align-items: flex-start;
    }

    .chat-message-row.assistant .chat-message-body {
        padding-left: 40px;
    }

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 6px;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    margin: 0 10px;
}

.chat-message-row.user .chat-message-avatar {
    /* background: var(--accent);*/
    background: #f0f0f0;
    color: #000;
    order: 2;
}

.chat-message-row.assistant .chat-message-avatar {
    background: var(--bg-secondary);
    color: var(--accent);
    border: 1px solid var(--border);
}

.chat-message-header .chat-message-avatar {
    margin: 0 8px 0 0;
}

.chat-message-meta {
    display: flex;
    align-items: center;
}

.chat-model-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.chat-message-body {
    /* max-width: 75%;*/
    display: flex;
    flex-direction: column;
    width: 100%;
}

.chat-message-content {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.65;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.chat-message-row.user .chat-message-content {
    /*background: var(--accent);
    color: #ffffff;*/
    background: #f0f0f0;
    color: #000;

    /*    border-bottom-right-radius: 4px;*/
}

.chat-message-row.assistant .chat-message-content {
    background: var(--bg-card);
    padding:0px;
    /*    border: 1px solid var(--border);*/
    color: var(--text-primary);
    /*    border-bottom-left-radius: 4px;*/
}

.chat-message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message-row.user .chat-message-time {
    text-align: right;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== Markdown Body ===== */
.markdown-body {
    line-height: 1.7;
    word-wrap: break-word;
}

.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

.markdown-body p {
    margin: 0.5em 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 1em 0 0.5em;
    font-weight: 600;
    line-height: 1.4;
}

.markdown-body h1 { font-size: 1.4em; }
.markdown-body h2 { font-size: 1.25em; }
.markdown-body h3 { font-size: 1.1em; }

.markdown-body ul, .markdown-body ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.markdown-body li { margin: 0.25em 0; }

.markdown-body blockquote {
    margin: 0.5em 0;
    padding: 0.4em 1em;
    border-left: 3px solid var(--accent);
    background: var(--bg-secondary);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
}

.markdown-body a {
    color: var(--accent);
    text-decoration: none;
}

.markdown-body a:hover { text-decoration: underline; }

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75em 0;
    font-size: 0.9em;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border);
    padding: 0.5em 0.75em;
    text-align: left;
}

.markdown-body th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.markdown-body mark {
    background: #fef08a;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1em 0;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 8px;
}

/* ===== Chat Image Wrapper ===== */
.chat-image-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 0.75em 0;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-secondary, #f5f5f5);
    transition: box-shadow 0.2s ease;
}

.chat-image-wrapper:hover {
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}

.chat-image-wrapper .chat-inline-image {
    display: block;
    max-width: 100%;
    max-height: 480px;
    width: auto;
    height: auto;
    border-radius: 0;
    transition: transform 0.3s ease;
}

.chat-image-wrapper:hover .chat-inline-image {
    transform: scale(1.02);
}

.chat-image-wrapper .chat-image-tip {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.65));
    color: #fff;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.25s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: none;
}

.chat-image-wrapper:hover .chat-image-tip {
    opacity: 1;
}

/* 图片加载失败 */
.chat-image-wrapper.chat-image-error {
    display: none;
}

.chat-image-broken {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 2rem 1rem;
    border: 2px dashed var(--border, #ddd);
    border-radius: 10px;
    color: var(--text-muted, #999);
    font-size: 0.85em;
    margin: 0.5em 0;
    background: var(--bg-secondary, #fafafa);
}

.chat-image-broken i {
    font-size: 1.8em;
    opacity: 0.6;
}

/* ===== Image Lightbox ===== */
.chat-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
}

.chat-image-lightbox.open {
    display: flex;
}

.chat-image-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.chat-image-lightbox-inner {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lightboxFadeIn 0.2s ease;
}

@keyframes lightboxFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.chat-image-lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 48px rgba(0,0,0,0.5);
    cursor: default;
}

.chat-image-lightbox-close {
    position: absolute;
    top: -40px;
    right: -8px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    transition: background 0.2s;
}

.chat-image-lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.chat-image-lightbox-prev,
.chat-image-lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    width: 40px;
    height: 56px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    transition: background 0.2s;
}

.chat-image-lightbox-prev {
    left: -52px;
}

.chat-image-lightbox-next {
    right: -52px;
}

.chat-image-lightbox-prev:hover,
.chat-image-lightbox-next:hover {
    background: rgba(255,255,255,0.3);
}

@media (max-width: 768px) {
    .chat-image-lightbox-prev {
        left: 8px;
    }
    .chat-image-lightbox-next {
        right: 8px;
    }
    .chat-image-lightbox-close {
        top: -44px;
        right: 0;
    }
    .chat-image-wrapper .chat-inline-image {
        max-height: 320px;
    }
}

/* ===== Chat Video Wrapper ===== */
.chat-video-wrapper {
    position: relative;
    max-width: 100%;
    margin: 0.75em 0;
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    transition: box-shadow 0.2s ease;
}

.chat-video-wrapper:hover {
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}

.chat-inline-video {
    display: block;
    width: 100%;
    max-height: 480px;
    border-radius: 10px;
    outline: none;
}

.chat-video-tip {
    position: absolute;
    bottom: 8px;
    left: 12px;
    padding: 4px 10px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 0.78em;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* 播放后隐藏提示 */
.chat-inline-video[controls] ~ .chat-video-tip,
.chat-video-wrapper:has(video.playing) .chat-video-tip {
    opacity: 0;
}

.chat-video-unsupported {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted, #999);
    font-size: 0.9em;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 10px;
}

.chat-media-error {
    display: none;
}

@media (max-width: 768px) {
    .chat-inline-video {
        max-height: 300px;
    }
}

/* ===== Chat File Card ===== */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin: 0.6em 0;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 10px;
    background: var(--bg-secondary, #fafafa);
    transition: border-color 0.2s, box-shadow 0.2s;
    max-width: 100%;
}

.chat-file-card:hover {
    border-color: var(--accent, #4a90d9);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.chat-file-card-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--bg-tertiary, #f0f0f0);
    font-size: 1.4em;
    color: var(--text-secondary, #666);
}

.chat-file-card-info {
    flex: 1;
    min-width: 0;
}

.chat-file-card-name {
    display: block;
    font-size: 0.9em;
    font-weight: 500;
    color: var(--text, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-file-card-download {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 6px;
    background: var(--accent, #4a90d9);
    color: #fff !important;
    text-decoration: none !important;
    font-size: 0.85em;
    font-weight: 500;
    transition: background 0.2s, transform 0.15s;
}

.chat-file-card-download:hover {
    background: var(--accent-hover, #3a7bc8);
    transform: translateY(-1px);
}

.chat-file-card-download:active {
    transform: translateY(0);
}

/* ===== Code Inline ===== */
.markdown-body code:not(.hljs) {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    color: #cc0033;
}

/* ===== Code Block Wrapper ===== */
/* ============================================== */
/*  Code Block — DeepSeek 风格                      */
/* ============================================== */

.code-block-wrapper {
    position: relative;
    margin: 1em 0;
    border-radius: 8px;
    overflow: hidden;
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
}

.code-block-wrapper pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.85em;
    line-height: 1.65;
    background: #1e1e1e;
}

.code-block-wrapper pre code {
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, 'SF Mono', monospace;
    font-size: 0.92em;
    color: #d4d4d4;
}

/* ===== Code Header — DeepSeek 风格 ===== */
.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 1rem;
    background: #252525;
    border-bottom: 1px solid #2e2e2e;
    user-select: none;
}

.code-dots {
    display: none;
}

.code-lang {
    font-size: 0.72rem;
    font-weight: 500;
    color: #999;
}

.code-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.code-actions button {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #999;
    font-size: 0.72rem;
    font-weight: 400;
    cursor: pointer;
    transition: color 0.15s ease;
}

.code-actions button:hover {
    color: #e0e0e0;
    background: transparent;
}

/* ===== Code Line Numbers ===== */
/* ===== Code Block 文本选中 ===== */
.code-block-wrapper ::selection {
    background: rgba(100, 160, 255, 0.35);
    color: #fff;
}

.code-block-wrapper ::-moz-selection {
    background: rgba(100, 160, 255, 0.35);
    color: #fff;
}

.code-lines-wrapper {
    display: block;
}

.code-line {
    display: flex;
    min-height: 1.65em;
}

.code-line-num {
    display: inline-block;
    width: 40px;
    min-width: 40px;
    padding-right: 16px;
    text-align: right;
    color: #555;
    user-select: none;
    flex-shrink: 0;
    font-size: 0.88em;
}

.code-line-content {
    flex: 1;
    white-space: pre-wrap;
}

/* ===== HTML/CSS Preview ===== */
.html-preview {
    margin: 0;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    overflow: hidden;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.preview-close {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
}

.preview-iframe {
    width: 100%;
    min-height: 300px;
    border: none;
    background: #fff;
}

/* ===== HTML 预览弹框 (Modal) ===== */
.html-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: none;
}

.html-preview-modal.open {
    display: block;
}

.html-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.html-preview-dialog {
    position: absolute;
    inset: 24px;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.html-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.2rem;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.html-preview-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
}

.html-preview-close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #666;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.html-preview-close-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.html-preview-frame {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
}

/* ===== Thinking Block ===== */
.thinking-block {
    margin: 0.5em 0 0.75em;
  /*  border: 1px solid rgba(147, 51, 234, 0.2);*/
   /* border-radius: 10px;*/
    overflow: hidden;
   /* background: rgba(147, 51, 234, 0.04);*/
}

.thinking-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.55rem;
    font-size: 1rem;
    color: #62666A;
    cursor: pointer;
    user-select: none;
}

.thinking-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking-toggle-arrow {
    margin-left: 2px;
    transition: transform 0.25s ease;
    color: #9CA3AF;
    font-size: 0.85rem;
}

.thinking-content {
    padding: 0.6rem 0.85rem;
    font-size: 0.95em;
    color: #696D71;
    line-height: 1.6;
}

/* 折叠状态 */
.thinking-block.collapsed .thinking-content {
    display: none;
}

.thinking-block.collapsed .thinking-toggle-arrow {
    transform: rotate(-90deg);
}

/* ===== Message Actions ===== */
.chat-message-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 4px;
}

.chat-message-row.user .chat-message-actions {
    justify-content: flex-end;
}

.chat-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-action-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.chat-action-btn:active {
    transform: scale(0.95);
}

.thinking-content > *:first-child { margin-top: 0; }
.thinking-content > *:last-child { margin-bottom: 0; }

/* ===== Error Text ===== */
.error-text {
    color: #ef4444;
    font-size: 0.9em;
}

/* ===== Send Button States ===== */
.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn:disabled:hover {
    background: var(--accent);
    transform: none;
}

@media (max-width: 768px) {
    .main-wrapper {
        margin-left: 0;
    }
    
    .main-wrapper.sidebar-collapsed {
        margin-left: 0;
    }
    
    .chat-model-dropdown {
        min-width: 280px;
        max-width: calc(100vw - 32px);
        left: 0;
        right: auto;
    }
    
    .chat-model-btn-inline span {
        display: none;
    }
    
    .chat-model-btn-inline {
        padding: 0.4rem;
    }
}

/* ===== Floating Toolbox ===== */
.chat-toolbox {
    position: fixed;
    right: 16px;
    top: 16px;
    display: flex;
    gap: 6px;
    z-index: 99;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.chat-toolbox.toolbox-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.toolbox-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.toolbox-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-light);
}

/* ===== Right Panel ===== */
.chat-right-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 320px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.chat-right-panel.open {
    transform: translateX(0);
}

.right-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.right-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.right-panel-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.right-panel-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0.75rem 1rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
}

.right-panel-search i {
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.right-panel-search input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: inherit;
}

.right-panel-search input::placeholder {
    color: var(--text-muted);
}

.right-panel-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0 1rem 0.75rem;
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.right-panel-new-chat:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.right-panel-history {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem;
}

.right-panel-loading,
.right-panel-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.55rem 0.75rem;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
    overflow: hidden;
}

.history-item:hover {
    background: var(--bg-secondary);
}

    .history-item.active {
        /* background: var(--accent-light);
    color: var(--accent);*/
        background: #f0f0f0;
        color:#000;
    }

.history-item i {
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.history-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item .history-time {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ===== Panel-Open State ===== */
.new-main-wrapper.panel-open {
    margin-right: 320px;
}

.new-main-wrapper.panel-open .chat-input-area {
    right: 320px;
}

@media (max-width: 768px) {
    .chat-toolbox {
        right: 8px;
    }

    .chat-right-panel {
        width: 100vw;
    }

    .new-main-wrapper.panel-open {
        margin-right: 0;
    }
}

/* ===== 用户消息编辑模式 (DeepSeek 风格) ===== */
.chat-message-body.is-editing {
    width: 100% !important;
    max-width: 720px;
}

.user-edit-area {
    width: 100%;
}

.user-edit-textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    min-height: 64px;
    padding: 14px 16px;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.6;
    color: var(--text-primary, #e5e7eb);
    background: var(--bg-card, #1a1d2e);
    border: 1px solid var(--border-color, #333333);
    border-radius: 12px;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.user-edit-textarea:focus {
    border-color: #333333;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.user-edit-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.user-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 34px;
    padding: 0 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.user-edit-btn.cancel-btn {
    background: transparent;
    color: var(--text-secondary, #999999);
}

.user-edit-btn.cancel-btn:hover {
    background: var(--bg-secondary, #2d3045);
    color: var(--text-primary, #e5e7eb);
}

.user-edit-btn.send-btn {
    background: #333333;
    color: #fff;
}

.user-edit-btn.send-btn:hover {
    background: #1a1a1a;
}

.user-edit-btn i {
    font-size: 0.9rem;
}

/* ===== 文件预览 (支持多个文件，输入框内) ===== */
.chat-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-file-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 2px;
    background: var(--bg-card, #1a1d2e);
    border: 1px solid #E5E5E5;
    border-radius: 8px;
}

/* 环形进度容器 */
.chat-file-item-ring {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.chat-file-item-svg {
    width: 28px;
    height: 28px;
    transform: rotate(-90deg);
}

.chat-file-item-track {
    fill: none;
    stroke: var(--border-color, #333333);
    stroke-width: 2.5;
}

.chat-file-item-fill {
    fill: none;
    stroke: #333333;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 81.68;
    stroke-dashoffset: 81.68;
    transition: stroke-dashoffset 0.15s;
}

.chat-file-item-fileicon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: #333333;
}

.chat-file-item-meta {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.chat-file-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary, #e5e7eb);
    font-size: 0.82rem;
    max-width: 160px;
}

.chat-file-item-size {
    color: var(--text-muted, #999999);
    font-size: 0.7rem;
}

.chat-file-item-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted, #999999);
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
    transition: all 0.15s;
}

.chat-file-item-remove:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ===== 消息中的文件展示 ===== */
.chat-msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.chat-msg-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-size: 0.9rem;
    color: inherit;
}

.chat-msg-file-chip i {
    font-size: 0.85rem;
    flex-shrink: 0;
}

.chat-msg-file-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 320px;
}

/* ===== 消息导航跳转按钮 (DeepSeek 风格) ===== */
.msg-nav-jump-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: 6px;
    align-self: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.chat-message-row.user:hover .msg-nav-jump-btn,
.chat-message-row.user:focus-within .msg-nav-jump-btn {
    opacity: 1;
}

.msg-nav-jump-btn:hover {
    background: var(--bg-secondary);
    color: var(--accent);
}

.msg-nav-jump-btn:focus-visible {
    outline: 2px solid var(--accent, #3b82f6);
    outline-offset: 2px;
}

.msg-nav-jump-btn:active {
    transform: scale(0.92);
}

/* 导航高亮动画 */
.msg-nav-highlight {
    animation: msgNavHighlight 1.5s ease-out;
}

@keyframes msgNavHighlight {
    0% {
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35);
        background-color: rgba(59, 130, 246, 0.06);
        border-radius: 12px;
    }
    100% {
        box-shadow: 0 0 0 0px rgba(59, 130, 246, 0);
        background-color: transparent;
    }
}
