:root {
    color-scheme: light dark;
    --bg-main: #f5f6f8;
    --bg-sidebar: #ffffff;
    --bg-panel: #ffffff;
    --border-color: #d8dce4;
    --primary: #1f77ff;
    --primary-text: #ffffff;
    --accent: #0d6efd;
    --text-color: #1a1a1a;
    --secondary-text: #6c757d;
    --user-message: #e9f2ff;
    --assistant-message: #f1f3f5;
    --shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
.hidden {
    display: none !important;
}

.auth-view {
    position: fixed;
    inset: 0;
    background: linear-gradient(120deg, #4f46e5, #9333ea);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}

.auth-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-card h1 {
    margin: 0;
    font-size: 24px;
    text-align: center;
    color: #111;
}

.auth-hint {
    margin: 0;
    font-size: 14px;
    color: var(--secondary-text);
    text-align: center;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form label {
    font-size: 14px;
    color: var(--secondary-text);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.auth-form input {
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 10px;
    font-size: 14px;
}

.auth-switch {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    float: right;
}

.user-badge {
    font-size: 14px;
    color: var(--secondary-text);
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width:300px;
    float:left;
}

.session-indicator {
    font-size: 14px;
    color: var(--secondary-text);
}

.admin-role-indicator {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    box-shadow: var(--shadow);
}

.admin-role-indicator svg {
    width: 18px;
    height: 18px;
}

.user-menu {
    position: relative;
}

.avatar-button {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 6px 10px;
    background: #fff;
    cursor: pointer;
    min-width: 0;
}

.avatar-initials {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.avatar-caret {
    width: 18px;
    height: 18px;
    color: var(--secondary-text);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: #fff;
    box-shadow: var(--shadow);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 5;
}

.user-menu.open .user-menu-dropdown {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.menu-item {
    border: none;
    background: none;
    padding: 8px 10px;
    text-align: left;
    border-radius: 8px;
    font-size: 14px;
    color:black;
    cursor: pointer;
}

.menu-item:hover:not(:disabled) {
    background: #f1f3f5;
}

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

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 30;
}

.overlay-content {
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.icon-button {
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

.overlay-close {
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: #f1f3f5;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.overlay-close:hover {
    background: #e6e9ef;
}

.overlay-close .icon-close {
    width: 16px;
    height: 16px;
}

.admin-form {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background: #f8fafc;
}

.admin-form h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.admin-form input {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 8px 10px;
}

.admin-section {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.admin-search {
    display: flex;
    gap: 8px;
}

.admin-search input {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-row {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    background: #fdfdfd;
}

.admin-row-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-row-info strong {
    font-size: 15px;
    color: #111;
}

.admin-row-meta {
    font-size: 13px;
    color: var(--secondary-text);
}

.admin-row-preview {
    font-size: 13px;
    color: var(--secondary-text);
    max-height: 60px;
    overflow: hidden;
}

.admin-row-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}

.empty-note {
    margin: 0;
    font-size: 14px;
    color: var(--secondary-text);
    text-align: center;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "PingFang SC", "Microsoft YaHei", "Helvetica", "Arial", sans-serif;
    background: var(--bg-main);
    color: var(--text-color);
    height: 100vh;
    display: flex;
}

.app-shell {
    display: flex;
    flex: 1;
    max-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 320px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-scroll {
    flex: 1;
    padding: 10px 16px 2px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar-history {
    border-top: 1px solid var(--border-color);
    padding: 3px ;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto; /* 允许滚动 */
    scrollbar-width: none; /* Firefox */
}
.sidebar-history::-webkit-scrollbar { 
    display: none; /* Chrome 和 Safari */
}

.sidebar-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

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

.sidebar-section {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-actions {
    flex-direction: row;
    align-items: center;
}

.sidebar-actions .primary-button,
.sidebar-actions .secondary-button {
    flex: 1;
}

.sidebar-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary-text);
}

.sidebar-input,
.sidebar-range {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: inherit;
}

.sidebar-range {
    height: 4px;
    padding: 0;
}

.sidebar-help {
    font-size: 13px;
    color: var(--secondary-text);
}

.sidebar-heading {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.primary-button,
.secondary-button {
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.primary-button {
    background: var(--primary);
    color: var(--primary-text);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.primary-button:hover:not(:disabled) {
    background: var(--accent);
}

.secondary-button {
    background: #f1f3f5;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.secondary-button:hover:not(:disabled) {
    background: #e6e9ef;
}

.secondary-button.small {
    font-size: 13px;
    padding: 6px 10px;
}

.secondary-button.danger {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

.secondary-button.danger:hover:not(:disabled) {
    background: #c82333;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.history-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 4px;
    align-items: center;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
}

.history-row.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.12);
}

.history-title-link {
    border: none;
    background: none;
    padding: 0;
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-decoration: none;
}

.history-title-link:hover,
.history-title-link:focus-visible {
    text-decoration: underline;
}

.history-row.active .history-title-link {
    color: var(--text-color);
    font-weight: 600;
}

.history-title-text,
.history-subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.history-subtitle {
    font-size: 11px;
    color: var(--secondary-text);
}

.history-icon-button {
    border: none;
    background: #f8f9fb;
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.history-icon-button:hover {
    background: #e6e9ef;
}

.history-pagination {
    display: flex;
    justify-content: space-between;
    gap: 2px;
    margin-bottom: 5px;
    margin-left: 10px;
    margin-right: 10px;
}

.history-pagination .secondary-button {
    padding: 3px 3px;
    font-size: 11px;
    border-radius: 6px;
}

.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    box-shadow: var(--shadow);
}

.app-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, rgba(243, 247, 255, 0.8), rgba(255, 255, 255, 0.9));
}

.message {
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    max-width: 860px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message.notice {
    background: #fff8e1;
    border-style: dashed;
    color: #8c6b00;
    align-self: center;
}

.message.user {
    background: var(--user-message);
    align-self: flex-end;
}

.message.assistant {
    background: var(--assistant-message);
    align-self: flex-start;
}

.message-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary-text);
}

.message-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-color);
    white-space: normal;
    word-break: break-word;
}

.message-content ul {
    margin: 8px 0 8px 18px;
    padding-left: 16px;
}

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

.message-content blockquote {
    margin: 10px 0;
    padding-left: 14px;
    border-left: 3px solid var(--border-color);
    color: var(--secondary-text);
}

.message-content table.md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
    background: #fff;
}

.message-content table.md-table th,
.message-content table.md-table td {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.message-content table.md-table thead {
    background: #f5f6f8;
    font-weight: 600;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 12px 0 6px;
    font-weight: 600;
}

.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 18px; }
.message-content h3 { font-size: 16px; }
.message-content h4 { font-size: 15px; }
.message-content h5,
.message-content h6 { font-size: 14px; }

.message-content pre {
    background: #0d1117;
    color: #e6edf3;
    padding: 12px;
    border-radius: 10px;
    overflow-x: auto;
    font-family: "JetBrains Mono", "Fira Code", "Menlo", "Consolas", monospace;
    font-size: 13px;
    line-height: 1.5;
    margin: 10px 0;
}

.code-block {
    position: relative;
    margin: 10px 0;
}

.code-block pre {
    margin: 0;
    padding-right: 48px;
}

.code-copy-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.code-copy-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.code-copy-btn:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.2);
}

.message-content code {
    font-family: "JetBrains Mono", "Fira Code", "Menlo", "Consolas", monospace;
    background: rgba(13, 110, 253, 0.12);
    color: #0d47a1;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 13px;
}

.message-content pre code {
    display: block;
    background: transparent;
    color: inherit;
    padding: 0;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 6px 0;
}

.big-content-placeholder {
    border: 1px dashed var(--border-color);
    background: var(--assistant-message);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.big-content-preview {
    max-height: 180px;
    overflow: hidden;
    font-size: 13px;
    color: var(--secondary-text);
}

.big-content-meta {
    font-size: 12px;
    color: var(--secondary-text);
}

.big-content-placeholder .message-button {
    align-self: flex-start;
}

.message-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.message-button {
    border: none;
    background: var(--primary);
    color: var(--primary-text);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease;
}

.message-button:hover {
    background: var(--accent);
}

.chat-form {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fff;
}

.chat-textarea {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 10px;
    font-size: 14px;
    resize: vertical;
    min-height: 70px;
}

.chat-form-footer {
    display: flex;
    align-items: center;
    gap: 10px;
}

#send-btn {
    margin-left: auto;
}

#end-chat-btn {
    min-width: 110px;
}

.file-input-label {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px dashed var(--border-color);
    color: var(--secondary-text);
    cursor: pointer;
    background: #fafbfc;
}

.file-input {
    display: none;
}

.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 4px;
}

.attachment-preview-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #f8fafc;
}

.attachment-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #fff;
}

.attachment-file-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: #e9ecf2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.attachment-filename {
    font-size: 13px;
    color: var(--secondary-text);
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-status {
    min-height: 20px;
    font-size: 13px;
    color: var(--secondary-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-status.running {
    color: var(--accent);
}

.chat-status-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: chat-spin 0.8s linear infinite;
}

.chat-status-text {
    display: inline-flex;
    align-items: center;
}

.chat-status.error {
    color: #dc3545;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(33, 37, 41, 0.9);
    color: #fff;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 999;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.success {
    background: #28a745;
}

.toast.error {
    background: #dc3545;
}

.hidden {
    display: none;
}

.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

mark.hl {
    background: #fff3a3;
    color: inherit;
    padding: 0 2px;
    border-radius: 3px;
}

@keyframes chat-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 960px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-scroll {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 16px;
    }

    .main-panel {
        box-shadow: none;
    }

    .history-list {
        max-height: 180px;
    }

    .sidebar-actions {
        flex-direction: column;
    }
}

@media (max-width: 600px) {
    .chat-form-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-form-footer .primary-button {
        width: 100%;
    }

    .file-input-label {
        width: 100%;
        justify-content: center;
    }
}
:root {
