:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1c2420;
  --muted: #65716a;
  --line: #dce2dc;
  --green: #2f7d5a;
  --green-strong: #14573b;
  --blue: #326fa8;
  --yellow: #c99521;
  --red: #b94a48;
  --teal: #18827a;
  --shadow: 0 18px 45px rgba(37, 48, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 247, 244, 0.88)),
    var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(460px, 100%);
}

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

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

.login-error {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

button,
input,
a {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green-strong);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.16;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

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

.primary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  color: #fff;
  background: var(--green);
  box-shadow: 0 10px 22px rgba(47, 125, 90, 0.22);
}

.ghost-button,
.icon-button {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.primary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.dashboard-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 4vw, 48px) 42px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-panel,
.insight-panel,
.history-panel,
.camera-panel,
.reading-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-panel {
  min-height: 100px;
  padding: 18px;
}

.metric-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-panel strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.9fr);
  gap: 18px;
  margin-top: 18px;
}

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

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

.section-heading.compact {
  margin-bottom: 18px;
}

.status-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--green);
}

.status-pill.muted {
  color: var(--muted);
  background: #eef2ef;
}

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  min-height: 324px;
}

.student-grid.empty-state {
  place-items: center;
  padding: 42px 20px;
  color: var(--muted);
  text-align: center;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.student-card {
  min-height: 270px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(42, 52, 47, 0.08);
}

.student-preview {
  display: grid;
  place-items: center;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f3f6f4;
  font-size: 13px;
}

.student-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.student-card.offline {
  opacity: 0.62;
}

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

.student-head h3 {
  margin-bottom: 4px;
  font-size: 18px;
  letter-spacing: 0;
}

.student-head small,
.table-wrap td {
  color: var(--muted);
}

.emotion-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 30px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  background: var(--blue);
}

.emotion-badge[data-emotion="愉悦"] { background: var(--yellow); }
.emotion-badge[data-emotion="舒畅"] { background: #52a36f; }
.emotion-badge[data-emotion="舒缓"] { background: var(--green); }
.emotion-badge[data-emotion="宁静"] { background: var(--blue); }
.emotion-badge[data-emotion="忧郁"] { background: #596da8; }
.emotion-badge[data-emotion="悲伤"] { background: #326fa8; }
.emotion-badge[data-emotion="恐惧"] { background: #7d7483; }
.emotion-badge[data-emotion="惊讶"] { background: var(--teal); }
.emotion-badge[data-emotion="愤怒"] { background: var(--red); }
.emotion-badge[data-emotion="厌恶"] { background: #7f6a3f; }
.emotion-badge[data-emotion="激昂"] { background: #b76b2a; }
.emotion-badge[data-emotion="激动"] { background: var(--yellow); }
.emotion-badge[data-emotion="焦虑"] { background: var(--red); }
.emotion-badge[data-emotion="离开"] { background: #79817c; }
.emotion-badge[data-emotion="未识别"] { background: #79817c; }

.card-metrics {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.mini-row,
.meter-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ee;
}

.meter i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 240ms ease;
}

.insight-panel,
.history-panel {
  padding: 18px;
}

.chart-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

#trendChart {
  display: block;
  width: 100%;
  height: auto;
}

.emotion-bars {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ee;
}

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

.history-panel {
  margin-top: 18px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.student-shell {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(300px, 0.9fr);
  gap: 18px;
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 42px);
  align-items: center;
}

.camera-panel,
.reading-panel {
  padding: clamp(16px, 3vw, 24px);
}

.video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #15201b;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#sampleCanvas {
  display: none;
}

.video-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: #f6fbf7;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(20, 87, 59, 0.78), rgba(50, 111, 168, 0.76)),
    #18241f;
}

.video-fallback.warn {
  background:
    linear-gradient(135deg, rgba(105, 39, 42, 0.82), rgba(50, 80, 112, 0.78)),
    #211b1d;
}

.video-fallback span {
  max-width: 32em;
  line-height: 1.6;
}

.video-fallback.hidden {
  display: none;
}

.student-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin-top: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.current-emotion {
  min-height: 170px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.current-emotion span,
.current-emotion small {
  color: var(--muted);
}

.current-emotion strong {
  font-size: clamp(44px, 9vw, 72px);
  line-height: 1;
  letter-spacing: 0;
}

.model-status {
  margin-top: 12px;
  min-height: 36px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--green-strong);
  background: #f6faf7;
  font-size: 13px;
}

.model-status.warn {
  color: var(--red);
  background: #fff7f7;
}

.meter-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.student-trend-panel {
  margin-top: 18px;
}

.student-trend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.student-trend-head h2 {
  font-size: 17px;
}

.student-trend-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.student-chart-frame {
  overflow: hidden;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

#studentTrendChart {
  display: block;
  width: 100%;
  min-height: 180px;
  height: auto;
}

.manual-panel {
  margin: 22px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.manual-panel legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.segmented button.active {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

@media (max-width: 980px) {
  .topbar,
  .workspace-grid,
  .student-shell {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar {
    position: static;
  }

  .summary-grid,
  .student-form,
  .student-actions,
  .segmented {
    grid-template-columns: 1fr;
  }

  .student-actions {
    flex-direction: column;
  }

  .nav-actions {
    width: 100%;
  }

  .primary-button,
  .ghost-button,
  .icon-button {
    flex: 1 1 auto;
  }
}
