:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #647084;
  --line: #d7dee8;
  --soft-line: #e7ebf1;
  --primary: #155d91;
  --primary-dark: #10486f;
  --primary-soft: #edf5fb;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok-bg: #eef8f2;
  --ok-text: #17663a;
  --shadow: 0 14px 34px rgba(31, 42, 68, 0.08);
  --small-shadow: 0 6px 16px rgba(31, 42, 68, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 36px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--small-shadow);
}

.topbar h1,
.login-panel h1,
.section-title h2,
.modal-box h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 26px;
  font-weight: 800;
}

.topbar p,
.login-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.container {
  width: min(1220px, calc(100% - 36px));
  margin: 28px auto;
}

.panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 26px;
  margin-bottom: 20px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-title h2 {
  font-size: 20px;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 18px;
  align-items: end;
  padding: 18px;
  background: #f8fafc;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
}

.stack-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: #344256;
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #c5cfdd;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus {
  outline: 2px solid #9dc3e6;
  border-color: var(--primary);
}

button,
.link-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.link-button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #ffffff;
  color: #25364a;
  border-color: #b9c1ce;
}

button.secondary:hover {
  background: #f1f3f6;
}

button.danger {
  background: #ffffff;
  color: var(--danger);
  border-color: #e2aaa5;
}

button.danger:hover {
  background: var(--danger-bg);
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.import-box {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
  padding: 18px;
  background: #f8fafc;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
}

.import-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.import-head h3 {
  margin: 0;
  font-size: 17px;
}

.import-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.import-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.import-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #a9d8bd;
  border-radius: 6px;
  background: var(--ok-bg);
  color: var(--ok-text);
}

.import-summary.has-error {
  border-color: #e2b1aa;
  background: var(--danger-bg);
  color: var(--danger);
}

.import-result {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.import-table-wrap {
  min-width: 760px;
}

.error-text {
  color: var(--danger);
}

.warn-text {
  color: #8a5a00;
}

.ok-text {
  color: var(--ok-text);
}

.student-picker-field {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.picker-head label {
  display: block;
}

.student-search-box {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
}

.student-search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 188px;
  overflow: auto;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #cfd7e3;
  border-radius: 8px;
}

.student-result {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.student-result:hover {
  border-color: #9fc2df;
  background: var(--primary-soft);
}

.student-name {
  font-weight: 700;
}

.student-grade {
  color: var(--muted);
  font-size: 13px;
}

.picker-empty {
  grid-column: 1 / -1;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.selected-student-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
}

.selected-student {
  display: inline-flex;
  min-height: 32px;
  gap: 8px;
  padding: 5px 10px;
  border-color: #9fc2df;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.selected-student:hover {
  background: #e4f0f8;
}

.remove-text {
  color: #6f7b8f;
  font-size: 12px;
}

.selected-empty {
  display: flex;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.notice {
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid #e2b1aa;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
}

.notice.success {
  border-color: #a9d8bd;
  background: var(--ok-bg);
  color: var(--ok-text);
}

.week-list {
  display: grid;
  gap: 12px;
}

.week-day {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.week-day h3 {
  margin: 0;
  padding: 10px 12px;
  background: #f1f3f6;
  border-bottom: 1px solid var(--soft-line);
  font-size: 15px;
}

.lesson {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  padding: 12px;
  border-top: 1px solid var(--soft-line);
}

.lesson:first-of-type {
  border-top: 0;
}

.lesson-time {
  font-weight: 700;
}

.lesson-detail {
  color: #334155;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #c8ced8;
  border-radius: 999px;
  color: #4b5563;
  font-size: 12px;
  background: #ffffff;
}

.tag.warn {
  border-color: #e2aaa5;
  color: var(--danger);
  background: var(--danger-bg);
}

.empty {
  padding: 18px;
  border: 1px dashed #c8ced8;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.center-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
}

.plain-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--primary);
  text-decoration: none;
}

.admin-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 22px;
  align-items: start;
}

.side-nav {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  background: #ffffff;
  color: #25364a;
  border-color: #ffffff;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: #c9d9e8;
}

.content-area {
  min-width: 0;
}

.table-wrap {
  width: 100%;
  margin-top: 20px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

td:nth-child(3) {
  white-space: normal;
  min-width: 180px;
}

th {
  background: #f6f8fb;
  color: #39475b;
  font-weight: 700;
}

tbody tr:hover {
  background: #f8fafc;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
  z-index: 20;
}

.modal-box {
  width: min(520px, 100%);
  padding: 22px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.conflict-text {
  margin: 16px 0;
  padding: 12px;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .container {
    width: 100%;
    margin: 0;
    padding: 12px;
  }

  .form-grid,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .form-grid {
    padding: 12px;
    gap: 14px;
  }

  .side-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding: 10px;
    border-radius: 8px;
  }

  .nav-item {
    min-width: 0;
    justify-content: center;
    padding: 8px 6px;
    font-size: 14px;
    white-space: nowrap;
  }

  .student-search-box {
    grid-template-columns: 1fr;
  }

  .student-search-results {
    grid-template-columns: 1fr;
    max-height: 216px;
  }

  .selected-student-list {
    max-height: 128px;
    overflow: auto;
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .import-head,
  .import-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .import-head .link-button,
  .import-actions button {
    width: 100%;
  }

  .import-result {
    max-height: none;
    overflow: visible;
    border: 0;
  }

  .import-table-wrap {
    min-width: 0;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    padding: 10px 12px;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .lesson {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
