:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e5e9f2;
  --text: #1f2937;
  --muted: #8a94a6;
  --primary: #4f46e5;
  --primary-d: #4338ca;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .7rem; }

/* 顶栏 */
.topbar { display: flex; align-items: center; gap: 1rem; background: #fff; border-bottom: 1px solid var(--line);
  padding: 0 1.2rem; height: 56px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 1.05rem; }
.nav { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }
.nav a { padding: .4rem .7rem; border-radius: 8px; color: #4b5563; font-weight: 500; }
.nav a:hover { background: #f1f2f8; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.me { display: flex; align-items: center; gap: .5rem; color: var(--muted); }
.me .role { font-style: normal; font-size: .72rem; background: #eef0f7; color: #5b6478; padding: .1rem .4rem; border-radius: 6px; }
.me .logout { color: var(--danger); }

.container { max-width: 1120px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
body.bare { background: linear-gradient(135deg, #eef1fb, #f7f8fc); }

/* 卡片 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.card.stat { text-align: center; }
.card.stat .num { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.card.stat .lbl { color: var(--muted); font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* 页头 */
.page-head { display: flex; align-items: center; gap: .8rem; margin-bottom: .8rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.spacer { flex: 1; }
.search { display: flex; gap: .4rem; }
.summary-bar { background: #eef0ff; border: 1px solid #e0e3ff; color: #4046a8; padding: .55rem .9rem; border-radius: 10px; margin-bottom: .8rem; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: #fff;
  color: #374151; padding: .42rem .85rem; border-radius: 9px; cursor: pointer; font-size: .88rem; font-weight: 500; }
.btn:hover { background: #f6f7fb; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); border-color: #f6d5d5; }
.btn.danger:hover { background: #fdf2f2; }
.btn.xs { padding: .22rem .55rem; font-size: .8rem; border-radius: 7px; }
.btn.block { width: 100%; justify-content: center; }

/* 表单 */
.form label, .form-inline label { display: block; margin-bottom: .7rem; font-size: .85rem; color: #4b5563; font-weight: 500; }
.form input, .form select, .form textarea,
.form-inline input, .form-inline select { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 9px; font-size: .9rem; font-family: inherit; background: #fff; margin-top: .25rem; }
.form input[type=color] { padding: .1rem; height: 38px; }
.form label.inline { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.form label.inline input { width: auto; margin: 0; }
.form-actions { display: flex; gap: .5rem; margin-top: .6rem; }
.form-inline { display: flex; gap: .7rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline label { margin-bottom: 0; }
.form-inline input, .form-inline select { width: auto; min-width: 130px; }
.filter { gap: .8rem; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.card.login { width: 360px; padding: 2rem; }
.card.login h1 { text-align: center; margin-bottom: .2rem; }
.card.login p.muted { text-align: center; margin-top: 0; }

/* 表格 */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.grid th, table.grid td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid thead th { background: #f8f9fc; color: #5b6478; font-weight: 600; white-space: nowrap; }
table.grid tbody tr:hover { background: #fafbff; }
table.grid tfoot td { background: #f8f9fc; }
td.empty { text-align: center; color: var(--muted); padding: 1.6rem !important; }
td.actions { white-space: nowrap; display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; }

/* 徽标 */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge.planned { background: #eef0ff; color: #4f46e5; }
.badge.done { background: #e7f7f0; color: #0f9d6b; }
.badge.cancelled { background: #f3f4f6; color: #9ca3af; }
.badge.ok { background: #e7f7f0; color: #0f9d6b; }
.badge.off { background: #f3f4f6; color: #9ca3af; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 999px; margin-right: .35rem; vertical-align: middle; }

/* 提示 */
.flash { padding: .6rem .9rem; border-radius: 10px; margin-bottom: .9rem; font-size: .88rem; }
.flash.success { background: #e7f7f0; color: #0f7a55; border: 1px solid #c8ecdd; }
.flash.error { background: #fdecec; color: #b3261e; border: 1px solid #f6d5d5; }
.flash.warning { background: #fff7e6; color: #a86b00; border: 1px solid #ffe6b3; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* 可排课时间 */
.avail-day { display: flex; gap: .8rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.avail-day-name { width: 64px; color: #5b6478; font-weight: 600; flex: none; }
.avail-slots { display: flex; gap: .4rem; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: .3rem; background: #eef0ff; color: #4046a8; padding: .18rem .55rem; border-radius: 8px; font-size: .82rem; }
.tag.free { background: #e7f7f0; color: #0f7a55; }
.tag .x { border: none; background: none; color: #8a94a6; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; }
.tag .x:hover { color: var(--danger); }

/* 进度条 */
.bar { background: #eef0f7; border-radius: 999px; height: 8px; width: 140px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); }

/* Logo */
.brand { display: flex; align-items: center; gap: .45rem; }
.brand .logo { width: 30px; height: 30px; object-fit: contain; border-radius: 7px; }
.login-brand { text-align: center; margin-bottom: .5rem; }
.login-brand .logo-lg { width: 76px; height: 76px; object-fit: contain; }

/* 登录页表单（保证 label/输入框纵向排列） */
.card.login { width: 380px; max-width: 92vw; }
.card.login h1 { font-size: 1.5rem; margin: .1rem 0 .2rem; }
.card.login label { display: block; margin-bottom: .85rem; font-size: .85rem; color: #4b5563; font-weight: 500; }
.card.login label input { width: 100%; margin-top: .3rem; padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: 9px; font-size: .95rem; background: #fff; }
.card.login label input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.card.login .btn.block { margin-top: .3rem; padding: .65rem; font-size: 1rem; }

/* ================= 移动端适配 ================= */
@media (max-width: 720px) {
  /* 顶栏改成两行：第一行 logo+用户，第二行导航可横向滑动 */
  .topbar { height: auto; flex-wrap: wrap; align-items: center; gap: .45rem .7rem;
    padding: .55rem .8rem; }
  .brand { flex: 1 1 auto; font-size: 1rem; }
  .brand .logo { width: 26px; height: 26px; }
  .me { order: 2; margin-left: auto; gap: .35rem; font-size: .9rem; }
  .nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: .2rem;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: .1rem; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: .4rem .65rem; font-size: .9rem; }

  /* 布局间距 */
  .container { padding: 1rem .8rem 3rem; }
  h1 { font-size: 1.22rem; margin: .1rem 0 .8rem; }
  h2 { font-size: 1rem; }
  .card { padding: .9rem 1rem; }

  /* 统计卡片固定两列 */
  .cards { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .card.stat .num { font-size: 1.55rem; }
  .grid2 { grid-template-columns: 1fr; }

  /* 页头 / 按钮 */
  .page-head { gap: .5rem; }
  .btn { font-size: .85rem; padding: .4rem .7rem; }
  .form-inline { gap: .5rem; }
  .form-inline input, .form-inline select { min-width: 0; flex: 1 1 45%; width: auto; }

  /* 表格（容器已可横向滚动） */
  table.grid { font-size: .84rem; }
  table.grid th, table.grid td { padding: .5rem .55rem; }

  /* 可排课时间 / 进度条 */
  .avail-day { flex-direction: column; gap: .25rem; }
  .avail-day-name { width: auto; }
  .bar { width: 100%; }

  /* 登录页 */
  .login-wrap { padding: .8rem; }
  .card.login { padding: 1.6rem 1.3rem; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}

/* ================= 周表格视图（课表） ================= */
.view-toggle { display: inline-flex; gap: .25rem; }
.tt-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table.tt { border-collapse: collapse; width: 100%; min-width: 820px; font-size: 12.5px; }
table.tt th, table.tt td { border: 1px solid var(--line); padding: 4px 5px; vertical-align: top; }
table.tt thead th { background: #e8f5e9; color: #2f6b34; text-align: center; font-weight: 600;
  white-space: nowrap; }
table.tt thead th.corner { background: #e8f5e9; color: #2f6b34; width: 92px; }
/* 时间列 / 左上角固定，横向滚动时不跑掉 */
table.tt td.tcol, table.tt th.corner { position: sticky; left: 0; z-index: 1; }
table.tt thead th.corner { z-index: 3; }
table.tt thead th div { font-size: .95rem; }
table.tt thead th small { font-weight: 400; color: #4b7a50; }
table.tt thead th.is-today { background: #cdeccd; box-shadow: inset 0 -2px 0 #4f9e57; }
table.tt td.tcol { background: #f2faf2; color: #47614a; text-align: center;
  white-space: nowrap; font-size: 12px; }
.tt-scrollhint { display: none; font-size: 11.5px; color: var(--muted); margin: .35rem 0 0; }
table.tt tbody td { height: 56px; min-width: 96px; }
table.tt tbody td.free { background: #f1fbf1; }
table.tt tbody td.busy { background: #fff; }
.tt-card { display: block; border-radius: 7px; padding: 3px 6px; margin-bottom: 3px;
  color: #fff; text-decoration: none; line-height: 1.3; }
.tt-card .n { font-weight: 600; }
.tt-card small { display: block; opacity: .92; font-size: 11px; }
.tt-card:hover { filter: brightness(1.06); }
.tt-add { display: block; color: #7fb787; font-size: 18px; text-align: center;
  text-decoration: none; opacity: .55; }
.tt-add:hover { opacity: 1; }
.tt-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem 1rem;
  font-size: 12px; color: var(--muted); margin: .2rem 0 .6rem; }
.tt-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  margin-right: .3rem; vertical-align: -1px; border: 1px solid var(--line); }
.tt-legend i.lg-free { background: #e7f6e7; border-color: #bfe3bf; }
.tt-legend i.lg-busy { background: #4f46e5; border-color: #4f46e5; }
.tt-legend i.lg-off  { background: #fff; }

@media (max-width: 720px) {
  /* 手机端：一周横向滑动看，时间列吸附在左侧 */
  table.tt { min-width: 720px; font-size: 11.5px; }
  table.tt thead th { font-size: .82rem; padding: 3px 2px; }
  table.tt thead th div { font-size: .82rem; }
  table.tt thead th small { font-size: .68rem; }
  table.tt thead th.corner, table.tt td.tcol { width: 66px; font-size: 10.5px; padding: 3px 2px; }
  table.tt tbody td { min-width: 88px; height: 50px; padding: 3px; }
  .tt-card { padding: 3px 4px; font-size: 10.5px; border-radius: 6px; }
  .tt-card small { font-size: 10px; }
  .tt-legend { font-size: 11.5px; gap: .25rem .7rem; }
  .tt-legend .hint { display: none; }
  .tt-scrollhint { display: block; }
  .view-toggle { margin-left: auto; }
}
