:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --primary: #2f4a52;
  --primary-dark: #21383e;
  --accent: #b5482e;
  --accent-dark: #97401f;
  --danger: #c0392b;
  --warn: #c98a1b;
  --ink: #2b2b2b;
  --text-2: #7c766a;
  --border: #e7e0d0;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(43, 43, 43, 0.06);
  --shadow-lg: 0 16px 44px rgba(43, 43, 43, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle at 12% 8%, rgba(181, 72, 46, 0.04), transparent 40%),
                    radial-gradient(circle at 88% 92%, rgba(47, 74, 82, 0.05), transparent 45%);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }

/* 顶部导航 */
.topbar {
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 18px; letter-spacing: 0.3px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 19px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(181, 72, 46, 0.28);
}
.brand .brand-short { display: none; }
.topbar .nav { display: flex; gap: 6px; align-items: center; }
.topbar .nav a {
  padding: 8px 15px; border-radius: 9px; font-size: 14px; color: var(--text-2);
  min-height: 40px; display: inline-flex; align-items: center;
  transition: all .15s;
}
.topbar .nav a:hover { background: #f0ece2; color: var(--primary); }
.topbar .nav a.active { background: var(--primary); color: #fff; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

/* 首页 hero */
.hero { text-align: center; padding: 52px 20px 30px; }
.hero h1 { font-size: 31px; font-weight: 800; letter-spacing: -0.4px; color: var(--primary-dark); }
.hero h1 .hl { color: var(--accent); }
.hero p { color: var(--text-2); margin-top: 12px; font-size: 15px; }
.hero p.hero-eyebrow { color: var(--accent); font-size: 14px; font-weight: 600; letter-spacing: 2px; margin: 0 0 4px; }

.role-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 30px; }
.role-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 30px 24px; box-shadow: var(--shadow); cursor: pointer; text-align: left;
  transition: transform .18s, box-shadow .18s, border-color .18s;
  border-top: 3px solid var(--accent);
}
.role-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); border-color: #dccfb6; }
.role-card .icon { font-size: 36px; }
.role-card h3 { margin: 14px 0 6px; font-size: 19px; color: var(--primary-dark); }
.role-card p { color: var(--text-2); font-size: 13.5px; }
.role-card .tag { display: inline-block; margin-top: 16px; font-size: 12.5px; color: var(--accent); background: #f7ece7; padding: 5px 12px; border-radius: 20px; font-weight: 600; }

/* 表单 */
label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
input, select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fcfbf8; color: var(--ink);
  transition: border .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(47, 74, 82, 0.12); }
.form-group { margin-bottom: 16px; }

/* 密码可见性切换 */
.input-wrap { position: relative; }
.input-wrap > input { padding-right: 46px; }
.eye-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: none; background: transparent; cursor: pointer;
  font-size: 16px; line-height: 1; color: #6b7280;
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
}
.eye-btn:hover { background: #f0ece2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border: none; border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #9fb0b4; cursor: not-allowed; }
.btn-ghost { background: #efe9dc; color: var(--primary); }
.btn-ghost:hover { background: #e4dcc8; }
.btn-danger { background: #fbe6e2; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 9px 14px; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; }

/* 提示 */
.alert { padding: 12px 15px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; display: none; }
.alert.show { display: block; }
.alert.error { background: #fdeceA; color: #b91c1c; border: 1px solid #f6c9c0; }
.alert.success { background: #ecf6ee; color: #15803d; border: 1px solid #c2e6cb; }
.alert.info { background: #eef4f6; color: #1d4ed8; border: 1px solid #cbe0e8; }

.muted { color: var(--text-2); font-size: 13px; }
.step-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 13px; font-weight: 700; margin-right: 8px;
}

/* 二维码结果 */
.qr-box { text-align: center; }
.qr-box img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 12px; padding: 8px; background: #fff; }
.qr-student { margin: 16px 0; }
.qr-student .name { font-size: 20px; font-weight: 700; }
.qr-student .meta { color: var(--text-2); font-size: 13.5px; margin-top: 4px; }

/* 学生候选列表 */
.candidate {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px;
}
.candidate .info .name { font-weight: 600; }
.candidate .info .meta { color: var(--text-2); font-size: 12.5px; }

/* 学生图片库 */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin-top: 6px; }
.img-card { border: 1px solid var(--border); border-radius: 10px; padding: 8px; background: #fff; display: flex; flex-direction: column; gap: 8px; }
.img-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 6px; background: #f5f3ee; }
.img-card .img-name { font-size: 13px; font-weight: 600; text-align: center; color: var(--text-1); }

/* 家长端班次 —— 分组列表形式（适配多班级） */
.cat-tabs { display: flex; gap: 10px; flex-wrap: nowrap; overflow-x: auto; padding: 4px 2px 12px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  flex-shrink: 0;
  padding: 9px 18px;
  min-height: 40px;
  display: inline-flex; align-items: center;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.cat-tab:hover { border-color: var(--primary); color: var(--primary); }
.cat-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(47, 74, 82, 0.18);
}
.class-list { display: flex; flex-direction: column; gap: 24px; margin-top: 12px; }
.cat-group { animation: fade .25s ease; }
.cat-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 800; color: var(--primary-dark); margin: 2px 0 14px;
}
.cat-head::before { content: ""; width: 5px; height: 19px; border-radius: 3px; background: var(--accent); }
.cat-head .count { font-size: 13px; font-weight: 600; color: var(--text-2); background: #efe9dc; padding: 2px 10px; border-radius: 20px; }

.class-row {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  transition: border-color .15s, box-shadow .15s;
}
.class-row:hover { border-color: #d8caa9; box-shadow: var(--shadow-lg); }
.class-row .info { min-width: 0; flex: 1; }
.class-row .title-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.class-row h3 { font-size: 17px; color: var(--ink); }
.cat-tag { font-size: 12px; padding: 2px 9px; border-radius: 6px; background: #f0ebe0; color: var(--text-2); font-weight: 600; }
.chip { font-size: 12.5px; padding: 4px 10px; border-radius: 20px; background: #f3efe6; color: var(--text-2); }
.chip.hl { background: #f7ece7; color: var(--accent); }
.chip.full { background: #fbe6e2; color: var(--danger); }
.class-row .meta { color: var(--text-2); font-size: 13px; margin-top: 9px; display: flex; flex-wrap: wrap; gap: 14px; }
.class-row .remain { font-size: 12.5px; color: var(--text-2); margin-top: 9px; }
.remain-bar { display: inline-block; width: 90px; height: 7px; border-radius: 4px; background: #f0ece2; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.remain-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #d98b4f); transition: width .3s; }
.class-row .act { flex-shrink: 0; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 管理后台 */
.admin-layout { display: grid; grid-template-columns: 210px 1fr; gap: 20px; margin-top: 20px; }
.sidebar { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; height: fit-content; position: sticky; top: 80px; }
.sidebar .menu-item {
  display: flex; align-items: center; min-height: 44px; padding: 11px 14px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--text-2); margin-bottom: 2px;
}
.sidebar .menu-item:hover { background: #f3efe6; }
.sidebar .menu-item.active { background: var(--primary); color: #fff; }
.panel { display: none; }
.panel.active { display: block; }
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat .lb { color: var(--text-2); font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
th { background: #f7f3ea; font-weight: 600; color: var(--text-2); }
tr:last-child td { border-bottom: none; }
.qr-mini { width: 46px; height: 46px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }

.section-title { font-size: 16px; font-weight: 700; margin: 6px 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.badge { font-size: 12px; padding: 3px 9px; border-radius: 20px; }
.badge.open { background: #e3f0e6; color: #15803d; }
.badge.closed { background: #f0ece2; color: #7c766a; }
.badge.full { background: #fbe6e2; color: #b91c1c; }
.cat-pill { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #f0ebe0; color: var(--text-2); margin-right: 4px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(33, 38, 33, 0.45); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal h3 { margin-bottom: 18px; color: var(--primary-dark); }

.spin { text-align: center; padding: 30px; color: var(--text-2); }

/* 课程细分管理（全局，桌面/移动端一致） */
.ct-item { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.ct-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ct-head b { font-size: 16px; color: var(--ink); }
.ct-subs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ct-sub { background: #f4f1ea; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.ct-x { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.ct-add-sub { border: 1px dashed var(--primary); background: none; color: var(--primary); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.ct-add-sub:hover { background: rgba(47, 74, 82, 0.06); }

/* ===================== 移动优先响应式 ===================== */
/* 手机优先：以下规则以窄屏为基础，桌面端保持原有布局（见上方全局样式）。 */
@media (max-width: 760px) {
  .container { padding: 16px 16px 48px; }
  .hero { padding: 36px 14px 22px; }
  .card { padding: 18px; }
  .modal { padding: 20px 18px; border-radius: 14px; max-width: 100%; }
  .role-grid, .two-col { grid-template-columns: 1fr; }
  .section-title { font-size: 15px; }

  /* 顶部导航：品牌简称 + 导航横滑（不换行） */
  .topbar { padding: 10px 14px; }
  .brand { font-size: 15px; gap: 8px; min-width: 0; }
  .brand .logo { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
  .brand .brand-full { display: none; }
  .brand .brand-short { display: inline; }
  .topbar .nav { gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex-shrink: 1; min-width: 0; }
  .topbar .nav::-webkit-scrollbar { display: none; }
  .topbar .nav a { flex-shrink: 0; white-space: nowrap; }

  /* 后台：侧边栏 → 顶部横滑标签栏 */
  .admin-layout { grid-template-columns: 1fr; gap: 14px; }
  .sidebar { position: static; display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 8px; }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .menu-item { flex-shrink: 0; white-space: nowrap; margin-bottom: 0; min-height: 42px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 23px; }

  /* 家长班次行：已竖排，强化操作按钮触控区 */
  .class-row { flex-direction: column; align-items: stretch; padding: 14px; }
  .class-row .act { width: 100%; }
  .class-row .act .btn { width: 100%; min-height: 44px; }

  /* 教师端查询图片自适应 */
  .qr-box img { width: min(240px, 68vw); height: auto; }

  /* 数据表卡片化（data-label 技术）：手机上每行变成带字段标签的卡片 */
  table.data-table { display: block; overflow: visible; }
  table.data-table thead { display: none; }
  table.data-table tbody { display: block; }
  table.data-table tr { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; padding: 4px 2px; box-shadow: var(--shadow); }
  table.data-table td { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; border: none; padding: 10px 14px; font-size: 14px; text-align: right; }
  table.data-table td::before { content: attr(data-label); color: var(--text-2); font-weight: 600; text-align: left; flex-shrink: 0; }
  table.data-table td[colspan] { justify-content: center; text-align: center; }
  table.data-table td[colspan]::before { content: ""; }

  /* 其余小表（如导入结果）保持横向滚动 */
  table:not(.data-table) { display: block; overflow-x: auto; }
}

@media (max-width: 420px) {
  .container { padding: 14px 12px 40px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .role-card { padding: 22px 18px; }
  .cat-tab { padding: 8px 14px; }
  .class-row .title-line { gap: 8px; }
}

/* 批量导入班次 */
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: #f0f3f4; }
.step-list { margin: 0 0 18px; padding-left: 20px; color: var(--text-2); font-size: 13.5px; line-height: 1.9; }
.step-list li { margin-bottom: 4px; }
.step-list b { color: var(--primary); }
.import-result:empty { display: none; }
.err-table { margin-top: 8px; font-size: 13px; }
.err-table th { background: #fbeaea; color: #b91c1c; }
.err-table td { color: var(--ink); }

/* 教师端学生图片即时过滤网格 */
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin-top: 8px; }
.student-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 12px; box-shadow: var(--shadow); text-align: center; }
.student-card .thumb { aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; background: #f4f1ea; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.student-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.student-card .name { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.student-card .hint { font-size: 12px; color: var(--text-2); }

@media (min-width: 640px) {
  .student-grid { grid-template-columns: repeat(3, 1fr); }
}
