:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #dfe4ea;
  --brand: #2f6fb3;
  --brand-dark: #1f3b63;
  --warn: #b7791f;
  --danger: #c0392b;
  --ok: #2f855a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; letter-spacing: .2px; }

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar.admin { border-bottom: 3px solid var(--brand); }

.brand { display: flex; align-items: center; }
.brand h1 { font-size: 17px; margin: 0 10px 0 0; font-weight: 600; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--brand); margin-right: 10px; display: inline-block;
}
.brand-dot.admin { background: #e67e22; }

.topbar-right { display: flex; align-items: center; }
.topbar-right > * { margin-left: 16px; }
.topbar-right .link { font-size: 13px; }

.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #fdf1e3; color: #b35c00; margin-left: 6px;
}

.course-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  padding: 2px 6px;
  border-radius: 4px;
  width: 220px;
}
.course-input:hover { border-color: var(--line); }
.course-input:focus { border-color: var(--brand); background: #fff; outline: none; }

/* ---------------------------------------------------------------- 布局 */

.wrap { padding: 18px 22px 60px; max-width: 1500px; margin: 0 auto; }
.wrap.narrow { max-width: 720px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }

/* ---------------------------------------------------------------- 控件 */

input[type=text], input[type=password], input[type=search], input[type=number], select {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 9px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid rgba(47, 111, 179, .25); border-color: var(--brand); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 5px;
  padding: 6px 13px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #b9c3cf; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #2a63a0; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.big { padding: 9px 22px; font-size: 15px; }
.btn.danger { color: var(--danger); border-color: #eccac6; }
.btn.danger:hover { background: #fdf2f1; }
.btn:disabled { opacity: .45; cursor: default; }

.link-btn {
  border: 0; background: none; color: var(--brand); cursor: pointer;
  font: inherit; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.inline-form { display: inline-flex; align-items: center; }
.inline-form > * { margin-right: 6px; }

.filters { display: flex; align-items: center; }
.filters > * { margin-right: 10px; }
.filters input[type=search] { width: 180px; }

.toolbar {
  display: flex; align-items: center; flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar > * { margin-right: 18px; margin-bottom: 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); grid-column-gap: 16px; }
.grid2 label, .grid3 label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.grid2 select, .grid3 select { margin-top: 4px; }

.checks { display: flex; flex-wrap: wrap; margin: 6px 0 12px; }
.check { display: inline-flex; align-items: center; margin: 0 16px 8px 0; font-size: 13px; }
.check input { margin-right: 6px; }

/* ---------------------------------------------------------------- 表格 */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
  max-height: 72vh;
}

table { border-collapse: separate; border-spacing: 0; width: 100%; }

thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f0f4f9;
  color: var(--brand-dark);
  font-weight: 600;
  font-size: 13px;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #eef1f5;
  white-space: nowrap;
}
tbody tr:nth-child(even) { background: #fbfcfe; }
tbody tr:hover { background: #f2f7fd; }

.col-idx { width: 46px; color: var(--muted); text-align: right; }
.col-no { width: 130px; }
.col-name { width: 90px; }
.col-class { width: 110px; }
.col-score { width: 90px; text-align: center; }

td.editable { cursor: pointer; }
td.editable:hover { box-shadow: inset 0 0 0 2px rgba(47, 111, 179, .35); }
td.editable.saving { background: #fff8e1; }
td.editable.saved { background: #eaf7ef; }
td.editable.failed { background: #fdecea; }

.cell-input {
  width: 100% !important;
  border: 0 !important;
  padding: 2px 4px !important;
  font: inherit;
  text-align: center;
  background: #fff;
  outline: 2px solid var(--brand);
}

table.manage { font-size: 13px; }
table.manage th { position: static; }
table.manage td { padding: 6px 8px; }
table.sample td, table.sample th { font-size: 12px; }
tr.dim { opacity: .5; }

.w-60 { width: 60px; }
.w-80 { width: 80px; }
.w-100 { width: 100px; }
.w-170 { width: 170px; }
.w-220 { width: 220px; }
.actions { display: flex; }
.actions form { margin-right: 4px; }

.empty {
  text-align: center; color: var(--muted); padding: 40px 0;
  background: var(--panel); border: 1px dashed var(--line); border-radius: 8px;
}

/* ---------------------------------------------------------------- 面板 */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 18px;
  box-shadow: var(--shadow);
}
.panel > summary {
  cursor: pointer;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--brand-dark);
  user-select: none;
}
.panel > summary:hover { background: #f7f9fc; }
.panel > *:not(summary) { padding: 0 16px; }
.panel table { margin: 8px 0; }
.panel > p { padding: 0 16px 12px; }
.add-student { padding: 8px 16px 4px !important; }

/* ---------------------------------------------------------------- 提示 */

.alert {
  padding: 9px 13px;
  border-radius: 6px;
  margin: 0 0 10px;
  font-size: 13px;
  background: #eef4fb;
  border: 1px solid #d4e3f4;
}
.alert.error { background: #fdecea; border-color: #f5c6c1; color: #922b21; }
.alert.warn { background: #fff8e6; border-color: #f2dfae; color: #7a5b10; }
.alert.ok, .alert.message { background: #eaf7ef; border-color: #c8e6d2; color: #24603f; }

.flashes { margin-bottom: 6px; }

.stats { display: flex; flex-wrap: wrap; margin: 6px -6px 10px; }
.stat {
  flex: 1 1 120px;
  margin: 6px;
  padding: 12px 14px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-align: center;
}
.stat .num { display: block; font-size: 24px; font-weight: 700; color: var(--brand-dark); }
.stat .lbl { font-size: 12px; color: var(--muted); }

.actions { margin-top: 18px; display: flex; align-items: center; }
.actions > * { margin-right: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #263238;
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  z-index: 99;
}
.toast.error { background: #a93226; }
.toast.ok { background: #1e6b47; }

/* ---------------------------------------------------------------- 登录 */

.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #eef3f9 0%, #f7f9fc 60%);
}

.login-box {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .08);
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box form { margin-top: 18px; }
.login-box label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.login-box input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
}
.login-box .btn { width: 100%; padding: 9px; margin-top: 4px; }

@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .wrap { padding: 12px; }
  .topbar { padding: 8px 12px; }
  .topbar-right > * { margin-left: 10px; }
}

/* ---------------------------------------------------------------- 手机窄屏 */

.narrow-only { display: none; }

@media (max-width: 680px) {
  body { font-size: 13px; }

  .wide-only { display: none; }
  .narrow-only { display: inline; }

  .topbar { flex-wrap: wrap; padding: 7px 10px; }
  .brand h1 { font-size: 15px; margin-right: 6px; }
  .brand-dot { margin-right: 7px; }
  .topbar-right > * { margin-left: 8px; }
  .topbar-right { font-size: 12px; }
  .course-input { width: 140px; font-size: 15px; }

  .wrap { padding: 10px 8px 40px; }

  thead th { font-size: 12px; padding: 7px 6px; }
  tbody td { padding: 6px 6px; }

  .col-idx { display: none; }
  .col-no { width: 58px; }
  .col-name { width: 62px; }
  .col-class { width: 40px; }
  .col-score { width: 52px; }

  .filters { flex-wrap: wrap; }
  .filters > * { margin-right: 6px; margin-bottom: 6px; }
  .filters input[type=search] { width: 128px; }

  .toolbar > * { margin-right: 10px; }
  .table-wrap { max-height: none; }

  .panel > summary { padding: 10px 12px; font-size: 13px; }
  .panel > *:not(summary) { padding: 0 12px; }
  .stats { margin: 4px -4px 8px; }
  .stat { flex-basis: 96px; padding: 9px 8px; margin: 4px; }
  .stat .num { font-size: 20px; }

  /* 手机上把顶栏链接收进"菜单" */
  .desktop-links { display: none; }
  .page-admin .brand { display: none; }
  .page-admin .topbar { justify-content: flex-end; }
  .mobile-menu { display: block; position: relative; }
  .mobile-menu summary {
    list-style: none;
    cursor: pointer;
    padding: 4px 12px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: 13px;
    background: #fff;
  }
  .mobile-menu summary::-webkit-details-marker { display: none; }
  .mobile-menu[open] summary { border-color: var(--brand); color: var(--brand); }
  .mobile-menu .menu-body {
    position: absolute;
    right: 0;
    top: 120%;
    min-width: 140px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
    z-index: 30;
  }
  .mobile-menu .menu-body .link { display: block; padding: 7px 0; font-size: 14px; }
  .mobile-menu .menu-body form { display: block; margin-top: 6px; }
  .mobile-menu .menu-body .link-btn { font-size: 14px; padding: 7px 0; }
}

.mobile-menu { display: none; }

.settings-form { padding: 12px 16px 6px !important; }
.settings-form label { margin-right: 8px; font-size: 12px; color: var(--muted); }
.settings-form input { min-width: 180px; }
