/* ==========================================================================
   钰汐学习平台 · 样式表 v30
   主题：亮色（默认） / 深色，一键切换（顶栏按钮，记忆到 localStorage）
   由 index.html 内联脚本在首屏前写入 data-theme，避免闪白/闪黑
   ========================================================================== */

/* ---------- 主题变量 ---------- */
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f2f5fa;
  --bg-glow: rgba(47,111,237,.08);
  --panel: #ffffff;
  --panel-2: #f5f8fd;
  --panel-3: #edf2fa;
  --line: #e3e9f3;
  --line-2: #cfdaea;
  --text: #16202e;
  --text-2: #4d5a6e;
  --muted: #78859a;
  --brand: #2f6fed;
  --brand-2: #0f9d76;
  --brand-ink: #ffffff;
  --brand-soft: #e8f0ff;
  --brand-2-soft: #e2f6ef;
  --warn: #b8770a;
  --warn-soft: #fdf2e0;
  --danger: #d92d20;
  --danger-soft: #fdeceb;
  --accent-4: #7c53d6;
  --accent-5: #cf3f8a;
  --shadow: 0 1px 2px rgba(16,32,64,.05), 0 8px 24px rgba(16,32,64,.06);
  --shadow-lg: 0 4px 12px rgba(16,32,64,.06), 0 18px 48px rgba(16,32,64,.10);
  --radius: 12px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --bg-glow: rgba(91,149,255,.10);
  --panel: #171a21;
  --panel-2: #1f242e;
  --panel-3: #252b36;
  --line: #2a3038;
  --line-2: #39414d;
  --text: #e6e9ef;
  --text-2: #c2cbd9;
  --muted: #9aa3b2;
  --brand: #5b95ff;
  --brand-2: #38d39f;
  --brand-ink: #0d1424;
  --brand-soft: rgba(91,149,255,.16);
  --brand-2-soft: rgba(56,211,159,.16);
  --warn: #f0a020;
  --warn-soft: rgba(240,160,32,.16);
  --danger: #ff7b7b;
  --danger-soft: rgba(255,107,107,.16);
  --accent-4: #a98bf0;
  --accent-5: #ef7fb4;
  --shadow: none;
  --shadow-lg: 0 18px 48px rgba(0,0,0,.45);
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: relative; z-index: 20;
}
.topbar .logo {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; color: var(--text); letter-spacing: .3px; font-size: 15px;
}
/* 品牌色块（两枚叠色小方块，代替图片 logo） */
.topbar .logo::before {
  content: ""; width: 20px; height: 20px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--brand) 0 50%, var(--brand-2) 50% 100%);
}
.topbar .spacer { flex: 1; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--panel-3); color: var(--muted); white-space: nowrap; }
.badge.super_admin { background: var(--brand-soft); color: var(--brand); }
.badge.teacher { background: var(--brand-2-soft); color: var(--brand-2); }
.badge.student { background: var(--warn-soft); color: var(--warn); }
.badge.parent { background: var(--brand-soft); color: var(--brand); }

/* 主题切换：一键亮/暗 */
.theme-toggle {
  width: 38px; height: 38px; min-height: 38px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.theme-toggle:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.theme-toggle svg { width: 18px; height: 18px; display: block; }

/* 站内信未读角标 */
.unread-dot {
  display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px;
  margin-left: 6px; border-radius: 999px; background: #e5484d; color: #fff;
  font-size: 11px; font-weight: 700; text-align: center; vertical-align: middle;
}

/* ---------- 布局 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 220px; background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 6px;
}
.sidebar .nav-item {
  position: relative; padding: 10px 12px; border-radius: 8px;
  color: var(--muted); cursor: pointer; font-size: 14px;
  transition: background .15s, color .15s;
}
.sidebar .nav-item.active {
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.sidebar .nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 2px; background: var(--brand);
}
.sidebar .nav-item:hover { background: var(--panel-3); }
.sidebar .nav-item.active:hover { background: var(--brand-soft); }
.content { flex: 1; padding: 26px; overflow: auto; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.link { color: var(--brand); cursor: pointer; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--brand); color: var(--brand-ink); border: 1px solid transparent;
  padding: 10px 16px; border-radius: 8px; font-size: 14px; cursor: pointer;
  transition: filter .15s, border-color .15s, background .15s, color .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); filter: none; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); filter: none; }
.btn.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- 表单 ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 14px; margin-top: 6px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
textarea { min-height: 84px; line-height: 1.6; resize: vertical; font-family: inherit; }
label { font-size: 13px; color: var(--text-2); }
.field { margin-bottom: 14px; }
.tts-rate { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  padding: 8px 14px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.tab:hover { color: var(--text); border-color: var(--line-2); }
.tab.active { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }

/* ---------- 登录页 ---------- */
.login-wrap {
  position: relative;
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(900px 400px at 50% -8%, var(--bg-glow), transparent 70%), var(--bg);
}
.login-theme { position: absolute; top: 18px; right: 18px; }
.login-card { width: 380px; max-width: 100%; position: relative; overflow: hidden; box-shadow: var(--shadow-lg); }
.login-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}
.login-card h2 { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; }
.login-card h2::before {
  content: ""; width: 18px; height: 18px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--brand) 0 50%, var(--brand-2) 50% 100%);
}
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.ok { color: var(--brand-2); font-size: 13px; margin-top: 8px; }

/* ---------- 通用块 ---------- */
.row { display: flex; gap: 8px; align-items: center; }
.col2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.plain { margin: 0; padding-left: 18px; }
.plain li { margin: 6px 0; line-height: 1.6; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; word-break: break-all; }

/* 学科卡：左侧色块 + 悬停抬升（颜色按序循环） */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.subject {
  --accent: var(--brand);
  position: relative; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 14px 14px 18px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.subject::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent);
}
.subject:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.subject-grid > *:nth-child(6n+2) { --accent: var(--brand-2); }
.subject-grid > *:nth-child(6n+3) { --accent: var(--warn); }
.subject-grid > *:nth-child(6n+4) { --accent: var(--accent-4); }
.subject-grid > *:nth-child(6n+5) { --accent: var(--accent-5); }
.subject-grid > *:nth-child(6n) { --accent: var(--brand-2); }

/* KPI 卡：左侧色块 */
.kpi { display: flex; gap: 12px; flex-wrap: wrap; }
.kpi .box {
  --accent: var(--brand);
  position: relative; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 16px 16px 20px; min-width: 120px;
}
.kpi .box::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent);
}
.kpi .box:nth-child(8n+2) { --accent: var(--brand-2); }
.kpi .box:nth-child(8n+3) { --accent: var(--warn); }
.kpi .box:nth-child(8n+4) { --accent: var(--accent-4); }
.kpi .box:nth-child(8n+5) { --accent: var(--accent-5); }
.kpi .box:nth-child(8n+6) { --accent: var(--brand-2); }
.kpi .box:nth-child(8n+7) { --accent: var(--warn); }
.kpi .num { font-size: 24px; font-weight: 700; }

/* ---------- 表格 ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--text-2); font-weight: 600; background: var(--panel-3); white-space: nowrap; }
.tbl tbody tr:hover td { background: var(--panel-2); }

/* ---------- 知识点 / 内容 ---------- */
.kp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.kp-item {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.kp-item:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.kp-title { font-weight: 600; margin-bottom: 6px; }
.content-box {
  white-space: pre-wrap; line-height: 1.7; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-top: 8px; font-size: 14px;
}

/* ---------- 聊天 / 问答 ---------- */
.chat-box { max-height: 420px; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
.bubble { max-width: 80%; padding: 10px 12px; border-radius: 12px; }
.bubble .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.bubble.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); }
.bubble.user .who { color: inherit; opacity: .85; }
.bubble.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); }
.bubble .txt { white-space: pre-wrap; line-height: 1.6; font-size: 14px; }

/* ---------- 测验 ---------- */
.quiz { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 10px; }
.quiz .q { font-weight: 600; margin-bottom: 6px; }
.quiz .opt { padding: 4px 0; }
.quiz .opt.chosen { background: var(--brand-soft); border-radius: 6px; padding: 4px 8px; }
.quiz .opt.correct { color: var(--brand-2); }
.quiz .opt.wrong { color: var(--danger); }
.quiz .explain { font-size: 12px; color: var(--muted); margin-top: 4px; }
.quiz .result { margin-top: 12px; font-weight: 600; color: var(--brand-2); }

/* ---------- 进度条 ---------- */
.bar { height: 10px; background: var(--panel-3); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.print-area { display: block; }

/* ---------- v16 阅读体验：富排版 / 朗读工具条 / 全屏 ---------- */
.read-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tts-mini { background: transparent; border: none; cursor: pointer; font-size: 13px; margin-left: 6px; opacity: .75; color: inherit; }
.tts-mini.on { opacity: 1; transform: scale(1.15); }
.rich { line-height: 1.9; font-size: 15px; margin-top: 8px; }
.rich p { margin: .55em 0; }
.rich h4 { margin: 1.1em 0 .35em; font-size: 16.5px; color: var(--brand); }
.rich ol, .rich ul { margin: .45em 0 .45em 1.5em; }
.rich li { margin: .3em 0; }
.rich strong { font-weight: 700; color: var(--text); }
.bubble .txt.rich-inline p { margin: .3em 0; }
.bubble .txt.rich-inline h4 { margin: .5em 0 .2em; font-size: 14.5px; }
.rich:fullscreen, .rich:-webkit-full-screen { background: var(--bg); padding: 40px 12%; overflow-y: auto; font-size: 18px; line-height: 2; }
.card:fullscreen, .card:-webkit-full-screen { background: var(--bg); padding: 24px 6%; overflow-y: auto; }
#card-qa:fullscreen .chat-box { max-height: none; height: calc(100vh - 190px); }
#card-qa:fullscreen .bubble { max-width: 78%; font-size: 16px; }

/* ---------- v17 全局消息条 ---------- */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 9999; max-width: 86vw;
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  box-shadow: var(--shadow-lg); font-weight: 500;
}
.toast.err { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.toast.ok2 { background: var(--brand-2-soft); color: var(--brand-2); border: 1px solid var(--brand-2); }

/* ---------- 页脚 ---------- */
.site-footer { text-align: center; padding: 18px 12px 24px; color: var(--muted); font-size: 12px; line-height: 1.8; }
.site-footer a { color: var(--muted); }

/* ---------- 移动端（≤820px：学生 90% / 老师 70% 场景在手机） ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line); padding: 8px; gap: 4px;
  }
  .sidebar .nav-item { white-space: nowrap; padding: 9px 12px; }
  .sidebar .nav-item.active::before { top: auto; bottom: 0; left: 10px; right: 10px; width: auto; height: 3px; }
  .content { padding: 14px; }
  .card { padding: 14px; overflow-x: auto; }
  .card h2 { font-size: 17px; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; padding: 9px 13px; }
  input, select, textarea { font-size: 16px; }
  .btn { padding: 10px 14px; min-height: 44px; }
  .btn.sm { min-height: 36px; }
  .tbl { display: table; width: auto; min-width: 720px; }
  .tbl.narrow { min-width: 0; width: 100%; }
  .row3 { grid-template-columns: 1fr; }
  .col2 { grid-template-columns: 1fr; }
  .row { flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 8px 12px; height: auto; }
  .topbar .muted { display: none; }
  .theme-toggle { width: 42px; height: 42px; min-height: 42px; }
  .kpi .box { flex: 1 1 40%; min-width: 0; }
  .login-card { width: 100%; }
  .bubble { max-width: 92%; }
  .content-box { font-size: 15px; }
}

/* ---------- 打印 / 导出 PDF ---------- */
@media print {
  body { background: #fff; color: #000; }
  .app-shell { display: block; }
  .topbar, .sidebar, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { border: none; padding: 0 0 16px; box-shadow: none; }
  .content-box { background: #fff; border: 1px solid #ccc; color: #000; }
  .bar { background: #eee; }
  .kpi .box, .subject { background: #fff; border: 1px solid #ccc; }
}
