/* ===== 设计变量 ===== */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6eaf0;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ===== 外壳布局（移动优先） ===== */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.main-col {
  order: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.hdr-title { font-size: 17px; font-weight: 700; }
.hdr-back {
  background: none; border: none; padding: 6px 4px; margin: -6px -4px;
  font-size: 15px; color: var(--primary); cursor: pointer; font-weight: 600;
}

.lock-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.lock-btn.locked { color: var(--muted); }
.lock-btn.unlocked { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.lock-tag { color: var(--green); font-size: 13px; font-weight: 600; }

.view {
  flex: 1;
  padding: 16px;
  padding-bottom: 24px;
}

/* ===== 导航（移动：底部标签栏） ===== */
.sidebar {
  order: 2;
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.sidebar .brand { display: none; }
.nav { display: flex; flex: 1; }
.nav-item {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}
.nav-item .ico { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--primary); }

/* ===== 桌面布局（≥ 900px：左侧栏 + 宽内容区） ===== */
@media (min-width: 900px) {
  .app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    max-width: 1280px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px var(--line);
  }
  .sidebar {
    order: 0;
    position: sticky;
    top: 0;
    bottom: auto;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    gap: 4px;
    border-top: none;
    border-right: 1px solid var(--line);
    background: #fff;
    padding: 16px 12px;
  }
  .sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 18px;
    font-size: 18px;
    font-weight: 800;
    color: var(--ink);
  }
  .brand-ico { font-size: 22px; }
  .nav { flex-direction: column; gap: 4px; }
  .nav-item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
  }
  .nav-item .ico { font-size: 20px; }
  .nav-item:hover { background: #f1f5f9; }
  .nav-item.active { background: #eef2ff; color: var(--primary); }

  .main-col { min-height: 100dvh; }
  .app-header { padding: 16px 28px; }
  .view {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 28px 28px 56px;
  }
  .view-sessionEdit,
  .view-sessionDetail,
  .view-settings { max-width: 720px; }
  .view-sessionEdit > .form { max-width: 600px; margin: 0 auto; }
  .view-settings .card .form { max-width: 460px; }
  .view-table { max-width: none; }

  /* 记录列表：多列卡片，月份标题占整行 */
  .view-sessions .month-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 10px;
    align-items: start;
  }
  .view-sessions .month-bar { grid-column: 1 / -1; }
  .view-sessions .session-card { margin-bottom: 0; }
}

/* ===== 卡片/通用 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 12px; letter-spacing: .02em; }
.muted { color: var(--muted); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 12px;
}
.section-head h2 { font-size: 16px; margin: 0; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ===== 按钮 ===== */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-ghost { background: #f8fafc; }
.btn-danger { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.btn-sm { min-height: 38px; padding: 8px 12px; font-size: 14px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-add { white-space: nowrap; }

/* ===== 月份分组 ===== */
.month-group { margin-bottom: 18px; }
.month-bar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 2px 8px; gap: 8px;
}
.month-bar .m-name { font-size: 15px; font-weight: 700; }
.month-bar .m-sum { font-size: 14px; color: var(--green); font-weight: 700; }
.month-bar .m-cnt { font-size: 12px; color: var(--muted); }

/* ===== 课程徽章 ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge.cpp { background: #dbeafe; color: #1e40af; }
.badge.python { background: #d1fae5; color: #065f46; }
.badge.school { background: #fef3c7; color: #92400e; }

/* ===== 记录卡片 ===== */
.session-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border: 1px solid transparent;
}
.session-card:active { border-color: var(--line); }
.sc-main { flex: 1; min-width: 0; }
.sc-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.sc-date { font-weight: 700; font-size: 15px; }
.sc-meta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sc-pay { font-size: 18px; font-weight: 800; color: var(--ink); white-space: nowrap; }
.sc-photo { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.chevron { color: #cbd5e1; font-size: 20px; }

/* ===== 顶部统计 ===== */
.stat-hero {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.stat-hero .label { font-size: 13px; opacity: .9; }
.stat-hero .value { font-size: 30px; font-weight: 800; margin-top: 2px; }
.stat-hero .sub { font-size: 12px; opacity: .85; margin-top: 4px; }

/* ===== 表单 ===== */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-label .muted { font-weight: 500; }
input[type="text"], input[type="number"], input[type="date"], input[type="password"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px; /* 防止 iOS 聚焦缩放 */
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.hint { font-size: 12px; color: var(--muted); }
.hint.warn { color: var(--amber); }

/* 分段控件 */
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  min-height: 46px;
}
.seg button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 学员选择 chip */
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  user-select: none;
}
.chip.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.empty-hint { border: none; color: var(--muted); padding-left: 2px; cursor: default; }
.quick-add { display: flex; gap: 8px; }
.quick-add input { flex: 1; }

.pay-preview {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
}
.form-actions { display: flex; gap: 10px; }
.form-actions .btn { flex: 1; }

/* ===== 照片 ===== */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #e2e8f0;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .rm {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff; border: none;
  font-size: 15px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.photo-add { margin-top: 10px; width: 100%; }
.photo-grid.view .photo-thumb { cursor: zoom-in; }
.photo-loading { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* 详情 */
.detail-pay { font-size: 34px; font-weight: 800; }
.detail-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.detail-line:last-child { border-bottom: none; }
.detail-line .k { color: var(--muted); }
.detail-line .v { font-weight: 600; text-align: right; }
.name-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.name-chip { background: #f1f5f9; border-radius: 999px; padding: 4px 11px; font-size: 13px; }
.note-box { background: #f8fafc; border-radius: 10px; padding: 12px; white-space: pre-wrap; color: #334155; }

/* ===== 工资分解 ===== */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.month-nav button { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 44px; height: 40px; font-size: 18px; cursor: pointer; }
.month-nav .cur { font-size: 16px; font-weight: 700; }
.breakdown-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .bk-info { font-size: 13px; color: var(--muted); }
.breakdown-row .bk-pay { font-weight: 700; font-size: 16px; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; padding-top: 12px; border-top: 2px solid var(--ink); }
.total-row .t-label { font-weight: 700; }
.total-row .t-val { font-size: 24px; font-weight: 800; color: var(--green); }

.list-mini { margin-top: 6px; }
.mini-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.mini-row:last-child { border-bottom: none; }
.mini-row .mr-l { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mini-row .mr-date { font-weight: 600; }

/* ===== 学员列表 ===== */
.student-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.student-row:last-child { border-bottom: none; }
.student-row .avatar {
  width: 38px; height: 38px; border-radius: 999px; background: #e0e7ff; color: #3730a3;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.student-row.inactive .avatar { background: #e2e8f0; color: #94a3b8; }
.student-row .s-main { flex: 1; min-width: 0; }
.student-row .s-name { font-weight: 600; }
.student-row .s-sub { font-size: 12px; color: var(--muted); }
.student-row .s-act { display: flex; gap: 6px; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 36px; height: 36px; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.banner {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 12px; padding: 12px 14px; font-size: 13px; margin-bottom: 14px;
}
.banner a { color: inherit; font-weight: 700; }

.about { font-size: 13px; color: var(--muted); line-height: 1.7; }
.about strong { color: var(--ink); }

/* ===== 模态框 ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 600px) { .modal-backdrop { align-items: center; padding: 16px; } }
.modal {
  background: #fff;
  width: 100%;
  max-width: 460px;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(18px + var(--safe-b));
  box-shadow: 0 -8px 40px rgba(0,0,0,.2);
}
@media (min-width: 600px) { .modal { border-radius: 18px; padding-bottom: 18px; } }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .form { gap: 14px; }

/* 图片大图 */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(15, 23, 42, .92); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 70;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid #cbd5e1; border-top-color: var(--primary); border-radius: 999px; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 记录表格（类 Excel） ===== */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg-sm { gap: 6px; }
.seg-sm button { flex: none; padding: 8px 14px; min-height: 38px; font-size: 13px; border-radius: 9px; }
.sel-sm { width: auto; padding: 8px 10px; font-size: 14px; border: 1px solid var(--line); border-radius: 9px; min-height: 38px; background: #fff; color: var(--ink); }

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table thead th {
  background: #f8fafc; position: sticky; top: 0; z-index: 1;
  font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .pay { font-weight: 700; }
.data-table .wd { color: var(--muted); margin-left: 6px; font-size: 12px; }
.data-table .ell { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.data-table tfoot .tfoot td { border-top: 2px solid var(--ink); border-bottom: none; font-weight: 700; background: #fff; }
