/* =============================================================
   科创港 KCG · 基础样式（设计令牌 + 布局 + 组件 + 响应式）
   ============================================================= */
:root {
  --c-primary: #4f6ef7;
  --c-primary-dark: #3b55d9;
  --c-primary-light: #eef1fe;
  --c-success: #16a34a;
  --c-warning: #d97706;
  --c-danger: #dc2626;
  --c-text: #1f2430;
  --c-text-2: #5b6472;
  --c-text-3: #98a1b0;
  --c-border: #e4e8ef;
  --c-bg: #f5f7fa;
  --c-card: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .16);
  --sidebar-w: 232px;
  --topbar-h: 56px;
  font-size: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* 关键：防止组件类名的 display 规则压过 hidden 属性（否则遮罩层永远无法隐藏） */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
a { color: var(--c-primary); text-decoration: none; }
button { font-family: inherit; }

/* ---------- 布局 ---------- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #1c2233;
  color: #cbd3e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  color: #fff; font-weight: 700; font-size: 16px;
}
.brand-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; color: #aab4c8;
  cursor: pointer; font-size: 14px;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--c-primary); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; }
.nav-group-title {
  padding: 14px 12px 6px; font-size: 11px; color: #6b7590;
  text-transform: uppercase; letter-spacing: .5px;
}
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-card { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.user-meta { overflow: hidden; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #8b95ab; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 16px; font-weight: 700; }
.topbar-right { margin-left: auto; }
.env-badge {
  background: var(--c-warning); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
}
.icon-btn {
  display: none; border: none; background: none; font-size: 20px;
  cursor: pointer; color: var(--c-text); padding: 4px 8px;
}
.mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 39; /* 低于 sidebar(40) 高于内容 */
}
.view { padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat .label { color: var(--c-text-2); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 6px; color: var(--c-primary); }
.stat .value.small { font-size: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); }
.btn-outline { background: #fff; border-color: var(--c-border); color: var(--c-text); }
.btn-outline:hover:not(:disabled) { border-color: var(--c-primary); color: var(--c-primary); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: #aab4c8; }
.btn-ghost:hover { color: #fff; background: rgba(255,255,255,.08); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--c-text-2); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  padding: 9px 10px; font-size: 14px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-light);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* 筛选栏 */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filter-bar .field { margin-bottom: 0; min-width: 140px; }
.filter-bar .field input, .filter-bar .field select { padding: 7px 9px; }

/* 表格（桌面） */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--radius); background: #fff; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table th { background: #f8fafc; color: var(--c-text-2); font-weight: 600; position: sticky; top: 0; }
.table tbody tr:hover { background: #f8faff; }
.table td.wrap { white-space: normal; min-width: 160px; }
.table .actions { display: flex; gap: 6px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; background: var(--c-primary-light); color: var(--c-primary);
}
.badge.green { background: #e7f7ee; color: var(--c-success); }
.badge.orange { background: #fdf1e2; color: var(--c-warning); }
.badge.red { background: #fdeaea; color: var(--c-danger); }
.badge.gray { background: #eef0f4; color: var(--c-text-2); }
.badge.blue { background: #e8f0fe; color: #1a73e8; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: var(--c-text-2); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 20px;
}
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* toast */
.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .2s ease;
  max-width: 340px;
}
.toast.success { background: var(--c-success); }
.toast.error { background: var(--c-danger); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 空状态 / 加载 */
.empty { text-align: center; color: var(--c-text-3); padding: 40px 0; }
.loading { text-align: center; color: var(--c-text-3); padding: 40px 0; }

/* 课程表网格 */
.tt-grid { display: grid; grid-template-columns: 64px repeat(5, 1fr); gap: 8px; }
.tt-head { font-weight: 700; text-align: center; color: var(--c-text-2); padding: 6px 0; }
.tt-cell { min-height: 88px; background: #fff; border: 1px dashed var(--c-border); border-radius: 8px; padding: 6px; }
.tt-item {
  background: var(--c-primary-light); color: var(--c-primary-dark);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; margin-bottom: 6px;
}
.tt-item b { display: block; font-size: 12px; }
.tt-item span { opacity: .85; }

/* 登录覆盖层 */
.auth-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: linear-gradient(135deg, #4f6ef7 0%, #7b5bf2 100%);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 36px 32px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); text-align: center;
}
.auth-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 10px; }
.auth-card h2 { font-size: 18px; margin-bottom: 22px; }
.auth-card form { text-align: left; }
.auth-tip { font-size: 12px; color: var(--c-danger); margin-top: 10px; min-height: 16px; text-align: center; }

/* 注册/登录选项卡 */
.auth-tabs { display: flex; gap: 4px; background: var(--c-bg, #f1f3f8); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px 0; border-radius: 8px;
  font-size: 14px; cursor: pointer; color: var(--c-text-2, #666);
}
.auth-tabs button.active { background: #fff; color: var(--c-primary, #4f6ef7); font-weight: 600; box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,.08)); }

/* 验证码行：输入框 + 发送按钮 */
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row .btn { white-space: nowrap; }
.code-row .btn:disabled { opacity: .6; cursor: not-allowed; }

/* 开发模式验证码提示条 */
.dev-code-tip {
  font-size: 12px; color: var(--c-text-2, #666); background: var(--c-bg, #f6f8fc);
  border-radius: 8px; padding: 6px 10px; margin-top: 8px; text-align: center;
}
.dev-code-tip b { color: var(--c-primary, #4f6ef7); font-size: 14px; letter-spacing: 2px; }

/* 多角色选择面板（手机号命中多个角色） */
.role-select-list { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.role-select-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 12px 14px; border: 1px solid var(--c-border, #e5e9f2);
  border-radius: 10px; background: #fff; cursor: pointer; text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.role-select-item:hover { border-color: var(--c-primary, #4f6ef7); box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,.08)); }
.role-select-item .rs-name { font-size: 14px; font-weight: 600; color: var(--c-text, #1f2733); }
.role-select-item .rs-role { font-size: 12px; color: var(--c-text-2, #666); }

/* 侧边栏角色切换入口 */
.role-switch-btn {
  width: 100%; margin-top: 6px; font-size: 12px; color: #aab4c8;
  background: transparent; border: 1px dashed rgba(255,255,255,.25);
  border-radius: 8px; padding: 6px 0; cursor: pointer;
}
.role-switch-btn:hover { color: #fff; border-color: rgba(255,255,255,.6); }

/* =============================================================
   响应式：<= 992px 平板；<= 768px 手机
   ============================================================= */
@media (max-width: 992px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .view { padding: 14px; }
}

@media (max-width: 768px) {
  /* 侧栏变为抽屉 */
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .sidebar.open { transform: none; }
  .icon-btn { display: inline-block; }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .view { padding: 12px; }

  /* 表格在手机上卡片化 */
  .table-wrap.responsive table.table thead { display: none; }
  .table-wrap.responsive table.table tbody tr {
    display: block; border-bottom: 1px solid var(--c-border); padding: 10px 12px;
  }
  .table-wrap.responsive table.table tbody tr:hover { background: #fff; }
  .table-wrap.responsive table.table td {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    border-bottom: none; padding: 5px 0; white-space: normal;
  }
  .table-wrap.responsive table.table td::before {
    content: attr(data-label); color: var(--c-text-3); font-size: 12px; flex-shrink: 0;
  }
  .table-wrap.responsive table.table td.actions { justify-content: flex-end; }

  .modal { padding: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .tt-grid { grid-template-columns: 44px repeat(5, 1fr); font-size: 11px; }
  .tt-cell { min-height: 64px; }
  .filter-bar .field { min-width: 100%; }
  .filter-bar .btn { width: 100%; }
}

/* ─────── 课程卡片（学生选课报名） ─────── */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.course-card {
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  padding: 16px 18px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow .2s, border-color .2s;
}
.course-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); border-color: var(--c-primary, #4f6ef7); }
.course-card.enrolled { border-color: #b7e4c7; background: #f6fff9; }
.course-card-head {
  display: flex; align-items: center; gap: 12px;
}
.course-card-head h4 { margin: 0; font-size: 16px; }
.course-icon { font-size: 28px; }
.course-desc {
  margin: 0; font-size: 13px; color: var(--c-text-2, #5a6473);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.5;
}
.course-schedules { display: flex; flex-wrap: wrap; gap: 6px; }
.course-schedules .badge { font-size: 12px; }
.course-card-foot {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid #f0f1f4; padding-top: 10px; margin-top: auto;
}

/* ─────── 通知铃铛 ─────── */
.notif-bell {
  position: relative; font-size: 18px; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; transition: background .15s;
}
.notif-bell:hover { background: rgba(0,0,0,.05); }
.notif-badge {
  position: absolute; top: -2px; right: -2px;
  background: #e53e3e; color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; line-height: 16px;
  border-radius: 8px; padding: 0 4px; text-align: center;
}

/* ─────── 通知列表 ─────── */
.notif-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid #f0f1f4;
  cursor: pointer; transition: background .12s; position: relative;
}
.notif-item:hover { background: #f8f9fb; }
.notif-item.unread { background: #f0f5ff; }
.notif-item.unread:hover { background: #e6efff; }
.notif-icon { font-size: 20px; flex-shrink: 0; width: 32px; text-align: center; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; margin-bottom: 2px; }
.notif-content { color: var(--c-text-2); font-size: 14px; line-height: 1.5; }
.notif-time { color: var(--c-text-3); font-size: 12px; margin-top: 4px; }
.notif-dot {
  position: absolute; top: 14px; right: 12px;
  width: 8px; height: 8px; border-radius: 50%; background: #e53e3e;
}

/* ─────── 考勤管理 ─────── */
.class-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.class-card {
  padding: 14px; border: 1px solid #e8eaef; border-radius: 10px;
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.class-card:hover { border-color: #a3a8d0; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.class-card.done { border-color: #c8e6c9; background: #f1f8f4; }
.class-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.class-card-title { font-weight: 600; font-size: 15px; }
.class-card-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--c-text-2); }

.att-students { display: flex; flex-direction: column; gap: 8px; }
.att-student {
  display: grid; grid-template-columns: 120px 120px 1fr 200px;
  gap: 12px; align-items: center; padding: 10px 12px;
  border: 1px solid #f0f1f4; border-radius: 8px;
}
.att-student-name { font-weight: 600; }
.att-student-phone { font-size: 13px; color: var(--c-text-3); }
.att-status-btns { display: flex; gap: 4px; }
.att-btn {
  padding: 4px 10px; border: 1px solid #e0e3eb; border-radius: 6px;
  font-size: 13px; cursor: pointer; background: #fff; transition: all .12s;
}
.att-btn:hover { border-color: #a3a8d0; }
.att-btn.active { color: #fff; border-color: transparent; }
.att-btn.active.green { background: #28a745; }
.att-btn.active.red { background: #e53e3e; }
.att-btn.active.orange { background: #ff9800; }
.att-btn.active.gray { background: #9e9e9e; }
.att-remark { border: 1px solid #e8eaef; border-radius: 6px; padding: 4px 8px; font-size: 13px; }

@media (max-width: 768px) {
  .att-student { grid-template-columns: 1fr; gap: 6px; }
  .class-cards { grid-template-columns: 1fr; }
}

/* ─────── P4 亲子绑定 / 学生导入（v2.0） ─────── */
.notice {
  border-radius: var(--radius-sm, 8px); padding: 10px 14px;
  font-size: 14px; line-height: 1.7; margin-bottom: 12px;
}
.notice.warn  { background: #fdf1e2; color: var(--c-warning, #d97706); }
.notice.info  { background: var(--c-primary-light, #eef1fe); color: var(--c-primary-dark, #3b55d9); }
.notice.error { background: #fdeaea; color: var(--c-danger, #dc2626); }
.bind-result { margin-top: 14px; }
.bind-actions { display: flex; gap: 8px; margin-top: 4px; }
.bind-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }
.bind-phone-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.filter-form .field { margin-bottom: 0; }

@media (max-width: 640px) {
  .bind-phone-row { flex-direction: column; align-items: stretch; }
}
