:root {
  --c-main: #1f6fb2;
  --c-main-weak: #e3effa;
  --c-sel: #8cc0ec;
  --c-text: #1d2733;
  --c-sub: #5e6b78;
  --c-line: #d5dce3;
  --c-bg: #f4f6f8;
  --c-warn: #fff4d6;
  --c-danger: #c0392b;
  /* 文字のフォント（設定で変更。fonts.js が上書きする） */
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 上部 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--c-line);
}
.topbar h1 { margin: 0; font-size: 18px; color: var(--c-main); }
/* ロゴ */
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { height: 34px; width: auto; display: block; }
.brand h1 { padding-left: 12px; border-left: 1px solid var(--c-line); }
@media (max-width: 480px) { .brand img { height: 26px; } .brand h1 { font-size: 15px; padding-left: 8px; } .brand { gap: 8px; } }
.login-logo { width: 100%; max-width: 260px; height: auto; margin: 0 auto 4px; display: block; }
.login-box h1 { text-align: center; }
.topbar-staff select { margin-left: 6px; padding: 6px 8px; border: 1px solid var(--c-line); border-radius: 6px; background: #fff; }
.topbar-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
@media (max-width: 480px) { .topbar-nav .btn { padding: 6px 10px; } }

.view { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- 部品 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--c-line); border-radius: 8px; background: #fff;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--c-main); }
.btn.active { background: var(--c-main-weak); border-color: var(--c-main); color: var(--c-main); font-weight: 600; }
.btn.primary { background: var(--c-main); border-color: var(--c-main); color: #fff; font-weight: 600; }
.btn.danger { color: var(--c-danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }

.field { display: block; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.field input, .field textarea, .field select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--c-line); border-radius: 8px; background: #fff; font-weight: 400; font-size: 16px;
}
.field textarea { resize: vertical; }
.field small { font-weight: 400; color: var(--c-sub); }
.field-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.hint { margin: 4px 0 8px; font-size: 13px; font-weight: 400; color: var(--c-sub); }
.chk { font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; font-weight: 400; }
.chip {
  padding: 5px 11px; border: 1px solid var(--c-line); border-radius: 999px; background: #fff;
  font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--c-main); }
.chips[data-target] .chip::before { content: "＋"; color: var(--c-main); margin-right: 2px; }
.chip.on { background: var(--c-main); border-color: var(--c-main); color: #fff; }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; background: var(--c-main-weak); }
.banner.warn { background: var(--c-warn); border: 1px solid #f0d27a; }
.banner .btn { margin: 4px 4px 0 0; }

.edit-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.edit-actions.left { justify-content: flex-start; }
.save-state { margin-right: auto; font-size: 13px; color: var(--c-sub); }

#form, #view-settings { background: #fff; border: 1px solid var(--c-line); border-radius: 12px; padding: 16px; }

/* ---------- 一覧 ---------- */
.list-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.list-tools input[type=search] { flex: 1 1 240px; padding: 9px 12px; border: 1px solid var(--c-line); border-radius: 8px; font-size: 16px; }
.list-body { display: grid; gap: 8px; }
.card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 14px; background: #fff; border: 1px solid var(--c-line); border-radius: 10px;
}
.card-main { flex: 1 1 260px; cursor: pointer; }
.card-date { font-size: 13px; color: var(--c-sub); }
.card-name { font-size: 17px; font-weight: 700; }
.card-meta { font-size: 13px; color: var(--c-sub); }
.card-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: 32px 0; text-align: center; color: var(--c-sub); }

/* ---------- 同期・ログイン ---------- */
body.loading #app { visibility: hidden; }
.sync-state { border: none; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.sync-state.ok { background: #e6f5ea; color: #217a3c; }
.sync-state.wait { background: var(--c-main-weak); color: var(--c-main); }
.sync-state.off { background: var(--c-warn); color: #7a5b00; }
.login { position: fixed; inset: 0; z-index: 100; display: grid; grid-template-columns: minmax(0, 1fr); align-content: center; justify-items: center; background: var(--c-bg); padding: 16px; overflow-y: auto; }
.login-box { width: 100%; max-width: 360px; min-width: 0; background: #fff; border: 1px solid var(--c-line); border-radius: 14px; padding: 24px 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.login-box h1 { margin: 0; font-size: 20px; color: var(--c-main); }
.login-box input { width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--c-line); border-radius: 8px; font-size: 16px; }
.login-error { margin: 0; min-height: 1.2em; color: var(--c-danger); font-size: 13px; }

/* ---------- 患者様・ログ ---------- */
.list-tools select { padding: 9px 10px; border: 1px solid var(--c-line); border-radius: 8px; background: #fff; }
a.card.link { color: inherit; text-decoration: none; }
a.card.link:hover { border-color: var(--c-main); }
.chev { font-size: 24px; color: var(--c-sub); }
.card-memo { margin-top: 2px; font-size: 13px; color: #7a5b00; }
.back { color: var(--c-main); text-decoration: none; font-size: 14px; }
.pt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 12px; }
.pt-head h2 { margin: 0; font-size: 22px; }
.pt-head .btn { margin-left: auto; }
.panel { background: #fff; border: 1px solid var(--c-line); border-radius: 12px; padding: 14px 16px 4px; }
.sec-title { font-size: 15px; margin: 20px 0 8px; color: var(--c-sub); }
.digest { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0 0; font-size: 13px; }
.digest dt { color: var(--c-sub); }
.digest dd { margin: 0; word-break: break-all; }
.log-list { background: #fff; border: 1px solid var(--c-line); border-radius: 10px; overflow: hidden; }
.log-row {
  display: grid; grid-template-columns: 9.5em 8em 7em 1fr auto; align-items: center; gap: 4px 10px;
  padding: 8px 12px; border-top: 1px solid var(--c-line); font-size: 14px;
}
.log-row:first-child { border-top: none; }
.log-at { color: var(--c-sub); font-size: 13px; }
.log-act { justify-self: start; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef1f4; }
.log-act.act-pdf { background: var(--c-main-weak); color: var(--c-main); }
.log-act.act-share { background: #e3f6e8; color: #06873a; }
/* LINE で送るボタン */
.btn.line { background: #06c755; border-color: #06c755; color: #fff; font-weight: 600; }
.btn.line:disabled { opacity: .5; }
.warn-text { color: #7a5b00; }
/* 送る形式（画像／PDF） */
.sh-format { display: grid; gap: 8px; margin: 4px 0 10px; }
.sh-opt { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--c-line); border-radius: 10px; cursor: pointer; }
.sh-opt:has(input:checked) { border-color: #06c755; background: #effbf3; }
.sh-opt input { margin-top: 4px; width: auto; flex: none; }
.sh-opt span { display: grid; min-width: 0; }
.sh-opt small { color: var(--c-sub); font-size: 12px; }
.log-act.act-del { background: #fde8e6; color: var(--c-danger); }
.log-act.act-create, .log-act.act-copy { background: #e6f5ea; color: #217a3c; }
.log-btns { display: flex; gap: 6px; align-items: center; }
.log-gone { font-size: 12px; color: var(--c-sub); }
@media (max-width: 760px) {
  .log-row { grid-template-columns: 1fr auto; }
  .log-what { grid-column: 1 / -1; }
  .log-btns { grid-column: 1 / -1; }
}

/* ---------- 人体図（入力） ---------- */
.body-wrap { display: grid; grid-template-columns: minmax(280px, 1.1fr) 1fr; gap: 16px; align-items: start; font-weight: 400; }
@media (max-width: 760px) { .body-wrap { grid-template-columns: 1fr; } }
.body-figs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #fafcfe; border: 1px solid var(--c-line); border-radius: 10px; padding: 8px; }
.body-svg { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.body-svg .sil > * { fill: #fff; stroke: #4a5560; stroke-width: 2.4; }
.body-svg .rg { fill: #fff; stroke: #c5ced6; stroke-width: 0.7; cursor: pointer; transition: fill .12s; }
.body-svg .rg:hover { fill: var(--c-main-weak); }
.body-svg .rg.on { fill: var(--c-sel); stroke: var(--c-main); stroke-width: 1; }
.body-svg .badge circle { fill: #123f66; }
.body-svg .badge text { fill: #fff; font-size: 7.5px; font-weight: 700; text-anchor: middle; font-family: var(--font); }
/* 鍼（赤）と電気（青） */
:root { --c-needle: #d62828; --c-electric: #1f63d8; }
.body-svg .pin .dot { fill: var(--c-needle); stroke: #fff; stroke-width: 0.9; }
.body-svg .pin .hit, .body-svg .link .hit { fill: transparent; stroke: transparent; }
.body-svg .link .hit { stroke-width: 9; stroke-linecap: round; }
.body-svg .link .ln { stroke: var(--c-electric); stroke-width: 2; stroke-linecap: round; }
.body-svg .pin.sel .dot { stroke: var(--c-electric); stroke-width: 2.2; }
/* 部位を選ぶ時は鍼・電気を素通りさせる */
.mode-region .body-svg .pin, .mode-region .body-svg .link { pointer-events: none; }
.mode-needle .body-svg .pin, .mode-electric .body-svg .pin, .mode-electric .body-svg .link { cursor: pointer; }
.mode-needle .body-svg .rg, .mode-electric .body-svg .rg { cursor: crosshair; }
.mode-needle .body-svg .rg:hover, .mode-electric .body-svg .rg:hover { fill: #fff; }
.mode-needle .body-svg .rg.on:hover, .mode-electric .body-svg .rg.on:hover { fill: var(--c-sel); }
.mk-needle, .mk-electric { display: inline-block; vertical-align: middle; margin-right: 4px; }
.mk-needle { width: 9px; height: 9px; border-radius: 50%; background: var(--c-needle); }
.mk-electric { width: 16px; height: 3px; border-radius: 2px; background: var(--c-electric); }
.selected-summary li.nd { cursor: default; }
.body-svg .cap { font-size: 10px; text-anchor: middle; fill: #4a5560; font-weight: 700; }
.body-svg .side { font-size: 9px; text-anchor: middle; fill: #8a96a2; }
.body-svg .deco path { fill: none; stroke: #4a5560; stroke-width: 1.2; stroke-linecap: round; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.diagram-toggle, .mode-toggle { display: inline-flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.field-head > span { min-width: 0; }
.diagram-toggle .cnt { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: #123f66; color: #fff; font-size: 11px; }

.region-checks { display: grid; gap: 10px; max-height: 560px; overflow: auto; padding-right: 4px; }
.rc-title { font-size: 13px; font-weight: 700; color: var(--c-sub); margin-bottom: 4px; }
.rc-items { display: flex; flex-wrap: wrap; gap: 5px; }
.rc {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 9px; border: 1px solid var(--c-line); border-radius: 6px; background: #fff;
  font-size: 13px; cursor: pointer;
}
.rc i { width: 13px; height: 13px; border: 1.5px solid #9aa6b2; border-radius: 3px; display: inline-block; }
.rc b { min-width: 17px; height: 17px; border-radius: 50%; background: #123f66; color: #fff; font-size: 11px; display: inline-grid; place-items: center; }
.rc.on { background: var(--c-main-weak); border-color: var(--c-main); }

.selected-summary { margin-top: 10px; font-weight: 400; }
.selected-summary ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.selected-summary li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--c-line); border-radius: 8px; cursor: pointer; font-size: 14px;
}
.selected-summary li span { color: var(--c-sub); }
.num, .pinl {
  min-width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 11px; color: #fff; background: #123f66; font-family: var(--font);
}
.pinl { background: #d62828; }

/* ---------- ダイアログ ---------- */
.dialog { width: min(480px, calc(100vw - 24px)); border: none; border-radius: 14px; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(20, 30, 40, .45); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.preview-dialog { width: min(860px, calc(100vw - 24px)); }
.preview-scroll { max-height: 75vh; overflow: auto; background: #888; padding: 12px; border-radius: 8px; margin-bottom: 12px; }
.preview-scroll .sheet { margin: 0 auto; box-shadow: 0 2px 10px rgba(0,0,0,.3); zoom: .8; }
@media (max-width: 700px) { .preview-scroll .sheet { zoom: .45; } }

.phrase-edit { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; font-weight: 400; margin-top: 6px; }
hr { border: none; border-top: 1px solid var(--c-line); margin: 20px 0; }

/* ---------- A4 シート ---------- */
/* 画面上では見えない位置に置き、文字サイズの自動調整に使う */
.print-area { position: absolute; left: -10000px; top: 0; }

.sheet {
  --s: 1;
  width: 210mm; height: 297mm; overflow: hidden;
  padding: 11mm 13mm 9mm;
  background: #fff; color: #000;
  font-size: calc(10.5pt * var(--s)); line-height: 1.45;
  display: flex; flex-direction: column; gap: calc(2.2mm * var(--s));
  font-family: var(--font);
}
.sheet .lbl { font-weight: 700; white-space: nowrap; }
.sheet .ul { border-bottom: 0.3mm solid #000; padding: 0 2mm; min-height: 1.5em; display: inline-block; }
.sh-title { text-align: center; font-size: 20pt; font-weight: 700; letter-spacing: .15em; line-height: 1.2; }
.sh-to { font-size: 12pt; font-weight: 700; display: flex; align-items: flex-end; gap: 1mm; }
.sh-to .w-clinic { min-width: 40mm; text-align: center; }
.sh-row { display: flex; gap: 8mm; align-items: flex-end; }
.sh-patient { flex: 1.2; display: flex; align-items: flex-end; gap: 2mm; font-size: 11.5pt; }
.sh-patient .grow { flex: 1; font-size: 13pt; font-weight: 700; }
.sh-visit { flex: 1; display: flex; align-items: flex-end; gap: 2mm; }
.sh-visit .ul { flex: 1; }

.sh-box { border: 0.3mm solid #000; border-radius: 1.5mm; padding: 1.2mm 2.5mm 1.6mm; flex: 1 0 auto; min-height: calc(17mm * var(--s)); }
.sh-box .lbl { font-size: .92em; margin-bottom: .6mm; }
.sh-box .txt { white-space: normal; word-break: break-all; }
.sh-box .txt.big { font-size: 1.25em; font-weight: 700; }
.sh-complaint { min-height: calc(14mm * var(--s)); }

.sh-mid { display: flex; gap: 3mm; flex: 0 0 auto; }
.sh-figs { flex: 0 0 auto; border: 0.3mm solid #000; border-radius: 1.5mm; padding: 1.2mm 2mm; }
.sh-figs .figs { display: flex; gap: 1mm; }
.sh-figs .figset { display: flex; gap: 1mm; }
.sh-figs .figset-body .body-svg { height: calc(90mm * var(--s)); width: auto; }
/* 頭部は 2×2。身体の2体と同じ大きさの枠に収める */
.sh-figs .figset-head { display: grid; grid-template-columns: auto auto; gap: 1mm 1.5mm; }
.sh-figs .figset-head .body-svg { height: calc(44.5mm * var(--s)); width: auto; }
.sh-figs .figs { gap: 4mm; }
/* 身体と頭部の両方に印がある時は横に並べ、主訴などは下に回す */
.sh-mid.both { flex-direction: column; }
.sh-mid.both .sh-figs { align-self: stretch; }
.sh-mid.both .figs { justify-content: space-around; }
.sh-mid.both .sh-side { flex-direction: row; }
.sh-mid.both .sh-side > .sh-box { flex: 1 1 0; min-height: calc(18mm * var(--s)); }
.sh-side { flex: 1; display: flex; flex-direction: column; gap: calc(2.2mm * var(--s)); min-width: 0; }
.sh-side .sh-complaint { flex: 1 0 auto; }
.sh-reaction { flex: 1 0 auto; min-height: calc(14mm * var(--s)); }
.sh-next { flex: 0 0 auto; min-height: calc(14mm * var(--s)); }
.sh-regions { flex: 0 0 auto; min-height: 0; padding-bottom: 2mm; }

.body-svg.print .sil > * { fill: #fff; stroke: #000; stroke-width: 1.8; }
.body-svg.print .rg { fill: #fff; stroke: #c8c8c8; stroke-width: 0.5; }
.body-svg.print .rg.on { fill: #b9d4ee; stroke: #2b5f8f; stroke-width: 0.8; }
.body-svg.print .badge circle { fill: #000; }
.body-svg.print .pin .dot { fill: #d00; }
.body-svg.print .link .ln { stroke: #0050d0; stroke-width: 1.8; }
.sh-figs .legend { margin-left: 3mm; font-weight: 400; font-size: .85em; }
.sh-figs .legend .mk-needle { width: 2.2mm; height: 2.2mm; margin: 0 .8mm 0 2mm; background: #d00; }
.sh-figs .legend .mk-electric { width: 4.5mm; height: .7mm; margin: 0 .8mm 0 3mm; background: #0050d0; }
.rtable .mk-needle { width: 2.4mm; height: 2.4mm; margin: 0; background: #d00; }
.body-svg.print .cap, .body-svg.print .side { fill: #000; }
.body-svg.print .deco path { stroke: #000; stroke-width: 1; }

/* 施術内容の表 */
.rtable { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .95em; line-height: 1.35; }
.rtable th {
  font-size: .82em; font-weight: 700; text-align: left; color: #333;
  background: #eef2f6; border-bottom: 0.3mm solid #555; padding: .8mm 1.6mm;
}
.rtable td { border-bottom: 0.15mm solid #bbb; padding: 1.1mm 1.6mm; vertical-align: top; word-break: break-all; }
.rtable tbody tr:last-child td { border-bottom: none; }
.rtable tbody tr:nth-child(even) td { background: #f7f9fb; }
.rtable .c-no { width: 9mm; text-align: center; }
.rtable .c-part { width: 33mm; font-weight: 700; }
.rtable th.c-m { width: 34mm; }
.rtable .c-n { width: 11mm; text-align: right; white-space: nowrap; }
.rtable th.c-n { text-align: right; }
.rtable .c-pin { color: #555; }
.rtable .num, .rtable .pinl { min-width: 1.5em; height: 1.5em; font-size: .78em; }
.rtable .num { background: #000; }
.rtable .pinl { background: #d00; }

.sh-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm; flex: 0 0 auto; margin-top: 1mm; }
.sh-staff { display: flex; align-items: flex-end; gap: 2mm; font-size: 11.5pt; }
.sh-staff .ul { min-width: 45mm; font-weight: 700; }
.sh-org { text-align: left; font-size: 9pt; font-weight: 700; line-height: 1.35; }
.sh-org .org-name { font-size: 12pt; color: #1f6fb2; }

/* 印刷時はシートだけを出す */
@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { background: #fff; margin: 0; }
  #app, dialog { display: none !important; }
  .print-area { position: static; }
  .sheet { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}


/* スマホ：上部を固定せず、メニューは1行で横にスクロール。下のボタンは大きめに */
.edit-actions.bottom { margin-top: 16px; }
@media (max-width: 640px) {
  .topbar { position: static; padding: 8px 12px; gap: 6px 10px; }
  .topbar-nav { flex-wrap: nowrap; overflow-x: auto; width: 100%; margin-left: 0; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .topbar-nav .btn { flex: 0 0 auto; }
  .edit-actions.bottom { display: grid; grid-template-columns: 1fr 1fr; }
  .edit-actions.bottom .btn.line { grid-column: 1 / -1; grid-row: 1; min-height: 48px; font-size: 16px; }
}
