:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --ink: #17232b;
  --muted: #67747e;
  --line: #dfe6e5;
  --teal: #0f766e;
  --teal-soft: #e6f4f1;
  --coral: #e35d4f;
  --coral-soft: #fdece9;
  --amber: #d98a16;
  --amber-soft: #fff3dc;
  --navy: #142b33;
  --danger: #b42318;
  --shadow: 0 8px 28px rgba(23, 35, 43, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef8f5 0%, #f4f2ee 100%);
}
.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--teal); margin-bottom: 28px; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  flex-shrink: 0;
}
.brand-mark svg { width: 24px; height: 24px; }
.login-card h1 { font-size: 26px; margin: 0 0 8px; }
.login-desc { color: var(--muted); margin: 0 0 28px; line-height: 1.6; }
.field-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.text-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  margin-bottom: 14px;
}
.text-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.login-note { font-size: 12px; color: var(--muted); margin: 16px 0 0; line-height: 1.5; }

.app-shell { height: 100vh; display: flex; overflow: hidden; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  background: var(--navy);
  color: #f4faf9;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-name { font-weight: 800; font-size: 17px; }
.brand-sub { font-size: 12px; color: #a9c2c9; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce9e7;
  text-align: left;
  font-weight: 600;
}
.nav-item:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.nav-item.active { background: var(--teal); color: #fff; }
.nav-item:disabled { opacity: 0.42; cursor: not-allowed; }
.nav-icon { font-size: 16px; width: 22px; text-align: center; }
.sidebar-card {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 16px;
  margin-top: auto;
}
.sidebar-card-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: #dce9e7; }
.progress-track { height: 8px; background: rgba(255, 255, 255, 0.15); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: #5eead4; border-radius: 999px; transition: width 0.3s ease; }
.progress-text { margin-top: 10px; font-size: 13px; font-weight: 700; }
.progress-note { margin-top: 4px; font-size: 12px; color: #a9c2c9; line-height: 1.5; }
.link-btn { border: 0; background: transparent; color: #a9c2c9; padding: 6px; text-align: left; }
.link-btn:hover { color: #fff; }

.main { flex: 1; overflow-y: auto; padding: 30px 36px 60px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.page-title { font-size: 25px; font-weight: 800; }
.page-subtitle { font-size: 14px; color: var(--muted); margin-top: 6px; }
.view { max-width: 1080px; }
.section-subhead { font-size: 15px; font-weight: 800; margin: 28px 0 14px; }

.info-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 16px;
  line-height: 1.75;
}
.info-panel h3 { margin: 0 0 8px; font-size: 17px; }
.info-panel p { margin: 0 0 10px; color: #33424c; }
.info-panel p:last-child { margin-bottom: 0; }
.info-panel-coral { border-left-color: var(--coral); }
.info-panel-amber { border-left-color: var(--amber); }
.consent-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.check-label { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; line-height: 1.5; }
.check-label input { width: 18px; height: 18px; accent-color: var(--teal); margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
}
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0d6a63; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--line); }
.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn-block { width: 100%; margin-top: 6px; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }

.module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.module-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  min-height: 230px;
}
.module-card.active { border-color: var(--teal); box-shadow: 0 10px 28px rgba(15, 118, 110, 0.14); }
.module-card.locked { background: #fbfcfc; }
.module-card.completed { background: #fafdfc; }
.module-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.module-index {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}
.module-card.coral .module-index { background: var(--coral-soft); color: var(--coral); }
.module-card.amber .module-index { background: var(--amber-soft); color: var(--amber); }
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status-pill.ready { background: var(--teal-soft); color: var(--teal); }
.status-pill.in_progress { background: var(--amber-soft); color: #7a4d07; }
.status-pill.completed { background: #e8f5f2; color: #0b6e5f; }
.status-pill.locked { background: #edf1f1; color: var(--muted); }
.module-title { font-size: 17px; font-weight: 800; margin: 0; }
.module-subtitle { font-size: 13px; color: var(--muted); margin: 5px 0 0; }
.module-desc { font-size: 13px; color: #475661; line-height: 1.65; margin: 0; }
.module-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.module-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.countdown { font-size: 12px; color: #8a4b09; background: var(--amber-soft); border-radius: 8px; padding: 7px 10px; line-height: 1.4; }
.countdown.neutral { color: var(--muted); background: #eef2f2; }

.homework-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
}
.homework-hero h3 { margin: 0 0 6px; font-size: 20px; }
.homework-hero .homework-brief { color: var(--muted); margin: 0 0 16px; line-height: 1.6; }
.homework-steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.homework-steps li { display: flex; gap: 10px; align-items: flex-start; line-height: 1.55; }
.step-dot { flex-shrink: 0; width: 22px; height: 22px; border-radius: 8px; background: var(--teal-soft); color: var(--teal); display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.homework-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.homework-time { font-size: 13px; color: var(--muted); }
.homework-textarea {
  width: 100%;
  min-height: 96px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
  outline: none;
  line-height: 1.6;
}
.homework-textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.homework-textarea:disabled { background: #f7f9f9; color: #51606a; }
.check-condition {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 20px;
  margin-top: 14px;
}
.check-condition h4 { margin: 0 0 10px; font-size: 14px; }
.condition-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 8px; }
.condition-row:last-child { margin-bottom: 0; }
.condition-mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.condition-mark.done { background: var(--teal); color: #fff; }
.condition-mark.pending { background: #edf1f1; color: var(--muted); }

.homework-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.homework-item { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; }
.homework-item h4 { margin: 0 0 6px; font-size: 15px; }
.homework-item p { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.homework-status { font-size: 12px; font-weight: 800; }

.chat-shell {
  height: calc(100vh - 150px);
  min-height: 520px;
  max-height: 840px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
  flex-shrink: 0;
}
.chat-head-main { flex: 1; min-width: 0; }
.chat-title { font-weight: 800; font-size: 16px; }
.chat-mode { font-size: 12px; color: var(--teal); background: var(--teal-soft); border-radius: 999px; padding: 5px 10px; font-weight: 700; white-space: nowrap; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px 22px; background: #fbfcfc; }

.msg-row { display: flex; gap: 10px; margin-bottom: 12px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.avatar {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid #cfe7e2;
}
.avatar svg { width: 20px; height: 20px; }
.avatar.user-avatar { background: #fff5e8; color: #d98a16; border-color: #f2d4a7; }
.msg {
  width: fit-content;
  max-width: 80%;
  padding: 10px 13px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}
.msg.user { background: var(--teal); color: #fff; }
.msg.assistant { background: #fff; border: 1px solid var(--line); }
.msg-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.user .msg-label { color: rgba(255, 255, 255, 0.75); }

.chat-input-bar { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line); background: #fff; flex-shrink: 0; }
.chat-input-bar textarea {
  flex: 1;
  min-height: 66px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline: none;
  line-height: 1.5;
}
.chat-input-bar textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(12, 21, 28, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-card h3 { margin: 0 0 10px; font-size: 19px; }
.modal-card p { margin: 0 0 20px; color: #43515b; line-height: 1.7; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.crisis-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(12, 21, 28, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.crisis-card {
  width: min(680px, 100%);
  background: #fff;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}
.crisis-top { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.crisis-shield { width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; border-radius: 8px; background: var(--coral-soft); color: var(--coral); font-size: 22px; font-weight: 800; }
.crisis-top h2 { margin: 0 0 8px; font-size: 22px; color: #8a2b22; }
.crisis-top p { margin: 0; line-height: 1.7; color: #43515b; font-size: 15px; }
.crisis-section h3 { margin: 0 0 12px; font-size: 15px; }
.hotline-list { display: grid; gap: 10px; }
.hotline { border: 1px solid var(--line); border-left: 4px solid var(--coral); border-radius: 8px; padding: 13px 15px; background: #fffbfa; }
.hotline-name { font-weight: 800; font-size: 14px; }
.hotline-note { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hotline-phones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.hotline-phone { font-size: 16px; font-weight: 800; color: var(--danger); background: #fff; border: 1px solid #f2c9c5; border-radius: 8px; padding: 7px 11px; }
.crisis-emergency { margin: 16px 0 0; font-size: 14px; font-weight: 700; color: #7a4d07; line-height: 1.6; }
.crisis-waiting-note { margin-top: 16px; background: var(--amber-soft); border: 1px solid #f0cf9b; border-radius: 8px; padding: 13px 16px; font-size: 14px; line-height: 1.6; color: #6f4706; font-weight: 700; }
.crisis-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.crisis-actions .btn { flex: 1; min-width: 180px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 1200;
  background: #1f2d33;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 40px);
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 12px 14px; gap: 12px; }
  .brand { padding: 0; }
  .nav { flex-direction: row; }
  .nav-item { justify-content: center; padding: 0 8px; min-height: 40px; }
  .sidebar-card, .link-btn { display: none; }
  .main { padding: 18px 16px 40px; }
  .topbar { flex-direction: column; gap: 10px; margin-bottom: 18px; }
  .page-title { font-size: 21px; }
  .module-grid, .homework-list { grid-template-columns: 1fr; }
  .consent-box { flex-direction: column; align-items: stretch; }
  .chat-shell { height: calc(100vh - 230px); min-height: 420px; }
  .msg { max-width: 88%; }
  .crisis-card { padding: 22px; }
  .crisis-actions .btn { min-width: 100%; }
}