/* ========== CSS变量 & 重置 ========== */
:root {
  --primary: #4A9EE0;
  --primary-light: #E8F4FD;
  --primary-dark: #2D7BC4;
  --bg: #F7F9FC;
  --white: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --glass: rgba(255,255,255,0.75);
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); overflow: hidden; height: 100vh; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
img { max-width: 100%; }

/* ========== 布局 ========== */
#sidebar {
  position: fixed; left: 0; top: 0; width: var(--sidebar-w); height: 100vh;
  background: var(--white); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 100;
}
#main {
  margin-left: var(--sidebar-w); height: 100vh; display: flex; flex-direction: column;
}
#topbar {
  height: var(--topbar-h); padding: 0 24px; display: flex; align-items: center; justify-content: space-between;
  background: var(--white); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#content {
  flex: 1; overflow-y: auto; padding: 24px;
}

/* ========== 侧边栏 ========== */
.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--primary); }
.logo i { width: 22px; height: 22px; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-secondary); transition: all var(--transition);
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item i { width: 18px; height: 18px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.version { font-size: 11px; color: var(--text-muted); }

/* ========== 顶栏 ========== */
#page-title { font-size: 18px; font-weight: 700; }
.status-badge {
  font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600;
  background: #FEE2E2; color: var(--danger);
}
.status-badge.ok { background: #DCFCE7; color: var(--success); }

/* ========== 卡片 ========== */
.card {
  background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--border);
  box-shadow: var(--shadow); padding: 20px; transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; }

/* ========== 按钮 ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; transition: all var(--transition);
  white-space: nowrap;
}
.btn i { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { background: #16A34A; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #DC2626; }
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); }
.btn-outline { border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== 表单 ========== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text); background: var(--white); transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,158,224,0.1); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ========== 模态框 ========== */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
#modal-overlay.hidden { display: none; }
#modal-container {
  background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 90%; max-width: 600px; max-height: 85vh; display: flex; flex-direction: column;
}
#modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
#modal-title { font-size: 16px; font-weight: 700; }
#modal-close { color: var(--text-muted); padding: 4px; }
#modal-close:hover { color: var(--text); }
#modal-body { padding: 20px; overflow-y: auto; flex: 1; }
#modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ========== Toast ========== */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md); min-width: 240px; display: flex; align-items: center; gap: 8px;
  animation: toastIn 0.3s ease;
}
.toast.success { background: #DCFCE7; color: #166534; }
.toast.error { background: #FEE2E2; color: #991B1B; }
.toast.warning { background: #FEF3C7; color: #92400E; }
.toast.info { background: var(--primary-light); color: var(--primary-dark); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Dashboard ========== */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.lesson-card { cursor: pointer; }
.lesson-card .lesson-meta { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.tag-subject { background: var(--primary-light); color: var(--primary); }
.tag-grade { background: #FEF3C7; color: #92400E; }
.tag-status-draft { background: #F1F5F9; color: var(--text-muted); }
.tag-status-ready { background: #DCFCE7; color: #166534; }
.tag-status-active { background: #DBEAFE; color: #1E40AF; }
.tag-status-completed { background: #F1F5F9; color: var(--text-secondary); }
.lesson-card .lesson-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.lesson-card .lesson-agent { font-size: 13px; color: var(--text-secondary); }
.lesson-card .lesson-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.lesson-card .lesson-time { font-size: 11px; color: var(--text-muted); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { width: 48px; height: 48px; margin-bottom: 12px; color: var(--border); }
.empty-state p { font-size: 14px; }

/* ========== Create View ========== */
.create-layout { max-width: 800px; margin: 0 auto; }
.section { margin-bottom: 24px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--primary-dark); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.section-title i { width: 18px; height: 18px; }
.avatar-upload {
  width: 120px; height: 120px; border-radius: var(--radius-lg); border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden;
  transition: all var(--transition); position: relative;
}
.avatar-upload:hover { border-color: var(--primary); }
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload .placeholder { text-align: center; color: var(--text-muted); font-size: 11px; }
.avatar-actions { display: flex; gap: 8px; margin-top: 8px; }
.knowledge-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.knowledge-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--primary-light); border-radius: var(--radius-sm); font-size: 13px; }
.knowledge-item .k-name { display: flex; align-items: center; gap: 6px; }
.knowledge-item .k-name i { width: 14px; height: 14px; color: var(--primary); }
.radio-group { display: flex; gap: 12px; }
.radio-item { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.radio-item input[type="radio"] { accent-color: var(--primary); }

/* ========== Settings View ========== */
.settings-layout { max-width: 600px; margin: 0 auto; }
.settings-section { margin-bottom: 24px; }
.test-result { margin-top: 8px; font-size: 12px; padding: 8px 12px; border-radius: var(--radius-sm); }
.test-result.ok { background: #DCFCE7; color: #166534; }
.test-result.fail { background: #FEE2E2; color: #991B1B; }

/* ========== Records View ========== */
.records-list { max-width: 800px; margin: 0 auto; }
.record-item { display: flex; justify-content: space-between; align-items: center; padding: 16px; }
.record-item + .record-item { border-top: 1px solid var(--border); }
.record-info h4 { font-size: 14px; font-weight: 600; }
.record-info p { font-size: 12px; color: var(--text-muted); }
.record-actions { display: flex; gap: 6px; }

/* ========== Classroom Mode ========== */
#classroom-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 500;
  display: flex; flex-direction: column;
}
#classroom-overlay.hidden { display: none; }
#classroom-container { display: flex; flex: 1; overflow: hidden; }
#classroom-sidebar {
  width: 260px; background: var(--white); border-right: 1px solid var(--border);
  padding: 20px; display: flex; flex-direction: column; gap: 16px; flex-shrink: 0;
}
.cl-info h3 { font-size: 15px; font-weight: 700; }
.cl-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.mic-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 14px; background: var(--primary); color: var(--white); border-radius: var(--radius);
  font-size: 14px; font-weight: 700; transition: all var(--transition);
}
.mic-btn i { width: 20px; height: 20px; }
.mic-btn:hover { background: var(--primary-dark); }
.mic-btn.recording { background: var(--danger); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.cl-text-input { display: flex; gap: 6px; }
.cl-text-input input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }
.cl-text-input button { padding: 8px; color: var(--primary); }
.cl-actions { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.cl-actions button { display: flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 12px; color: var(--text-secondary); border-radius: var(--radius-sm); transition: all var(--transition); }
.cl-actions button i { width: 14px; height: 14px; }
.cl-actions button:hover { background: var(--primary-light); color: var(--primary); }

#classroom-main { flex: 1; display: flex; overflow: hidden; }
#cl-character-area {
  width: 40%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px; background: linear-gradient(135deg, var(--primary-light), var(--white));
  position: relative;
}
#cl-character-img-wrap {
  width: 260px; height: 260px; border-radius: 50%; overflow: hidden; position: relative;
  box-shadow: 0 8px 30px rgba(74,158,224,0.2);
}
#cl-character-img { width: 100%; height: 100%; object-fit: cover; animation: breathe 3s ease-in-out infinite; }
.speaking-ring {
  position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--primary);
  opacity: 0; transition: opacity 0.3s;
}
.speaking .speaking-ring { opacity: 1; animation: speakRing 1s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }
@keyframes speakRing { 0%,100% { transform: scale(1); opacity: 0.6; } 50% { transform: scale(1.06); opacity: 1; } }
#cl-character-name { margin-top: 16px; font-size: 20px; font-weight: 700; color: var(--primary-dark); }

#cl-chat-area { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow: hidden; }
#cl-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 8px 0; }
.msg { display: flex; gap: 10px; max-width: 85%; animation: msgIn 0.3s ease; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .msg-bubble { background: var(--primary); color: var(--white); border-radius: var(--radius) var(--radius) 4px var(--radius); }
.msg.assistant { align-self: flex-start; }
.msg.assistant .msg-bubble { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) var(--radius) 4px; }
.msg-bubble { padding: 10px 14px; font-size: 14px; line-height: 1.6; word-break: break-word; }
.msg-role { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.msg.user .msg-role { text-align: right; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

#cl-thinking {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 13px; color: var(--text-muted);
}
#cl-thinking.hidden { display: none; }
.thinking-dots { display: flex; gap: 3px; }
.thinking-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); animation: dot 1.4s infinite; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot { 0%,80%,100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ========== 工具类 ========== */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }

/* ========== 响应式 ========== */
@media (max-width: 900px) {
  :root { --sidebar-w: 60px; }
  .sidebar-nav .nav-item span, .sidebar-header .logo span, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .logo { justify-content: center; }
  #cl-character-area { width: 35%; padding: 20px; }
  #cl-character-img-wrap { width: 180px; height: 180px; }
}
