:root {
  --green: #069b87;
  --green-dark: #047766;
  --purple: #a23785;
  --purple-dark: #792665;
  --ink: #17211f;
  --muted: #66736f;
  --line: #dbe7e4;
  --soft: #f6faf9;
  --card: #ffffff;
  --warning: #d97706;
  --danger: #a23785;
  --shadow: 0 18px 50px rgba(18, 43, 39, 0.11);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  color: white;
  background: linear-gradient(112deg, var(--green), #078a78 60%, var(--purple));
  box-shadow: 0 10px 30px rgba(6, 155, 135, 0.22);
}

.topbar h1,
.summary-heading h2,
.section-header h2 {
  margin: 0;
}

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

.draft-status {
  display: inline-flex;
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 650;
}

.eyebrow {
  margin: 0 0 6px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.78;
}

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

.primary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button {
  padding: 0 18px;
  color: white;
  background: var(--purple);
}

.ghost-button {
  padding: 0 16px;
  color: white;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.32);
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  gap: 18px;
  padding: 18px;
}

.sidebar,
.content-panel,
.summary-panel {
  min-width: 0;
}

.sidebar,
.summary-panel {
  position: sticky;
  top: 94px;
  align-self: start;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.patient-card,
.summary-panel,
.content-panel {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.patient-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.patient-card strong,
.patient-card span {
  display: block;
}

.patient-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(6, 155, 135, 0.12);
  flex: 0 0 auto;
}

.section-nav {
  display: grid;
  gap: 8px;
}

.nav-card {
  overflow: hidden;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.nav-card.is-active {
  background: var(--green);
  border-color: var(--green);
}

.nav-item {
  width: 100%;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 0;
  text-align: left;
}

.nav-card.is-active .nav-item {
  color: white;
}

.nav-index {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(6, 155, 135, 0.1);
  color: var(--green);
  font-weight: 800;
}

.nav-card.is-active .nav-index {
  color: var(--green);
  background: white;
}

.nav-title {
  display: block;
  font-weight: 750;
}

.nav-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.nav-card.is-active .nav-meta {
  color: rgba(255, 255, 255, 0.78);
}

.nav-progress {
  display: block;
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(6, 155, 135, 0.12);
}

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

.nav-card.is-active .nav-progress {
  background: rgba(255, 255, 255, 0.2);
}

.nav-card.is-active .nav-progress span {
  background: white;
}

.nav-missing-list {
  display: grid;
  gap: 4px;
  padding: 0 12px 12px 52px;
}

.nav-missing-link {
  padding: 4px 0;
  color: var(--purple);
  background: transparent;
  border: 0;
  text-align: left;
  font-size: 12px;
  line-height: 1.45;
}

.nav-card.is-active .nav-missing-link,
.nav-card.is-active .nav-missing-list span {
  color: rgba(255, 255, 255, 0.9);
}

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

.content-panel,
.summary-panel {
  border-radius: 8px;
}

.content-panel {
  padding: 22px;
}

.mobile-stepper {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  background: #fbfdfc;
}

.mobile-stepper span,
.mobile-stepper strong {
  display: block;
  text-align: center;
}

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

.icon-button {
  width: 42px;
  color: white;
  background: var(--green);
  font-size: 28px;
  line-height: 1;
}

.section-header {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.section-header .eyebrow,
.summary-panel .eyebrow {
  color: var(--green);
}

.section-header h2 {
  font-size: 25px;
}

.section-header p:last-child {
  max-width: 820px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.form-area {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.section-bottom-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section-bottom-nav button {
  min-height: 48px;
  font-size: 15px;
  white-space: normal;
}

.module {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.module-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: #fbfdfc;
  border-bottom: 1px solid var(--line);
}

.module-header h3 {
  margin: 0;
  font-size: 18px;
}

.module-header p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.score-pill {
  color: var(--green-dark);
  text-align: right;
  font-weight: 800;
}

.module-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--purple-dark);
  background: rgba(162, 55, 133, 0.08);
  border: 1px solid rgba(162, 55, 133, 0.18);
  border-radius: 8px;
  font-weight: 750;
}

.module-body {
  padding: 16px;
}

.module-result {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin: 0 16px 16px;
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(6, 155, 135, 0.08);
  border: 1px solid rgba(6, 155, 135, 0.18);
  border-radius: 8px;
}

.module-result span {
  font-size: 13px;
  font-weight: 750;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.question-title {
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.number-input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.computed-value {
  min-height: 42px;
  padding: 9px 11px;
  color: var(--green-dark);
  background: rgba(6, 155, 135, 0.08);
  border: 1px solid rgba(6, 155, 135, 0.2);
  border-radius: 8px;
  font-weight: 800;
}

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

.scale-group {
  padding: 14px;
  color: var(--green-dark);
  background: #edf7f5;
  border: 1px solid rgba(6, 155, 135, 0.2);
  border-radius: 8px;
}

.scale-group strong {
  display: block;
  font-size: 16px;
}

.scale-group p {
  margin: 8px 0 0;
  color: var(--ink);
  line-height: 1.65;
}

.question {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.question-title {
  margin-bottom: 10px;
  line-height: 1.5;
}

.question-note {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.mmse-figure {
  max-width: 360px;
  margin: 10px 0;
  padding: 12px;
  background: #fbfdfc;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.mmse-figure svg {
  display: block;
  width: 100%;
  height: auto;
}

.mmse-figure path {
  fill: none;
  stroke: #8a9692;
  stroke-width: 2;
}

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

.option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.option input {
  accent-color: var(--green);
}

.metric-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.42fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.metric-row:last-child {
  border-bottom: 0;
}

.metric-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.pain-reference {
  margin-top: 10px;
  overflow-x: auto;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pain-reference-title {
  padding: 10px 12px;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
  border-bottom: 1px solid var(--line);
  background: #edf7f5;
}

.pain-reference table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
}

.pain-reference th,
.pain-reference td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.pain-reference th {
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
  background: #f8fbfa;
}

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

.summary-panel {
  padding: 18px;
}

.summary-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

#completionBadge {
  padding: 7px 9px;
  color: white;
  background: var(--green);
  border-radius: 8px;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.summary-item {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfdfc;
}

.summary-item strong {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.summary-item p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tag {
  color: var(--green-dark);
}

.tag.warning {
  color: var(--warning);
}

.tag.danger {
  color: var(--danger);
}

.tag.pending {
  color: var(--muted);
}

.note-box {
  padding: 14px;
  border-radius: 8px;
  color: #3b2b38;
  background: rgba(162, 55, 133, 0.08);
  border: 1px solid rgba(162, 55, 133, 0.22);
}

.note-box p {
  margin: 8px 0 0;
  line-height: 1.6;
  white-space: pre-line;
}

.quality-box {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.quality-box p {
  margin: 8px 0 0;
  color: var(--muted);
}

.quality-box ul {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--text);
  line-height: 1.7;
}

.missing-jump {
  padding: 0;
  color: var(--purple);
  background: transparent;
  border: 0;
  text-align: left;
  font: inherit;
  line-height: inherit;
}

.missing-jump:hover,
.nav-missing-link:hover {
  text-decoration: underline;
}

.field.is-targeted,
.question.is-targeted,
.metric-row.is-targeted {
  outline: 3px solid rgba(162, 55, 133, 0.32);
  outline-offset: 4px;
  animation: targetPulse 1.1s ease-in-out 2;
}

@keyframes targetPulse {
  0%,
  100% {
    background-color: transparent;
  }

  50% {
    background-color: rgba(162, 55, 133, 0.08);
  }
}

.report-preview {
  display: grid;
  gap: 14px;
}

.report-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.report-stats div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.report-stats strong,
.report-stats span {
  display: block;
}

.report-stats strong {
  color: var(--green-dark);
  font-size: 24px;
}

.report-stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.result-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: white;
}

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

.result-table th {
  color: var(--green-dark);
  background: #edf7f5;
  font-size: 13px;
}

.signed-result {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.signed-result h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 20px;
  text-align: center;
}

.signed-info-table {
  width: 100%;
  margin-bottom: 10px;
  border-collapse: collapse;
  table-layout: fixed;
  color: var(--ink);
  font-size: 13px;
}

.signed-info-table td {
  padding: 3px 6px;
  border: 0;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

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

.signed-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  table-layout: fixed;
  background: white;
}

.signed-table th,
.signed-table td {
  height: 34px;
  padding: 6px 8px;
  color: var(--ink);
  border: 1px solid #23312e;
  text-align: center;
  vertical-align: middle;
  word-break: break-word;
}

.signed-table th {
  font-weight: 750;
  background: #f8fbfa;
}

.signed-table th:nth-child(1),
.signed-table td:nth-child(1) {
  width: 56px;
}

.signed-table th:nth-child(2),
.signed-table td:nth-child(2) {
  width: 208px;
}

.signed-table th:nth-child(3),
.signed-table td:nth-child(3) {
  width: 92px;
}

.signed-table th:nth-child(4),
.signed-table td:nth-child(4) {
  width: 140px;
}

.signed-table th:nth-child(5),
.signed-table td:nth-child(5),
.signed-table th:nth-child(6),
.signed-table td:nth-child(6) {
  width: 92px;
}

.signed-check {
  color: var(--green-dark);
  font-size: 18px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 50;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 16px;
  color: white;
  background: var(--green-dark);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

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

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .summary-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

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

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

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

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .topbar-actions button {
    grid-column: span 2;
    padding: 0 8px;
  }

  #wordBtn,
  #downloadBtn {
    grid-column: span 3;
  }

  .workspace {
    display: block;
    padding: 12px;
  }

  .sidebar {
    display: none;
  }

  .content-panel,
  .summary-panel {
    padding: 14px;
    box-shadow: none;
  }

  .summary-panel {
    margin-top: 12px;
  }

  .mobile-stepper {
    display: flex;
  }

  .section-bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-right: -14px;
    margin-left: -14px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -10px 24px rgba(6, 60, 52, 0.08);
  }

  .section-header h2 {
    font-size: 21px;
  }

  .field-grid,
  .option-grid,
  .summary-grid,
  .report-stats {
    grid-template-columns: 1fr;
  }

  .module-header {
    display: block;
  }

  .module-result {
    grid-template-columns: 1fr;
  }

  .score-pill {
    text-align: left;
  }

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

}

@media (max-width: 460px) {
  .topbar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions button {
    grid-column: span 1;
  }

  #wordBtn,
  #downloadBtn {
    grid-column: 1 / -1;
  }
}

@media print {
  .topbar,
  .sidebar,
  .mobile-stepper,
  .section-bottom-nav,
  .content-panel {
    display: none;
  }

  body {
    background: white;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .summary-panel {
    position: static;
    max-height: none;
    box-shadow: none;
    border: 0;
  }
}
