* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --primary: #4f6ef7;
  --primary-d: #3b56d6;
  --danger: #ef5350;
  --text: #1f2733;
  --muted: #8696a7;
  --border: #e6eaf0;
  --shadow: 0 4px 18px rgba(31, 39, 51, 0.08);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ---- 登录 ---- */
.auth-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  background: var(--panel); width: 340px; padding: 36px 30px;
  border-radius: 16px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 24px; text-align: center; }
.subtitle { text-align: center; color: var(--muted); margin: 8px 0 22px; }
.tabs { display: flex; margin-bottom: 18px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.tab { flex: 1; padding: 10px; border: none; background: #f0f2f7; color: var(--muted); cursor: pointer; font-size: 14px; }
.tab.active { background: var(--primary); color: #fff; }
#auth-form input { width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
#auth-form input:focus { outline: none; border-color: var(--primary); }
#auth-submit { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-size: 15px; margin-top: 4px; }
#auth-submit:hover { background: var(--primary-d); }
.msg { text-align: center; margin-top: 12px; min-height: 18px; font-size: 13px; color: var(--danger); }

/* ---- 主界面 ---- */
.topbar { height: 56px; background: var(--panel); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.brand { font-size: 17px; font-weight: 600; cursor: pointer; user-select: none; transition: opacity .15s ease; }
.brand:hover { opacity: .7; }
.top-right { display: flex; align-items: center; gap: 14px; }
.top-right #user-name { color: var(--muted); }
.layout { display: flex; height: calc(100vh - 56px); }
.sidebar { width: 220px; background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; overflow-y: auto; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 12px; padding: 0 6px; }
.tag-list { list-style: none; }
.tag-list li { padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.tag-list li:hover { background: #f0f2f7; }
.tag-list li.active { background: #eaf0ff; color: var(--primary-d); font-weight: 600; }

/* ===== 两级栏目树 ===== */
.tag-list li.col-all { font-weight: 500; }
.tag-list li.col-grade {
  font-weight: 600; display: flex; align-items: center; gap: 2px;
  background: #fafbfe; border: 1px solid var(--border); margin-bottom: 3px;
}
.tag-list li.col-grade .arrow {
  width: 18px; text-align: center; color: var(--muted); font-size: 11px;
  user-select: none; transition: transform .15s ease; cursor: pointer;
}
.tag-list li.col-grade .label { flex: 1; }
.tag-list li.col-grade .count {
  font-size: 11px; color: var(--muted); background: #eef1f6; border-radius: 10px;
  padding: 1px 7px; margin-left: 4px;
}
.tag-list li.col-grade.active { background: #eaf0ff; border-color: var(--primary); color: var(--primary-d); }
.tag-list li.col-grade.active .count { background: #dbe6ff; color: var(--primary-d); }

/* 二级学科：嵌套、缩进、带连接竖线，可收缩 */
.col-subs {
  list-style: none; margin: 0 0 6px 14px; padding: 0 0 0 12px;
  border-left: 1.5px solid var(--border);
  overflow: hidden; transition: max-height .2s ease, opacity .2s ease;
  max-height: 600px; opacity: 1;
}
.col-subs.collapsed { max-height: 0; opacity: 0; margin-bottom: 0; }
.col-subs .col-sub {
  padding: 7px 10px; font-size: 13px; color: var(--muted);
  border-radius: 6px; position: relative; margin-bottom: 2px;
}
.col-subs .col-sub::before {
  content: ''; position: absolute; left: -12px; top: 50%;
  width: 10px; height: 1.5px; background: var(--border);
}
.col-subs .col-sub:hover { background: #f0f2f7; color: var(--text); }
.col-subs .col-sub.active { background: #eaf0ff; color: var(--primary-d); font-weight: 600; }
.cm-grade { font-weight: 600; }
.cm-sub { padding-left: 22px; font-size: 13px; color: var(--muted); }
.content { flex: 1; padding: 20px; overflow-y: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; align-items: center; }
.toolbar input { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.toolbar input:focus { outline: none; border-color: var(--primary); }
.sel-all { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.sel-all input { width: 16px; height: 16px; cursor: pointer; }
.sel-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.btn-ghost:disabled { opacity: .45; cursor: not-allowed; }
.card-check { position: absolute; top: 14px; right: 14px; z-index: 2; }
.card-check input { width: 18px; height: 18px; cursor: pointer; }
.q-content { padding-right: 26px; }
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }
.pg-btn { min-width: 34px; height: 34px; padding: 0 10px; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text); }
.pg-btn:hover:not(:disabled) { border-color: var(--primary); }
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.pg-ellipsis { color: var(--muted); padding: 0 2px; }
.pg-info { margin-left: 10px; font-size: 13px; color: var(--muted); }

/* ---- 题目卡片 ---- */
.question-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; transition: transform .12s; position: relative; }
.card:hover { transform: translateY(-2px); }
.card .q-content { white-space: pre-wrap; line-height: 1.6; word-break: break-word; max-height: 120px; overflow: hidden; }
.card img.q-img { width: 100%; max-height: 160px; object-fit: cover; border-radius: 10px; margin: 10px 0; }
.card img.q-answer-img { width: 100%; max-height: 160px; object-fit: cover; border-radius: 10px; margin: 8px 0 0; }
.card .q-answer { margin-top: 8px; padding: 8px 10px; background: #f6f8fc; border-radius: 8px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.card .q-tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #eaf0ff; color: var(--primary-d); font-size: 12px; padding: 3px 9px; border-radius: 20px; }
.chip.col-chip { background: #e8f7ee; color: #2e9e5b; }
.card .card-foot { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 10px; }
.wrong-badge { background: #fff0f0; color: var(--danger); font-weight: 600; font-size: 13px; padding: 3px 10px; border-radius: 20px; }
.btn-wrong { background: var(--danger); color: #fff; border: none; border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.btn-wrong:hover { opacity: .9; }
.empty-hint { text-align: center; color: var(--muted); margin-top: 60px; }

/* ---- 视图切换（表格 / 列表） ---- */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.view-btn { border: none; background: var(--panel); color: var(--muted); padding: 9px 14px; cursor: pointer; font-size: 14px; line-height: 1; }
.view-btn + .view-btn { border-left: 1px solid var(--border); }
.view-btn:hover { color: var(--primary-d); }
.view-btn.active { background: var(--primary); color: #fff; }

/* ---- 列表视图 ---- */
.question-grid.list-view { display: flex; flex-direction: column; gap: 10px; }
.q-row { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: background .12s, border-color .12s; }
.q-row:hover { background: #f7f9fd; border-color: var(--primary); }
.row-index { flex-shrink: 0; width: 26px; text-align: center; font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-check { display: flex; align-items: center; flex-shrink: 0; }
.row-check input { width: 18px; height: 18px; cursor: pointer; }
.row-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #f0f2f7; }
.row-main { flex: 1; min-width: 0; }
.row-content { font-size: 14px; line-height: 1.5; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-ans-icon { margin-left: 6px; font-size: 12px; color: var(--muted); }
.row-meta { margin-top: 6px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.row-meta .wrong-badge { font-size: 12px; padding: 2px 8px; }

/* ---- 按钮 ---- */
.btn-primary { background: var(--primary); color: #fff; border: none; border-radius: 10px; padding: 10px 18px; cursor: pointer; font-size: 14px; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 9px 16px; cursor: pointer; font-size: 14px; }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 10px; padding: 9px 16px; cursor: pointer; font-size: 14px; }
.btn-danger:hover { opacity: .9; }
.btn-mini { background: #f0f2f7; border: none; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--muted); }

/* ---- 弹窗 ---- */
.modal { position: fixed; inset: 0; background: rgba(20, 28, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); width: 520px; max-width: 92vw; max-height: 88vh; overflow-y: auto; border-radius: 16px; padding: 22px 24px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
#question-form label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
#question-form textarea, #question-form input[type=text], #question-form input[type=file] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit; }
#question-form textarea:focus, #question-form input:focus, #question-form select:focus { outline: none; border-color: var(--primary); }
#question-form select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; }
.img-preview { margin-top: 10px; }
.img-preview img { max-width: 100%; max-height: 200px; border-radius: 10px; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-picker .tag-opt { padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px; cursor: pointer; font-size: 13px; user-select: none; }
.tag-picker .tag-opt.sel { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-input-row { margin-bottom: 10px; }
.field-hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

/* ---- 筛选 / 统计 ---- */
.filter-select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; max-width: 150px; }
.wrong-badge.none { background: #eef1f5; color: var(--muted); }
.cnt-wrong { color: var(--danger); }
.cnt-correct { color: #1f9d55; }
.d-stat { margin-top: 12px; font-size: 14px; color: #445; background: #f6f8fc; border-radius: 10px; padding: 10px 12px; }
.d-stat b { font-size: 16px; }
.d-stat b.cnt-wrong { color: var(--danger); }
.d-stat b.cnt-correct { color: #1f9d55; }

/* ---- 复习筛选按钮（提醒） ---- */
.review-filters { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.rf-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 12px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap;
}
.rf-btn:hover { border-color: var(--primary); }
.rf-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.rf-count {
  display: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600;
}
.rf-count.show { display: inline-block; }
.rf-btn.active .rf-count { background: rgba(255,255,255,.9); color: var(--primary-d); }
.rf-btn[data-review="mastered"] .rf-count { background: #1f9d55; }

/* ---- 复习状态徽标 ---- */
.chip.rev-mastered { background: #e7f6ee; color: #1f9d55; }
.chip.rev-due { background: #fdecec; color: var(--danger); }
.chip.rev-soon { background: #fff6e6; color: #c77700; }

/* ---- 详情：复习状态 ---- */
.d-review { margin-top: 10px; font-size: 13px; color: var(--muted); background: #f6f8fc; border-radius: 10px; padding: 8px 12px; }

/* ---- 错题弹窗按钮 ---- */
.wrong-btns { display: flex; gap: 10px; }
.btn-success { background: #1f9d55; color: #fff; border: none; border-radius: 10px; padding: 10px 14px; font-size: 14px; cursor: pointer; font-family: inherit; }
.btn-success:hover { background: #18853f; }
.wrong-count { margin: 16px 0 10px; color: var(--muted); font-size: 14px; }
.wrong-count strong { font-size: 18px; }
.w-badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; margin-right: 8px; vertical-align: middle; }
.w-badge.bad { background: #fdecec; color: var(--danger); }
.w-badge.ok { background: #e7f6ee; color: #1f9d55; }
.wrong-list li { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.wrong-list li .w-note { color: var(--text); white-space: pre-wrap; display: inline-block; }
.wrong-list li .w-time { color: var(--muted); font-size: 12px; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- 标签管理 ---- */
.tag-add { display: flex; gap: 10px; margin-bottom: 16px; }
.tag-add input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.tag-manage-list { list-style: none; }
.tag-manage-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.tag-manage-list .del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; }

/* ---- 错题弹窗 ---- */
.wrong-add { display: flex; flex-direction: column; gap: 10px; }
.wrong-add textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit; resize: vertical; }
.wrong-img-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.wrong-count { margin: 16px 0 10px; color: var(--muted); }
.wrong-count strong { color: var(--danger); font-size: 18px; }
.wrong-list { list-style: none; max-height: 240px; overflow-y: auto; }
.wrong-list li { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.wrong-list li .w-note { color: var(--text); white-space: pre-wrap; }
.wrong-list li .w-time { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* 单条错题记录（含图片 + 操作） */
.w-item .w-top { display: flex; align-items: center; justify-content: space-between; }
.w-item .w-ops { display: flex; gap: 4px; }
.w-item .w-ops button { border: none; background: #f0f2f7; border-radius: 7px; width: 28px; height: 28px; cursor: pointer; font-size: 14px; line-height: 1; transition: background .15s; }
.w-item .w-ops .w-edit:hover { background: #e3ecff; }
.w-item .w-ops .w-del:hover { background: #fdecec; }
.w-item .w-img { display: block; max-width: 100%; max-height: 180px; border-radius: 10px; margin: 8px 0 2px; cursor: zoom-in; border: 1px solid var(--border); }
.w-item .w-note { color: var(--text); white-space: pre-wrap; }
.w-item .w-time { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* 内联编辑态 */
.w-item.editing { background: #fafbff; border-radius: 10px; }
.w-edit-note { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit; resize: vertical; margin-top: 8px; }
.w-cur-img { margin-top: 8px; }
.w-cur-img img { display: block; max-width: 100%; max-height: 140px; border-radius: 8px; border: 1px solid var(--border); }
.w-cur-img .w-rm { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 6px; cursor: pointer; }
.w-new-img { margin-top: 8px; }
.w-edit-btns { display: flex; gap: 8px; margin-top: 10px; }
.w-edit-btns .btn-primary, .w-edit-btns .btn-ghost { padding: 7px 16px; font-size: 13px; }

/* ---- 详情 ---- */
.detail-body .d-content { white-space: pre-wrap; line-height: 1.7; font-size: 15px; }
.detail-body img { max-width: 100%; border-radius: 10px; margin: 12px 0; }
.detail-body .d-answer { background: #f6f8fc; border-radius: 10px; padding: 12px; margin-top: 12px; white-space: pre-wrap; color: #445; }
.detail-body .d-answer-img, .detail-body .d-answer img.q-img { max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 10px; display: block; }
.detail-body .d-tags { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: #1f2733; color: #fff; padding: 10px 20px; border-radius: 10px; z-index: 100; font-size: 14px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

/* ============================================================ */
/* 移动端适配：手机屏下左侧菜单默认收起（抽屉式，点汉堡展开） */
/* ============================================================ */
.top-left { display: flex; align-items: center; gap: 10px; }
.btn-menu-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 9px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
}
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
  /* 顶栏：显示汉堡，隐藏用户名以节省空间 */
  .topbar { padding: 0 12px; }
  #user-name { display: none; }
  .btn-menu-toggle { display: inline-flex; }

  /* 布局改为块级，侧边栏变固定抽屉，默认滑出屏幕左侧 */
  .layout { display: block; position: relative; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0;
    width: 82%; max-width: 300px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 50;
    box-shadow: 2px 0 14px rgba(0, 0, 0, .15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show {
    display: block;
    position: fixed; top: 56px; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 49;
  }

  /* 主区域更紧凑 */
  .content { padding: 12px; }
  .toolbar { gap: 8px; }
  .toolbar input { flex: 1 1 100%; }
  .toolbar .filter-select,
  .toolbar .review-filters,
  .toolbar .view-toggle,
  .toolbar .btn-ghost,
  .toolbar .btn-primary { flex: 1 1 auto; }
  .review-filters { width: 100%; }
  .review-filters .rf-btn { flex: 1 1 auto; justify-content: center; }

  /* 题目网格单列 */
  .question-grid { grid-template-columns: 1fr; }

  /* 弹窗在手机端接近全屏 */
  .modal { padding: 0; }
  .modal-box {
    width: 100%; max-width: none; height: 100%; max-height: 100%;
    border-radius: 0; overflow-y: auto;
  }
}
