/* ============================================================
   院内カルテ — スタイル
   ティール基調（参考スクショの Dental X / Hub のトーンに合わせる）。
   スマホ／iPad／PCブラウザ兼用。下部タブ＋ボトムシートのモバイルUI。
   ============================================================ */
:root {
  --teal: #0f9e8e;
  --teal-d: #0a7d70;
  --teal-l: #e6f6f3;
  --ink: #1f2a30;
  --sub: #6b7b82;
  --line: #e3e9ec;
  --bg: #f4f7f8;
  --card: #ffffff;
  --danger: #d8584f;
  --warn: #e2a13b;
  --shadow: 0 1px 3px rgba(20,40,45,.08), 0 6px 18px rgba(20,40,45,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(64px + var(--safe-b));
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- ヘッダ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: linear-gradient(180deg, var(--teal), var(--teal-d));
  color: #fff; box-shadow: var(--shadow);
}
.topbar__menu {
  border: none; background: rgba(255,255,255,.18); color: #fff;
  width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.topbar__menu svg { width: 20px; height: 20px; }
.topbar__title { font-weight: 700; font-size: 17px; flex: 1; }
.topbar__mode {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: rgba(255,255,255,.2);
}
.topbar__mode.is-online { background: #fff; color: var(--teal-d); }
.topbar__mode.is-local  { background: #ffe9b8; color: #7a5400; }

/* ---------- 本体 ---------- */
.view { padding: 14px; max-width: 980px; margin: 0 auto; }
.section-title { font-size: 13px; font-weight: 700; color: var(--sub); margin: 18px 4px 8px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.muted { color: var(--sub); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 14px; border-radius: 11px; font-size: 15px; font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--teal-d); }
.btn--danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.fab {
  position: fixed; right: 16px; bottom: calc(78px + var(--safe-b)); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--teal); color: #fff; box-shadow: 0 6px 16px rgba(15,158,142,.45);
  display: flex; align-items: center; justify-content: center;
}
.ico--fab { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------- 入力 ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--sub); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-l); border-color: var(--teal); }
textarea { min-height: 70px; resize: vertical; }
.search { position: relative; }
.search input { padding-left: 38px; }
.search__ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--sub); }

/* ---------- 下部タブ ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; color: var(--sub); font-size: 11px; font-weight: 600;
}
.tab__ico { display:flex; align-items:center; justify-content:center; opacity: .7; }
.tab__ico svg { width: 23px; height: 23px; }
.tab.is-active { color: var(--teal-d); }
.tab.is-active .tab__ico { opacity: 1; }

/* ---------- リスト行 ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
}
.item__main { flex: 1; min-width: 0; }
.item__name { font-weight: 700; font-size: 15px; }
.item__sub { font-size: 12px; color: var(--sub); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__chev { color: var(--sub); font-size: 20px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--teal-l); color: var(--teal-d);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}

/* ---------- バッジ/チップ ---------- */
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--teal-l); color: var(--teal-d); }
.chip--gray { background: #eef1f2; color: var(--sub); }
.chip--warn { background: #fdf0d8; color: #8a6311; }
.chip--done { background: #e4f3ec; color: #1f7a4d; }
.chip--cancel { background: #fbe4e2; color: #9c3c34; }

/* ---------- ダッシュボード ---------- */
.hero { display: flex; align-items: center; gap: 13px; }
.hero__badge { width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, var(--teal), var(--teal-d)); display:flex; align-items:center; justify-content:center; flex-shrink:0; box-shadow: 0 4px 10px rgba(15,158,142,.35); }
.hero__txt { flex: 1; min-width: 0; }
.hero__ttl { font-weight: 800; font-size: 17px; }
.hero__donut { width: 58px; flex-shrink: 0; }
.donut { width: 58px; height: 58px; }
.donut-bg { fill: none; stroke: var(--line); stroke-width: 9; }
.donut-fg { fill: none; stroke: var(--teal); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.donut-n { font-size: 22px; font-weight: 800; fill: var(--teal-d); text-anchor: middle; }
.donut-l { font-size: 12px; fill: var(--sub); text-anchor: middle; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 10px 12px; text-align: center; box-shadow: var(--shadow); }
.stat__ico { display:flex; justify-content:center; color: var(--teal); margin-bottom: 4px; }
.stat__ico svg { width: 20px; height: 20px; }
.stat__n { font-size: 24px; font-weight: 800; color: var(--teal-d); line-height: 1.1; }
.stat__l { font-size: 11px; color: var(--sub); margin-top: 2px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick a { display: flex; flex-direction: column; gap: 5px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.quick .q-ico { width: 30px; height: 30px; border-radius: 9px; background: var(--teal-l); color: var(--teal-d); display:flex; align-items:center; justify-content:center; }
.quick .q-ico svg { width: 19px; height: 19px; }
.quick .q-lbl { font-weight: 700; }
.quick .q-sub { font-size: 12px; color: var(--sub); }

/* ---------- アイコン共通 ---------- */
.ico { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.btn .ico { width: 18px; height: 18px; }
.btn--icon { padding: 7px 9px; }
.btn--has-ico { gap: 6px; }
.section-title.with-ico { display: flex; align-items: center; gap: 6px; }
.section-title.with-ico .ico { width: 17px; height: 17px; color: var(--teal); }
.item__chev .ico { width: 18px; height: 18px; color: var(--sub); }

/* ---------- 予約: 日付ナビ ---------- */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav__date { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.daynav__date small { display: block; font-size: 11px; color: var(--sub); font-weight: 600; }

/* ---------- 予約: チェア別グリッド ---------- */
.sched { overflow: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; background: #fff; max-height: calc(100vh - 200px); }
.sched-grid { display: grid; position: relative; min-width: max-content; }
.sched-corner, .sched-chair { position: sticky; top: 0; z-index: 3; background: var(--teal-d); color: #fff; font-weight: 700; font-size: 12px; text-align: center; padding: 5px 4px; border-left: 1px solid rgba(255,255,255,.2); cursor: pointer; }
.sched-corner { left: 0; z-index: 4; font-size: 10px; line-height: 1.2; }
.sched-chair .sc-name { font-size: 12px; }
.sched-chair .sc-staff { font-size: 10px; font-weight: 600; opacity: .95; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-chair .sc-none { opacity: .6; font-weight: 500; }
.sched-times { position: relative; border-right: 1px solid var(--line); background: #fafcfc; position: sticky; left: 0; z-index: 2; }
.sched-hr { position: absolute; right: 4px; font-size: 10px; color: var(--sub); transform: translateY(-1px); }
.sched-col { position: relative; border-left: 1px solid var(--line); }
.sched-line { position: absolute; left: 0; right: 0; border-top: 1px solid #dde6e9; }   /* 毎正時=実線 */
.sched-line.half { border-top-style: dotted; }
.sched-line.dash { border-top: 1px dashed #e7eef0; }   /* 15/30/45分=破線 */
.appt-blk { position: absolute; left: 2px; right: 2px; border-radius: 6px; padding: 2px 4px; overflow: hidden; background: var(--teal-l); border-left: 3px solid var(--teal); box-shadow: 0 1px 2px rgba(0,0,0,.12); z-index: 1; }
.appt-blk .ab-t { font-weight: 700; font-size: 11px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-blk .ab-m { font-size: 10px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-blk[data-status="来院"]  { background:#eaf4ff; border-left-color:#3b82c4; }
.appt-blk[data-status="完了"]  { background:#e7f4ec; border-left-color:#2f9e6a; }
.appt-blk[data-status="キャンセル"] { background:#f6eeee; border-left-color:#bda0a0; opacity:.6; text-decoration: line-through; }
/* 選択中ブロック＋決定バー */
.sel-blk { position: absolute; left: 1px; right: 1px; border-radius: 6px; background: rgba(59,130,196,.30); border: 2px solid #3b82c4; z-index: 2; pointer-events: none; }
.selbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(74px + var(--safe-b)); z-index: 45; display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: 8px 10px; }
.selbar__t { font-weight: 800; font-size: 14px; color: var(--teal-d); }
.selbar__t small { display: block; font-size: 10px; color: var(--sub); font-weight: 600; }

/* ---------- 患者詳細タブ ---------- */
.tabs { display: flex; gap: 4px; background:#eef2f3; padding:4px; border-radius:12px; margin-bottom:14px; }
.tabs button { flex:1; border:none; background:transparent; padding:9px 4px; border-radius:9px; font-weight:700; font-size:13px; color:var(--sub); white-space:nowrap; }
.tabs button.is-active { background:#fff; color:var(--teal-d); box-shadow: var(--shadow); }
.tabs--scroll { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.tabs--scroll button { flex:0 0 auto; padding:9px 14px; }

/* 治療計画/見積 */
.plan-row { display:grid; grid-template-columns: 1fr 72px 44px 76px 28px; gap:6px; align-items:center; margin-bottom:6px; }
.plan-row input { padding:8px 8px; }
.plan-row .pl-sub { font-size:12px; text-align:right; color:var(--sub); }
.plan-row .pl-rm { border:none; background:#f4e4e2; color:var(--danger); border-radius:7px; height:30px; font-size:16px; }
.plan-total { text-align:right; font-size:14px; margin-top:6px; }
.plan-total b { font-size:20px; color:var(--teal-d); }

/* 所見チップ */
.chips-row { display:flex; flex-wrap:wrap; gap:7px; margin-bottom:4px; }

/* 写真タイムライン */
.date-jump { display:flex; gap:6px; overflow-x:auto; -webkit-overflow-scrolling:touch; padding-bottom:6px; margin-bottom:8px; }
.date-chip { flex:0 0 auto; border:1px solid var(--line); background:#fff; border-radius:999px; padding:6px 12px; font-weight:700; font-size:12px; color:var(--teal-d); }
.date-chip small { display:inline-block; margin-left:5px; background:var(--teal-l); border-radius:999px; padding:1px 6px; font-size:10px; }
.photo-day-h { font-weight:700; font-size:13px; margin:10px 2px 8px; padding-bottom:4px; border-bottom:1px solid var(--line); }

/* 印刷ドキュメント */
#printArea { display:none; }
.pdoc { color:#000; font-family: serif; }
@media print {
  body.printing > *:not(#printArea) { display:none !important; }
  body.printing #printArea { display:block; padding:0; }
  body { background:#fff; }
}
.pdoc h1 { font-size:20px; text-align:center; margin:0 0 16px; }
.pdoc-meta { font-size:13px; line-height:1.7; margin-bottom:14px; }
.pdoc-tbl { width:100%; border-collapse:collapse; font-size:13px; }
.pdoc-tbl th, .pdoc-tbl td { border:1px solid #888; padding:7px 9px; text-align:left; }
.pdoc-tbl .r { text-align:right; }
.pdoc-tbl tfoot th { font-size:15px; }
.pdoc-note { margin-top:12px; font-size:13px; white-space:pre-wrap; border:1px solid #ccc; padding:10px; border-radius:6px; }
.pdoc-foot { margin-top:18px; font-size:12px; color:#444; }

/* ---------- 歯式図（SVG 解剖図・Dental X 風） ---------- */
.chart-wrap { overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chart-svg { min-width: 720px; margin: 0 auto; background:
  radial-gradient(120% 70% at 50% 0%, #fbe9e3 0%, #f7ddd4 38%, transparent 60%),
  radial-gradient(120% 70% at 50% 100%, #fbe9e3 0%, #f7ddd4 38%, transparent 60%);
  border-radius: 12px; padding: 6px 4px; }
.svg-defs { position:absolute; width:0; height:0; }
.arch-svg { display:block; width:100%; height:auto; }
.tooth-hit { cursor:pointer; }
.t-hit { fill: transparent; }
.tooth-hit:active .t-crown, .tooth-hit:active .t-root { filter: brightness(.94); }

.t-crown { fill: url(#g-enamel); stroke:#c8bb9b; stroke-width:1.4; stroke-linejoin:round; }
.t-root  { fill: url(#g-root); stroke:#c8b88f; stroke-width:1.2; }
.t-crown.is-metal { fill: url(#g-gold); stroke:#b2851f; }
.t-root.is-rest { fill:#caa46f; stroke:#9c7740; }
.t-ghost { fill:#eceff0; stroke:#d4dbdd; stroke-width:1.2; stroke-dasharray:3 3; opacity:.85; }
.t-caries { fill:#c0392b; opacity:.82; }
.t-fill   { fill:#2f6fb0; opacity:.92; }
.t-bridge { fill: url(#g-gold); stroke:#b2851f; stroke-width:1; }
.t-implant{ fill: url(#g-metal); stroke:#6f797e; stroke-width:1.2; }
.t-thread { stroke:#6f797e; stroke-width:1.4; }
.t-note   { fill: var(--warn); stroke:#fff; stroke-width:1; }

.tooth-nums { display:grid; grid-template-columns: repeat(16, 1fr); margin: 2px 0; }
.tooth-nums span { text-align:center; font-size:13px; font-weight:800; color:var(--teal-d); padding:5px 0; letter-spacing:.5px; }
.tooth-nums span.mid { box-shadow: inset 1px 0 0 var(--line); }

/* 凡例（バケット代表色） */
.legend { display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; }
.legend .lg { display:inline-flex; align-items:center; gap:5px; font-size:11px; font-weight:600; color:var(--ink); }
.lg-sw { width:14px; height:14px; border-radius:4px; display:inline-block; border:1px solid #c8bb9b; background:#f6efe0; }
.lg-sw[data-bk="caries"]  { background:#c0392b; border-color:#8e271c; }
.lg-sw[data-bk="fill"]    { background:#2f6fb0; border-color:#23568a; }
.lg-sw[data-bk="crown"]   { background: linear-gradient(#f7e09a,#cf9c33); border-color:#b2851f; }
.lg-sw[data-bk="bridge"]  { background: linear-gradient(#f7e09a,#cf9c33); border-color:#b2851f; box-shadow: inset 0 0 0 2px #fff; }
.lg-sw[data-bk="impl"]    { background: linear-gradient(#cfd6da,#8f989d); border-color:#6f797e; }
.lg-sw[data-bk="rest"]    { background:#caa46f; border-color:#9c7740; }
.lg-sw[data-bk="missing"] { background:#eceff0; border-color:#c9d0d2; border-style:dashed; }
.lg-sw[data-bk="unerupt"] { background:#f3f5f6; border-color:#c9d0d2; border-style:dotted; }

/* 歯のSVG: 追加状態 */
.t-crown.is-nonvital { fill:#dfe1e0; }
.t-ghost.is-ue { opacity:.5; stroke-dasharray:2 2; }
.t-rct { stroke:#d14b3f; stroke-width:2.4; stroke-linecap:round; }
.t-impacted { fill:none; stroke:#8a5cc0; stroke-width:1.6; stroke-dasharray:4 3; }

/* 一括入力 */
.tooth-hit.is-sel .t-hit { fill: rgba(15,158,142,.20); }
.tooth-hit.is-sel .t-hit { stroke: var(--teal); stroke-width: 2; }
.chart-svg.is-bulk { outline: 2px dashed var(--teal-l); border-radius: 12px; }
.bulkbar { background:#fff; border:1px solid var(--line); border-radius:12px; padding:12px; box-shadow:var(--shadow); margin-bottom:12px; }
.bulk-grid .pal2 { padding:9px 4px; font-size:11px; }

/* フラグ・トグルチップ */
.flag-row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.flag-row .pal-grp-ttl { width:100%; }
.chiptgl { border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:999px; padding:8px 14px; font-weight:700; font-size:13px; }
.chiptgl[aria-pressed="true"] { background:var(--teal-l); border-color:var(--teal); color:var(--teal-d); }
.sf { stroke:#9aa6ab; stroke-width:.6; }
.mk-red { fill:#c0392b; }
.mk-redo { fill:none; stroke:#c0392b; stroke-width:2; }
.mk-frac { fill:none; stroke:#7d211a; stroke-width:2; stroke-linejoin:round; stroke-linecap:round; }
.mk-wsd { fill:#caa46f; stroke:#9c7740; stroke-width:.6; }

/* 状態パレット（グループ表示・ボトムシート内） */
.pal-grp-ttl { font-size:11px; font-weight:700; color:var(--sub); margin:12px 2px 6px; }
.pal2-grid { display:grid; grid-template-columns: repeat(5,1fr); gap:6px; }
.pal2 { border:1px solid var(--line); border-radius:9px; padding:11px 4px; font-weight:700; font-size:12px; background:#fff; color:var(--ink); position:relative; }
.pal2[aria-pressed="true"] { outline:3px solid var(--teal-l); border-color:var(--teal); color:var(--teal-d); }
.pal2::before { content:""; position:absolute; top:5px; left:5px; width:8px; height:8px; border-radius:3px; border:1px solid rgba(0,0,0,.15); background:#f6efe0; }
.pal2[data-bk="caries"]::before { background:#c0392b; }
.pal2[data-bk="fill"]::before   { background:#2f6fb0; }
.pal2[data-bk="crown"]::before  { background:linear-gradient(#f7e09a,#cf9c33); }
.pal2[data-bk="bridge"]::before { background:linear-gradient(#f7e09a,#cf9c33); }
.pal2[data-bk="impl"]::before   { background:linear-gradient(#cfd6da,#8f989d); }
.pal2[data-bk="rest"]::before   { background:#caa46f; }
.pal2[data-bk="missing"]::before{ background:#eceff0; }
.pal2[data-bk="mark"]::before   { background:#e2a13b; }
.pal2[data-bk="sound"]::before  { background:#fff; }

/* 部位選択（B/M/O/D/P） */
.surf-box:empty { display:none; }
.surf-box { display:flex; flex-direction:column; align-items:center; }
.surf-svg { display:block; }
.surf-svg .isf { stroke:#aeb8bc; stroke-width:1.2; cursor:pointer; }
.surf-svg .sfl { font-size:10px; fill:var(--sub); text-anchor:middle; font-weight:700; }
.surf-svg .sfl-o { fill:#fff; mix-blend-mode:difference; }

/* ---------- 歯周検査 ---------- */
.perio-card { cursor: pointer; }
.perio-card .chip { margin-left: 5px; }
.perio-charts { margin-top: 10px; display: grid; gap: 6px; }
.pc-arch { position: relative; background: linear-gradient(#fbfdfd, #f3f7f8); border: 1px solid var(--line); border-radius: 10px; padding: 4px 4px 0; }
.pc-lbl { position: absolute; top: 4px; left: 8px; font-size: 10px; font-weight: 700; color: var(--sub); }
.perio-chart { width: 100%; height: auto; display: block; }
.perio-chart .thr { stroke: #e9a59f; stroke-width: 1; stroke-dasharray: 4 3; }
.perio-chart .pline { fill: none; stroke: var(--teal); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.perio-chart .pp { fill: var(--teal); }
.perio-chart .pp.deep { fill: #c0392b; }
.perio-chart .pl { font-size: 7px; fill: var(--sub); text-anchor: middle; }

/* ---------- セグメント切替（並べて/重ねて） ---------- */
.segctl { display: inline-flex; background: #eef2f3; border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.segctl .seg { border: none; background: transparent; padding: 7px 16px; border-radius: 8px; font-weight: 700; font-size: 13px; color: var(--sub); }
.segctl .seg.is-active { background: #fff; color: var(--teal-d); box-shadow: var(--shadow); }

/* ---------- 写真ワイプ比較 ---------- */
.wipe { position: relative; width: 100%; aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; background: #000; user-select: none; touch-action: none; cursor: ew-resize; }
.wipe__layer { position: absolute; inset: 0; background-size: cover; background-position: center; }
.wipe__top { clip-path: inset(0 50% 0 0); }
.wipe__line { position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fff; transform: translateX(-1.5px); box-shadow: 0 0 6px rgba(0,0,0,.5); pointer-events: none; }
.wipe__grip { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 34px; height: 34px; border-radius: 50%; background: #fff; color: var(--teal-d); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.wipe__grip .ico { width: 20px; height: 20px; }
.wipe__tagL, .wipe__tagR { position: absolute; bottom: 8px; font-size: 11px; color: #fff; background: rgba(0,0,0,.5); padding: 3px 7px; border-radius: 6px; max-width: 45%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wipe__tagL { left: 8px; } .wipe__tagR { right: 8px; }

.perio-table { width:100%; border-collapse: collapse; font-size: 12px; min-width: 540px; }
.perio-table th, .perio-table td { border:1px solid var(--line); padding:3px; text-align:center; }
.perio-table th { background:#f3f6f7; color:var(--sub); font-weight:700; position: sticky; left: 0; }
.perio-table input { width:34px; padding:5px 2px; text-align:center; border-radius:6px; font-size:12px; }
.perio-table input.deep { background:#fdeceb; border-color:#e9a59f; color:#c0392b; font-weight:800; }
.perio-table td.na { color:var(--line); }
.perio-table select { padding:5px 4px; font-size:12px; }
/* BOP/PCR トグルセル */
.perio-table .dot { width:22px; height:22px; border-radius:50%; border:1px solid var(--line); background:#fff; padding:0; }
.perio-table .dot.on { background:#c0392b; border-color:#8e271c; }
.perio-table .sq { width:30px; height:24px; border-radius:6px; border:1px solid var(--line); background:#fff; font-size:11px; font-weight:700; color:var(--sub); padding:0; }
.perio-table .sq.on { background:#c0392b; border-color:#8e271c; color:#fff; }
/* 測定サブナビ（横スクロール可） */
.perio-sub { display:flex; overflow-x:auto; max-width:100%; -webkit-overflow-scrolling:touch; }
.perio-sub .seg { white-space:nowrap; padding:7px 12px; }
.pmeas { margin-top:6px; }

/* ポケット: マス目歯列＋キーパッド */
.pk-board { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.pk-board-inner { min-width:700px; padding:4px 0; }
.pk-arch-row { display:flex; gap:2px; justify-content:center; }
.pk-tooth { display:flex; flex-direction:column; align-items:center; width:42px; }
.pk-cells { display:grid; grid-template-columns:repeat(3,1fr); grid-auto-rows:17px; gap:1px; width:100%; }
.pdcell { font-size:11px; line-height:1; border:1px solid var(--line); background:#fff; padding:0; border-radius:3px; height:17px; color:var(--ink); }
.pdcell.deep { background:#fdeceb; color:#c0392b; font-weight:800; border-color:#e9a59f; }
.pdcell.cur { outline:2px solid var(--teal); outline-offset:-1px; z-index:1; }
.pdcell.is-bld { border-top:3px solid #d14b3f; }
.pdcell.is-pus { border-bottom:3px solid #8a5cc0; }
.pk-no { font-size:11px; font-weight:800; color:var(--teal-d); margin-top:2px; }
.pk-pad { position:sticky; bottom:0; background:#eef2f3; border-radius:12px; padding:10px; margin-top:10px; box-shadow:0 -2px 8px rgba(0,0,0,.06); }
.pk-keys { display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.pk-key { padding:11px 0; border:1px solid var(--line); border-radius:9px; background:#fff; font-weight:800; font-size:15px; }
.pk-key:active { background:var(--teal-l); }
.pk-bld { display:grid; grid-template-columns:repeat(4,1fr); gap:6px; margin-top:6px; }
.pk-bldbtn { padding:9px 0; border:1px solid var(--line); border-radius:9px; background:#fff; font-weight:700; font-size:12px; }

/* プラーク: 4分割Xマス＋率 */
.pq-rate { font-weight:700; margin:2px 2px 8px; }
.pq-rate b { font-size:22px; color:var(--teal-d); }
.pq-board { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.pq-arch-row { display:flex; gap:3px; justify-content:center; }
.pq-tooth { width:30px; display:flex; flex-direction:column; align-items:center; }
.pq-svg { width:26px; height:26px; }
.pqcell { fill:#fff; stroke:#cfd6da; stroke-width:.6; cursor:pointer; }
.pqcell.on { fill:#d83a2c; }
.pq-box { fill:none; stroke:#9aa6ab; stroke-width:1; }

/* 歯周検査表 出力（カード） */
.perio-out { overflow-x:auto; -webkit-overflow-scrolling:touch; background:linear-gradient(#fbfdfd,#f3f7f8); border:1px solid var(--line); border-radius:10px; padding:6px 4px; margin-top:6px; }
.perio-out > svg { display:block; min-width:560px; width:100%; height:auto; }
.perio-bar .pb-grn { fill:#cfe6dd; } .perio-bar .pb-org { fill:#f0c98a; } .perio-bar .pb-red { fill:#d97c72; }
.perio-bar .pb-gm { fill:#e7c14a; }
.perio-bar .pb-n { font-size:7px; fill:#5b6a70; text-anchor:middle; }
.perio-bar .pb-bld { fill:#c0392b; }
.plaque-mini .pq { fill:#fff; stroke:#cfd6da; stroke-width:.5; }
.plaque-mini .pq.on { fill:#d83a2c; }
.plaque-mini .pq-box { fill:none; stroke:#9aa6ab; stroke-width:.7; }
.perio-numrow .pl { font-size:8px; fill:var(--sub); text-anchor:middle; font-weight:700; }
.perio-stats { display:flex; flex-wrap:wrap; gap:10px 14px; margin-top:8px; font-size:12px; color:var(--sub); }
.perio-stats b { color:var(--teal-d); font-size:13px; }
.perio-summary { display:flex; gap:14px; flex-wrap:wrap; margin:8px 2px; font-size:13px; }
.perio-summary b { color: var(--teal-d); }

/* ---------- 写真 ---------- */
.photo-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap:8px; }
@media (min-width: 720px){ .photo-grid { grid-template-columns: repeat(5,1fr); } }
.photo-cell { position:relative; aspect-ratio:1; border-radius:10px; overflow:hidden; background:#000; border:1px solid var(--line); }
.photo-cell img { width:100%; height:100%; object-fit:cover; display:block; }
.photo-cell.is-sel { outline:3px solid var(--teal); }
.photo-cell .photo-cap { position:absolute; left:0; right:0; bottom:0; background:linear-gradient(transparent,rgba(0,0,0,.65)); color:#fff; font-size:10px; padding:10px 6px 4px; }
.photo-cell .photo-pick { position:absolute; top:5px; left:5px; width:20px; height:20px; border-radius:50%; background:rgba(255,255,255,.8); display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:800; color:var(--teal-d); }
.compare { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.compare figure { margin:0; }
.compare img { width:100%; border-radius:10px; background:#000; }
.compare figcaption { font-size:12px; color:var(--sub); text-align:center; margin-top:4px; }

/* ---------- ボトムシート ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20,30,33,.45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(20px + var(--safe-b));
  max-width: 720px; margin: 0 auto;
  animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet__grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 8px auto 12px; }
.sheet__title { font-weight: 800; font-size: 17px; margin: 0 0 14px; }
.sheet__actions { display:flex; gap:10px; margin-top: 8px; }

/* ---------- トースト/空状態 ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); z-index: 60;
  background: rgba(30,42,48,.95); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
}
.empty { text-align:center; color:var(--sub); padding:40px 16px; }
.empty .e-ico { font-size:40px; opacity:.5; }
.empty p { margin:10px 0 0; }

/* ============================================================
   スマホ最適化（狭幅・タッチ）
   ============================================================ */
/* iOS の入力フォーカス時ズーム抑止: 入力系は16px以上に */
input, select, textarea { font-size: 16px; }
.btn { min-height: 44px; }            /* タップ目標を確保 */
.btn--sm { min-height: 36px; }
.tab { min-height: 52px; }
.fab { width: 60px; height: 60px; bottom: calc(82px + var(--safe-b)); }

/* タブレット以上では本文を広く、余白を増やす */
@media (min-width: 768px) {
  .view { padding: 20px; }
}

/* スマホ縦（狭幅）: 余白圧縮・2カラムを1カラムへ・チャート操作性UP */
@media (max-width: 460px) {
  .view { padding: 11px; }
  .card { padding: 12px; border-radius: 12px; }
  .grid2 { grid-template-columns: 1fr; gap: 8px; }    /* フォームの2列を縦積み */
  .stat__n { font-size: 21px; }
  .stat__l { font-size: 10px; }
  .quick { grid-template-columns: 1fr; }              /* クイック操作も縦 */
  .tabs--scroll button { padding: 9px 12px; font-size: 13px; }
  .sheet { padding: 8px 12px calc(20px + var(--safe-b)); }
  .sheet__title { font-size: 16px; }

  /* 治療計画の明細: 狭幅は2段組レイアウト */
  .plan-row { grid-template-columns: 1fr 44px 28px; grid-template-areas: "name name name" "price qty rm" "sub sub sub"; gap: 5px 6px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .plan-row .pl-name { grid-area: name; }
  .plan-row .pl-price { grid-area: price; }
  .plan-row .pl-qty { grid-area: qty; }
  .plan-row .pl-rm { grid-area: rm; }
  .plan-row .pl-sub { grid-area: sub; text-align: right; }

  /* キーパッドのキーを大きく押しやすく */
  .pk-key { padding: 13px 0; font-size: 16px; }
  .pk-bldbtn { padding: 11px 0; }

  /* 歯式図/歯周/写真の横スクロール領域を画面端まで使う */
  .chart-wrap, .pk-board, .pq-board, .perio-out { margin-left: -11px; margin-right: -11px; padding-left: 11px; padding-right: 11px; }
  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .legend .lg { font-size: 10px; }
  .perio-stats { gap: 8px 12px; font-size: 11px; }
}

/* ごく狭い端末(<=360px) */
@media (max-width: 360px) {
  .stat-row { gap: 7px; }
  .pk-keys { gap: 5px; }
  .pk-key { padding: 12px 0; font-size: 15px; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
}

/* 横向き(ランドスケープ)のスマホ: シートの高さを抑え内部スクロール */
@media (max-height: 480px) and (orientation: landscape) {
  .sheet { max-height: 96vh; }
}

/* 横スクロールできる領域に控えめなスクロールバー */
.chart-wrap, .pk-board, .pq-board, .perio-out, .date-jump, .perio-sub, .tabs--scroll { scrollbar-width: thin; }

/* ---------- 手書きキャンバス（サブカルテ） ---------- */
body.cv-open { overflow: hidden; }
.cv-overlay { position: fixed; inset: 0; z-index: 70; background: #6b7b82; display: flex; flex-direction: column; }
.cv-bar { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-t)) 8px 6px; background: #2f3b40; color: #fff; flex-wrap: wrap; }
.cv-bar .cv-btn { border: none; background: rgba(255,255,255,.15); color: #fff; padding: 8px 12px; border-radius: 8px; font-weight: 700; font-size: 13px; }
.cv-bar .cv-done { background: var(--teal); }
.cv-tools { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; justify-content: center; }
.cv-ink { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); padding: 0; }
.cv-ink.is-on { border-color: #fff; box-shadow: 0 0 0 2px var(--teal); }
.cv-sz, .cv-tool { border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.12); color: #fff; padding: 7px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; }
.cv-sz.is-on, .cv-tool.is-on { background: var(--teal); border-color: var(--teal); }
.cv-tpl { padding: 7px 8px; border-radius: 8px; border: none; font-size: 12px; }
.cv-stage { position: relative; flex: 1; margin: 8px; background: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.3); overflow: hidden; }
.cv-bg, .cv-draw { position: absolute; inset: 0; }
.cv-draw { touch-action: none; cursor: crosshair; }

/* 書類サムネ */
.doc-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; flex-shrink: 0; }

/* ---------- 事務: タイムカード（カード実寸に氏名と年月だけオーバープリント） ---------- */
.tc-break { page-break-before: always; }
.tcard { position: relative; color: #000; font-family: -apple-system, "Hiragino Kaku Gothic ProN", sans-serif; overflow: hidden; }
.tc-abs { position: absolute; white-space: nowrap; font-weight: 700; color: #000; line-height: 1; }
/* 設定プレビュー */
.tc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tc-prevwrap { margin: 6px 0 10px; }
.tc-prev { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }
.tc-prev .tcard { box-shadow: inset 0 0 0 1px #eee; }

/* ---------- 事務: 給与封筒（長形3号 235×120mm 横） ---------- */
.env3 { width: 235mm; height: 120mm; position: relative; color: #000; font-family: serif; overflow: hidden; }
.env-top { position: absolute; top: 14mm; left: 16mm; right: 16mm; display: flex; align-items: center; gap: 8mm; }
.env-logo { height: 16mm; width: auto; }
.env-label { font-size: 18pt; }
.env-name { position: absolute; top: 48mm; left: 0; right: 0; text-align: center; font-size: 40pt; letter-spacing: 6pt; }
.env-sama { font-size: 26pt; letter-spacing: 0; }
.env-from { position: absolute; bottom: 12mm; right: 16mm; font-size: 12pt; }

/* 事務: スタッフ選択 */
.staff-pick { margin: 4px 0 6px; }
.staff-grp { margin: 10px 0 6px; display: flex; align-items: center; gap: 8px; }
.staff-grp .lnk { border: none; background: none; color: var(--teal-d); font-weight: 700; font-size: 12px; text-decoration: underline; }
.staff-chk { display: inline-flex; align-items: center; gap: 6px; background: #f4f7f8; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; margin: 0 6px 6px 0; font-size: 13px; font-weight: 600; }
.staff-chk input { width: auto; }
.env-sheet { }

/* ホームの当日ボード（ミニ・読み取り専用） */
.sched--mini { max-height: 340px; }
/* スクロール無しで全体表示（横=全列が画面幅に収まる／縦=1日分） */
.sched--fit { max-height: none; overflow: visible; }
.sched--fit .sched-grid { min-width: 0; }
.sched--fit .sched-corner, .sched--fit .sched-chair { position: static; padding: 2px 1px; }
.sched--fit .sched-chair .sc-name { font-size: 9px; }
.sched--fit .sched-chair .sc-staff { font-size: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched--fit .sched-times { position: relative; background: #f3f7f8; }
.sched--fit .sched-hr { font-size: 9px; right: 3px; color: var(--ink); font-weight: 600; }
.sched--fit .appt-blk { left: 0; right: 0; border-radius: 3px; padding: 0 1px; border-left-width: 2px; }
.sched--fit .appt-blk .ab-t { font-size: 7px; line-height: 1.1; }
.sched--mini .sched-corner { font-size: 9px; padding: 3px 2px; }
.sched--mini .sched-chair { padding: 3px 2px; }
.sched--mini .sched-chair .sc-name { font-size: 10px; }
.sched--mini .sched-chair .sc-staff { font-size: 9px; }
.sched--mini .sched-hr { font-size: 8px; }
.sched--mini .appt-blk { padding: 0 2px; border-left-width: 2px; }
.sched--mini .appt-blk .ab-t { font-size: 8px; line-height: 1.15; }

/* ---------- アプリ選択（ランチャー） ---------- */
.launcher { padding: 8px 4px; }
.launch-head { display: flex; align-items: center; gap: 12px; margin: 6px 4px 18px; }
.launch-head .tooth-logo { background: var(--teal); border-radius: 12px; padding: 6px; }
.launch-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 600px) { .launch-grid { grid-template-columns: 1fr 1fr; } }
.launch-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px; box-shadow: var(--shadow); }
.launch-tile:active { transform: translateY(1px); }
.launch-ico { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, var(--teal), var(--teal-d)); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.launch-ico .ico { width: 28px; height: 28px; }
.launch-t { font-weight: 800; font-size: 18px; }
.launch-s { font-size: 12px; color: var(--sub); }

/* ---------- 封筒・宛名（汎用） ---------- */
.env-g { position: relative; color: #000; font-family: serif; overflow: hidden; }
.env-g .eg-zip { position: absolute; top: 10mm; left: 14mm; font-size: 13pt; letter-spacing: 1pt; }
.env-g .eg-addr { position: absolute; top: 20mm; left: 14mm; font-size: 12pt; line-height: 1.6; }
.env-g .eg-name { position: absolute; top: 46%; left: 0; right: 0; text-align: center; font-size: 28pt; letter-spacing: 4pt; }
.env-g .eg-hon { font-size: 18pt; }
.env-g .eg-from { position: absolute; bottom: 8mm; right: 12mm; font-size: 10pt; line-height: 1.5; text-align: right; }

/* ---------- シフト表 ---------- */
.sh-table { border-collapse: collapse; font-size: 11px; }
.sh-table th, .sh-table td { border: 1px solid #cfd8db; padding: 0; text-align: center; }
.sh-table th { background: #f3f6f7; color: var(--sub); font-weight: 700; padding: 2px 3px; }
.sh-table th small { font-weight: 500; }
.sh-name { position: sticky; left: 0; background: #f3f6f7; min-width: 72px; text-align: left !important; padding: 4px 6px !important; z-index: 1; }
.sh-sun { color: #c0392b; } .sh-sat { color: #2566c8; }
.sh-cell { width: 26px; height: 30px; border: none; background: #fff; font-weight: 700; font-size: 12px; color: var(--ink); }
.sh-cell.off { background: #f1eceb; color: #b06; }
.sh-cell.paid { background: #eef6ec; color: #2f7a4d; }
.sh-print h2 { font-size: 16px; margin: 0 0 8px; }
.sh-print .sh-table { width: 100%; font-size: 10px; }
.sh-print .sh-cell { width: auto; }

/* ---------- 定型書類 ---------- */
.tu-prev { border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 13px; line-height: 1.7; min-height: 80px; background: #fff; white-space: normal; }
.doc-print { color: #000; font-family: serif; }
.doc-print .dp-title { font-size: 18pt; text-align: center; margin: 0 0 16pt; }
.doc-print .dp-body { font-size: 12pt; line-height: 2; }

/* ---------- 勤怠集計 ---------- */
.att-table { border-collapse: collapse; font-size: 12px; width: 100%; min-width: 420px; }
.att-table th, .att-table td { border: 1px solid #cfd8db; padding: 2px 4px; text-align: center; }
.att-table th { background: #f3f6f7; color: var(--sub); font-weight: 700; }
.att-table input { width: 56px; padding: 6px 4px; text-align: center; font-size: 13px; }
.att-table .at-work { font-weight: 700; color: var(--teal-d); }
.att-sum { margin: 10px 2px; font-size: 14px; }
.att-sum b { color: var(--teal-d); font-size: 16px; }

/* ---------- スキャンPDF 一括取込レビュー ---------- */
.pdfrev { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pdfrev-thumb { width: 46px; height: 60px; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; background: #fff; flex-shrink: 0; }
.pdfrev-main { flex: 1; min-width: 0; }
.pdfrev-times { font-size: 11px; color: var(--sub); margin-top: 4px; }

/* ---------- タイムカード: 手差し図・詳細折りたたみ ---------- */
.insert-guide { display: flex; align-items: center; gap: 12px; background: #f3f7f8; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0 12px; }
.insert-svg { width: 120px; height: auto; flex-shrink: 0; }
.insert-cap { font-size: 13px; color: var(--ink); line-height: 1.6; }
.tc-details { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; margin-bottom: 12px; background: #fff; }
.tc-details > summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--teal-d); padding: 8px 2px; list-style: none; }
.tc-details > summary::-webkit-details-marker { display: none; }
.tc-details > summary::before { content: "▸ "; }
.tc-details[open] > summary::before { content: "▾ "; }
