:root {
      --bg: #f6f7f4;
      --panel: #ffffff;
      --ink: #17231c;
      --muted: #68756d;
      --line: #dce4dc;
      --green: #16814a;
      --green-soft: #e6f4ec;
      --yellow: #9a6b00;
      --yellow-soft: #fff5d6;
      --red: #c7382f;
      --red-soft: #fde7e5;
      --blue: #2468a2;
      --purple: #7a5ca7;
      --shadow: 0 14px 40px rgba(34, 49, 37, 0.08);
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    }

    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      background: #dfe6df;
      color: var(--ink);
      font-size: 17px;
      line-height: 1.5;
      overflow-x: hidden;
    }

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

    a {
      color: inherit;
    }

    .app {
      width: min(430px, 100%);
      min-height: 100vh;
      margin: 0 auto;
      padding: 12px 12px 142px;
      background: var(--bg);
    }

    header,
    .page-title {
      display: grid;
      gap: 8px;
      padding: 12px 2px 16px;
    }

    .title-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

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

    h1 {
      font-size: 32px;
      line-height: 1.08;
      letter-spacing: 0;
    }

    h2 {
      font-size: 21px;
      line-height: 1.2;
      margin-bottom: 12px;
    }

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

    .section-title-row h2 {
      margin-bottom: 0;
    }

    .title-actions-inline {
      display: flex;
      align-items: center;
      gap: 14px;
      flex: 0 0 auto;
    }

    .text-button {
      border: 0;
      background: transparent;
      color: var(--green);
      font-size: 15px;
      font-weight: 800;
      padding: 6px 0 6px 10px;
      white-space: nowrap;
      cursor: pointer;
    }

    .subtle {
      color: var(--muted);
      font-size: 15px;
    }

    .page-title > .subtle,
    header > .subtle {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .compact-title {
      grid-template-columns: auto 1fr;
      align-items: start;
      gap: 10px;
    }

    .back-button {
      width: 36px;
      height: 36px;
      border: 0;
      background: transparent;
      color: var(--ink);
      font-size: 38px;
      line-height: 1;
      padding: 0;
      cursor: pointer;
    }

    .page {
      display: none;
    }

    .page.active {
      display: block;
    }

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

    .summary-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      margin-top: 0;
      margin-bottom: 12px;
    }

    .summary-grid .card:first-child {
      grid-column: 1 / -1;
    }

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

    .card {
      min-height: 110px;
      padding: 15px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      gap: 12px;
    }

    .panel {
      padding: 15px;
      margin-top: 12px;
    }

    .page-title + .panel {
      margin-top: 0;
    }

    .record-card {
      margin-top: 0;
      padding-top: 0;
      overflow: hidden;
    }

    .record-card h2 {
      display: none;
    }

    .metric {
      display: flex;
      align-items: baseline;
      gap: 8px;
      flex-wrap: wrap;
    }

    .latest-metric {
      align-items: center;
      flex-wrap: nowrap;
    }

    .metric strong {
      font-size: 34px;
      line-height: 1;
    }

    .button {
      min-height: 52px;
      border: 0;
      border-radius: 8px;
      background: #1c5d3d;
      color: #fff;
      padding: 0 18px;
      font-weight: 700;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      text-decoration: none;
      white-space: nowrap;
    }

    .button.secondary {
      background: #eef3ee;
      color: var(--ink);
      border: 1px solid var(--line);
    }

    .button.warn {
      background: #d92d20;
      color: #fff;
      border: 1px solid #d92d20;
    }

    .title-actions {
      display: flex;
      gap: 8px;
      flex-shrink: 0;
    }

    .title-actions .button {
      min-height: 42px;
      padding: 0 14px;
      font-size: 15px;
    }

    .status {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex: 0 0 auto;
      width: fit-content;
      min-height: 30px;
      border-radius: 999px;
      padding: 3px 11px;
      font-size: 14px;
      font-weight: 700;
      white-space: nowrap;
      word-break: keep-all;
    }

    .status.good {
      color: var(--green);
      background: var(--green-soft);
    }

    .status.watch {
      color: var(--yellow);
      background: var(--yellow-soft);
    }

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

    form {
      display: grid;
      gap: 13px;
    }

    .form-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 12px;
    }

    label {
      display: grid;
      gap: 7px;
      color: #2d3b31;
      font-weight: 700;
    }

    .input-hint {
      color: var(--muted);
      font-size: 13px;
      font-weight: 500;
    }

    .quick-group {
      display: grid;
      gap: 8px;
    }

    .quick-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }

    .quick-title > span:first-child {
      color: #2d3b31;
      font-size: 15px;
      font-weight: 800;
    }

    .quick-done {
      color: var(--green);
      cursor: pointer;
      font-size: 15px;
      font-weight: 800;
    }

    .quick-done[hidden] {
      display: none;
    }

    .quick-chips {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }

    .quick-chips button {
      min-height: 38px;
      border: 1px solid var(--line);
      border-radius: 999px;
      background: #fff;
      color: #315140;
      padding: 0 12px;
      font-size: 14px;
      font-weight: 800;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    .quick-chips .add-chip {
      border-style: dashed;
      color: var(--green);
      background: #f7fbf8;
    }

    .chip-x {
      color: #7d8780;
      font-size: 18px;
      line-height: 1;
      padding-left: 2px;
    }

    .label-row {
      display: flex;
      align-items: baseline;
      justify-content: space-between;
      gap: 10px;
    }

    .label-row span:last-child {
      flex: 0 0 auto;
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
      white-space: nowrap;
    }

    input,
    select,
    textarea {
      width: 100%;
      max-width: 100%;
      min-width: 0;
      min-height: 52px;
      border: 1px solid #cdd8cf;
      border-radius: 8px;
      background: #fff;
      color: var(--ink);
      padding: 11px 12px;
      outline: none;
    }

    input:disabled,
    select:disabled,
    textarea:disabled {
      background: #f6f8f6;
      color: var(--ink);
      opacity: 1;
    }

    input[type="datetime-local"] {
      -webkit-appearance: none;
      appearance: none;
      display: flex;
      align-items: center;
      height: 52px;
      font-size: 16px;
      line-height: 52px;
      padding-top: 0;
      padding-bottom: 0;
      text-align: left;
    }

    input[type="datetime-local"]::-webkit-date-and-time-value {
      min-width: 0;
      text-align: left;
      line-height: 52px;
    }

    input[type="date"] {
      -webkit-appearance: none;
      appearance: none;
      height: 52px;
      min-width: 0;
      font-size: 15px;
      line-height: 52px;
      padding: 0 10px;
    }

    input[type="date"]::-webkit-date-and-time-value {
      min-width: 0;
      text-align: left;
      line-height: 52px;
    }

    textarea {
      min-height: 78px;
      resize: vertical;
    }

    input:focus,
    select:focus,
    textarea:focus {
      border-color: #28764e;
      box-shadow: 0 0 0 3px rgba(40, 118, 78, 0.16);
    }

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

    .quick-form {
      background: var(--panel);
      border-color: var(--line);
    }

    .segment {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0;
      padding: 0;
      margin: 0 -15px 15px;
      border: 0;
      border-bottom: 1px solid var(--line);
      border-radius: 0;
      background: #fff;
    }

    .segment button {
      min-height: 54px;
      border: 0;
      border-right: 1px solid var(--line);
      border-radius: 0;
      background: #fff;
      color: var(--muted);
      font-weight: 800;
      cursor: pointer;
    }

    .segment button:last-child {
      border-right: 0;
    }

    .segment button.active {
      background: #1c5d3d;
      color: #fff;
      box-shadow: none;
    }

    .record-pane {
      display: none;
    }

    .record-pane.active {
      display: block;
    }

    .edit-actions {
      display: grid;
      grid-template-columns: 1fr;
      gap: 10px;
    }

    .edit-actions .button {
      width: 100%;
    }

    .delete-action {
      display: none;
      margin-top: 0;
    }

    .record-pane.editing .delete-action {
      display: inline-flex;
    }

    .record-pane.editing .edit-actions {
      grid-template-columns: 1fr 1fr;
    }

    .list {
      display: grid;
      gap: 10px;
    }

    .compact-list {
      gap: 8px;
    }

    .alert-panel {
      margin-top: 0;
      margin-bottom: 12px;
    }

    .alert-item {
      display: grid;
      gap: 3px;
      border-radius: 8px;
      padding: 10px 12px;
      border: 1px solid var(--line);
      background: #fbfcfb;
    }

    .alert-item strong {
      font-size: 16px;
      line-height: 1.25;
    }

    .alert-item p {
      color: var(--muted);
      font-size: 14px;
    }

    .alert-item.risk {
      border-color: #f1c9c5;
      background: var(--red-soft);
    }

    .alert-item.watch {
      border-color: #efe0a6;
      background: var(--yellow-soft);
    }

    .compact-empty {
      padding: 12px;
    }

    .list-item {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 13px;
      background: #fff;
      display: grid;
      gap: 6px;
    }

    .timeline-button {
      width: 100%;
      color: inherit;
      text-align: left;
      cursor: pointer;
      font: inherit;
      appearance: none;
      -webkit-appearance: none;
    }

    .all-records-list {
      display: grid;
      gap: 14px;
    }

    .records-month {
      color: var(--ink);
      font-size: 17px;
      font-weight: 800;
      padding: 0 2px 8px;
    }

    .records-month + .panel {
      margin-top: 0;
    }

    .date-record-group {
      display: grid;
      grid-template-columns: 34px minmax(0, 1fr);
      gap: 6px;
    }

    .month-divider {
      grid-column: 1 / -1;
      margin: 2px 0 -2px;
      padding: 0;
      background: transparent;
      color: var(--ink);
      font-size: 15px;
      font-weight: 800;
    }

    .month-divider span {
      display: inline-block;
      padding: 0 0 2px 0;
    }

    .date-rail {
      display: grid;
      justify-items: center;
      align-content: start;
      gap: 0;
      color: var(--muted);
      padding-top: 2px;
    }

    .date-rail strong {
      color: var(--muted);
      font-size: 26px;
      line-height: 1.05;
    }

    .date-rail span:last-child {
      font-size: 13px;
      line-height: 1.2;
    }

    .date-record-items {
      display: grid;
      gap: 10px;
      min-width: 0;
    }

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

    .item-head > div {
      min-width: 0;
    }

    .item-title {
      font-weight: 800;
      overflow-wrap: anywhere;
    }

    .pair {
      color: var(--muted);
      font-size: 14px;
    }

    .meal-title {
      color: #9a6b00;
    }

    .empty {
      display: grid;
      gap: 10px;
      padding: 18px;
      border-radius: 8px;
      border: 1px dashed #c8d4cb;
      background: #fbfcfb;
      color: var(--muted);
    }

    .empty strong {
      color: var(--ink);
      font-size: 18px;
    }

    .empty .button {
      width: fit-content;
      min-height: 42px;
      padding: 0 14px;
      font-size: 15px;
    }

    .chart-wrap {
      min-height: 0;
      overflow: hidden;
    }

    svg {
      width: 100%;
      height: auto;
      display: block;
    }

    .chart-wrap svg {
      height: 220px;
    }

    .legend {
      display: flex;
      gap: 14px;
      flex-wrap: wrap;
      margin-top: 2px;
      color: var(--muted);
      font-size: 14px;
    }

    .legend span {
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    .dot {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      display: inline-block;
    }

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

    .stat-box {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 12px;
      background: #fbfcfb;
    }

    .stat-box strong {
      display: block;
      font-size: 24px;
      line-height: 1.2;
      margin-top: 4px;
    }

    .medical-note {
      margin-top: 16px;
      padding: 14px 16px;
      border-radius: 8px;
      background: #eef3ee;
      color: #34443a;
      border: 1px solid var(--line);
      font-size: 15px;
    }

    .report-note {
      color: var(--muted);
      font-size: 15px;
    }

    .tab-bar {
      position: fixed;
      left: 50%;
      bottom: 0;
      z-index: 5;
      width: min(430px, 100%);
      transform: translateX(-50%);
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      align-items: center;
      gap: 0;
      min-height: calc(66px + env(safe-area-inset-bottom));
      padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
      background: rgba(255, 255, 255, 0.96);
      border: 1px solid var(--line);
      border-bottom: 0;
      border-radius: 8px 8px 0 0;
      box-shadow: 0 -10px 24px rgba(34, 49, 37, 0.08);
      transform: translate3d(-50%, 0, 0);
    }

    .tab-bar button {
      border: 0;
      background: transparent;
      display: flex;
      align-items: center;
      justify-content: center;
      align-self: stretch;
      min-width: 0;
      min-height: 48px;
      color: var(--muted);
      font-size: 17px;
      line-height: 1;
      font-weight: 700;
      padding: 0 2px;
      text-decoration: none;
      text-align: center;
      white-space: nowrap;
      word-break: keep-all;
      writing-mode: horizontal-tb;
      cursor: pointer;
    }

    .tab-bar button.active {
      color: var(--green);
    }

    .modal-backdrop {
      position: fixed;
      inset: 0;
      z-index: 10;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
      background: rgba(23, 35, 28, 0.36);
    }

    .modal-backdrop.open {
      display: flex;
    }

    .modal {
      width: min(380px, 100%);
      border-radius: 8px;
      border: 1px solid var(--line);
      background: #fff;
      box-shadow: 0 20px 60px rgba(23, 35, 28, 0.22);
      padding: 18px;
    }

    .modal p {
      margin-top: 8px;
      color: var(--muted);
      font-size: 15px;
    }

    .sheet-backdrop {
      align-items: flex-end;
      padding: 0;
    }

    .sheet-modal {
      border-bottom: 0;
      border-radius: 22px 22px 0 0;
      padding: 22px 14px calc(22px + env(safe-area-inset-bottom));
      width: min(430px, 100%);
    }

    .sheet-modal h2 {
      font-size: 22px;
      margin-bottom: 8px;
      text-align: center;
    }

    .sheet-modal p {
      margin-top: 0;
      text-align: center;
    }

    .sheet-list {
      display: grid;
      gap: 0;
      margin-top: 18px;
      overflow: hidden;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
    }

    .sheet-row {
      align-items: center;
      display: grid;
      grid-template-columns: 1fr minmax(0, 150px);
      gap: 12px;
      min-height: 62px;
      padding: 0 12px;
    }

    .sheet-row + .sheet-row {
      border-top: 1px solid var(--line);
    }

    .sheet-row > span {
      color: var(--ink);
      font-size: 17px;
      font-weight: 800;
    }

    .sheet-row input {
      border: 0;
      min-height: 50px;
      padding: 0;
      text-align: right;
    }

    .sheet-actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-top: 16px;
    }

    .modal-input-row {
      display: grid;
      gap: 8px;
      margin-top: 14px;
      color: #2d3b31;
      font-weight: 800;
    }

    .modal-input-row[hidden],
    #customInputLabel[hidden] {
      display: none;
    }

    .modal-actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-top: 16px;
    }

    .data-actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-top: 12px;
    }

    .data-actions .button {
      width: 100%;
    }

    .data-note {
      margin-top: 10px;
    }

    .export-range {
      gap: 10px;
    }

    .settings-data-section {
      margin-top: 12px;
    }

    .settings-group-label {
      color: var(--muted);
      font-size: 14px;
      font-weight: 800;
      margin: 0 0 6px 6px;
    }

    .settings-list {
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: var(--shadow);
      overflow: hidden;
    }

    .settings-row {
      align-items: center;
      display: grid;
      grid-template-columns: 38px minmax(0, 1fr) auto;
      gap: 10px;
      min-height: 76px;
      padding: 14px 14px;
    }

    .settings-row + .settings-row {
      border-top: 1px solid var(--line);
    }

    .settings-row-icon {
      align-items: center;
      color: #1f2d25;
      display: inline-flex;
      font-size: 27px;
      height: 38px;
      justify-content: center;
      line-height: 1;
      width: 38px;
    }

    .settings-row-main {
      display: grid;
      gap: 5px;
      min-width: 0;
    }

    .settings-row-main strong {
      color: var(--ink);
      font-size: 18px;
      line-height: 1.2;
    }

    .settings-row-main span {
      color: var(--muted);
      font-size: 13px;
      line-height: 1.35;
    }

    .settings-row-actions {
      align-items: center;
      display: flex;
      flex: 0 0 auto;
      gap: 12px;
    }

    .settings-row-actions .text-button {
      padding: 4px 0;
    }

    .muted-action {
      color: var(--muted);
    }

    .settings-row-stacked {
      align-items: stretch;
      grid-template-columns: 1fr;
    }

    .settings-row-top {
      align-items: center;
      display: grid;
      grid-template-columns: 38px minmax(0, 1fr) auto;
      gap: 10px;
    }

    .target-form {
      gap: 12px;
    }

    .target-grid {
      display: grid;
      gap: 12px;
    }

    .target-form .button {
      width: 100%;
    }

    .range-segment {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 0;
      border: 1px solid var(--line);
      border-radius: 8px;
      overflow: hidden;
      background: #fff;
    }

    .range-segment button {
      min-height: 48px;
      border: 0;
      border-right: 1px solid var(--line);
      background: #fff;
      color: var(--muted);
      font-weight: 800;
      cursor: pointer;
    }

    .range-segment button:last-child {
      border-right: 0;
    }

    .range-segment button.active {
      background: #1c5d3d;
      color: #fff;
    }

    .compact-segment {
      margin-bottom: 12px;
    }

    .visit-report {
      display: grid;
      gap: 14px;
      border: 0;
      border-radius: 0;
      background: transparent;
      padding: 0;
    }

    .visit-report-head {
      display: grid;
      gap: 6px;
      border-bottom: 1px solid var(--line);
      padding-bottom: 12px;
    }

    .visit-report-head strong {
      font-size: 22px;
      line-height: 1.2;
    }

    .visit-section {
      display: grid;
      gap: 10px;
      padding-top: 8px;
    }

    .visit-section h3 {
      font-size: 21px;
      line-height: 1.25;
    }

    .visit-section-head h3 {
      display: inline-flex;
      align-items: baseline;
      gap: 8px;
      margin: 0;
    }

    .visit-section-head h3 span {
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
      white-space: nowrap;
    }

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

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

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

    .visit-kpi strong {
      display: block;
      margin-top: 3px;
      font-size: 22px;
      line-height: 1.2;
    }

    .visit-list {
      display: grid;
      gap: 7px;
      margin: 0;
      padding: 0;
      list-style: none;
    }

    .visit-list li {
      display: flex;
      justify-content: space-between;
      gap: 10px;
      border-bottom: 1px solid #edf2ed;
      padding-bottom: 7px;
      color: #2d3b31;
    }

    .visit-list li:last-child {
      border-bottom: 0;
      padding-bottom: 0;
    }

    .visit-list span {
      min-width: 0;
      overflow-wrap: anywhere;
    }

    .visit-list strong {
      flex: 0 0 auto;
      white-space: nowrap;
    }

    .visit-list .visit-long-value {
      flex: 1 1 auto;
      text-align: right;
      display: grid;
      justify-items: end;
      gap: 2px;
      white-space: normal;
      overflow-wrap: anywhere;
    }

    .visit-list .visit-anomaly-row > span {
      flex: 0 0 auto;
      white-space: nowrap;
      overflow-wrap: normal;
    }

    .file-input {
      position: absolute;
      width: 1px;
      height: 1px;
      opacity: 0;
      pointer-events: none;
    }

    .update-prompt {
      position: fixed;
      left: 50%;
      bottom: 92px;
      z-index: 20;
      transform: translateX(-50%);
      width: min(390px, calc(100% - 28px));
      min-height: 48px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      box-shadow: 0 16px 46px rgba(23, 35, 28, 0.18);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 9px 12px;
      color: var(--ink);
      font-size: 15px;
      font-weight: 700;
    }

    .update-prompt button {
      min-height: 34px;
      border: 0;
      border-radius: 8px;
      background: #1c5d3d;
      color: #fff;
      padding: 0 14px;
      font-weight: 800;
      white-space: nowrap;
    }

    @media (max-width: 520px) {
      .app {
        padding: 12px 10px 142px;
      }

      .panel,
      .card {
        padding: 15px;
      }

      .record-card {
        padding-top: 0;
      }
    }
  
