/* 自习出勤与请假管理系统 · 共享样式（零外链，移动优先） */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  padding-bottom: 90px;
}
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #e6f5ec;
  --warn: #a8600a;
  --warn-bg: #fdf2dd;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --leave-bg: #eef1f5;
  --leave-ink: #808b98;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -18px rgba(16, 24, 40, .35);
  --zebra: rgba(15, 23, 42, .035);
  --topbar: rgba(255, 255, 255, .78);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --card: #181f28;
    --text: #e7edf4;
    --muted: #9aa7b6;
    --line: #2a3441;
    --primary: #3b82f6;
    --primary-ink: #ffffff;
    --ok: #4ade80;
    --ok-bg: #14301f;
    --warn: #fbbf24;
    --warn-bg: #33280f;
    --bad: #f87171;
    --bad-bg: #351b1d;
    --leave-bg: #222b36;
    --leave-ink: #7f8b9a;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03);
    --zebra: rgba(255, 255, 255, .045);
    --topbar: rgba(16, 21, 27, .82);
  }
}
h1, h2, h3 { margin: 0; font-size: 16px; }
h2 { font-size: 15px; color: var(--text); }
p { margin: 0; }
a { color: var(--primary); }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  will-change: backdrop-filter;
}
.topbar-main { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand { font-weight: 700; font-size: 16px; }
.who { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 6px; flex: none; }

main { padding: 12px 12px 0; }
main.stack > * + * { margin-top: 14px; }
.is-hidden { display: none !important; }

.tabs { display: flex; gap: 6px; padding: 10px 12px 0; overflow-x: auto; }
.tab {
  flex: 1 0 auto; min-height: 44px; padding: 0 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); border-radius: 999px;
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.tab.is-on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 12px; box-shadow: var(--shadow);
}
.card > h2 { margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row-between { justify-content: space-between; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 120px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.input {
  min-height: 44px; padding: 8px 10px; width: 100%;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.input-sm { min-height: 40px; font-size: 14px; width: auto; }
select.input { appearance: none; background-image: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .tab:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 13px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stats.stats-4 { grid-template-columns: repeat(4, 1fr); }
.stats.stats-4 .stat { padding: 8px 2px; }
.stats.stats-4 .stat b { font-size: 18px; }
.stats.stats-4 .stat span { font-size: 11px; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
}
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat-leave b { color: var(--warn); }
.stat-absent b { color: var(--bad); }
.stat-ok b { color: var(--ok); }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 6px; }
.chip {
  min-height: 44px; padding: 4px 4px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--ok); background: var(--ok-bg); color: var(--text);
  font: inherit; font-size: 13px; line-height: 1.2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; overflow: hidden;
}
.chip u { text-decoration: none; font-size: 10px; color: var(--ok); letter-spacing: .5px; }
.chip.is-absent { border-color: var(--bad); background: var(--bad-bg); }
.chip.is-absent u { color: var(--bad); }
.chip.is-leave { border-color: var(--line); background: var(--leave-bg); color: var(--leave-ink); cursor: not-allowed; }
.chip.is-leave u { color: var(--leave-ink); }
.chip:disabled { opacity: .9; }
.chip .nm { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.actionbar .btn { flex: 1; }
.actionbar .btn-ghost { flex: 0 0 34%; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.pill-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill-off { background: var(--leave-bg); color: var(--leave-ink); border-color: transparent; }
.savestate { font-size: 12px; color: var(--muted); min-height: 18px; }
.savestate.is-busy { color: var(--muted); }
.savestate.is-ok { color: var(--ok); }
.savestate.is-bad { color: var(--bad); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; font-weight: 700;
  vertical-align: 2px;
}
.notice {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  font-size: 13px; line-height: 1.45;
  background: var(--warn-bg); border: 1px solid var(--warn); color: var(--warn);
}
.notice.is-hidden { display: none; }
.notice b { display: block; font-size: 14px; margin-bottom: 2px; }
.notice-sub { display: block; font-size: 12px; opacity: .92; }
.notice-sub:empty { display: none; }
.sr-count { font-size: 12px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.sub-h { font-size: 14px; font-weight: 700; margin: 16px 0 4px; }
.form .err { margin-top: -2px; }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; }

.form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.form > .btn { align-self: flex-start; }

.leave-item, .off-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.leave-item:last-child, .off-item:last-child { border-bottom: 0; }
.leave-item .meta, .off-item .meta { min-width: 0; }
.leave-item .sub, .off-item .sub { display: block; font-size: 12px; color: var(--muted); }

.pwrow {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.1fr) auto;
  gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.pwrow:last-child { border-bottom: 0; }
.pwrow .pwinfo { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pwcur { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.pwcur-label { font-size: 11px; color: var(--muted); }
.pwcur-val { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 1px; }
.pwcur-missing { font-size: 12px; color: var(--muted); }
.tbl tr.is-cancelled td { opacity: .45; }
.tbl tr.is-cancelled td .pill { opacity: 1; }
@media (max-width: 380px) {
  .pwrow { grid-template-columns: minmax(0, 1fr) auto; }
  .pwrow .pwcur { grid-column: 1 / 2; grid-row: 2; }
  .pwrow .btn { grid-column: 2 / 3; grid-row: 1 / 3; }
}

.cal-head, .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { margin: 8px 0 4px; }
.cal-head span { text-align: center; font-size: 11px; color: var(--muted); }
.cal { grid-auto-rows: 1fr; }
.cal-cell {
  min-height: 52px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); padding: 3px; font-size: 10px; line-height: 1.15;
  display: flex; flex-direction: column; gap: 1px; overflow: hidden;
}
.cal-cell b { font-size: 12px; font-weight: 600; }
.cal-cell i { font-style: normal; color: var(--muted); }
.cal-cell.is-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--text); }
.cal-cell.is-miss { background: var(--warn-bg); border-color: var(--warn); }
.cal-cell.is-idle { opacity: .45; }
.cal-cell.is-off { opacity: .45; }
.cal-cell.is-off b { text-decoration: line-through; }
.cal-cell.is-empty { border: 0; background: transparent; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { font-weight: 600; color: var(--muted); font-size: 12px; letter-spacing: .04em; white-space: nowrap; }
.tbl tbody tr:nth-child(even) { background: var(--zebra); }
.tbl tbody tr:hover { background: rgba(37, 99, 235, .06); }
.tbl td { font-variant-numeric: tabular-nums; }
.tbl td, .tbl th { overflow-wrap: break-word; }
.tbl .name { text-align: left; }
/* 长文本单元格：限宽 + 多行截断，避免把表格撑出页面（操作日志的未到名单、个人明细的请假事由） */
.tbl .clamp {
  max-width: 46vw; overflow: hidden; word-break: break-word;
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 4; line-clamp: 4;
}
/* 列多的表（个人明细 8 列）在卡片内横向滚动，页面本身不被撑宽 */
.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.bar-row { display: grid; grid-template-columns: 88px 1fr 52px; gap: 8px; align-items: center; margin: 6px 0; font-size: 12px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-track { height: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.bar-track.seg { display: flex; }
.seg-p { height: 100%; background: var(--ok); }
.seg-l { height: 100%; background: var(--warn); }
.seg-a { height: 100%; background: var(--bad); }
.seg-u { height: 100%; background: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 4px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; }

.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0; }
.checks label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 14px; }
.checks input { width: 18px; height: 18px; accent-color: var(--primary); }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 96px; margin: 8px 0; padding: 12px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--bg);
}
.drop.is-over { border-color: var(--primary); background: var(--card); }

.cls { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: var(--card); }
.cls + .cls { margin-top: 8px; }
.cls-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cls-head .input { flex: 1 1 110px; min-width: 90px; }
.week { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.week label {
  display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 13px; cursor: pointer;
}
.week input { accent-color: var(--primary); width: 16px; height: 16px; }
.pw {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok);
}
.pw-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.pw-l { font-size: 12px; opacity: .85; }
.pw-v { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; font-weight: 700; letter-spacing: 1px; }
.pw-sub { font-size: 11px; opacity: .8; }
.name-edit {
  display: flex; flex-direction: column; gap: 4px; flex: 1 1 100%;
  padding: 8px; border-radius: 10px; background: var(--warn-bg); border: 1px solid var(--warn);
}
.name-edit > span { font-size: 12px; color: var(--warn); font-weight: 600; }
.cls-code { font-size: 12px; color: var(--muted); }
.cls-title { font-size: 15px; font-weight: 700; letter-spacing: .3px; }
.cls-name { font-size: 14px; font-weight: 700; letter-spacing: .2px; }
.sub-label { font-size: 13px; font-weight: 700; margin: 14px 0 4px; color: var(--muted); }
.weeknav { display: flex; align-items: center; gap: 6px; }
.weeknav .wk-label {
  display: flex; align-items: center; justify-content: center;
  flex: 1; min-width: 0; font-variant-numeric: tabular-nums; text-align: center;
}
.clsbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 10px 12px 0; padding: 10px 12px; border-radius: var(--radius);
  background: var(--primary); color: var(--primary-ink);
}
.clsbar-main { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.clsbar-label { font-size: 11px; opacity: .85; letter-spacing: 1px; }
.clsbar-name { font-size: 20px; font-weight: 700; letter-spacing: .5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clsbar-meta { font-size: 13px; opacity: .95; flex: none; }
.map-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.map-tbl th, .map-tbl td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.map-tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.map-tbl td.arrow { color: var(--muted); width: 22px; text-align: center; }
.map-tbl code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.stu-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stu-row .input { flex: 1 1 90px; min-width: 80px; }
.stu-row .off { opacity: .5; }

.toast-host { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; color: #fff;
  background: #303742; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 90vw;
}
.toast.is-ok { background: #15803d; }
.toast.is-bad { background: #b3261e; }

.login-wrap { max-width: 420px; margin: 0 auto; padding: 28px 12px; }
.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; cursor: pointer; }
.seg button.is-on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.banner { margin-bottom: 12px; padding: 10px; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }

@media (pointer: coarse) {
  .btn-sm, .input-sm, .week label, .tab, .checks label { min-height: 44px; }
}

@media (min-width: 640px) {
  main { max-width: 860px; margin: 0 auto; }
  .tabs { max-width: 860px; margin: 0 auto; }
  .stats { grid-template-columns: repeat(6, 1fr); }
  .chips { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}

.login-card { position: relative; }
.role-switch {
  position: absolute; top: 14px; right: 16px;
  font-size: 12px; color: var(--muted); text-decoration: none;
  padding: 6px 8px; border-radius: 8px;
}
.role-switch:hover { color: var(--text); text-decoration: underline; }
/* SPEC §27 只读访客账号：顶部常驻提示条（api.js 注入，非只读账号不会出现） */
.ro-banner {
  position: sticky; top: 0; z-index: 40;
  margin: 0; padding: 9px 14px;
  background: var(--warn-bg); color: var(--warn);
  border-bottom: 1px solid var(--warn);
  font-size: 13px; text-align: center;
}
