:root {
  --border-color: #4a4a4a;
  --bg-paper: #ffffff;
  --bg-gray: #f0f0f0;
  --text-color: #333;
  --green-basic: #2d7d61;
  --green-respiratory: #4a9e7a;
  --yellow-digestive: #e8c97a;
  --blue-dampness: #7fb3e8;
  --darkblue-mental: #4a7fc7;
  --orange-diet: #c9763e;
  --red-sleep: #a03030;
  --brown-exercise: #8b6b4a;
  --yellowgreen-emotion: #b3c43a;
  --purple-living: #6a4c8c;
  --green-other: #2d5d46;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #e8e8e8;
  color: var(--text-color);
  font-family: "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: 16px 8px 80px;
}

.banner {
  max-width: 900px;
  margin: 0 auto 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
  font-size: 13px;
}

.page {
  max-width: 900px;
  margin: 0 auto 24px;
  background: var(--bg-paper);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  padding: 24px 20px 32px;
  position: relative;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  position: relative;
}

.logo {
  text-align: right;
  font-size: 13px;
  line-height: 1.3;
  color: #222;
  font-weight: 600;
  white-space: pre-line;
}
.logo small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.5px;
  font-weight: 400;
  color: #555;
  margin-top: 2px;
}

.title-wrap {
  flex: 1;
  text-align: center;
}

.main-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  margin: 0;
  color: #222;
}

.page-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid #2d7d61;
  border-radius: 50%;
  color: #2d7d61;
  font-size: 14px;
  font-weight: 700;
  vertical-align: middle;
  margin-left: 8px;
}

.habit-title {
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  margin: 0 0 16px;
  letter-spacing: 2px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 16px;
  font-size: 13px;
}

td, th {
  border: 1px solid var(--border-color);
  padding: 6px 4px;
  vertical-align: middle;
  text-align: center;
  word-break: break-word;
}

.section-title-row td {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  padding: 8px 4px;
  border: 1px solid var(--border-color);
}

.section-subtitle {
  font-size: 14px;
  font-weight: 600;
  margin-left: 8px;
  letter-spacing: 2px;
}

/* Basic info */
.basic-info-table tr {
  display: flex;
  flex-wrap: wrap;
}
.basic-info-table td {
  border: 1px solid var(--border-color);
  padding: 6px 4px;
  min-height: 38px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
.basic-info-table td.field-cell {
  gap: 6px;
  background: #fff;
}
.basic-info-table td.field-cell .field-label {
  flex: 0 1 auto;
  min-width: 0;
  font-weight: 500;
  color: #333;
}
.basic-info-table td.field-cell input[type="text"],
.basic-info-table td.field-cell input[type="date"] {
  flex: 1 1 40px;
  min-width: 40px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 13px;
  outline: none;
}

.inline-input {
  border: none;
  border-bottom: 1px solid #999;
  background: transparent;
  text-align: center;
  font-size: 13px;
  outline: none;
  width: 40px;
  margin: 0 4px;
}
.inline-input.wide {
  width: 80%;
  text-align: left;
  display: block;
  margin: 4px auto;
}

.label-with-input {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
}

.radio-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.radio-group .field-label.inline {
  margin-right: 4px;
}

.radio-inline, .checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 6px;
  white-space: nowrap;
}

input[type="radio"], input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0 2px 0 0;
  accent-color: #2d7d61;
  cursor: pointer;
}

/* Checkbox grid */
.checkbox-grid td {
  text-align: left;
  padding: 5px 4px 5px 6px;
  height: 34px;
}
.checkbox-grid .num {
  width: 26px;
  text-align: center;
  color: #444;
  font-size: 12px;
}
.checkbox-grid .text {
  flex: 1;
}
.checkbox-grid .check {
  width: 22px;
  text-align: center;
}
.checkbox-grid label {
  display: flex;
  align-items: center;
  width: 100%;
  cursor: pointer;
}
.checkbox-grid label .num {
  min-width: 22px;
}
.checkbox-grid label .text {
  flex: 1;
  padding: 0 4px;
}
.checkbox-grid label input[type="checkbox"] {
  margin-left: auto;
}

/* Others table */
.others-table td {
  text-align: left;
  padding: 6px 8px;
}
.others-table td.row-label {
  background: var(--bg-gray);
  text-align: center;
  font-weight: 500;
  width: 10%;
}
.others-table input[type="text"] {
  width: 100%;
  border: none;
  border-bottom: 1px solid #bbb;
  background: transparent;
  font-size: 13px;
  outline: none;
  padding: 2px 4px;
}
.others-table .checkbox-inline,
.others-table .radio-inline {
  margin: 0 10px 0 0;
}

/* Habit grid */
.habit-grid td {
  text-align: left;
  padding: 6px 4px 6px 8px;
  height: 36px;
}
.habit-grid label {
  display: flex;
  align-items: center;
  width: 100%;
  cursor: pointer;
}
.habit-grid label .text {
  flex: 1;
  padding-right: 6px;
}
.habit-grid label input[type="checkbox"] {
  margin-left: auto;
}

/* Footer */
.page-footer {
  margin-top: 24px;
  text-align: center;
}
.page-footer .slogan {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
  margin-bottom: 16px;
}
.page-footer .notes {
  font-size: 12px;
  color: #555;
  line-height: 1.8;
}
.page-footer .notes p {
  margin: 0;
}

/* Submit */
.submit-bar {
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
  padding: 0 12px;
}
.submit-bar button {
  background: var(--green-basic);
  color: #fff;
  border: none;
  padding: 14px 48px;
  font-size: 17px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 2px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.18);
}
.submit-bar button:disabled {
  background: #999;
  cursor: not-allowed;
}
.msg {
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}
.msg.ok { color: var(--green-basic); font-weight: 600; }
.msg.err { color: #c0392b; font-weight: 600; }

/* Responsive */
@media (max-width: 640px) {
  body { padding: 8px 4px 80px; }
  .page { padding: 16px 10px 24px; }
  .main-title, .habit-title { font-size: 20px; letter-spacing: 1px; }
  .logo { font-size: 11px; }
  table { font-size: 13px; }
  td, th { padding: 5px 2px; }
  .section-title-row td { font-size: 14px; letter-spacing: 2px; }

  /* 基本信息表：手机上一排两个字段，自诉等宽字段占一整行 */
  .basic-info-table tr {
    display: flex;
    flex-wrap: wrap;
  }
  .basic-info-table td.field-cell,
  .basic-info-table td {
    flex: 1 1 50% !important;
    min-width: 140px;
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    height: auto;
    min-height: 44px;
    justify-content: flex-start;
  }
  .basic-info-table td.field-cell.wide {
    flex: 1 1 100% !important;
  }
  .basic-info-table td.field-cell .field-label {
    flex: 0 0 auto;
    max-width: 50%;
    white-space: normal;
  }
  .basic-info-table td.field-cell input[type="text"],
  .basic-info-table td.field-cell input[type="date"] {
    flex: 1 1 60px;
    min-width: 60px;
  }

  /* 疾病史/亚健康：每行 2 项 */
  .checkbox-grid tr,
  .habit-grid tr {
    display: flex;
    flex-wrap: wrap;
  }
  .checkbox-grid td,
  .habit-grid td {
    flex: 1 1 50%;
    min-width: 140px;
    height: auto;
    min-height: 44px;
    border-bottom: 1px solid var(--border-color);
  }
  .checkbox-grid label,
  .habit-grid label {
    align-items: flex-start;
  }
  .checkbox-grid label .text,
  .habit-grid label .text {
    padding-right: 6px;
  }

  /* 过敏/用药/手术/先天：堆叠显示 */
  .others-table,
  .others-table tbody,
  .others-table tr,
  .others-table td {
    display: block;
    width: 100%;
  }
  .others-table tr {
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
  }
  .others-table td {
    border: none;
    border-bottom: 1px solid #e0e0e0;
    text-align: left;
  }
  .others-table td.row-label {
    width: 100%;
    text-align: left;
    background: var(--bg-gray);
    font-weight: 600;
  }
  .others-table td:last-child { border-bottom: none; }

  /* radio/checkbox 允许换行 */
  .radio-inline, .checkbox-inline {
    margin: 3px 10px 3px 0;
    font-size: 13px;
    white-space: normal;
  }
  .inline-input { width: 50px; }
}

@media print {
  body { background: #fff; padding: 0; }
  .page { box-shadow: none; margin: 0 auto; }
  .submit-bar { display: none; }
}
