:root {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --ink: #1f2933;
  --muted: #667085;
  --line: #ddd6c8;
  --green: #1f7a4d;
  --green-soft: #e5f3eb;
  --blue: #315f9f;
  --blue-soft: #e7eef8;
  --amber: #9a650f;
  --amber-soft: #fff2d8;
  --red: #b42318;
  --shadow: 0 8px 26px rgba(32, 41, 51, .08);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  width: min(100%, 440px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 240, .96);
  backdrop-filter: blur(12px);
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand strong {
  font-size: 17px;
  line-height: 1.3;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.link-btn,
.small-btn,
.btn {
  min-height: 38px;
  border-radius: var(--radius);
  font-weight: 720;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
}

.main {
  padding: 14px 14px 92px;
}

.privacy-notice {
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid #e3c98f;
  border-radius: var(--radius);
  background: #fff8e8;
}

.privacy-notice strong {
  display: block;
  color: #7a4b00;
  font-size: 14px;
  line-height: 1.35;
}

.privacy-notice p {
  margin: 5px 0 0;
  color: #5e513e;
  font-size: 12px;
  line-height: 1.55;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid #c8ddcf;
  background: #f0f7f3;
  border-radius: var(--radius);
}

.fill-section-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.fill-section-nav button {
  min-height: 42px;
  padding: 6px 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf2;
  color: #46515c;
  font-size: 12px;
  line-height: 1.2;
}

.form-section {
  margin-bottom: 14px;
  padding: 0 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.form-section.is-collapsed { padding-bottom: 0; }

.form-section-head {
  align-items: center;
  margin: 0 0 12px;
  padding: 14px 0 10px;
  border-top: 0;
  border-bottom: 1px solid var(--line);
}

.form-section-head h1 { font-size: 18px; }

.form-section-fields { display: block; }

.form-section.is-collapsed .form-section-fields { display: none; }

.section-toggle {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf2;
  color: var(--muted);
  font-size: 12px;
}

.status-strip strong {
  display: block;
  font-size: 14px;
  line-height: 1.4;
}

.status-strip small {
  display: block;
  margin-top: 3px;
  color: #51705d;
  font-size: 12px;
}

.score {
  min-width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 750;
  font-size: 15px;
}

.section-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.section-nav button {
  min-height: 48px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf2;
  color: #46515c;
  font-size: 12px;
  line-height: 1.2;
}

.section-nav button.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: #145a38;
  font-weight: 760;
}

.band-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.band-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.band-title h1,
.band-title h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  text-wrap: balance;
}

.band-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tag,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.tag { background: var(--blue-soft); color: var(--blue); }
.pill.green { background: var(--green-soft); color: #145a38; }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }

.field { margin-bottom: 13px; }

.field label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  color: #28333f;
  font-size: 14px;
  font-weight: 740;
}

.required {
  color: var(--red);
  font-size: 12px;
  font-weight: 780;
}

input, textarea, select {
  width: 100%;
  border: 1px solid #d8d1c2;
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--ink);
  outline: none;
  font-size: 15px;
}

input, select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 94px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 77, .12);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: #f4f0e7;
  color: #47515d;
  opacity: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.small-btn {
  border: 1px solid #d8d1c2;
  background: #fffefa;
  color: #4d5965;
}

.chip {
  min-height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
}

.chip.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: #145a38;
  font-weight: 760;
}

.chip:disabled,
.source-options button:disabled {
  cursor: default;
  opacity: .78;
}

.source-row {
  margin-top: 8px;
  padding: 8px;
  background: #f8f4eb;
  border-radius: var(--radius);
}

.source-row span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.source-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.source-options button {
  min-height: 32px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: #fffefa;
  color: #59636e;
  font-size: 12px;
}

.source-options button.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 760;
}

.bottom-actions {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 12;
  width: min(100%, 440px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, .94);
  backdrop-filter: blur(14px);
}

.btn {
  min-height: 46px;
  font-size: 15px;
}

.btn.secondary {
  border: 1px solid var(--line);
  background: #fffefa;
  color: #3f4a55;
}

.btn.primary {
  background: var(--green);
  color: #fff;
}

.btn.danger {
  border: 1px solid #f0b4ae;
  background: #fff4f2;
  color: var(--red);
}

.admin-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px;
}

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.admin-head h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.admin-head p {
  max-width: 720px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

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

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  margin-bottom: 16px;
}

.toolbar .filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.row-link {
  color: var(--blue);
  font-weight: 760;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid #e8e1d4;
  text-align: left;
  vertical-align: middle;
}

td.select-cell,
th.select-cell {
  width: 42px;
  text-align: center;
}

th {
  background: #fbf5e8;
  color: #5b6470;
  font-size: 12px;
  font-weight: 780;
}

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

.progress {
  height: 8px;
  min-width: 92px;
  border-radius: 999px;
  background: #e8e1d4;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.student-panel {
  padding: 14px;
  margin-bottom: 14px;
}

.student-panel .band-title {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.form-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.form-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.form-actions .btn { width: 100%; }

.message {
  padding: 11px 12px;
  margin-bottom: 14px;
  border: 1px solid #e3c98f;
  border-radius: var(--radius);
  background: #fff8e8;
  color: #6d510f;
  font-size: 13px;
  line-height: 1.5;
}

.message.error {
  border-color: #f0b4ae;
  background: #fff4f2;
  color: var(--red);
}

.message.success {
  border-color: #c8ddcf;
  background: #f0f7f3;
  color: #145a38;
}

.profile-head,
.list-head,
.student-card-head,
.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.profile-head h2,
.list-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.profile-meta,
.client-meta,
.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.student-list,
.history-list {
  display: grid;
  gap: 10px;
}

.student-card,
.history-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.student-card strong,
.history-item strong {
  font-size: 15px;
  line-height: 1.4;
}

.student-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.student-card-actions .btn {
  min-height: 40px;
  font-size: 13px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 11px;
  border-radius: var(--radius);
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
  font-weight: 760;
}

.button-link.primary {
  background: var(--green);
  color: #fff;
}

.loading {
  padding: 18px 8px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.history-item p {
  margin: 8px 0 0;
  color: #46515c;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 8px 0 0;
  color: #46515c;
  font-size: 14px;
  line-height: 1.5;
}

.check-row input {
  width: 18px;
  min-width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--green);
}

.pdf-page {
  display: none;
}

@media print {
  body.printing > *:not(.pdf-page) {
    display: none !important;
  }

  body.printing .pdf-page {
    display: block;
    background: #fff;
    color: #111827;
    font-family: "Songti SC", "SimSun", serif;
    padding: 18mm;
  }

  .pdf-record {
    break-after: page;
  }

  .pdf-record:last-child {
    break-after: auto;
  }

  .pdf-record h1 {
    margin: 0 0 10mm;
    font-size: 20pt;
    text-align: center;
  }

  .pdf-record h2 {
    margin: 8mm 0 3mm;
    padding: 2mm 0;
    border-bottom: 1px solid #111827;
    font-size: 13pt;
  }

  .pdf-record table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10.5pt;
  }

  .pdf-record th,
  .pdf-record td {
    border: 1px solid #9ca3af;
    padding: 2.5mm;
    vertical-align: top;
  }

  .pdf-record th {
    width: 28%;
    background: #f3f4f6;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #1f2933;
  color: #fff;
  font-size: 14px;
  transition: .22s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    border: 0;
  }

  .admin-shell {
    padding: 0;
  }

  .admin-head {
    display: block;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .admin-head h1 { font-size: 22px; }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0 14px;
  }

  .toolbar {
    margin: 0 14px 14px;
  }

  .table-wrap {
    margin: 0 14px 80px;
  }

  .fill-section-nav {
    position: sticky;
    top: 61px;
    z-index: 9;
    padding: 8px 0;
    background: rgba(255, 253, 248, .96);
  }

  .bottom-actions {
    width: 100%;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .bottom-actions #submitBtn {
    grid-column: 1 / -1;
    order: -1;
  }

  .main { padding-bottom: 148px; }

  table {
    min-width: 720px;
  }
}

@media (max-width: 380px) {
  .section-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fill-section-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-options { grid-template-columns: 1fr; }
}
