:root {
    --accent: #0F6E56;
    --accent-light: #E1F5EE;
    --accent-rgb: 15, 110, 86;
    --bg: #f5f5f4;
    --surface: #ffffff;
    --border: #e7e5e4;
    --text: #1c1917;
    --text-secondary: #78716c;
    --text-tertiary: #a8a29e;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #ca8a04;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

.header-left { flex-shrink: 0; }

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.subject-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: center;
    overflow-x: auto;
}

.subject-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
}

.subject-tab:hover {
    background: var(--bg);
}

.subject-tab.active {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
}

.subject-tab .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tab-color, var(--accent));
}

.subject-tab.active .dot {
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.2);
}

.header-right { flex-shrink: 0; }

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg);
    color: var(--text);
}

/* Main */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Chat */
.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.teacher-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.teacher-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    transition: background 0.3s;
}

.teacher-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.teacher-status-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-left: 8px;
}

.kb-source-inline {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 10px;
}

.teacher-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.kb-source {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    padding-left: 14px;
}

.text-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.text-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    color: white;
}

.msg.user .msg-avatar {
    background: var(--text-tertiary);
}

.msg.assistant .msg-avatar {
    background: var(--accent);
    transition: background 0.3s;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
}

.msg.user .msg-bubble {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
    transition: background 0.3s;
}

.msg.assistant .msg-bubble {
    background: var(--bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 8px 20px; }
.msg-bubble li { margin-bottom: 2px; }
.msg-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
}
.msg.user .msg-bubble code {
    background: rgba(255,255,255,0.2);
}
.msg-bubble .mistake-tag {
    display: inline-block;
    margin-top: 8px;
    padding: 2px 8px;
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    border-radius: 4px;
    font-size: 12px;
}
.msg-bubble .mastery-tag {
    display: inline-block;
    margin-top: 8px;
    padding: 2px 8px;
    background: rgba(22, 163, 74, 0.1);
    color: var(--success);
    border-radius: 4px;
    font-size: 12px;
}

.msg-bubble .knowledge-source-tag {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-tertiary);
    font-weight: 400;
    border: none;
    background: transparent;
}


.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat input */
.chat-input-area {
    border-top: 1px solid var(--border);
    padding: 6px 16px 10px;
    flex-shrink: 0;
    background: var(--surface);
}

.quick-commands {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    overflow-x: auto;
    flex-wrap: wrap;
}

.quick-cmd {
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quick-cmd:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.input-row {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

#chatInput {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.5;
}

#chatInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.send-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.attach-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn.recording {
    border: 1px solid #dc2626;
    background: #fee2e2;
    color: #dc2626;
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
    50% { transform: scale(1.08); box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.attach-btn .rec-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #dc2626;
    animation: recBlink 1s ease-in-out infinite;
}

@keyframes recBlink {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); opacity: 1; }
    50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); opacity: 0.6; }
}

.rec-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 13px;
    font-weight: 500;
}

.rec-status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #dc2626;
    animation: recBlink 1s ease-in-out infinite;
}

.attach-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.attachment-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.attachment-thumb {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 200px;
}

.attachment-thumb img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.attachment-thumb .file-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.attachment-remove {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}

.attachment-remove:hover { color: var(--danger); }

#chatInput.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

.msg-attachments {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.msg-attachment-img {
    max-width: 220px;
    max-height: 160px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.3);
}

.msg-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
    font-size: 12px;
    word-break: break-all;
}

.msg.assistant .msg-attachment-file {
    background: var(--bg);
    color: var(--text);
}

/* Sidebar */
.sidebar {
    width: 340px;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    flex-shrink: 0;
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.sidebar-tab:hover {
    color: var(--text);
}

.sidebar-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Mistake cards */
.mistake-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: all 0.2s;
}

.mistake-card:hover {
    border-color: var(--text-tertiary);
}

.mistake-card.mastered {
    opacity: 0.6;
}

.mistake-card .mistake-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.mistake-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.tag-concept { background: #fee2e2; color: #991b1b; }
.tag-formula { background: #fef3c7; color: #854d0e; }
.tag-calculation { background: #e0e7ff; color: #3730a3; }
.tag-condition { background: #f3e8ff; color: #6b21a8; }
.tag-method { background: #d1fae5; color: #065f46; }
.tag-unknown { background: var(--bg); color: var(--text-tertiary); }

.mistake-date {
    font-size: 11px;
    color: var(--text-tertiary);
}

.mistake-question {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.5;
}

.mistake-actions {
    display: flex;
    gap: 8px;
}

.mistake-actions button {
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.mistake-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
}

.empty-state svg {
    margin-bottom: 12px;
    opacity: 0.4;
}

/* Knowledge base */
.kb-search {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.kb-search input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.kb-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.kb-search button {
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.kb-search button:hover { opacity: 0.9; }

.kb-doc {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.kb-doc:hover {
    border-color: var(--text-tertiary);
}

.kb-doc-header {
    padding: 10px 14px;
    background: var(--accent-light);
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kb-doc-header .arrow {
    transition: transform 0.2s;
    font-size: 11px;
}

.kb-doc.collapsed .kb-doc-header .arrow {
    transform: rotate(-90deg);
}

.kb-doc-body {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.kb-doc.collapsed .kb-doc-body {
    display: none;
}

.kb-doc-body strong { font-weight: 600; }
.kb-doc-body code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
}

/* Analytics */
.analytics-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}

.analytics-card h3 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    text-align: center;
    padding: 12px 8px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
    transition: color 0.3s;
}

.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.5s, background 0.3s;
}

.error-type-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.error-type-bar .label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 60px;
}

.error-type-bar .bar {
    flex: 1;
    height: 18px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.error-type-bar .fill {
    height: 100%;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 11px;
    color: white;
    font-weight: 500;
    min-width: 20px;
    transition: width 0.5s;
}

.weak-point {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 12px;
}

.weak-point .count {
    color: var(--danger);
    font-weight: 500;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: 16px;
    width: 460px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 0 4px;
    line-height: 1;
}

.close-btn:hover { color: var(--text); }

.modal-body {
    padding: 20px;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.btn-primary, .btn-secondary {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
    background: var(--bg);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--border);
    color: var(--text);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    z-index: 200;
    transition: transform 0.3s;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .subject-tabs { gap: 2px; }
    .subject-tab { padding: 4px 10px; font-size: 12px; }
}

/* Admin Panel */
.modal-sm { width: 400px; }
.modal-lg { width: 900px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-lg .modal-body { overflow-y: auto; flex: 1; min-height: 0; }

.admin-body {
    display: flex;
    gap: 0;
    padding: 0 !important;
    min-height: 480px;
    max-height: calc(85vh - 110px);
}

.admin-left {
    width: 200px;
    flex-shrink: 0;
    padding: 16px;
    border-right: 1px solid var(--border);
    background: var(--bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-right {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    min-width: 0;
}

.admin-edit-head {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.admin-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.admin-subject-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-subject-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    font-family: inherit;
    transition: all 0.15s;
}

.admin-subject-item:hover {
    background: var(--surface);
    color: var(--text);
}

.admin-subject-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.admin-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 0;
}

.admin-right textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.5;
    background: var(--bg);
}

.admin-right textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.admin-right input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg);
}

.admin-right input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.admin-right input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.admin-right input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.admin-advanced {
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
}

.admin-advanced summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    user-select: none;
}

.admin-advanced summary:hover {
    color: var(--accent);
}

@media (max-width: 768px) {
    .admin-body { flex-direction: column; }
    .admin-left { width: 100%; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; padding: 10px; }
    .admin-section-title { display: none; }
    .admin-hr { display: none; }
    .admin-subject-item { width: auto; }
}

/* ============ 新壳层：仿 pyModel_latest 界面 ============ */
#app { flex-direction: row; }

/* 左侧深色导航 */
.app-nav {
    width: 224px;
    background: #1e1e2d;
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}
.app-nav-brand {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 18px;
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    letter-spacing: 0.3px;
}
.app-nav-logo { color: #3b82f6; font-size: 20px; }
.app-nav-menu { flex: 1; overflow-y: auto; padding: 10px 0 12px; }
.app-nav-group { padding: 6px 12px; }
.app-nav-label {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin: 8px 6px 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.app-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    margin: 2px 0;
    border: none;
    background: transparent;
    color: #cbd5e1;
    font-size: 13.5px;
    cursor: pointer;
    border-left: 3px solid transparent;
    border-radius: 6px;
    transition: all 0.15s;
}
.app-nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.app-nav-item.active {
    background: rgba(59,130,246,0.14);
    color: #fff;
    border-left-color: #3b82f6;
}
.app-nav-item.active .app-nav-icon { color: #60a5fa; }
.app-nav-icon { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.app-nav-foot {
    padding: 12px 18px;
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* 右侧壳 */
.app-shell { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f4f6f8; }
/* 聊天区内不再重复显示品牌 logo，顶栏已承担标题 */
#view-chat .app-header .header-left .logo { display: none; }
.app-topbar {
    height: 56px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    z-index: 10;
    flex-shrink: 0;
}
.app-topbar-title { font-size: 16px; font-weight: 600; color: #1f2937; white-space: nowrap; }
.topbar-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    margin: 0 16px;
    overflow-x: auto;
}
.topbar-toolbar .chat-toolbar-select {
    gap: 4px;
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
}

/* ---------- 学科入口（顶栏筛选区） ---------- */
/* 学科切换放到底部对话区的顶栏，避免藏在「对话记录」抽屉里找不到 */
.topbar-toolbar { flex-wrap: wrap; row-gap: 6px; }
.chat-subject-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    flex: 0 1 auto;
    min-width: 0;
    order: -1;
}
.chat-subject-bar .subject-tab {
    flex: 0 0 auto;
    padding: 4px 11px;
    font-size: 12.5px;
    min-height: 30px;
}
.chat-subject-bar .subject-tab .dot { width: 7px; height: 7px; }
/* 「模型」下拉取消：系统只绑定一个模型，不再需要选择 */
.topbar-toolbar .tb-model { display: none; }
/* 学科入口已在顶栏，对话记录面板内不再重复一行 */
.chat-history-subjects { display: none; }
.ocr-plain { white-space: pre-wrap; word-break: break-word; font-family: "Microsoft YaHei", "PingFang SC", ui-monospace, monospace; line-height: 1.9; font-size: 14px; background:#fff; color:#111827; margin:0; }

.ocr-mode { display:flex; align-items:center; gap:18px; flex-wrap:wrap; margin-bottom:12px; font-size:13px; color:var(--text-secondary); }
.ocr-mode-label { font-weight:600; color:var(--text-primary); }
.ocr-mode label { display:inline-flex; align-items:center; gap:6px; cursor:pointer; }

.ocr-structured { background:#fff; border:1px solid var(--border); border-radius:10px; padding:16px; overflow:auto; line-height:1.75; }
.ocr-structured table { border-collapse:collapse; width:100%; margin:10px 0; font-size:13px; }
.ocr-structured th, .ocr-structured td { border:1px solid var(--border); padding:6px 8px; text-align:left; vertical-align:top; }
.ocr-structured th { background:#f9fafb; }
.ocr-structured pre { background:#f6f8fa; padding:10px; border-radius:8px; overflow:auto; }
.ocr-toolbar { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:10px; flex-wrap:wrap; }
.ocr-actions { display:flex; gap:8px; flex-wrap:wrap; }
.ocr-meta { font-size:12px; color:#6b7280; }
.ocr-layout-frame { width:100%; min-height:680px; border:1px solid var(--border); border-radius:10px; background:#fff; display:block; }

/* ===== 彩色笔记（复刻 / 美化） ===== */
.ocr-note { margin:14px 0; padding:14px 16px; border:1px solid #e5e7eb; border-radius:12px; background:linear-gradient(180deg,#fffdf8 0%,#ffffff 100%); }
.ocr-note-head { font-size:13px; color:#6b7280; line-height:1.8; margin-bottom:10px; display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.ocr-note-badge { display:inline-block; padding:2px 10px; border-radius:999px; background:#fde7ef; color:#b4325f; font-size:12px; font-weight:600; white-space:nowrap; }
.ocr-note-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.ocr-note-style { display:inline-flex; align-items:center; gap:6px; font-size:13px; color:var(--text-secondary); }
.ocr-note-style select { padding:6px 10px; border:1px solid var(--border); border-radius:8px; background:#fff; font-size:13px; color:var(--text-primary); cursor:pointer; }
.ocr-note-tip { margin-top:10px; font-size:12px; color:#6b7280; }
.ocr-note-tip.err { color:#dc2626; }
.ocr-note-frame-head { font-size:12px; color:#6b7280; margin:12px 0 6px; display:flex; align-items:center; gap:8px; }
.ocr-note-mini { cursor:pointer; color:#2563eb; }
.ocr-note-frame { width:100%; height:760px; border:1px solid var(--border); border-radius:12px; background:#fff; display:block; }
.topbar-toolbar .chat-toolbar-select select {
    max-width: 140px;
    min-width: 80px;
    padding: 4px 6px;
    font-size: 12px;
}
.topbar-toolbar .chat-icon-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
}
.app-topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.app-role-badge {
    color: #dc2626;
    background: #fef2f2;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    border: 1px solid #fee2e2;
}
.app-username { color: #374151; }
.app-topbar-link {
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.15s;
}
.app-topbar-link:hover { color: #2563eb; }
.app-topbar-logout:hover { color: #dc2626; }

/* 内容视区 */
.app-view-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    min-height: 0;
    padding: 0;
}
.app-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow: hidden;
}
.app-view > .view-head {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #eef0f2;
}
.app-view > .view-head h2 { font-size: 16px; font-weight: 600; color: #1f2937; }
.app-view > .view-head p { font-size: 12px; color: #6b7280; margin-top: 2px; }
.view-pad { flex: 1; overflow-y: auto; padding: 20px; }

/* 知识库卡片 */
.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.kb-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.2s, transform 0.2s;
}
.kb-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.08); transform: translateY(-2px); }
.kb-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.kb-card-folder { font-size: 26px; }
.kb-card-badge {
    font-size: 11px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 10px;
}
.kb-card-name { font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 4px; }
.kb-card-desc { font-size: 12px; color: #9ca3af; margin-bottom: 14px; min-height: 16px; }
.kb-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 14px;
    border-top: 1px dashed #eef0f2;
    padding-top: 12px;
}
.kb-card-actions { display: flex; gap: 8px; }
.kb-btn {
    flex: 1;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    padding: 7px 10px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.kb-btn:hover { background: #f9fafb; color: #2563eb; border-color: #bfdbfe; }
.kb-btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.kb-btn-primary:hover { background: #1d4ed8; color: #fff; }
.kb-btn-ghost { background: #fff; color: #374151; }

/* 学科行 */
.subject-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid #eef0f2;
    border-radius: 10px;
    margin-bottom: 10px;
}
.subject-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.subject-name { font-weight: 600; color: #1f2937; min-width: 120px; }
.subject-teacher { color: #6b7280; flex: 1; }
.subject-kbid { color: #9ca3af; font-size: 12px; }

/* 多数据源卡片 */
.ds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.ds-card { border: 1px solid #eef0f2; border-radius: 10px; padding: 14px; }
.ds-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ds-icon { font-size: 16px; }
.ds-name { font-weight: 600; color: #1f2937; flex: 1; }
.ds-badge { font-size: 11px; color: #6b7280; background: #f3f4f6; padding: 2px 8px; border-radius: 10px; }
.ds-badge.ok { color: #16a34a; background: #f0fdf4; }
.ds-desc { font-size: 12px; color: #9ca3af; }
.ds-note { font-size: 12px; color: #6b7280; background: #f9fafb; border: 1px solid #eef0f2; padding: 10px 12px; border-radius: 8px; }

/* OCR */
.ocr-drop {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}
.ocr-drop:hover, .ocr-drop.over { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.ocr-actions { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.ocr-cam-btn { background: linear-gradient(135deg, #2563eb, #0ea5e9); color: #fff; border: none; border-radius: 10px; padding: 9px 18px; font-size: 13px; cursor: pointer; font-family: inherit; box-shadow: 0 4px 14px rgba(37,99,235,.28); transition: .15s; }
.ocr-cam-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(37,99,235,.36); }
.ocr-cam-hint { font-size: 12px; color: #94a3b8; }
.ocr-status { color: #6b7280; font-size: 13px; }
.ocr-status.err { color: #dc2626; }
.ocr-ok { color: #16a34a; font-size: 13px; margin-bottom: 8px; font-weight: 600; }
.ocr-text {
    background: #f9fafb;
    border: 1px solid #eef0f2;
    border-radius: 8px;
    padding: 12px;
    white-space: pre-wrap;
    font-size: 12.5px;
    color: #374151;
    max-height: 420px;
    overflow-y: auto;
}

/* RAG 评估 */
.rag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.rag-stat { border: 1px solid #eef0f2; border-radius: 10px; padding: 14px; text-align: center; }
.rag-stat-name { font-size: 13px; color: #6b7280; margin-bottom: 6px; }
.rag-stat-val { font-size: 22px; font-weight: 700; color: #2563eb; }
.rag-test { border-top: 1px solid #eef0f2; padding-top: 18px; }
.rag-test h4 { font-size: 14px; color: #1f2937; margin-bottom: 12px; }
.rag-test select, .rag-test input {
    padding: 8px 10px; border: 1px solid #e5e7eb; border-radius: 6px; margin-right: 8px; font-size: 13px;
}
.rag-test input { flex: 1; min-width: 200px; }
.rag-hit { border: 1px solid #eef0f2; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.rag-hit b { color: #1f2937; font-size: 13px; }
.rag-hit p { color: #6b7280; font-size: 12px; margin-top: 4px; }

/* 小屏折叠侧栏 */
@media (max-width: 900px) {
    .app-nav { width: 64px; }
    .app-nav-brand span:last-child, .app-nav-label, .app-nav-label-txt, .app-nav-foot { display: none; }
    .app-nav-item { justify-content: center; }
}

/* ============ 问答界面：RAG 风格（仿知识库源码系统） ============ */
.chat-view { flex-direction: row; border-radius: 0; border: none; }

/* 左侧历史对话面板 */
.chat-history-panel {
    width: 200px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #eef0f2;
    display: flex;
    flex-direction: column;
    transition: width 0.22s ease;
    overflow: hidden;
}
.chat-history-panel.collapsed { width: 0; border-right: none; }
.chat-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 10px 6px;
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    flex-shrink: 0;
}
.chat-history-new {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 8px;
    background: #eef2ff;
    color: #2563eb;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
}
.chat-history-new:hover { background: #2563eb; color: #fff; }
.chat-history-list { flex: 1; overflow-y: auto; padding: 0 10px 14px; }
.chat-history-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid #eef0f2;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.15s;
    background: #fff;
}
.chat-history-item:hover { border-color: #d1d5db; background: #f9fafb; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.chat-history-item.active { background: var(--accent-light, #eef2ff); border-color: var(--accent, #c7d2fe); }
.chat-history-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: #eef2ff;
}
.chat-history-item-body { flex: 1; min-width: 0; }
.chat-history-item-t { font-size: 14px; font-weight: 600; color: #1f2937; line-height: 1.3; }
.chat-history-item-s { font-size: 12px; color: #6b7280; margin-top: 2px; }
.chat-history-item-d { font-size: 11px; color: #9ca3af; margin-top: 5px; }
.chat-history-empty { padding: 20px 8px; text-align: center; color: #9ca3af; font-size: 12px; }

/* 右侧问答工作区 */
.chat-workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-toolbar {
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid #eef0f2;
    background: #fff;
}
.chat-toolbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-toolbar-title { font-size: 15px; font-weight: 600; color: #1f2937; white-space: nowrap; }
.chat-toolbar-right { display: flex; align-items: center; gap: 10px; }
.chat-icon-btn {
    width: 34px;
    height: 34px;
    border: 1px solid #eef0f2;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.chat-icon-btn:hover { background: #f3f4f6; color: #2563eb; border-color: #d1d5db; }
.chat-toolbar-select {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
}
.chat-toolbar-select select {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: #374151;
    outline: none;
    cursor: pointer;
    max-width: 160px;
    transition: border-color 0.15s;
}
.chat-toolbar-select select:focus { border-color: #2563eb; }

.chat-body { flex: 1; display: flex; min-height: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* 右侧学习工具侧栏 */
.chat-sidebar {
    width: 0;
    overflow: hidden;
    border-left: 1px solid #eef0f2;
    background: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: width 0.22s ease;
}
.chat-sidebar.open { width: 340px; }
.chat-sidebar .sidebar-tabs,
.chat-sidebar .sidebar-body { min-width: 340px; }
.chat-sidebar .sidebar-tab { padding: 12px 4px; font-size: 12px; white-space: nowrap; }
.chat-sidebar-close {
    border: none;
    background: #f9fafb;
    color: #6b7280;
    font-size: 12px;
    padding: 8px;
    cursor: pointer;
    border-top: 1px solid #eef0f2;
    flex-shrink: 0;
}
.chat-sidebar-close:hover { color: #2563eb; background: #eef2ff; }

/* 底部输入提示 */
.chat-input-area { position: relative; }
.input-hint {
    font-size: 10px;
    color: #c0c4cc;
    margin-top: 3px;
    text-align: center;
}

/* ============ 知识库：学科文档列表弹窗 ============ */
.kb-doc-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-bottom: 14px;
    margin-bottom: 12px;
    border-bottom: 1px solid #f0f1f3;
}
.kb-doc-action {
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    padding: 7px 14px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.kb-doc-action:hover { background: #f9fafb; color: #2563eb; border-color: #bfdbfe; }
.kb-doc-action.danger:hover { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.kb-doc-check-all { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #6b7280; cursor: pointer; }
.kb-doc-check-all input { width: 15px; height: 15px; accent-color: #2563eb; }
.kb-doc-empty { text-align: center; color: #9ca3af; font-size: 13px; padding: 50px 20px; }
.kb-doc-loading { text-align: center; color: #9ca3af; font-size: 13px; padding: 40px 20px; }

.kb-doc-group { margin-bottom: 14px; }
.kb-doc-group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #f9fafb;
    border-radius: 8px 8px 0 0;
    border: 1px solid #f0f1f3;
    border-bottom: none;
    font-size: 13px;
}
.kb-doc-folder { font-size: 14px; }
.kb-doc-folder-name { font-weight: 600; color: #1f2937; }
.kb-doc-count { font-size: 12px; color: #9ca3af; margin-left: auto; }
.kb-doc-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #f0f1f3;
    border-top: none;
    cursor: pointer;
    transition: background 0.15s;
}
.kb-doc-row:hover { background: #f9fafb; }
.kb-doc-row:last-child { border-radius: 0 0 8px 8px; }
.kb-doc-row-link:hover .kb-doc-title { color: #2563eb; }
.kb-doc-content { white-space: pre-wrap; word-break: break-word; font-size: 13px; color: #374151; line-height: 1.7; max-height: 60vh; overflow: auto; }
.kb-doc-page-img { display: block; max-width: 100%; margin: 10px auto; border: 1px solid #e5e7eb; border-radius: 6px; }
.kb-doc-check { width: 15px; height: 15px; accent-color: #2563eb; flex-shrink: 0; }
.kb-doc-icon { font-size: 16px; }
.kb-doc-name { flex: 1; font-size: 13px; color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-doc-meta { font-size: 12px; color: #9ca3af; white-space: nowrap; }
.kb-doc-open {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #2563eb;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.kb-doc-open:hover { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ============ 知识库：文档查看器弹窗 ============ */
.modal-xl { width: 1100px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal-xl .modal-body { overflow-y: auto; flex: 1; min-height: 0; }
.kb-viewer-body { padding: 16px 20px; }
.kb-viewer-pages { text-align: center; margin-bottom: 16px; }
.kb-page-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.kb-viewer-meta {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f1f3;
}
.kb-viewer-content {
    font-family: inherit;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    color: #374151;
    background: #f9fafb;
    border: 1px solid #f0f1f3;
    border-radius: 8px;
    padding: 14px 16px;
}

/* 小屏适配：收起历史面板与工具侧栏 */
@media (max-width: 900px) {
    .chat-history-panel { position: absolute; z-index: 30; height: 100%; box-shadow: var(--shadow-lg); }
    .chat-history-panel.collapsed { width: 0; }
    .chat-sidebar { position: absolute; right: 0; top: 0; height: 100%; top: 52px; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); }
    .chat-toolbar-select span, .chat-toolbar-select label { display: none; }
    .chat-toolbar { height: 48px; padding: 0 10px; }
}


/* Agents page */
.agents-toolbar { margin-bottom: 16px; }
.agent-group { margin-bottom: 24px; }
.agent-group h3 { font-size: 15px; color: var(--text-secondary, #666); margin-bottom: 12px; border-bottom: 1px solid var(--border, #e5e7eb); padding-bottom: 8px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.agent-card { background: #fff; border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); transition: box-shadow 0.2s; cursor: default; }
.agent-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.agent-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.agent-card-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0; }
.agent-card-info { flex: 1; min-width: 0; }
.agent-card-name { font-size: 14px; font-weight: 600; color: var(--text-primary, #1f2937); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-card-subject { font-size: 12px; color: var(--text-secondary, #9ca3af); margin-top: 2px; }
.agent-card-desc { font-size: 13px; color: var(--text-secondary, #6b7280); line-height: 1.5; }
.agent-form { max-width: 640px; margin: 0 auto; }
.agent-form h3 { margin-bottom: 20px; }
.agent-subgroup h4 { font-size: 13px; font-weight: 600; color: var(--text-secondary, #6b7280); margin: 12px 0 8px; }
.agent-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.agent-use-btn { padding: 6px 12px; font-size: 12px; }

.view-empty { text-align: center; padding: 40px 0; color: var(--text-secondary, #9ca3af); font-size: 14px; }

/* 语音配置 */
.voice-note { background: #eef6ff; border: 1px solid #d6e8ff; color: #2563eb; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 18px; display: flex; align-items: center; gap: 6px; }
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 18px; align-items: start; }
.voice-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.voice-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.voice-card-head h3 { font-size: 15px; font-weight: 600; color: #1f2937; flex: 1; }
.voice-badge { font-size: 11px; color: #9ca3af; background: #f3f4f6; padding: 2px 8px; border-radius: 10px; }
.voice-badge.on { color: #d97706; background: #fff7ed; border: 1px solid #fed7aa; }
.voice-badge-default { font-size: 11px; color: #2563eb; background: #eff6ff; border: 1px solid #bfdbfe; padding: 2px 8px; border-radius: 10px; }
.voice-field { margin-bottom: 12px; }
.voice-field label { display: block; font-size: 12px; color: #6b7280; margin-bottom: 5px; }
.voice-field input, .voice-field select { width: 100%; border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px 10px; font-size: 13px; color: #374151; background: #fff; transition: border-color 0.15s; }
.voice-field input:focus, .voice-field select:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.12); }
.voice-default { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #4b5563; margin: 14px 0; cursor: pointer; }
.voice-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.voice-btn { border: 1px solid #e5e7eb; background: #fff; color: #374151; padding: 7px 14px; font-size: 13px; border-radius: 6px; cursor: pointer; transition: all 0.15s; }
.voice-btn:hover { border-color: #bfdbfe; color: #2563eb; background: #f9fafb; }
.voice-btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.voice-btn.primary:hover { background: #1d4ed8; color: #fff; }
.voice-test-result { margin-top: 12px; font-size: 12px; border-radius: 6px; padding: 8px 10px; }
.voice-test-result.ok { color: #047857; background: #ecfdf5; border: 1px solid #a7f3d0; }
.voice-test-result.err { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; }
.voice-hint { margin: 0 0 12px; padding: 9px 11px; font-size: 12px; line-height: 1.7; color: #475569; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; }
.voice-hint b { color: #1e293b; font-weight: 600; }
.voice-hint a { color: #2563eb; text-decoration: none; word-break: break-all; }
.voice-hint a:hover { text-decoration: underline; }
.voice-loading { text-align: center; padding: 40px 0; color: #9ca3af; font-size: 14px; }

/* ????????? slices + ???? */
.chat-history-subjects {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 2px 8px 8px;
    border-bottom: 1px solid #eef0f2;
    flex-shrink: 0;
}
.chat-history-subjects .subject-tab {
    padding: 3px 10px;
    font-size: 12px;
    gap: 4px;
    border-radius: 14px;
}
.chat-history-subjects .subject-tab .dot {
    width: 6px;
    height: 6px;
}
.chat-history-item.chat-session-item.active {
    border-color: var(--accent, #3849a0);
    background: var(--accent-light, #eef2ff);
}

/* Chat toolbar breathing room */
.chat-toolbar {
    height: auto;
    min-height: 40px;
    padding: 4px 14px;
    gap: 10px;
    flex-wrap: wrap;
}
.chat-toolbar-left { flex: 0 0 auto; }
.chat-toolbar-right {
    flex: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}
.chat-toolbar-select {
    gap: 4px;
    max-width: 190px;
    min-width: 0;
    white-space: nowrap;
}
.chat-toolbar-select select {
    max-width: 140px;
    min-width: 92px;
    padding: 5px 8px;
    font-size: 12.5px;
}
@media (max-width: 1500px) {
    .chat-toolbar-select { max-width: 175px; }
    .chat-toolbar-select select { max-width: 120px; }
}

/* Chat header actions */
.chat-header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topic-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid #c3d3ff; background: #eef4ff; color: #204ecf;
    padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
    cursor: pointer; white-space: nowrap; transition: all .15s;
}
.topic-btn:hover { background: #dbe8ff; border-color: #9db4ff; transform: translateY(-1px); }
.danger-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff1f2; color: #be123c; border: 1px solid #fda4af;
    padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 800;
    cursor: pointer; white-space: nowrap; transition: all .15s;
}
.danger-btn:hover { background: #dc2626; color: #fff; border-color: #dc2626; transform: translateY(-1px); }

/* History tabs and archive */
.chat-history-tabs { display: flex; align-items: center; gap: 6px; }
.history-view-btn {
    border: 1px solid #e5e7eb; background: #fff; color: #6b7280;
    border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.history-view-btn.active { border-color: #c3d3ff; background: #eef4ff; color: #204ecf; }
.chat-history-item { position: relative; }
.archive-delete-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca;
    border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.archive-delete-btn:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

/* Diagram generation */
.diagram-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 10px;
    padding: 6px 14px 6px 10px;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    background: linear-gradient(135deg, #eff6ff, #f8fafc);
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.10);
    transition: transform 0.16s, box-shadow 0.16s, border-color 0.16s, background 0.16s;
}
.diagram-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 8px;
    background: #dbeafe;
    font-size: 13px;
    line-height: 1;
}
.diagram-btn-text { white-space: nowrap; }
.diagram-btn:hover {
    transform: translateY(-1px);
    border-color: #bfdbfe;
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    box-shadow: 0 5px 16px rgba(37, 99, 235, 0.16);
}
.diagram-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
.diagram-container {
    margin-top: 10px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.diagram-img {
    width: 100%;
    height: auto;
    display: block;
}

/* Chat panel resize handle */
.chat-panel-resize {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
    z-index: 5;
}
.chat-panel-resize:hover {
    background: var(--accent, #2563eb);
}
.chat-history-panel {
    overflow: hidden;
    min-width: 0;
}

/* Credits badge and activation key */
.credits-badge {
    font-size: 12px;
    color: #f59e0b;
    font-weight: 600;
    white-space: nowrap;
}

/* ===== 生图后的操作（保存到知识点卡片） ===== */
.diagram-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.diagram-save-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #c7d7fe;
    background: #eef4ff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: all .15s;
    min-height: 34px;
}
.diagram-save-btn:hover { background: #dbe8ff; border-color: #9db4ff; }
.diagram-save-btn:disabled { opacity: .6; cursor: default; }
.diagram-save-btn.saved { background: #e8f7ee; border-color: #a7e0bf; color: #15803d; }
.diagram-auto {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
}
.diagram-auto input { cursor: pointer; }

/* ===== 知识点卡片页 ===== */
.kc-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.kc-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid #eef0f2;
    background: #fff;
}
.kc-toolbar select, .kc-toolbar input[type="text"] {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    min-height: 36px;
}
.kc-toolbar-spacer { flex: 1; }
.kc-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #374151;
    font-size: 13px;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    min-height: 36px;
    transition: all .15s;
}
.kc-btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.kc-btn.danger { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.kc-btn.danger:hover { background: #fee2e2; }
.kc-btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.kc-body { flex: 1; overflow-y: auto; padding: 18px; background: #f7f8fa; }
.kc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.kc-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: box-shadow .18s, transform .18s;
}
.kc-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,0.10); transform: translateY(-2px); }
.kc-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #f1f3f5;
    cursor: zoom-in;
    overflow: hidden;
}
.kc-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kc-card-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: #2563eb;
}
.kc-card-meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.kc-card-title { font-size: 14px; font-weight: 600; color: #1f2937; line-height: 1.35; word-break: break-word; }
.kc-card-sub { font-size: 12px; color: #9ca3af; }
.kc-card-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.kc-tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: #4338ca; }
.kc-card-ops { display: flex; gap: 8px; margin-top: 4px; }
.kc-card-ops button {
    flex: 1;
    font-size: 12px;
    padding: 7px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: #374151;
    cursor: pointer;
    min-height: 34px;
}
.kc-card-ops button:hover { background: #f9fafb; }
.kc-empty { text-align: center; color: #9ca3af; padding: 60px 20px; font-size: 14px; line-height: 1.9; }
.kc-viewer {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.86);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.kc-viewer.open { display: flex; }
.kc-viewer img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.kc-viewer-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: rgba(255,255,255,0.14);
    border: none;
    color: #fff;
    font-size: 22px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
}

.kc-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
}
.kc-count { font-size: 13px; color: #6b7280; }
.kc-toast {
    position: fixed;
    left: 50%;
    bottom: 40px;
    transform: translate(-50%, 16px);
    background: rgba(17,24,39,0.94);
    color: #fff;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 10001;
    opacity: 0;
    transition: all .25s;
    pointer-events: none;
    max-width: 86vw;
    text-align: center;
}
.kc-toast.show { opacity: 1; transform: translate(-50%, 0); }
/* ============================================================
   移动端 / 平板自适应（手机、平板可用）
   ============================================================ */

/* 小屏专属控件：桌面默认隐藏 */
.app-nav-toggle { display: none; }
.app-nav-close { display: none; }
.app-nav-backdrop { display: none; }
.chat-history-toggle { display: none; }
/* 🛠️ 按钮：桌面只显示图标，手机显示「学习工具」文字 */
.chat-icon-btn-ico { display: inline; }
.chat-icon-btn-txt { display: none; }

/* 导航分组标题（补齐缺失样式） */
.app-nav-group-title {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin: 8px 6px 4px;
    letter-spacing: 0.5px;
}

@supports (height: 100dvh) {
    #app { height: 100dvh; }
}

/* ---------- 平板（769px – 1024px） ---------- */
@media (max-width: 1024px) {
    /* 导航收成图标条，保留常驻 */
    .app-nav { width: 76px; }
    .app-nav-brand { padding: 0 8px; font-size: 0; gap: 0; justify-content: center; }
    .app-nav-brand .app-nav-logo { font-size: 20px; }
    .app-nav .app-nav-group { padding: 4px 8px; }
    .app-nav .app-nav-group-title { display: none; }
    .app-nav .app-nav-item { justify-content: center; padding: 11px 8px; }
    /* 图标条模式下隐藏文字，避免挤出栏宽 */
    .app-nav .app-nav-brand span:last-child,
    .app-nav .app-nav-label,
    .app-nav .app-nav-label-txt,
    .app-nav .app-nav-foot { display: none; }

    /* 顶栏改为两行，避免标题/筛选/账号互相挤压 */
    .app-topbar {
        height: auto;
        min-height: 56px;
        padding: 8px 12px;
        flex-wrap: wrap;
        row-gap: 6px;
        align-items: center;
    }
    .app-topbar-title { flex: 1 1 auto; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
    .app-topbar-right { margin-left: auto; gap: 10px; flex-shrink: 0; }
    .topbar-toolbar {
        order: 5;
        flex: 1 0 100%;
        margin: 0;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .topbar-toolbar::-webkit-scrollbar { display: none; }
    .topbar-toolbar .chat-toolbar-select { flex: 0 0 auto; font-size: 12px; }
    .topbar-toolbar .chat-toolbar-select select { max-width: none; min-width: 88px; min-height: 34px; font-size: 12px; }
    .topbar-toolbar .chat-icon-btn { width: 34px; height: 34px; flex: 0 0 34px; }

    /* 学科入口独占一行，其余筛选紧接着排布 */
    .topbar-toolbar { flex-wrap: wrap; row-gap: 6px; overflow: visible; }
    .topbar-toolbar .chat-subject-bar { flex: 1 0 100%; gap: 6px; }
    .topbar-toolbar .chat-subject-bar .subject-tab { flex: 0 0 auto; min-height: 34px; padding: 5px 12px; font-size: 12.5px; }
    /* 对话记录 / 工具面板改为浮层，不再遮挡或挤压正文 */
    .chat-history-panel,
    .chat-history-panel.collapsed {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100% !important;
        width: min(72vw, 300px) !important;
        transform: translateX(-101%);
        transition: transform .26s ease;
        z-index: 1250;
        box-shadow: 0 0 30px rgba(0,0,0,.18);
        border-right: none;
    }
    .chat-history-panel.open { transform: translateX(0); }
    .chat-panel-resize { display: none; }

    .chat-sidebar {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: auto !important;
        height: 100% !important;
        z-index: 1300;
    }
    .chat-sidebar.open { width: min(90vw, 340px); box-shadow: -8px 0 30px rgba(0,0,0,.16); }
    /* 学习工具面板：窄屏下标签行可横向滑动，避免「任务模式」被截断 */
    .chat-sidebar .sidebar-tabs,
    .chat-sidebar .sidebar-body { min-width: 0; width: 100%; }
    .chat-sidebar .sidebar-tabs { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .chat-sidebar .sidebar-tabs::-webkit-scrollbar { display: none; }

    .chat-history-toggle {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        border: 1px solid #e5e7eb;
        background: #fff;
        color: #374151;
        padding: 8px 12px;
        border-radius: 999px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        white-space: nowrap;
        min-height: 36px;
    }

    .chat-messages { padding: 12px 14px; }
    /* 平板也是触屏，适当加大按钮 */
    .attach-btn { width: 40px; height: 40px; flex: 0 0 40px; }
    .send-btn { width: 42px; height: 42px; flex: 0 0 42px; }
    .chat-input-area { padding: 8px 12px 10px; }
    .topic-btn, .danger-btn { min-height: 34px; }
}

/* ---------- 手机 / 小平板（≤ 768px） ---------- */
@media (max-width: 768px) {
    html, body { height: auto; min-height: 100%; }
    #app { height: 100vh; height: 100dvh; overflow: hidden; }

    .app-topbar { padding: 8px 10px; }

    /* 筛选区：2×2 平铺，所有选项一屏可见，不用左右拖动 */
    .topbar-toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: center;
        gap: 8px;
        overflow: visible;
        padding-bottom: 0;
    }
    .topbar-toolbar .tb-agent { order: 1; }
    .topbar-toolbar .tb-grade { order: 2; }
.topbar-toolbar .tb-kb { order: 3; grid-column: 1 / -1; }
    /* 学科入口：放在筛选区最上面一行，整行铺满，方便一眼看到 */
    .topbar-toolbar .chat-subject-bar {
        grid-column: 1 / -1;
        order: 0;
        gap: 5px;
        margin-bottom: 2px;
    }
    .topbar-toolbar .chat-subject-bar .subject-tab {
        flex: 0 1 auto;
        padding: 4px 7px;
        font-size: 12px;
        gap: 5px;
        min-height: 32px;
    }
    .topbar-toolbar .chat-toolbar-select {
        display: flex;
        align-items: center;
        gap: 5px;
        min-width: 0;
        max-width: none;
        font-size: 12px;
        color: #6b7280;
        white-space: nowrap;
    }
    .topbar-toolbar .chat-toolbar-select select {
        flex: 1 1 auto;
        width: 100%;
        min-width: 0;
        max-width: none;
        min-height: 36px;
        padding: 4px 6px;
        font-size: 12.5px;
        border-radius: 9px;
    }
    .topbar-toolbar .chat-icon-btn#chatToolsBtn {
        grid-column: 1 / -1;
        order: 9;
        width: 100%;
        height: 38px;
        flex: none;
        gap: 6px;
        font-size: 13px;
        font-weight: 600;
        border-radius: 9px;
        color: #374151;
        background: #f9fafb;
    }
    .topbar-toolbar .chat-icon-btn#chatToolsBtn .chat-icon-btn-txt { display: inline; }

    .app-nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        background: #fff;
        color: #374151;
        font-size: 18px;
        line-height: 1;
        cursor: pointer;
    }
    .app-nav-toggle:active { background: #f3f4f6; }
    .app-role-badge, .app-username { display: none; }
    .app-topbar-link { font-size: 12px; padding: 6px 2px; }

    /* ===== 左侧导航 → 抽屉 ===== */
    .app-nav {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(84vw, 300px);
        transform: translateX(-101%);
        transition: transform .26s ease;
        z-index: 1200;
        overflow: hidden;
    }
    .app-nav.open { transform: translateX(0); }
    .app-nav .app-nav-group { padding: 6px 12px; }
    .app-nav .app-nav-group-title {
        display: block;
        font-size: 11px;
        color: rgba(255,255,255,0.4);
        margin: 10px 6px 5px;
    }
    .app-nav .app-nav-brand {
        font-size: 15px;
        gap: 8px;
        justify-content: flex-start;
        padding: 0 14px 0 18px;
    }
    .app-nav .app-nav-brand span:last-child,
    .app-nav .app-nav-label,
    .app-nav .app-nav-label-txt { display: inline; }
    .app-nav .app-nav-foot { display: block; }
    .app-nav .app-nav-item { justify-content: flex-start; font-size: 14.5px; padding: 13px 12px; }
    .app-nav-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        margin-left: auto;
        border: none;
        border-radius: 9px;
        background: rgba(255,255,255,0.08);
        color: #cbd5e1;
        font-size: 15px;
        cursor: pointer;
    }
    .app-nav-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.45);
        z-index: 1100;
    }
    body.app-nav-open .app-nav-backdrop { display: block; }

    /* ===== 对话区 ===== */
    .chat-header {
        padding: 6px 12px;
        gap: 8px;
        flex-wrap: wrap;
        row-gap: 6px;
    }
    .teacher-info { min-width: 0; gap: 8px; flex: 1 1 auto; }
    .teacher-status-inline, .kb-source-inline { display: none; }
    .chat-header-actions { gap: 6px; flex-wrap: wrap; }
    .topic-btn, .danger-btn { font-size: 12px; padding: 8px 11px; min-height: 36px; }
    .chat-messages { padding: 12px 12px 8px; gap: 12px; }
    .msg { max-width: 92%; }

    /* 输入区：加大触控目标 */
    .chat-input-area { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
    .input-row { gap: 5px; }
    .attach-btn { width: 38px; height: 38px; flex: 0 0 38px; font-size: 15px; }
    .send-btn { width: 46px; height: 46px; flex: 0 0 46px; }
    #chatInput {
        font-size: 16px;
        line-height: 1.35;
        padding: 9px 12px;
        min-height: 42px;
        max-height: 120px;
    }
    .quick-commands { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
    .quick-commands::-webkit-scrollbar { display: none; }
    .quick-cmd { flex: 0 0 auto; min-height: 30px; }
    .input-hint { display: none; }

    /* 弹窗铺满窄屏 */
    .modal { width: calc(100vw - 24px) !important; max-width: calc(100vw - 24px) !important; margin: 12px; }
    .modal-lg, .modal-xl { max-height: 88vh; }
    .modal-body { padding: 14px; }
    .admin-body { max-height: none; }
}

/* ---------- 超窄屏（≤ 420px） ---------- */
@media (max-width: 420px) {
    .app-topbar-title { font-size: 14px; }
    .app-topbar-right { gap: 6px; }
    .app-topbar-link { font-size: 11.5px; }
    .credits-badge { font-size: 11px; }
    .topic-btn, .danger-btn { font-size: 11.5px; padding: 7px 9px; }
    .chat-history-toggle { padding: 7px 10px; font-size: 11.5px; }
    /* 超窄屏：学科标签再收紧，保证一行放得下 */
    .topbar-toolbar .chat-subject-bar { gap: 4px; }
    .topbar-toolbar .chat-subject-bar .subject-tab { padding: 4px 6px; font-size: 11.5px; gap: 4px; }
    .kc-body { padding: 12px; }
    .kc-toolbar { padding: 10px 12px; }
}

/* ---------- 覆盖层：置于文件末尾，确保覆盖各断点既有规则 ---------- */
/* 学科入口只在顶栏出现，对话记录面板内不再重复 */
.chat-history-panel .chat-history-subjects { display: none; }
/* 「模型」下拉取消 */
.topbar-toolbar .tb-model { display: none; }

/* 桌面端顶栏允许两行（学科入口 + 筛选），避免内容被裁切 */
@media (min-width: 1025px) {
    #app .app-topbar { height: auto; min-height: 56px; padding: 6px 20px; }
}


/* ============ 学习资料库：添加文件夹 / 资料源管理 ============ */
.kb-doc-action.primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    font-weight: 600;
}
.kb-doc-action.primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.kb-doc-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 500;
    color: #2563eb;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    vertical-align: middle;
}

.kb-src-body { display: flex; flex-direction: column; gap: 12px; }
.kb-src-tip { margin: 0; font-size: 13px; color: #6b7280; line-height: 1.7; }
.kb-src-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-src-btn {
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.kb-src-btn:hover { border-color: #bfdbfe; color: #2563eb; background: #f9fafb; }
.kb-src-btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; font-weight: 600; }
.kb-src-btn.primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.kb-src-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.kb-src-btn.ghost { background: #f9fafb; }
.kb-src-path {
    flex: 1;
    min-width: 220px;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #1f2937;
    background: #fff;
}
.kb-src-path:focus { outline: none; border-color: #bfdbfe; box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.kb-src-field, .kb-src-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #6b7280; }
.kb-src-field select {
    padding: 7px 12px;
    font-size: 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
}
.kb-src-check input { width: 15px; height: 15px; accent-color: #2563eb; }
.kb-src-preview {
    font-size: 13px;
    color: #374151;
    line-height: 1.7;
    background: #f9fafb;
    border: 1px solid #f0f1f3;
    border-radius: 8px;
    padding: 12px 14px;
    min-height: 20px;
}
.kb-src-preview:empty { display: none; }
.kb-src-sample { margin-top: 6px; font-size: 12px; color: #9ca3af; }
.kb-src-warn { color: #dc2626; }
.kb-src-fallback { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.kb-src-hint { font-size: 12px; color: #9ca3af; }

.kb-src-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px;
    border: 1px solid #f0f1f3;
    border-radius: 10px;
    margin-bottom: 12px;
    background: #fff;
}
.kb-src-item:hover { border-color: #e5e7eb; background: #fcfcfd; }
.kb-src-item-main { flex: 1; min-width: 0; }
.kb-src-item-name { font-size: 14px; font-weight: 600; color: #1f2937; margin-bottom: 4px; }
.kb-src-item-path {
    font-size: 12px;
    color: #6b7280;
    word-break: break-all;
    margin-bottom: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.kb-src-item-meta { font-size: 12px; color: #9ca3af; }
.kb-src-item-actions { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

.kb-progress { margin-top: 10px; }
.kb-progress-bar {
    height: 6px;
    background: #eef2f7;
    border-radius: 999px;
    overflow: hidden;
}
.kb-progress-bar span {
    display: block;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #60a5fa, #2563eb);
    border-radius: 999px;
    transition: width 0.3s ease;
}
.kb-progress-text { margin-top: 6px; font-size: 12px; color: #6b7280; line-height: 1.6; }

.kb-progress-card {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    padding: 16px 18px;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}
.kb-progress-card.show { opacity: 1; visibility: visible; transform: translateY(0); }
.kb-progress-title { font-size: 14px; font-weight: 600; color: #1f2937; margin-bottom: 10px; }
.kb-progress-msg { margin-top: 8px; font-size: 12px; color: #6b7280; line-height: 1.6; word-break: break-all; }
.kb-progress-close {
    margin-top: 12px;
    width: 100%;
    padding: 7px 0;
    font-size: 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    cursor: pointer;
}
.kb-progress-close:hover { border-color: #bfdbfe; color: #2563eb; background: #f9fafb; }

@media (max-width: 640px) {
    .kb-progress-card { right: 12px; left: 12px; bottom: 12px; width: auto; }
    .kb-src-item { flex-direction: column; }
    .kb-src-item-actions { flex-direction: row; width: 100%; }
    .kb-src-item-actions .kb-doc-action { flex: 1; }
}
