:root {
  --bg: #f4f7fb;
  --surface: #fff;
  --soft: #f8fafc;
  --text: #111827;
  --muted: #667085;
  --line: #d8e0ea;
  --primary: #1456d9;
  --primary-soft: #eaf1ff;
  --green: #078455;
  --green-soft: #e8f7ef;
  --amber: #b54708;
  --amber-soft: #fff4e5;
  --red: #c4322b;
  --red-soft: #fdeceb;
  --shadow: 0 12px 30px rgba(15, 23, 42, .07);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  min-width: 0;
}
html, body {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}
img, svg, canvas, video { max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 86, 217, .14);
}
label { color: var(--muted); font-size: 13px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 10%, rgba(20,86,217,.18), transparent 32%),
    radial-gradient(circle at 82% 78%, rgba(7,132,85,.13), transparent 34%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  padding: 28px;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; font-size: 28px; }
.login-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  overflow-x: clip;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 100%;
  max-width: 100%;
  padding: 16px 12px;
  background: #111827;
  color: #dbe4f0;
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 16px;
  max-width: 100%;
}
.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: #ffd166;
  color: #111827;
  border-radius: var(--radius);
}
.brand span:last-child {
  margin-left: auto;
  padding: 2px 7px;
  color: #b9c7da;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  font-size: 12px;
}
.nav {
  display: grid;
  gap: 6px;
  max-width: 100%;
}
.nav a {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  color: #cbd5e1;
  border-radius: var(--radius);
  white-space: nowrap;
}
.nav a.active, .nav a:hover {
  color: #fff;
  background: rgba(255,255,255,.13);
}
.main {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 0 24px;
  background: rgba(255,255,255,.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.topbar > div {
  min-width: 0;
}
.topbar h1 { margin: 0; font-size: 21px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.userbar { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.content {
  display: grid;
  gap: 18px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 22px;
}

.panel, .card, .modal {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(15,23,42,.045);
}
.panel { padding: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-width: 0;
}
.panel-head > * {
  min-width: 0;
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: 16px; }
.toolbar, .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.toolbar { justify-content: space-between; }
.toolbar > div {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 7px;
  background: #edf2f7;
  color: var(--text);
  white-space: nowrap;
  max-width: 100%;
}
.btn.primary { color: #fff; background: var(--primary); }
.btn.green { color: #fff; background: var(--green); }
.btn.red { color: #fff; background: var(--red); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
}
.alert.success { color: var(--green); background: var(--green-soft); border-color: #b8e6ce; }
.alert.error { color: var(--red); background: var(--red-soft); border-color: #f2b8b4; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.stat-card {
  padding: 18px;
}
.stat-label {
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.stat-value {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 850;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.grid-2, .grid-3, .form-grid, .draw-grid {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.draw-grid { grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }

.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th {
  color: var(--muted);
  background: var(--soft);
  font-size: 13px;
}
tr:hover td { background: #fbfdff; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.muted { color: var(--muted); }
.empty { padding: 24px; color: var(--muted); text-align: center; }

.chart-box {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.bars { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(80px, 130px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.bar-track { height: 12px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.line-list { display: grid; gap: 8px; }
.line-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 12px;
  min-width: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.line-item > * { min-width: 0; overflow-wrap: anywhere; }

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}
.student-chip {
  display: block;
  min-height: 58px;
  padding: 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.student-chip.active { background: var(--primary-soft); border-color: var(--primary); }
.draw-result {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 190px;
  padding: 24px;
  text-align: center;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.draw-result strong { font-size: clamp(34px, 9vw, 72px); line-height: 1; }

.timeline { display: grid; gap: 10px; }
.timeline-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: var(--soft);
  border-left: 4px solid var(--primary);
  border-radius: 7px;
}
.timeline-item strong, .timeline-item span { overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    padding: 10px 12px;
  }
  .brand { padding-bottom: 10px; }
  .nav {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 3px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .nav a { flex: 0 0 auto; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3, .draw-grid { grid-template-columns: 1fr; }
}

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

@media (max-width: 700px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px;
  }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .userbar { width: 100%; justify-content: space-between; }
  .content { padding: 12px; gap: 12px; }
  .panel, .card { padding: 14px; }
  .panel-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .toolbar,
  .toolbar > div,
  .toolbar form,
  .actions {
    width: 100%;
    max-width: 100%;
    align-items: stretch;
  }
  .toolbar input,
  .toolbar select,
  .toolbar textarea,
  .toolbar .btn,
  .toolbar [style*="width"],
  .actions .btn,
  .actions form {
    width: 100% !important;
    max-width: 100% !important;
  }
  .toolbar .badge {
    width: 100%;
    justify-content: flex-start;
    white-space: normal;
  }
  .brand {
    padding-left: 2px;
    padding-right: 2px;
  }
  .brand strong {
    max-width: calc(100vw - 120px);
  }
  .btn {
    white-space: normal;
    text-align: center;
  }
  .form-grid { grid-template-columns: 1fr; }
  table { min-width: 560px; }
  th, td { padding: 9px 10px; }
  .bar-row { grid-template-columns: 1fr; }
  .student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 390px) {
  .student-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 26px; }
  .content { padding: 10px; }
  .panel, .card { padding: 12px; }
  table { min-width: 520px; }
}
