/* 治療ノート — スマホ優先。文字サイズは html の fs-s / fs-m / fs-l で切り替える */
:root {
  --main: #1f6f8b;
  --main-dark: #17566c;
  --main-soft: #e3f1f5;
  --bg: #f4f8f9;
  --card: #ffffff;
  --text: #222;
  --muted: #667;
  --line: #d7e2e6;
  --high: #d9534f;
  --low: #2f6fd0;
  --warn-bg: #fde8ea;
  --latest: #dff3f7;
  --ok: #2e8b57;
}
html { font-size: 17px; }
html.fs-s { font-size: 15px; }
html.fs-l { font-size: 20px; }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.6; -webkit-text-size-adjust: 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
.loading { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--main); color: #fff;
  display: flex; align-items: center; gap: .5rem; padding: .55rem 1rem;
  padding-top: calc(.55rem + env(safe-area-inset-top));
}
.top h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 700; letter-spacing: .05em; }
.top h1 a { color: #fff; text-decoration: none; }
.top .who { font-size: .85rem; opacity: .9; }
.fs { display: flex; border: 1px solid rgba(255,255,255,.6); border-radius: 6px; overflow: hidden; }
.fs button { background: transparent; color: #fff; border: 0; padding: .1rem .45rem; font-size: .8rem; cursor: pointer; }
.fs button.on { background: #fff; color: var(--main); font-weight: 700; }

main { max-width: 980px; margin: 0 auto; padding: 1rem; }
h2 { font-size: 1.25rem; margin: .3rem 0 1rem; color: var(--main-dark); border-left: 5px solid var(--main); padding-left: .6rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; color: var(--main-dark); }

/* 下のメニュー（スマホ） */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; text-align: center; padding: .45rem 0 .4rem; color: var(--muted); text-decoration: none; font-size: .72rem; line-height: 1.3;
}
.nav a .i { display: block; font-size: 1.35rem; line-height: 1.2; }
.nav a.on { color: var(--main); font-weight: 700; }
@media (min-width: 820px) {
  body { padding-bottom: 0; }
  .nav { position: sticky; top: 3.1rem; bottom: auto; justify-content: center; border-top: 0; border-bottom: 1px solid var(--line); }
  .nav a { flex: 0 0 auto; padding: .6rem 1.2rem; font-size: .9rem; }
  .nav a .i { display: inline; font-size: 1rem; margin-right: .3rem; }
}

/* カード・ボタン */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-bottom: 1.2rem; }
@media (min-width: 820px) { .menu { grid-template-columns: repeat(3, 1fr); } }
.menu a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; min-height: 6.2rem;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--main-dark);
  font-weight: 700; text-align: center; padding: .6rem; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.menu a .i { font-size: 1.9rem; line-height: 1.2; }
.menu a.primary { background: var(--main); color: #fff; border-color: var(--main); }

.btn {
  display: inline-block; border: 1px solid var(--main); background: var(--main); color: #fff; border-radius: 8px;
  padding: .55rem 1.1rem; font-size: 1rem; cursor: pointer; text-decoration: none; font-family: inherit; line-height: 1.4;
}
.btn.sub { background: #fff; color: var(--main); }
.btn.danger { background: #fff; color: var(--high); border-color: var(--high); }
.btn.small { padding: .25rem .7rem; font-size: .85rem; }
.btn.wide { display: block; width: 100%; text-align: center; padding: .8rem; font-size: 1.1rem; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.actions .grow { flex: 1; }

/* 入力欄 */
label.f { display: block; font-weight: 700; margin: 1rem 0 .3rem; color: var(--main-dark); }
label.f small { font-weight: 400; color: var(--muted); margin-left: .3rem; }
input[type=text], input[type=date], input[type=password], input[type=number], select, textarea {
  width: 100%; font-size: 1rem; font-family: inherit; padding: .55rem .65rem; border: 1px solid #b9c9cf; border-radius: 8px; background: #fff; color: var(--text);
}
textarea { min-height: 5.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8cc5d6; border-color: var(--main); }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  border: 1px solid #b9c9cf; background: #fff; border-radius: 999px; padding: .35rem .85rem; font-size: .95rem; cursor: pointer; font-family: inherit; color: var(--text);
}
.chip.on { background: var(--main); border-color: var(--main); color: #fff; }

.faces { display: flex; gap: .35rem; }
.faces button {
  flex: 1; border: 1px solid #b9c9cf; background: #fff; border-radius: 10px; padding: .35rem 0; cursor: pointer; font-size: 1.6rem; line-height: 1.2; font-family: inherit;
}
.faces button small { display: block; font-size: .65rem; color: var(--muted); }
.faces button.on { background: var(--main-soft); border-color: var(--main); box-shadow: 0 0 0 2px var(--main) inset; }

/* 治療記録の一覧 */
.search { margin-bottom: 1rem; }
.visit { display: block; text-decoration: none; color: inherit; }
.visit .d { font-weight: 700; color: var(--main-dark); font-size: 1.05rem; }
.visit .tags { margin: .3rem 0; display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { background: var(--main-soft); color: var(--main-dark); border-radius: 6px; padding: 0 .5rem; font-size: .85rem; }
.tag.part { background: #fff3dc; color: #7a4d00; }
.visit .ex { color: var(--muted); font-size: .9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
dl.detail { margin: 0; }
dl.detail dt { font-weight: 700; color: var(--main-dark); margin-top: .9rem; font-size: .95rem; }
dl.detail dd { margin: .2rem 0 0; white-space: pre-wrap; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

/* 数値入力 */
details.cat { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: .7rem; }
details.cat summary { padding: .75rem 1rem; font-weight: 700; color: var(--main-dark); cursor: pointer; list-style: none; }
details.cat summary::after { content: "＋"; float: right; }
details.cat[open] summary::after { content: "－"; }
details.cat .rows { padding: 0 1rem .6rem; }
.vrow { display: grid; grid-template-columns: 1fr 7rem; gap: .5rem; align-items: center; padding: .45rem 0; border-top: 1px dashed var(--line); }
.vrow .n { line-height: 1.3; }
.vrow .n small { display: block; color: var(--muted); font-size: .78rem; }
.vrow input { text-align: right; }
.vrow input.hi { color: var(--high); font-weight: 700; background: var(--warn-bg); }
.vrow input.lo { color: var(--low); font-weight: 700; background: var(--warn-bg); }
.savebar { position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); padding: .6rem 0; background: linear-gradient(transparent, var(--bg) 30%); }
@media (min-width: 820px) { .savebar { bottom: 0; } }

/* 一覧表（参考：腎Webカルテの検査結果） */
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: .5rem 0; font-size: .9rem; }
.tablewrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: .45rem .5rem; white-space: nowrap; text-align: right; }
table.grid thead th { background: #f3e2c3; color: #4a3a1a; font-weight: 700; text-align: center; font-size: .82rem; line-height: 1.25; }
table.grid thead th.latest { background: #8fd3e0; }
table.grid td.latest { background: var(--latest); }
table.grid th.item { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 8.5rem; max-width: 11rem; white-space: normal; }
table.grid thead th.item { background: #f3e2c3; }
table.grid th.item a { color: var(--main-dark); text-decoration: none; font-weight: 700; }
table.grid th.item small { display: block; color: var(--muted); font-weight: 400; font-size: .75rem; }
table.grid td.ref { color: var(--muted); font-size: .8rem; text-align: center; }
table.grid tr.catrow th { background: var(--main-soft); color: var(--main-dark); text-align: left; position: sticky; left: 0; }
table.grid td.hi, table.grid td.lo { background: var(--warn-bg); font-weight: 700; }
table.grid td.hi { color: var(--high); }
table.grid td.lo { color: var(--low); }
.legend { font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.hi-t { color: var(--high); font-weight: 700; }
.lo-t { color: var(--low); font-weight: 700; }

/* グラフ */
.gctl { display: grid; grid-template-columns: 1fr; gap: .6rem; margin-bottom: .8rem; }
@media (min-width: 820px) { .gctl { grid-template-columns: 1fr 1fr auto; align-items: end; } }
.chartbox { position: relative; height: 320px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .6rem; }
@media (min-width: 820px) { .chartbox { height: 420px; } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .8rem; }
.stats div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .5rem; text-align: center; }
.stats b { display: block; font-size: 1.2rem; color: var(--main-dark); }
.stats span { font-size: .78rem; color: var(--muted); }

/* 設定 */
.itemrow { display: flex; align-items: center; gap: .5rem; padding: .5rem 0; border-top: 1px dashed var(--line); }
.itemrow .n { flex: 1; line-height: 1.3; }
.itemrow .n small { display: block; color: var(--muted); font-size: .78rem; }
.itemrow.hidden .n { opacity: .45; }

/* 知らせ */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: #333; color: #fff; padding: .6rem 1.2rem; border-radius: 999px; font-size: .95rem; box-shadow: 0 3px 12px rgba(0,0,0,.2);
}
.toast.err { background: var(--high); }
.note { font-size: .85rem; color: var(--muted); }
.next { background: #fff8e6; border-color: #f0d7a0; }
