:root {
  --bg: #f3f6f4;
  --ink: #17201b;
  --muted: #6d7871;
  --panel: #ffffff;
  --line: #dde5df;
  --green: #16745f;
  --green-soft: #e7f4ee;
  --red: #d9342b;
  --orange: #d88922;
  --blue: #346aa9;
  --teal: #237b83;
  --shadow: 0 18px 45px rgba(26, 41, 33, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  border: 0;
  cursor: pointer;
}

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

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

.chronic-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.side {
  background: linear-gradient(180deg, #1d4ed8 0%, #1e40af 100%);
  color: white;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.logo-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f3fff7;
  color: #1e3a8a;
  font-size: 22px;
  font-weight: 900;
}

.logo-row strong,
.logo-row span {
  display: block;
}

.logo-row span {
  margin-top: 4px;
  color: #c8dbf3;
  font-size: 13px;
}

.nav,
.side-links {
  display: grid;
  gap: 8px;
}

.nav button,
.side-links a {
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  color: #eaf2ff;
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
}

.nav button.active {
  background: #eff6ff;
  color: #1e3a8a;
}

.nav button:hover,
.side-links a:hover {
  background: rgba(147, 197, 253, 0.36);
  color: #ffffff;
}

.side-links {
  margin-top: auto;
}

.side-links a {
  display: flex;
  align-items: center;
  border: 1px solid rgba(216, 231, 251, 0.26);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
}

.top-actions,
.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary,
.ghost {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 900;
}

.primary {
  background: var(--green);
  color: white;
}

.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.75fr);
}

.panel,
.score-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  min-height: 62px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.api-card,
.question-form,
.question-bank,
.rule-list,
.loop-list,
.follow-list,
.recommend-list,
.class-board,
.explain-box,
.tag-cloud {
  padding: 16px;
}

.api-flow,
.follow-list,
.recommend-list,
.class-board,
.question-bank,
.rule-list,
.loop-list {
  display: grid;
  gap: 12px;
}

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

article,
.question-row,
.rule-row,
.class-card,
.recommend-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 14px;
}

article.done,
.question-row.enabled,
.rule-row.active {
  border-color: #add8c5;
  background: #f0faf5;
}

article p,
.question-row p,
.rule-row p,
.recommend-card p,
.class-card p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

pre {
  overflow: auto;
  margin: 14px 0 0;
  border-radius: 8px;
  background: #14201b;
  color: #e8f5ee;
  padding: 14px;
  line-height: 1.55;
}

.form-grid,
.question-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

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

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

input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
}

.button-row {
  padding: 0 16px 16px;
}

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

.score-card {
  padding: 18px;
}

.score-card span {
  color: var(--muted);
  font-weight: 800;
}

.score-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 34px;
  line-height: 1;
}

.score-card.red strong {
  color: var(--red);
}

.score-card.orange strong {
  color: var(--orange);
}

.score-card.green strong {
  color: var(--green);
}

.score-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-cloud span {
  border-radius: 99px;
  background: #fff2e2;
  color: #835015;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
}

.explain-box {
  color: var(--muted);
  line-height: 1.8;
}

.question-row,
.rule-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.question-row button,
.rule-row button {
  min-height: 34px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  padding: 0 10px;
  font-weight: 900;
}

.toast-stack {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 44px));
}

.toast {
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.toast strong {
  display: block;
  margin-bottom: 4px;
}

.toast p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.kpi-grid article {
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  padding: 18px;
}

.kpi-grid span,
.kpi-grid em {
  display: block;
  color: var(--muted);
  font-style: normal;
}

.kpi-grid strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 34px;
  line-height: 1;
}

.red {
  color: var(--red);
}

.orange {
  color: var(--orange);
}

.member-list,
.reminder-list,
.task-list,
.rule-list,
.family-summary,
.ai-summary,
.ocr-table,
.trend-grid {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.member-row,
.reminder-row,
.task-row,
.metric-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 14px;
}

.member-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.risk-dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 900;
}

.risk-dot.orange {
  background: #fff2e2;
  color: var(--orange);
}

.risk-dot.red {
  background: var(--red-soft);
  color: var(--red);
}

.member-row p,
.reminder-row p,
.task-row p,
.metric-card p,
.family-summary p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.upload-box {
  margin: 16px;
  min-height: 220px;
  border: 2px dashed #b7c9bf;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  background: #fbfdfb;
  padding: 24px;
}

.upload-box.uploaded {
  border-style: solid;
  border-color: #add8c5;
  background: #f0faf5;
}

.ocr-item {
  display: grid;
  grid-template-columns: 1fr 90px 90px 72px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.ocr-item strong {
  font-size: 15px;
}

.ocr-item span {
  color: var(--muted);
  font-size: 13px;
}

.ocr-item.abnormal {
  border-color: #f2c7a0;
  background: #fff8f0;
}

.profile-grid {
  grid-template-columns: 280px minmax(0, 1fr);
}

.member-profile {
  padding: 20px;
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  color: var(--green);
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 14px;
}

.tag-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.tag-wrap span {
  border-radius: 99px;
  background: #fff2e2;
  color: #835015;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 900;
}

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

.metric-card strong {
  display: block;
  font-size: 28px;
  margin: 8px 0;
}

.bar-track {
  height: 9px;
  border-radius: 99px;
  background: #edf2ef;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.bar-fill.orange {
  background: var(--orange);
}

.bar-fill.red {
  background: var(--red);
}

.family-summary {
  color: var(--muted);
  line-height: 1.7;
}

.task-row.done,
.reminder-row.done {
  border-color: #add8c5;
  background: #f0faf5;
}

.task-row button,
.reminder-row button {
  margin-top: 10px;
  min-height: 34px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  padding: 0 10px;
  font-weight: 900;
}

@media (max-width: 1180px) {
  .kpi-grid,
  .profile-grid,
  .trend-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 720px) {
  .kpi-grid,
  .profile-grid,
  .trend-grid,
  .ocr-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .chronic-shell,
  .grid.two {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid,
  .api-flow,
  .score-grid {
    grid-template-columns: 1fr;
  }
}
