/* 背书打卡 · 样式（PRD §7：系统中文字体、正文约 14px、标题约 17px、背景 #f4f6fb、白卡片圆角 12px、间距 4 的倍数） */

:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #6b778c;
  --line: #e3e8f0;
  --primary: #4f55e3;
  --primary-soft: #eef0ff;
  --s0-bg: #ffffff;
  --s0-ink: #2a3445;
  --s0-line: #b9c2d0;
  --s1-bg: #facc15;
  --s1-ink: #3d2f00;
  --s2-bg: #16a34a;
  --s2-ink: #ffffff;
  --danger: #c93a4f;
  --warn-bg: #fff6d6;
  --warn-ink: #6b4f00;
  --ok-bg: #def7e8;
  --ok-ink: #146c37;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 3px solid rgba(79, 85, 227, .45); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { padding: 0 4px; border-radius: 4px; background: #eef1f6; font-size: 12px; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  /* 宽屏时左右留白与内容区（最宽 880px）对齐，不再贴满屏幕两侧 */
  padding: calc(8px + var(--safe-t)) max(calc(12px + var(--safe-r)), calc((100% - 880px) / 2 + 8px)) 8px max(calc(12px + var(--safe-l)), calc((100% - 880px) / 2 + 8px));
  background: rgba(244, 246, 251, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.brand-mark { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 800; }
.title-text { flex: 1; min-width: 0; overflow: hidden; font-size: 17px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.title-button { display: flex; flex: 1; align-items: center; gap: 4px; min-width: 0; min-height: 44px; padding: 0 4px; border: 0; background: none; text-align: left; }
.title-button .title-text { flex: 0 1 auto; }
.caret { color: var(--muted); font-size: 12px; }
.icon-button { position: relative; display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 20px; color: #3b4659; }
.icon-button:active { background: #e7ebf3; }
.red-dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 2px var(--bg); }
.red-dot.static { position: static; display: inline-block; margin-left: 4px; vertical-align: middle; box-shadow: none; }
.sync-chip { flex: none; max-width: 46vw; min-height: 32px; padding: 0 10px; overflow: hidden; border: 0; border-radius: 999px; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.sync-chip.inline { display: inline-flex; align-items: center; min-height: 24px; }
.sync-chip--local { background: #e7ebf2; color: #5a6578; }
.sync-chip--ok { background: var(--ok-bg); color: var(--ok-ink); }
.sync-chip--saving { background: var(--warn-bg); color: var(--warn-ink); }
.sync-chip--error { background: #fde4e8; color: #a3283c; }
.sync-chip--alert { background: #d92d45; color: #fff; }

/* 横幅 */
.banners { position: sticky; top: calc(56px + var(--safe-t)); z-index: 15; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; width: min(calc(100% - 32px), 848px); margin: 8px auto 0; padding: 12px; border-radius: var(--radius); background: var(--primary-soft); color: #2e338f; }
.banner > span { flex: 1 1 200px; }
.banner--error { background: #fde4e8; color: #8f2133; }
.banner--warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner--edit { background: #e6f0ff; color: #1f3f86; }
.banner-btn { min-height: 36px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 600; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.conflict { margin: 0 12px 12px; }

/* 主体 */
.main { width: min(100%, 880px); margin: 0 auto; padding: 16px max(16px, var(--safe-r)) calc(32px + var(--safe-b)) max(16px, var(--safe-l)); }
body.has-undo .main { padding-bottom: calc(96px + var(--safe-b)); }
.loading { padding: 48px 0; color: var(--muted); text-align: center; }
.crumb { margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.hint { margin-top: 8px; color: var(--muted); font-size: 12px; }
.warn { margin-top: 8px; color: var(--warn-ink); font-size: 13px; font-weight: 600; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 20px 0 12px; }
.section-head h2, .sub-head { font-size: 16px; }
.sub-head { margin: 24px 0 4px; }

/* 按钮 */
.primary-button, .secondary-button, .danger-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; font-weight: 600; white-space: nowrap;
}
.primary-button { border: 0; background: var(--primary); color: #fff; }
.secondary-button { border: 1px solid var(--line); background: #fff; color: #2f3a4d; }
.danger-button { border: 0; background: var(--danger); color: #fff; }
.primary-button:active, .secondary-button:active, .danger-button:active { transform: translateY(1px); }
.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.full { width: 100%; margin-top: 16px; }
.text-button { min-height: 40px; padding: 0 4px; border: 0; background: none; color: var(--primary); font-weight: 600; }
.text-button.danger { color: var(--danger); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.action-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.grid-actions { margin-top: 20px; }

/* 统计 */
.stats { padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.stats--empty p { margin-top: 4px; color: var(--muted); }
.stats-label { display: inline-block; margin-bottom: 8px; padding: 2px 8px; border-radius: 6px; background: #eef1f6; color: #4a5568; font-size: 12px; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 0; }
.stats-grid div { min-width: 0; }
.stats-grid dt { color: var(--muted); font-size: 12px; }
.stats-grid dd { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-grid dd small { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }
.st-pass dd { color: var(--ok-ink); }
.st-fail dd { color: #8a6400; }
.stats-note { margin-top: 6px; color: var(--muted); font-size: 12px; }
@media (max-width: 480px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* 卡片 */
.card-list { display: grid; gap: 8px; }
.card { position: relative; display: flex; flex-wrap: wrap; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.card.is-active { border-color: var(--primary); }
.card-main { flex: 1; min-width: 0; padding: 12px 16px; border: 0; border-radius: var(--radius); background: none; text-align: left; }
button.card-main:active { background: #f6f8fc; }
.card-main.static { cursor: default; }
.card-main h3 { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.card-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-menu { align-self: center; margin-right: 4px; }
.row-card .card-main { display: flex; flex-direction: column; justify-content: center; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 12px 8px 0; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; color: #4a5568; font-size: 12px; font-variant-numeric: tabular-nums; }
.c-pass { color: var(--ok-ink); font-weight: 600; }
.c-fail { color: #8a6400; font-weight: 600; }
.plan-card .stats-label { margin: 8px 0 0; font-size: 11px; }
.progress { display: flex; height: 6px; margin-top: 8px; overflow: hidden; border-radius: 3px; background: #edf0f5; }
.progress i { display: block; height: 100%; }
.p-pass { background: var(--s2-bg); }
.p-fail { background: var(--s1-bg); }
.type-tag { align-self: flex-start; margin-bottom: 4px; padding: 0 6px; border-radius: 4px; background: #eef1f6; color: #4a5568; font-size: 11px; }
.quick-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.link-chip { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #3b4659; font-size: 13px; }

/* 空态 */
.empty-state { margin-top: 16px; padding: 32px 16px; border: 1px dashed #cfd6e2; border-radius: var(--radius); text-align: center; }
.empty-icon { font-size: 28px; color: #9aa5b8; }
.empty-state h3 { margin-top: 4px; font-size: 16px; }
.empty-state p { margin: 4px 0 16px; color: var(--muted); }

/* 学号网格 */
.class-switch { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; }
.filter-chip { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #3b4659; font-size: 13px; }
.filter-chip.is-on { border-color: var(--primary); background: var(--primary); color: #fff; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 12px; color: #4a5568; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; }
.dot--s0 { border: 1.5px solid var(--s0-line); background: var(--s0-bg); }
.dot--s1 { background: var(--s1-bg); }
.dot--s2 { background: var(--s2-bg); }
.seat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
  margin-top: 12px;
  touch-action: manipulation; /* 消除双击放大和点击延迟，保留双指缩放 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.seat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 44px; min-height: 52px; padding: 4px 2px;
  border: 1.5px solid var(--s0-line); border-radius: 10px;
  background: var(--s0-bg); color: var(--s0-ink);
  transition: transform .08s ease, opacity .12s ease;
  touch-action: manipulation;
}
.seat b { font-size: 16px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.seat small { margin-top: 2px; font-size: 10px; line-height: 1; }
.seat:active { transform: scale(.93); }
.seat--s1 { border-color: #d9ab00; background: var(--s1-bg); color: var(--s1-ink); }
.seat--s2 { border-color: #12823b; background: var(--s2-bg); color: var(--s2-ink); }
.seat--vacant { border: 1.5px dashed #b4bccb; background: #e9ecf2; color: #8792a5; }
.seat-grid.is-editing .seat { box-shadow: 0 0 0 2px rgba(79, 85, 227, .15); }
.seat-grid.is-editing .seat--vacant { border-color: var(--primary); }
.seat-grid[data-filter="0"] .seat:not(.seat--s0):not(.seat--vacant),
.seat-grid[data-filter="1"] .seat:not(.seat--s1):not(.seat--vacant),
.seat-grid[data-filter="2"] .seat:not(.seat--s2):not(.seat--vacant) { opacity: .25; }

/* 撤销条 */
.undo-bar {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); z-index: 25;
  display: flex; align-items: center; gap: 16px;
  width: min(calc(100% - 32px), 420px); min-height: 52px; padding: 4px 4px 4px 16px;
  border-radius: 12px; background: #1d2433; color: #fff;
  box-shadow: 0 8px 24px rgba(16, 22, 38, .25);
  transform: translate(-50%, 140%); opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.undo-bar.is-visible { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.undo-bar span { flex: 1; }
.undo-btn { min-width: 72px; min-height: 44px; border: 0; border-radius: 8px; background: #fff; color: #1d2433; font-weight: 700; }

/* 弹层 */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 20, 32, .38); }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 50;
  width: min(100%, 560px); max-height: 88vh; overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-b));
  border-radius: 16px 16px 0 0; background: #fff;
  transform: translateX(-50%);
  box-shadow: 0 -8px 32px rgba(16, 22, 38, .18);
}
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 8px; border-radius: 2px; background: #d6dbe5; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-header h2 { font-size: 17px; }
.close-button { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 24px; }
.dialog {
  position: fixed; left: 50%; top: 50%; z-index: 60;
  width: min(calc(100% - 32px), 420px); max-height: 86vh; overflow-y: auto;
  padding: 20px; border-radius: 16px; background: #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 16px 48px rgba(16, 22, 38, .25);
}
.dialog h2 { font-size: 17px; }
.dialog-msg { margin-top: 8px; color: #3b4659; white-space: pre-line; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.action-list { display: grid; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.action-row { min-height: 48px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--line); background: #fff; text-align: left; }
.action-row:last-child { border-bottom: 0; }
.action-row:active { background: #f4f6fb; }
.action-row.is-active { color: var(--primary); font-weight: 600; }
.action-row.danger { color: var(--danger); }

/* 表单 */
.field-label { display: block; margin: 12px 0 6px; color: #3b4659; font-size: 13px; font-weight: 600; }
.field-label span { color: var(--muted); font-weight: 400; }
.text-input { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #cfd6e2; border-radius: 10px; background: #fff; font-size: 16px; }
.text-input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(79, 85, 227, .15); }
.number-wrap { display: flex; align-items: center; gap: 8px; }
.number-wrap .text-input { width: 120px; }
.number-wrap.compact .text-input { width: 76px; min-height: 40px; padding: 0 8px; }
.inline-row { display: flex; gap: 8px; }
.form-error { min-height: 20px; margin-top: 8px; color: var(--danger); font-size: 13px; }
.pick-list { display: grid; gap: 4px; }
.pick-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; }
.pick-row input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--primary); }
.pick-name { flex: 1; min-width: 0; }
.pick-name small { margin-left: 6px; color: var(--muted); }
.pick-row.is-disabled { opacity: .55; }
.copy-area { width: 100%; min-height: 160px; padding: 12px; border: 1px solid #cfd6e2; border-radius: 10px; font-size: 15px; -webkit-user-select: text; user-select: text; }
.preview-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.preview-table th, .preview-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.preview-table th:first-child { text-align: left; font-weight: 500; }
.preview-table thead th { color: var(--muted); font-size: 12px; }

/* 设置 */
.settings-card { display: block; padding: 16px; margin-bottom: 12px; }
.settings-card h2 { margin-bottom: 8px; font-size: 16px; }
.settings-card p { margin-top: 4px; }
.settings-card > button { margin-top: 12px; }
.restore-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.restore-row:last-child { border-bottom: 0; }
.sub-box { margin-top: 12px; padding: 12px; border-radius: 10px; background: #f6f8fc; }
.version { margin-top: 16px; color: var(--muted); font-size: 12px; text-align: center; }

/* 提示 */
.toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); z-index: 70;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 32px); padding: 10px 14px;
  border-radius: 10px; background: #1d2433; color: #fff; font-size: 13px;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast-action { min-height: 32px; padding: 0 10px; border: 0; border-radius: 6px; background: #fff; color: #1d2433; font-weight: 700; }

/* 页面内（计划、网格等）的横幅跟随所在容器宽度 */
.main .banner { width: auto; margin: 0 0 12px; }
.card .banner.conflict { flex-basis: 100%; width: auto; margin: 0 12px 12px; }

/* 电脑等宽屏 */
@media (min-width: 720px) {
  .main { padding-top: 24px; }
  /* 卡片双列，减少右侧空白 */
  .card-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 底部弹出面板在宽屏改为居中对话框 */
  .sheet {
    top: 50%; bottom: auto;
    width: min(calc(100% - 48px), 520px); max-height: 80vh;
    padding-bottom: 20px;
    border-radius: 16px;
    transform: translate(-50%, -50%);
    box-shadow: 0 16px 48px rgba(16, 22, 38, .25);
  }
  .sheet-handle { display: none; }
  .seat-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 10px; }
  .seat { min-height: 58px; }
  .undo-bar { bottom: 24px; }
}

/* 有鼠标的设备：悬停反馈 */
@media (hover: hover) {
  button.card-main:hover, .action-row:hover, .link-chip:hover, .filter-chip:not(.is-on):hover, .secondary-button:hover { background: #f6f8fc; }
  .primary-button:hover { background: #4148cf; }
  .danger-button:hover { background: #b33246; }
  .icon-button:hover { background: #e7ebf3; }
  .seat:hover { box-shadow: 0 0 0 2px rgba(79, 85, 227, .25); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
