:root {
  --teal: #0f766e;
  --teal-dark: #0b5751;
  --bg: #f1f5f4;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e2e8e6;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: env(safe-area-inset-top) 12px 0;
  height: calc(52px + env(safe-area-inset-top));
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow);
}
.appbar h1 { font-size: 1.1rem; margin: 0; font-weight: 600; }
.icon-btn {
  background: none; border: none; color: #fff;
  font-size: 2rem; line-height: 1; cursor: pointer;
  width: 36px; height: 36px; margin-top: -2px;
}

#main { padding: 12px; max-width: 720px; margin: 0 auto; padding-bottom: 40px; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

/* ---- ホーム ---- */
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }
.patient-list { list-style: none; margin: 0; padding: 0; }
.patient-list li {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.patient-list li:active { background: #f8fafa; }
.pl-main .pl-chart { font-weight: 700; font-size: 1.05rem; }
.pl-main .pl-sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.pl-salt { text-align: right; white-space: nowrap; }
.pl-salt .val { font-weight: 700; font-size: 1.2rem; }
.pl-salt .val.over { color: var(--danger); }
.pl-salt .unit { color: var(--muted); font-size: .8rem; }
.pl-salt .date { color: var(--muted); font-size: .75rem; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }
.home-foot { margin-top: 16px; text-align: center; }

/* ---- フォーム ---- */
.form label { display: block; margin-bottom: 14px; font-size: .9rem; color: #374151; font-weight: 600; }
.form .row2 { display: flex; gap: 12px; }
.form .row2 label { flex: 1; }
.req { color: var(--danger); margin-left: 2px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; margin-top: 2px; }

input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15,118,110,.12);
}
textarea { resize: vertical; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ---- 和暦入力 ---- */
.wareki { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.wareki select.w-era { width: auto; margin-top: 0; padding: 11px 8px; }
.wareki input.w-num { width: 4em; margin-top: 0; text-align: center; }
.wareki .w-unit { color: var(--muted); font-size: .9rem; font-weight: 400; }
#birthPreview { color: var(--teal); font-weight: 600; }

/* ---- ボタン ---- */
.btn {
  border: none; border-radius: 9px; padding: 11px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:active { background: var(--teal-dark); }
.btn.ghost { background: none; color: var(--teal); padding: 10px 14px; }
.btn.danger { background: none; color: var(--danger); border: 1px solid var(--danger); }
.btn.danger:active { background: #fef2f2; }
.btn.sm { padding: 6px 12px; font-size: .85rem; }

/* ---- 患者情報バー ---- */
.patient-info { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 12px 16px; }
.patient-info .pi-chart { font-weight: 700; font-size: 1.05rem; width: 100%; }
.patient-info span.pi-item { color: var(--muted); font-size: .85rem; }

/* ---- 結果 ---- */
.result { border-left: 4px solid var(--teal); }
.result.over { border-left-color: var(--danger); }
.result .salt-big { font-size: 2.4rem; font-weight: 800; color: var(--teal); }
.result.over .salt-big { color: var(--danger); }
.result .salt-big .u { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.result .detail { margin-top: 10px; font-size: .85rem; color: var(--muted); line-height: 1.7; }
.result .detail b { color: var(--text); }
.result .warn { color: var(--warn); font-weight: 600; margin-top: 8px; }
.result .disc { font-size: .75rem; color: var(--muted); margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---- グラフ・テーブル ---- */
.chart-card { padding: 12px; }
.history-toolbar { margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; }
td.salt { font-weight: 700; }
td.salt.over { color: var(--danger); }
.row-del { color: var(--danger); background: none; border: none; font-size: 1rem; cursor: pointer; padding: 4px 8px; }

/* ---- データ管理 ---- */
h2 { font-size: 1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; line-height: 1.6; }
.import-label { display: block; margin-top: 14px; font-size: .9rem; font-weight: 600; }
.import-label input { margin-top: 8px; }

/* ---- トースト ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: .9rem; box-shadow: var(--shadow); z-index: 100; max-width: 90%;
}
