:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --elevated: #fbfcfe;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-fill: #2563eb;
  --accent-fg: #ffffff;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --gold: #fef3c7;
  --radius: 10px;
  --font-body: system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
}
* { box-sizing: border-box; }
/* 必须放在最前：避免 .modal{display:grid} 之类的作者样式压过 hidden 属性，
   否则遮罩层会一直显示并拦截所有点击 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 15px; margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.sub { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.btn:hover { background: var(--elevated); border-color: var(--accent); }
.btn.primary { background: var(--accent-fill); color: var(--accent-fg); border-color: var(--accent-fill); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--elevated); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tabs { display: flex; gap: 4px; padding: 8px 18px 0; flex-wrap: wrap; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: var(--hdr-h, 55px); z-index: 20; }
.tab {
  border: 1px solid transparent; border-bottom: none; background: transparent; padding: 8px 14px;
  border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; color: var(--muted); font-family: inherit;
}
.tab:hover { background: var(--elevated); color: var(--text); }
.tab.active { background: var(--bg); color: var(--accent); border-color: var(--border); font-weight: 600; }

main { padding: 14px 12px 60px; max-width: 100%; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 6px 0 10px; }
.count { color: var(--muted); font-weight: 400; font-size: 12px; }

label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
label.inline { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--text); }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 7px;
  font-family: inherit; font-size: 13px; background: var(--surface); color: var(--text); margin-top: 3px;
}
label.inline input[type=text], label.inline input[type=number], label.inline select { width: auto; margin: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.25); border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tiny { width: 86px !important; }
.filterbar { display: flex; gap: 8px; margin-bottom: 8px; }
.filterbar input, .filterbar select { max-width: 240px; }

.tablewrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { border: 1px solid var(--border); padding: 5px 7px; text-align: left; vertical-align: middle; }
table.tbl th { background: var(--elevated); font-weight: 600; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
table.tbl td input, table.tbl td select { margin: 0; }
table.tbl tr.grouprow td { background: #eef2ff; font-weight: 600; }
.mini { padding: 2px 7px; font-size: 11.5px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-family: inherit; }
.mini:hover { border-color: var(--accent); color: var(--accent); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 11px; background: var(--elevated); border: 1px solid var(--border); margin: 1px 3px 1px 0; }
.tag.a { background: #dbeafe; border-color: #bfdbfe; }
.tag.b { background: #fce7f3; border-color: #fbcfe8; }
.tag.ab { background: #ede9fe; border-color: #ddd6fe; }
.tag.star { background: #fef3c7; border-color: #fde68a; }
.tag.warn { background: #ffedd5; border-color: #fed7aa; color: #9a3412; }

/* 课表 */
.ttwrap { overflow-x: auto; margin-bottom: 18px; }
table.tt { border-collapse: collapse; font-size: 12px; width: 100%; }
table.tt th, table.tt td { border: 1px solid var(--border-strong); padding: 3px 5px; text-align: center; vertical-align: middle; height: 32px; }
table.tt th { background: var(--elevated); font-weight: 600; }
table.tt th.dayth { background: #e0e7ff; font-size: 13px; }
table.tt td.period { background: var(--elevated); font-weight: 600; white-space: nowrap; font-size: 12px; }
table.tt td.period.golden { background: var(--gold); }
table.tt td.cell { min-width: 62px; }
table.tt td.cell .s { font-weight: 600; }
table.tt td.cell .t { color: var(--muted); font-size: 11px; }
table.tt td.cell.main { background: #eff6ff; }
table.tt td.cell.morning { background: #ecfeff; }
table.tt td.cell.evening { background: #f5f3ff; }
table.tt td.cell.mk { outline: 2px solid #f59e0b; outline-offset: -2px; }
table.tt td.empty { color: #cbd5e1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.legend span::before { content: ''; display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 1px solid var(--border-strong); }
.legend .lg-main::before { background: #eff6ff; }
.legend .lg-morning::before { background: #ecfeff; }
.legend .lg-evening::before { background: #f5f3ff; }
.legend .lg-golden::before { background: var(--gold); }
.legend .lg-mark::before { background: #fff; outline: 2px solid #f59e0b; outline-offset: -2px; }

.notes { list-style: none; padding: 0; margin: 0; }
.notes li { padding: 7px 10px; border-radius: 8px; margin-bottom: 6px; border-left: 3px solid var(--border-strong); background: var(--elevated); line-height: 1.6; }
.notes li.error { border-color: var(--danger); background: #fef2f2; }
.notes li.warn { border-color: var(--warn); background: #fffbeb; }
.notes li.info { border-color: var(--accent); background: #eff6ff; }
.notes li.ok { border-color: var(--ok); background: #ecfdf5; }

.summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.kpi { background: var(--elevated); border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; min-width: 108px; }
.kpi .v { font-size: 19px; font-weight: 700; }
.kpi .k { color: var(--muted); font-size: 11.5px; }
.kpi.good .v { color: var(--ok); }
.kpi.warn .v { color: var(--warn); }

.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; }
.modal-box { background: var(--surface); border-radius: 12px; width: min(760px, 94vw); max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); text-align: right; }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px 12px; }
.checkgrid label { display: flex; align-items: center; gap: 6px; color: var(--text); margin: 0; padding: 3px 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 18px; border-radius: 9px; z-index: 200; font-size: 13px; }
.steps { line-height: 1.9; padding-left: 20px; }
.steps b { color: var(--accent); }
.impgrid { display: grid; gap: 10px; }
.improw { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.improw .col { background: var(--elevated); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 132px; }
.improw .col .h { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; word-break: break-all; }
.preview { overflow-x: auto; max-height: 240px; }
@media print {
  .topbar, .tabs, .actions, .card-head .inline, .legend, #notesCard .card-head { display: none !important; }
  .panel { display: none !important; }
  .panel.active { display: block !important; }
  body { background: #fff; }
  .card { border: none; padding: 0; }
  table.tt th, table.tt td { height: 26px; }
}

/* 锁定格 */
.cell.locked { box-shadow: inset 0 0 0 2px var(--warn); }
.lockbtn { display: block; margin: 2px auto 0; padding: 0 4px; font-size: 10px; line-height: 16px; opacity: .3; }
.cell:hover .lockbtn { opacity: 1; }
.lockbtn.on { opacity: 1; }
.lg-lock { background: var(--gold); color: #92400e; }

/* 游客提示条 + 方案卡片栏 */
.guestnotice { flex-basis: 100%; background: var(--gold); color: #92400e; padding: 6px 14px; font-size: 12.5px; border-radius: 8px; margin-top: 8px; }
.planbar { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; padding: 10px 0 2px; border-top: 1px dashed var(--border); margin-top: 6px; }
.planbar-label { align-self: center; color: var(--muted); font-size: 12.5px; }
.plancard { position: relative; border: 1px solid var(--border); border-radius: 9px; background: var(--elevated); padding: 16px 10px 8px; min-width: 190px; }
.pl-x { position: absolute; top: 3px; right: 3px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; line-height: 1; padding: 3px 6px; border-radius: 6px; }
.pl-x:hover { background: var(--danger); color: #fff; }
.plname { font-weight: 600; font-size: 13px; }
.plmeta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.plchk { font-size: 11.5px; color: var(--muted); }
.placts { margin-top: 6px; display: flex; gap: 4px; }

/* 每周课时输入（早读 / 常规 / 晚自习） */
.wkrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.wkrow label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.wkrow input { width: 52px; padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: 7px; font-size: 13px; font-family: inherit; text-align: center; }
.wkrow input:focus { outline: none; border-color: var(--accent); }

/* 登录 / 注册 */
.authbox { width: min(400px, 94vw); max-width: 400px; position: relative; overflow: hidden; }
.auth-x { position: absolute; top: 9px; right: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 5px 8px; border-radius: 7px; }
.auth-x:hover { background: var(--elevated); color: var(--text); }
.auth-head { text-align: center; padding: 30px 24px 4px; }
.auth-logo { width: 44px; height: 44px; border-radius: 13px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 21px; margin: 0 auto 12px; }
.auth-title { font-size: 18px; text-align: center; }
.auth-sub { color: var(--muted); font-size: 12.5px; margin: 7px 0 0; text-align: center; line-height: 1.6; }
.auth-body { padding: 18px 26px 26px; }
.auth-field { display: block; margin-bottom: 14px; }
.auth-field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.auth-field input { display: block; width: 100%; box-sizing: border-box; padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 10px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text); }
.auth-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .13); }
.auth-msg { color: var(--danger); font-size: 12.5px; min-height: 17px; margin: 0 0 12px; text-align: center; }
.auth-go { width: 100%; padding: 12px; font-size: 15px; }

/* 每周课时：一行放下，不要折行 */
.wkrow { flex-wrap: nowrap; white-space: nowrap; gap: 6px; }
.wkrow input { width: 46px; }

/* 页头 · 作者联系方式（跟着头部吸顶） */
.contactbar { flex-basis: 100%; padding: 6px 2px 0; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--border); margin-top: 8px; text-align: right; line-height: 1.5; }
.contactbar-sub { font-size: 12px; opacity: .85; margin-top: 2px; }
.contactbar a { color: var(--accent); text-decoration: none; font-weight: 600; }
.contactbar a:hover { text-decoration: underline; }

/* 排课规则开关 */
.rulebox { display: flex; flex-direction: column; gap: 7px; margin: 4px 0 2px; }
.rulebox label { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; line-height: 1.55; cursor: pointer; }
.rulebox input { margin-top: 3px; flex: none; }

/* 课表字号放大（排课完成后看得更清楚） */
table.tt { font-size: 15px; }
table.tt th.dayth { font-size: 14.5px; }
table.tt td.period { font-size: 14px; }
table.tt td.cell { padding: 7px 9px; }
table.tt td.cell .s { font-size: 15px; font-weight: 600; }
table.tt td.cell .t { font-size: 12.5px; }

/* 高亮某人 */
table.tt td.cell.hl { background: #fde68a !important; box-shadow: inset 0 0 0 2px #f59e0b; }
.legend .lg-hl::before { background: #fde68a; outline: 2px solid #f59e0b; outline-offset: -2px; }
