/* ═══════════════════════════════════════════════════════════════
   课时签到系统 — 样式
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg:        #f4f5f9;
  --surface:   #ffffff;
  --line:      #e5e7ef;
  --text:      #1a1c25;
  --text-2:    #626676;
  --text-3:    #9aa0b0;

  --brand:     #4f46e5;
  --brand-dk:  #4338ca;
  --brand-sf:  #eef0ff;

  --ok:        #10b981;
  --ok-sf:     #e8f9f2;
  --warn:      #f59e0b;
  --warn-sf:   #fff5e2;
  --danger:    #ef4444;
  --danger-sf: #fdeced;
  --gray-sf:   #f1f2f6;

  --r:   14px;
  --r-s: 9px;
  --sh:    0 1px 2px rgba(16,20,40,.05), 0 1px 3px rgba(16,20,40,.06);
  --sh-md: 0 4px 12px rgba(16,20,40,.09), 0 2px 4px rgba(16,20,40,.05);
  --sh-lg: 0 18px 50px rgba(16,20,40,.20);
}

* { box-sizing: border-box; }
/* 背景色放在 html 上：内容比视口短时，body 只有内容那么高，
   底下会露出浏览器的白底。html 兜住整个视口，背景才铺得满。 */
html {
  margin: 0; padding: 0; background: var(--bg); min-height: 100%;
  /* 一直留出滚动条槽：否则内容长短切换时（比如换标签页）整页会左右跳一下 */
  scrollbar-gutter: stable;
  /* 槽的底色跟着页面走，不然右边会出现一条突兀的白带 */
  scrollbar-color: #c8ccd8 var(--bg);
}
body { margin: 0; padding: 0; min-height: 100vh; }
/* WebKit 系（Safari / 旧 Chrome）不认 scrollbar-color，单独写 */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #c8ccd8; border: 3px solid var(--bg); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #b0b5c5; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.right { text-align: right; }
.hint { color: var(--text-3); font-size: 12.5px; margin: 5px 0 0; line-height: 1.5; }
code { background: var(--gray-sf); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ───────────────────────────── 顶栏 ───────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px max(16px, env(safe-area-inset-left)) 11px max(16px, env(safe-area-inset-right));
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c6cf5);
  color: #fff; display: grid; place-items: center;
  font-size: 17px; font-weight: 700; box-shadow: 0 2px 8px rgba(79,70,229,.35);
}
.topbar h1 { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 9px; flex: none; }
.today-pill {
  display: flex; align-items: baseline; gap: 5px;
  background: var(--brand-sf); color: var(--brand-dk);
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; white-space: nowrap;
}
.tp-num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ───────────────────────────── 标签页 ───────────────────────────── */
.tabs {
  display: flex; gap: 3px; padding: 9px 16px 0;
  background: rgba(255,255,255,.86); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 53px; z-index: 39; overflow-x: auto;
}
.tab {
  border: 0; background: none; cursor: pointer; white-space: nowrap;
  padding: 8px 14px 11px; color: var(--text-2); font-size: 14.5px;
  border-bottom: 2.5px solid transparent; margin-bottom: -1px; border-radius: 8px 8px 0 0;
  transition: color .15s;
}
.tab:hover { color: var(--text); background: var(--gray-sf); }
.tab.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }
.tab-badge {
  display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 5px;
  margin-left: 5px; border-radius: 99px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; vertical-align: 1px;
}

/* ───────────────────────────── 待审核 ───────────────────────────── */
.pending-box {
  background: var(--brand-sf); border: 1px solid #cfd2fa;
  border-radius: var(--r); padding: 16px; margin-bottom: 18px;
}
.pending-list { display: grid; gap: 7px; }
.pd-row {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border-radius: var(--r-s); padding: 11px 14px;
}
.pd-info { flex: 1; min-width: 0; }
.pd-name { font-weight: 650; font-size: 14.5px; }
.pd-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.pd-when { font-weight: 400; font-size: 12px; color: var(--text-3); margin-left: 6px; }
.pd-row.stale { border-left: 3px solid var(--warn); }

/* ─────────────────── 待确认签到（学生提交，等老师通过）─────────────────── */
.pending-checkin {
  background: linear-gradient(100deg, #eef6ff, #eaf1ff);
  border: 1px solid #c6d8f5; border-radius: var(--r);
  padding: 15px 16px; margin-bottom: 16px;
}
.pc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; flex-wrap: wrap; }
.pc-head h2 { font-size: 15px; color: #1c4f9c; }
.pc-actions { display: flex; gap: 6px; }
.pc-note { margin: 0 0 9px; font-size: 12.5px; color: #9a6206; background: var(--warn-sf); padding: 7px 11px; border-radius: var(--r-s); }

/* 待确认状态标签：黄色系，和「已撤销」的灰色作废语义区分开 */
.tag-pending {
  font-size: 11px; background: var(--warn-sf); color: #9a6206;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap;
}
.pill.pending { background: var(--warn-sf); color: #9a6206; }
.rrow.pending { border-color: #f3ddb0; background: #fffdf7; }
/* 待确认不是作废，不能用删除线和半透明 */
.mi.pending { border-color: #f3ddb0; background: #fffdf7; }

/* 学生卡片：角标显示待确认，同时用左边框保留余额等级，两个信息不抢同一个位置 */
.sc-badge.tag-pending { background: var(--brand-sf); color: var(--brand-dk); }
.scard.pending { box-shadow: 0 0 0 2px var(--brand-sf), var(--sh); }

/* 老师端铺满窗口：这是内部工具，屏幕多大就用多大，
   不做「居中窄栏」——列表和表格越宽越好用。 */
main {
  padding: 18px max(20px, env(safe-area-inset-right)) 60px max(20px, env(safe-area-inset-left));
  width: 100%;
}
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ───────────────────────────── 预警横幅 ───────────────────────────── */
.alert-banner {
  background: linear-gradient(100deg, #fff8ea, #fff3dd);
  border: 1px solid #f7dfae; border-radius: var(--r);
  margin-bottom: 16px; overflow: hidden;
}
.alert-banner.urgent { background: linear-gradient(100deg, #fdeeee, #fde5e5); border-color: #f6bebe; }
.ab-main { display: flex; align-items: center; gap: 10px; padding: 13px 16px; cursor: pointer; user-select: none; }
.ab-icon { font-size: 17px; }
.ab-text { flex: 1; font-weight: 600; color: #8a5a05; font-size: 14.5px; }
.alert-banner.urgent .ab-text { color: #a52020; }
.ab-toggle { font-size: 12.5px; color: var(--text-2); flex: none; }
.ab-list { border-top: 1px solid rgba(0,0,0,.06); padding: 6px; display: grid; gap: 5px; }
.ab-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: rgba(255,255,255,.75); border-radius: var(--r-s); font-size: 14px;
}
.ab-row .n { font-weight: 600; min-width: 4.5em; }
.ab-row .b { color: var(--warn); font-weight: 650; font-variant-numeric: tabular-nums; }
.ab-row.lv-urgent .b, .ab-row.lv-empty .b { color: var(--danger); }
.ab-row .p { color: var(--text-3); font-size: 12.5px; margin-left: auto; }

/* ───────────────────────────── 工具栏 ───────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar.wrap { flex-wrap: wrap; }
.sep { color: var(--text-3); font-size: 13px; }
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .5; pointer-events: none; }
.search {
  width: 100%; padding: 11px 38px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); outline: none; box-shadow: var(--sh);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus { border-color: var(--brand); box-shadow: 0 0 0 3.5px rgba(79,70,229,.13); }
.search::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: var(--gray-sf); width: 24px; height: 24px; border-radius: 50%;
  cursor: pointer; color: var(--text-2); line-height: 1;
}
.filter-chips { display: flex; gap: 6px; flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  padding: 8px 13px; border-radius: 999px; font-size: 13.5px; color: var(--text-2);
  white-space: nowrap; transition: all .15s;
}
.chip:hover { border-color: #c9cddd; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }

/* ───────────────────────────── 按钮 ───────────────────────────── */
.btn {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  padding: 9px 15px; border-radius: var(--r-s); font-size: 14px; white-space: nowrap;
  box-shadow: var(--sh); transition: all .14s;
}
.btn:hover  { border-color: #c9cddd; transform: translateY(-1px); box-shadow: var(--sh-md); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 550; }
.btn.primary:hover { background: var(--brand-dk); }
.btn.ghost { box-shadow: none; background: transparent; }
.btn.warn   { background: var(--warn);   border-color: var(--warn);   color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small  { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; box-shadow: none; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ───────────────────────────── 学生卡片 ───────────────────────────── */
.grid {
  display: grid; gap: 11px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}
.scard {
  position: relative; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: var(--r); padding: 14px 14px 12px;
  box-shadow: var(--sh); transition: transform .13s, box-shadow .13s, border-color .13s;
  overflow: hidden;
}
.scard:hover  { transform: translateY(-2px); box-shadow: var(--sh-md); }
.scard:active { transform: translateY(0) scale(.985); }
.scard.lv-warn   { border-left-color: var(--warn); }
.scard.lv-urgent { border-left-color: var(--danger); }
.scard.lv-empty  { border-left-color: #9aa0b0; background: #fafafc; }
.scard.paused    { opacity: .62; }
.sc-name { font-size: 17.5px; font-weight: 650; letter-spacing: .3px; margin-bottom: 7px; }
.sc-bal  { display: flex; align-items: baseline; gap: 4px; }
.sc-num  { font-size: 25px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ok); }
.scard.lv-warn   .sc-num { color: var(--warn); }
.scard.lv-urgent .sc-num,
.scard.lv-empty  .sc-num { color: var(--danger); }
.sc-unit { font-size: 13px; color: var(--text-2); }
.sc-sub  { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.sc-badge {
  position: absolute; top: 9px; right: 9px; font-size: 10.5px; font-weight: 600;
  padding: 2.5px 7px; border-radius: 999px; background: var(--ok-sf); color: #077e5a;
}
.sc-badge.tag-paused { background: var(--gray-sf); color: var(--text-2); }
.sc-badge.tag-warn   { background: var(--warn-sf); color: #9a6206; }

.empty { text-align: center; padding: 54px 20px; color: var(--text-3); }
.empty b { display: block; font-size: 16px; color: var(--text-2); margin-bottom: 6px; }

/* ───────────────────────────── 最近操作 ───────────────────────────── */
.recent { margin-top: 30px; }
.section-title { font-size: 14px; color: var(--text-2); margin-bottom: 10px; font-weight: 600; }
.section-title .hint { display: inline; font-size: 12px; }
.recent-list { display: grid; gap: 6px; }
.rrow {
  display: flex; align-items: center; gap: 11px; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-s); padding: 9px 13px;
  min-width: 0;   /* grid 子项默认 min-width:auto，内容会把整页顶宽 */
}
.rrow .t { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 12.5px; flex: none; }
.rrow .n { font-weight: 600; flex: none; }
.rrow .d { color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrow .h { font-weight: 650; font-variant-numeric: tabular-nums; flex: none; }
.rrow .h.plus  { color: var(--ok); }
.rrow .h.minus { color: var(--danger); }
.rrow.revoked  { opacity: .5; }
.rrow.revoked .n, .rrow.revoked .h { text-decoration: line-through; }
.tag-revoked { font-size: 11px; background: var(--gray-sf); color: var(--text-2); padding: 2px 7px; border-radius: 5px; }

/* ───────────────────────────── 表格 ───────────────────────────── */
.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow-x: auto; box-shadow: var(--sh);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-2);
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid #f0f1f6; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfbfe; }
.table .right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.stu-name { font-weight: 600; }
.stu-py { font-size: 11px; color: var(--text-3); font-weight: 400; margin-left: 5px; }
.bal-cell { font-weight: 650; font-variant-numeric: tabular-nums; }
.bal-cell.lv-warn { color: var(--warn); }
.bal-cell.lv-urgent, .bal-cell.lv-empty { color: var(--danger); }
.pill { font-size: 11.5px; padding: 2.5px 9px; border-radius: 999px; white-space: nowrap; }
.pill.active   { background: var(--ok-sf);   color: #077e5a; }
.pill.paused   { background: var(--warn-sf); color: #9a6206; }
.pill.archived { background: var(--gray-sf); color: var(--text-2); }
.pill.checkin  { background: var(--brand-sf); color: var(--brand-dk); }
.pill.topup    { background: var(--ok-sf);   color: #077e5a; }
.pill.adjust   { background: var(--warn-sf); color: #9a6206; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.ledger-summary { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; color: var(--text-2); font-size: 13.5px; }
.ledger-summary b { color: var(--text); font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; color: var(--text-2); font-size: 13.5px; }

/* ───────────────────────────── 表单 / 卡片 ───────────────────────────── */
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--sh); }
.card h2 { font-size: 15.5px; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3.5px rgba(79,70,229,.13); }
textarea.input { resize: vertical; line-height: 1.6; }
select.input { cursor: pointer; }
.toolbar .input { width: auto; min-width: 118px; box-shadow: var(--sh); }
.check { display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }
.preview-box { background: var(--gray-sf); border-radius: var(--r-s); padding: 11px 13px; font-size: 13px; color: var(--text-2); line-height: 1.65; min-height: 42px; }
.addr-box { background: #12141c; color: #7ee8b0; border-radius: var(--r-s); padding: 12px 14px; font: 13.5px/1.9 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
.danger-zone { border-color: #f0d6d6; }

/* ───────────────────────────── 弹窗 ───────────────────────────── */
.mask {
  position: fixed; inset: 0; z-index: 100; background: rgba(18,20,32,.42);
  backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center;
  padding: 18px; animation: fade .15s ease;
}
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 430px;
  box-shadow: var(--sh-lg); max-height: 92vh; overflow-y: auto;
  animation: pop .2s cubic-bezier(.2,.9,.35,1.1);
}
.modal.wide { max-width: 560px; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.modal-head { padding: 20px 22px 0; }
.modal-head h3 { font-size: 18px; }
.modal-head .sub { color: var(--text-3); font-size: 13px; margin-top: 4px; }
.modal-body { padding: 18px 22px; }
.modal-foot { display: flex; gap: 9px; padding: 0 22px 20px; }
.modal-foot .btn { flex: 1; padding: 11px; justify-content: center; }

.confirm-hero { text-align: center; padding: 8px 0 16px; }
.confirm-hero .nm { font-size: 30px; font-weight: 700; letter-spacing: 1.5px; }
.confirm-hero .py { color: var(--text-3); font-size: 12.5px; margin-top: 3px; }
.balance-flow {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: var(--gray-sf); border-radius: var(--r); padding: 15px; margin-bottom: 15px;
}
.bf-col { text-align: center; min-width: 62px; }
.bf-label { font-size: 11.5px; color: var(--text-3); margin-bottom: 3px; }
.bf-val { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bf-val.after { color: var(--brand); }
.bf-val.neg { color: var(--danger); }
.bf-arrow { color: var(--text-3); font-size: 17px; }
.bf-minus { color: var(--danger); font-weight: 650; }

.deduct-opts { display: flex; gap: 7px; flex-wrap: wrap; }
.deduct-opts .chip { flex: 1; text-align: center; min-width: 58px; }
.warn-box {
  background: var(--warn-sf); border: 1px solid #f3ddb0; color: #8a5a05;
  border-radius: var(--r-s); padding: 11px 13px; font-size: 13.5px; margin-bottom: 14px; line-height: 1.6;
}
.warn-box.danger { background: var(--danger-sf); border-color: #f4c4c4; color: #a52020; }
.warn-box b { display: block; margin-bottom: 3px; }

/* ───────────────────────────── 提示条 ───────────────────────────── */
.toast-root { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; pointer-events: none; }
.toast {
  background: #1c1f2b; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--sh-lg); animation: rise .22s cubic-bezier(.2,.9,.35,1.1);
  display: flex; align-items: center; gap: 8px; max-width: 88vw;
}
.toast.ok   { background: #0d8a63; }
.toast.err  { background: #c62f2f; }
.toast.warn { background: #b57209; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ───────────────────────────── 成功全屏 ───────────────────────────── */
.success {
  position: fixed; inset: 0; z-index: 300;
  background: linear-gradient(160deg, #10b981, #059669);
  display: flex; align-items: center; justify-content: center;
  color: #fff; animation: fade .2s ease;
}
.success.miss { background: linear-gradient(160deg, #f59e0b, #d97706); }
.success.waiting { background: linear-gradient(160deg, #f59e0b, #d97706); }
.success-inner { text-align: center; padding: 24px; }
.success-mark {
  width: 108px; height: 108px; margin: 0 auto 22px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: grid; place-items: center;
  font-size: 62px; animation: mark .45s cubic-bezier(.2,1.3,.4,1);
}
@keyframes mark { from { transform: scale(.3); opacity: 0; } }
.success-name { font-size: 40px; font-weight: 700; letter-spacing: 3px; }
.success-msg  { font-size: 19px; margin-top: 10px; opacity: .95; }
.success-sub  { font-size: 15px; margin-top: 16px; opacity: .8; }

/* ───────────────────────────── 响应式 ─────────────────────────────
   三档：
     ≤1024  平板 / 小窗口——收窄留白，卡片列数自适应
     ≤720   手机横屏 / 大手机——表格换成卡片式堆叠，不再左右拖
     ≤380   小屏手机——再压一档字号与间距
   表格转卡片靠 td 上的 data-label，渲染函数里已带好。
   ──────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 13px; }
  .card { padding: 17px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr)); }
}

/* ── 大屏：把多出来的横向空间用起来 ──
   宽度本身已经铺满，这里只调密度：卡片大一点、表格行宽松一点，
   否则 1920 屏上会出现一排十几张小卡片，反而更难扫。 */
@media (min-width: 1500px) {
  main { padding: 24px max(28px, env(safe-area-inset-right)) 60px max(28px, env(safe-area-inset-left)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
  .table th, .table td { padding: 13px 18px; }
}

@media (min-width: 1900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
}

@media (max-width: 720px) {
  .tabs { top: 52px; padding: 8px 12px 0; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 11px 10px; font-size: 14px; }
  main { padding: 14px max(12px, env(safe-area-inset-right)) 60px max(12px, env(safe-area-inset-left)); }
  .hide-sm { display: none; }
  .toolbar { flex-wrap: wrap; }
  .toolbar .search-wrap { min-width: 100%; }
  .toolbar .btn, .toolbar .input { flex: 1 1 auto; }
  .filter-chips { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .filter-chips::-webkit-scrollbar { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: 9px; }
  .cards { grid-template-columns: 1fr; }
  .success-name { font-size: 32px; }
  .today-pill .tp-label { display: none; }

  /* 最近操作：一行挤不下五段信息，改成上下两行 */
  .rrow {
    display: grid; align-items: center; gap: 2px 9px; padding: 10px 12px;
    grid-template-columns: 1fr auto auto;
    grid-template-areas: 'name hours action' 'desc desc action';
  }
  .rrow .t { grid-area: time; display: none; }
  .rrow .n { grid-area: name; font-size: 14.5px; }
  .rrow .h { grid-area: hours; }
  .rrow .d { grid-area: desc; font-size: 12.5px; white-space: normal; overflow: visible; }
  .rrow .tag-pending, .rrow .tag-revoked { grid-area: hours; justify-self: end; }
  .rrow .btn { grid-area: action; align-self: center; }

  /* ── 表格 → 卡片堆叠 ──
     每行变成一张卡，每格前面用 data-label 补上表头文字。
     这样操作按钮永远在可见范围内，不需要横向拖动。 */
  .table-wrap { border: 0; background: none; box-shadow: none; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: var(--sh); padding: 12px 14px; margin-bottom: 9px;
  }
  .table tbody tr:hover { background: var(--surface); }
  .table td {
    border: 0; padding: 3px 0; display: flex; align-items: center; gap: 10px;
    justify-content: space-between; text-align: right; min-width: 0;
  }
  .table td::before {
    content: attr(data-label); flex: none; text-align: left;
    font-size: 12.5px; color: var(--text-3); font-weight: 500;
  }
  .table td:empty { display: none; }
  /* 第一格当卡片标题：撑满一行、放大、下方分隔 */
  .table td:first-child {
    justify-content: flex-start; text-align: left; font-size: 16px;
    padding-bottom: 9px; margin-bottom: 7px; border-bottom: 1px solid var(--line);
  }
  .table td:first-child::before { display: none; }
  .table td.right { text-align: right; }
  .row-actions { justify-content: flex-end; flex-wrap: wrap; }
  .table td .row-actions { width: 100%; }
  /* 卡片式下操作按钮更容易点中 */
  .table .btn.small { padding: 7px 12px; font-size: 13px; }
  /* 空状态那一行不要套卡片壳 */
  .table td[colspan] { justify-content: center; text-align: center; }
  .table td[colspan]::before { display: none; }

  /* 复选框标签在窄屏必须能折行，否则长说明文字会把整张卡片撑破 */
  .check { white-space: normal; align-items: flex-start; }
  .check input { margin-top: 2px; flex: none; }

  /* iOS Safari 会自动放大 font-size < 16px 的输入框，聚焦时整页会跳。
     手机上一律 16px，从根上避免这个缩放。 */
  .input, .search, input, select, textarea { font-size: 16px; }

  .ledger-summary { gap: 4px 14px; font-size: 13px; }
  .pager { gap: 6px; }
  .modal-foot { flex-wrap: wrap; }
  /* 弹窗按钮在窄屏至少 44px 高，好点 */
  .modal-foot .btn { min-height: 44px; }
  .balance-flow { gap: 9px; padding: 13px 10px; }
  .bf-col { min-width: 54px; }
  .bf-val { font-size: 19px; }
  .pd-row { flex-wrap: wrap; }
  .pd-info { flex: 1 1 100%; margin-bottom: 7px; }
  .pd-row .btn { flex: 1; }
  .pc-actions { width: 100%; }
  .pc-actions .btn { flex: 1; }
}

@media (max-width: 380px) {
  .topbar h1 { font-size: 15px; }
  .logo { width: 27px; height: 27px; font-size: 15px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .sc-name { font-size: 16px; }
  .sc-num { font-size: 22px; }
  .mask { padding: 10px; }
  .modal-head { padding: 17px 17px 0; }
  .modal-body { padding: 15px 17px; }
  .modal-foot { padding: 0 17px 17px; }
  .confirm-hero .nm { font-size: 26px; }
  .deduct-opts .chip { min-width: 0; padding: 8px 9px; }
}

/* 触屏设备上 hover 位移会残留，关掉 */
@media (hover: none) {
  .btn:hover { transform: none; box-shadow: var(--sh); }
  .scard:hover { transform: none; box-shadow: var(--sh); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --surface: #191c25; --line: #2a2e3b;
    --text: #eceef4; --text-2: #9ba2b4; --text-3: #6b7285;
    --brand-sf: #232449; --ok-sf: #11302a; --warn-sf: #33270e; --danger-sf: #37191b; --gray-sf: #232733;
  }
  .topbar, .tabs { background: rgba(25,28,37,.86); }
  html { scrollbar-color: #3a3f4e var(--bg); }
  ::-webkit-scrollbar-thumb { background: #3a3f4e; }
  ::-webkit-scrollbar-thumb:hover { background: #4a5060; }
  .table th { background: #1d2029; }
  .table tbody tr:hover { background: #1d2029; }
  .scard.lv-empty { background: #15171f; }
  .alert-banner { background: linear-gradient(100deg, #2b2410, #33290f); border-color: #4a3c17; }
  .alert-banner .ab-text { color: #f0c069; }
  .alert-banner.urgent { background: linear-gradient(100deg, #331a1a, #3a1c1c); border-color: #5a2828; }
  .alert-banner.urgent .ab-text { color: #f19595; }
  .ab-row { background: rgba(255,255,255,.05); }
  .danger-zone { border-color: #4a2a2a; }
  .auth-body, .me-body { background: #0f1117; }
  .me-card { background: linear-gradient(160deg, #1e2130, #191c25); }
}

/* ═══════════════════════════ 登录 / 注册 ═══════════════════════════ */

.auth-body {
  background: var(--bg);
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 18px max(24px, env(safe-area-inset-bottom));
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.logo.big { width: 52px; height: 52px; font-size: 28px; border-radius: 15px; }
.auth-brand h1 { font-size: 20px; letter-spacing: .5px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 26px 24px; box-shadow: var(--sh-md);
}
.auth-head { margin-bottom: 20px; text-align: center; }
.auth-head h2 { font-size: 20px; margin-bottom: 7px; }
.auth-head p { margin: 0; color: var(--text-2); font-size: 13.5px; line-height: 1.7; }
.auth-loading { text-align: center; color: var(--text-3); padding: 30px 0; margin: 0; }
.auth-note { border-radius: var(--r-s); padding: 10px 13px; font-size: 13.5px; margin-bottom: 16px; }
.auth-note.ok { background: var(--ok-sf); color: #077e5a; }
.auth-switch { text-align: center; margin: 16px 0 0; font-size: 13.5px; color: var(--text-2); }
.auth-switch.muted { color: var(--text-3); font-size: 12.5px; }
.auth-switch a { color: var(--brand); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }
.auth-foot { text-align: center; color: var(--text-3); font-size: 12px; margin: 18px 0 0; }
.lbl-sub { color: var(--text-3); font-weight: 400; margin-left: 4px; }
.btn.block { width: 100%; justify-content: center; padding: 12px; }
.btn.primary.block { font-size: 15.5px; font-weight: 600; }
.hint.center { text-align: center; }
.auth-done { text-align: center; padding: 10px 0; }
.auth-done .done-mark { font-size: 46px; margin-bottom: 12px; }
.auth-done h2 { font-size: 19px; margin-bottom: 10px; }
.auth-done p { color: var(--text-2); font-size: 13.5px; line-height: 1.8; margin: 0 0 20px; }

/* ═══════════════════════════ 学生端 ═══════════════════════════ */

.me-body { background: var(--bg); }
.me-wrap {
  max-width: 480px; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(30px, env(safe-area-inset-bottom));
}
.me-top { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 16px; }
.me-top-name { font-size: 16px; font-weight: 650; }
.me-menu {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  width: 38px; height: 38px; border-radius: 12px; font-size: 17px; color: var(--text-2);
}
.me-menu:hover { border-color: #c9cddd; }

.me-alert {
  background: var(--warn-sf); border: 1px solid #f3ddb0; color: #8a5a05;
  border-radius: var(--r); padding: 13px 15px; font-size: 13.5px; line-height: 1.65; margin-bottom: 14px;
}
.me-alert.lv-urgent, .me-alert.lv-empty { background: var(--danger-sf); border-color: #f4c4c4; color: #a52020; }
.me-alert b { display: block; margin-bottom: 3px; font-size: 14.5px; }
.ma-contact { display: block; margin-top: 7px; font-weight: 600; }

.me-card {
  background: linear-gradient(160deg, #ffffff, #fbfbff);
  border: 1px solid var(--line); border-radius: 22px;
  padding: 26px 22px 20px; text-align: center; box-shadow: var(--sh-md);
  position: relative; overflow: hidden;
}
.me-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--ok);
}
.me-card.lv-warn::before   { background: var(--warn); }
.me-card.lv-urgent::before,
.me-card.lv-empty::before  { background: var(--danger); }
.mc-name { font-size: 17px; font-weight: 650; letter-spacing: 2px; color: var(--text-2); margin-bottom: 12px; }
.mc-balance { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.mc-num {
  font-size: 68px; font-weight: 750; line-height: 1; color: var(--ok);
  font-variant-numeric: tabular-nums; letter-spacing: -2px;
}
.me-card.lv-warn   .mc-num { color: var(--warn); }
.me-card.lv-urgent .mc-num,
.me-card.lv-empty  .mc-num { color: var(--danger); }
.mc-unit { font-size: 19px; color: var(--text-2); font-weight: 500; }
.mc-hours { color: var(--text-3); font-size: 13px; margin-top: 6px; }

.mc-bar { height: 7px; background: var(--gray-sf); border-radius: 99px; margin: 20px 0 7px; overflow: hidden; }
.mc-bar-fill {
  height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--brand), #7c6cf5);
  transition: width .5s cubic-bezier(.3,.9,.4,1);
}
.mc-bar-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-3); }
.mc-meta { display: flex; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.mc-meta > div { flex: 1; }
.mm-label { display: block; font-size: 11.5px; color: var(--text-3); margin-bottom: 2px; }
.mm-val { font-size: 13.5px; font-weight: 600; }

.me-checkin {
  width: 100%; margin-top: 18px; border: 0; cursor: pointer;
  background: linear-gradient(160deg, #10b981, #059669); color: #fff;
  border-radius: 20px; padding: 22px; box-shadow: 0 8px 24px rgba(16,185,129,.32);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .13s, box-shadow .13s, filter .2s;
}
.me-checkin:hover:not(:disabled)  { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(16,185,129,.4); }
.me-checkin:active:not(:disabled) { transform: scale(.98); }
.me-checkin .mk-icon { font-size: 27px; line-height: 1; }
.me-checkin .mk-text { font-size: 20px; font-weight: 700; letter-spacing: 3px; }
.me-checkin .mk-sub  { font-size: 12.5px; opacity: .85; letter-spacing: .5px; }
.me-checkin.done {
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--line); box-shadow: var(--sh);
}
.me-checkin.done .mk-icon { color: var(--ok); }
.me-checkin.blocked {
  background: var(--surface); color: var(--danger);
  border: 1px solid #f4c4c4; box-shadow: none;
}
.me-checkin.waiting {
  background: linear-gradient(160deg, #f59e0b, #d97706); color: #fff;
  box-shadow: 0 8px 24px rgba(245,158,11,.3);
}
.me-checkin:disabled { cursor: default; }
.me-tip { text-align: center; color: var(--text-3); font-size: 12.5px; margin: 11px 0 0; }

.me-history { margin-top: 30px; }
.mh-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.mh-head h2 { font-size: 15px; }
.mh-tabs { display: flex; gap: 4px; background: var(--gray-sf); padding: 3px; border-radius: 99px; }
.mh-tab {
  border: 0; background: none; cursor: pointer; padding: 5px 12px;
  border-radius: 99px; font-size: 12.5px; color: var(--text-2);
}
.mh-tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--sh); }

.me-list { display: grid; gap: 8px; }
.mi {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px;
}
.mi.revoked { opacity: .5; }
.mi.revoked .mi-amt { text-decoration: line-through; }
.mi-icon { font-size: 18px; flex: none; }
.mi-main { flex: 1; min-width: 0; }
.mi-title { font-size: 14px; font-weight: 550; }
.mi-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.mi-amt { text-align: right; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; flex: none; }
.mi-amt.plus  { color: var(--ok); }
.mi-amt.minus { color: var(--danger); }
.mi-bal { display: block; font-size: 11px; font-weight: 400; color: var(--text-3); margin-top: 1px; }
.me-empty { text-align: center; color: var(--text-3); font-size: 13.5px; padding: 34px 0; margin: 0; }

/* ── 学生端响应式 ──
   学生端本来就是手机优先（480px 居中），这里只做两头的收尾：
   小屏压字号防止巨大数字挤掉单位，大屏放宽一点别让整页只剩一条窄带。 */
@media (max-width: 380px) {
  .me-wrap { padding-left: 12px; padding-right: 12px; }
  .me-card { padding: 22px 16px 18px; border-radius: 18px; }
  .mc-num { font-size: 54px; letter-spacing: -1px; }
  .mc-unit { font-size: 17px; }
  .me-checkin { padding: 19px; border-radius: 17px; }
  .me-checkin .mk-text { font-size: 18px; letter-spacing: 2px; }
  .mc-meta { gap: 6px; }
  .mi { padding: 11px 12px; gap: 9px; }
  .mh-head { flex-wrap: wrap; }
}

/* ── 学生端 PC 布局 ──
   把手机的窄栏拉宽是凑数：一个大数字加一个大按钮拉到全屏，
   绿按钮会变成一条突兀的横条，右边全空。
   电脑上改成两栏——左边余额卡＋签到按钮（要点的东西），
   右边课时记录（要看的东西）——纵向就不会拖得很长。
   me.js 全靠 ID 取元素，所以这里纯靠 CSS 重排，不动 HTML 和 JS。 */
@media (min-width: 860px) {
  /* 内容比视口矮时整体垂直居中，不然全挤在左上角、右下一大片空 */
  .me-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
  .me-wrap {
    width: 100%; max-width: none;
    padding: 30px max(28px, env(safe-area-inset-right)) 40px max(28px, env(safe-area-inset-left));
    display: grid; align-items: start; gap: 0 28px;
    /* 左栏定宽放操作，右栏吃掉剩下的所有宽度 */
    grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
    grid-template-areas:
      'top     top'
      'alert   alert'
      'card    history'
      'checkin history'
      'tip     history'
      'foot    history';
  }
  .me-top     { grid-area: top; padding: 0 2px 18px; }
  .me-alert   { grid-area: alert; }
  .me-card    { grid-area: card; }
  .me-checkin { grid-area: checkin; }
  .me-tip     { grid-area: tip; }
  .me-history { grid-area: history; margin-top: 0; }
  .me-foot    { grid-area: foot; text-align: left; padding-left: 2px; }

  .me-top-name { font-size: 19px; }
  .mc-num { font-size: 72px; }
  /* 左栏定宽，按钮不会被拉成横条 */
  .me-checkin { padding: 24px; }
  /* 右栏记录多时单独滚动，页面不会被拖得很长 */
  .me-list { max-height: calc(100vh - 210px); overflow-y: auto; padding-right: 2px; }
}

@media (min-width: 1200px) {
  .me-wrap { grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 0 36px; }
  .mc-num { font-size: 78px; }
}
.me-foot { text-align: center; color: var(--text-3); font-size: 11.5px; margin: 26px 0 0; }
.success-sub { white-space: pre-line; }
