:root {
  --c-primary: #2b7a78;
  --c-primary-d: #205653;
  --c-accent: #3aafa9;
  --c-bg: #f4f6f8;
  --c-card: #ffffff;
  --c-border: #d9e0e3;
  --c-text: #1d2d2c;
  --c-muted: #6b7b7a;
  --c-danger: #c0392b;
  --radius: 10px;
  --gap: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
  font-size: 16px;
  line-height: 1.5;
}

/* sticky-footer (flexbox) パターン。position:fixed は iframe 内で崩れるため不使用 */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  gap: 8px;
}
.app-header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.header-back {
  background: transparent; border: none; color: #fff;
  font-size: 28px; line-height: 1; width: 32px; height: 32px;
  cursor: pointer; padding: 0; display: none;
}
.header-back.show { display: block; }

.app-nav {
  display: flex;
  background: var(--c-primary-d);
}
.app-nav a {
  flex: 1; text-align: center; color: #cfe7e5; text-decoration: none;
  padding: 10px 4px; font-size: 14px; border-bottom: 3px solid transparent;
}
.app-nav a.active { color: #fff; border-bottom-color: var(--c-accent); font-weight: 600; }

.app-view {
  flex: 1;
  padding: var(--gap);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  text-align: center;
  color: var(--c-muted);
  font-size: 11px;
  padding: 8px;
}

.loading { text-align: center; color: var(--c-muted); padding: 40px 0; }

/* ---- card / section ---- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
}
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 16px 0 8px; color: var(--c-primary-d); }
.muted { color: var(--c-muted); font-size: 13px; }

.summary-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.summary-grid .stat {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 12px 8px; text-align: center;
}
.summary-grid .stat .num { font-size: 24px; font-weight: 700; color: var(--c-primary); }
.summary-grid .stat .lbl { font-size: 11px; color: var(--c-muted); }

/* ---- list ---- */
.list-item {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; text-decoration: none; color: inherit;
}
.list-item:active { background: #eef5f4; }
.list-item .li-main { font-weight: 600; }
.list-item .li-sub { font-size: 12px; color: var(--c-muted); }
.list-item .chevron { color: var(--c-muted); font-size: 20px; }

.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  margin-left: 6px;
}
.badge.todo { background: #fdecea; color: var(--c-danger); }
.badge.done { background: #e8f5e9; color: #2e7d32; }
.badge.gray { background: #eceff1; color: var(--c-muted); }
.badge.karte { background: var(--c-primary); color: #fff; font-weight: 700; margin-left: 0; margin-right: 4px; }

/* 要対応ブロック（ホーム） */
.todo-block { margin-bottom: 12px; }
.todo-block:last-child { margin-bottom: 0; }
.todo-head { font-weight: 600; font-size: 13px; margin: 4px 0; }

/* 月切替バー（書類ハブ） */
.month-bar { display: flex; align-items: center; justify-content: space-between; }
.month-bar b { font-size: 16px; }

/* 書類チップ（①②③…） */
.docchip {
  display: inline-block; min-width: 18px; text-align: center;
  font-size: 12px; padding: 0 4px; border-radius: 4px; margin-right: 2px;
  background: #fdecea; color: var(--c-danger);
}
.docchip.done { background: #e8f5e9; color: #2e7d32; }

/* カルテ番号の見出し（患者ダッシュボード上部） */
.karte-no {
  display: inline-block;
  background: #e7f3f2; color: var(--c-primary-d);
  border: 1px solid var(--c-accent); border-radius: 8px;
  padding: 4px 12px; font-size: 14px; margin-bottom: 8px;
}
.karte-no b { font-size: 20px; margin-left: 4px; }

/* ---- buttons ---- */
.btn {
  display: inline-block; width: 100%; text-align: center;
  background: var(--c-primary); color: #fff; border: none;
  border-radius: var(--radius); padding: 13px; font-size: 16px;
  cursor: pointer; text-decoration: none; margin-bottom: 8px;
}
.btn:active { background: var(--c-primary-d); }
.btn.secondary { background: #fff; color: var(--c-primary); border: 1px solid var(--c-primary); }
.btn.danger { background: var(--c-danger); }
.btn.ghost { background: transparent; color: var(--c-primary); }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-bottom: 0; }

.menu-btn {
  display: flex; align-items: center; gap: 10px;
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 8px;
  cursor: pointer; text-decoration: none; color: inherit; font-size: 16px;
}
.menu-btn .ico { font-size: 22px; }
.menu-btn:active { background: #eef5f4; }

/* ---- forms ---- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--c-primary-d); margin-bottom: 5px; font-weight: 600; }
.field .req { color: var(--c-danger); margin-left: 3px; }
.field input[type=text], .field input[type=tel], .field input[type=date],
.field input[type=time], .field input[type=number], .field select, .field textarea {
  width: 100%; padding: 10px; border: 1px solid var(--c-border);
  border-radius: 8px; font-size: 16px; background: #fff; font-family: inherit;
}
.field textarea { min-height: 72px; resize: vertical; }
.field .hint { font-size: 11px; color: var(--c-muted); margin-top: 3px; }

.radio-group, .check-group { display: flex; flex-wrap: wrap; gap: 6px; }
.radio-group label, .check-group label {
  border: 1px solid var(--c-border); border-radius: 999px; padding: 7px 14px;
  font-size: 14px; cursor: pointer; background: #fff; user-select: none;
}
.radio-group input, .check-group input { display: none; }
.radio-group input:checked + span,
.radio-group label:has(input:checked),
.check-group label:has(input:checked) {
  /* fallback handled by JS class .sel */
}
.radio-group label.sel, .check-group label.sel {
  background: var(--c-accent); color: #fff; border-color: var(--c-accent);
}

/* tri-state group (あり/なし/分からない) compact */
.tri-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tri-row .tri-label { flex: 1; font-size: 14px; }
.tri-row .tri-opts { display: flex; gap: 4px; }
.tri-row .tri-opts label {
  border: 1px solid var(--c-border); border-radius: 6px; padding: 5px 9px;
  font-size: 12px; cursor: pointer; background: #fff;
}
.tri-row .tri-opts label.sel { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.tri-row .tri-opts input { display: none; }

.form-section {
  border-top: 1px solid var(--c-border);
  margin-top: 18px; padding-top: 14px;
}
.form-section:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.form-section > .sec-title {
  font-size: 15px; font-weight: 700; color: var(--c-primary);
  margin-bottom: 12px;
}
.subfield { padding-left: 12px; border-left: 2px solid var(--c-border); margin: 8px 0; }

/* ---- tooth chart ---- */
.tooth-chart { margin: 10px 0; }
.tooth-legend { font-size: 11px; color: var(--c-muted); margin-bottom: 8px; line-height: 1.7; }
.tooth-row { display: flex; justify-content: center; gap: 3px; margin-bottom: 4px; flex-wrap: nowrap; }
.tooth {
  width: 30px; height: 36px; border: 1px solid var(--c-border); border-radius: 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 9px; cursor: pointer; background: #fff; padding: 1px;
}
.tooth .t-num { color: var(--c-muted); font-size: 8px; }
.tooth .t-state { font-weight: 700; font-size: 11px; min-height: 12px; }
.tooth.set { background: #fff4e0; border-color: #e6a23c; }
.tooth-mid { border-left: 2px dashed var(--c-muted); }

/* ---- bottom sheet ---- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; z-index: 1000;
}
.sheet {
  background: #fff; width: 100%; border-radius: 16px 16px 0 0;
  padding: 16px; max-height: 80vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { margin: 0 0 12px; font-size: 16px; }
.sheet-opt {
  padding: 13px; border: 1px solid var(--c-border); border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; font-size: 15px;
}
.sheet-opt:active, .sheet-opt.sel { background: var(--c-accent); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 2000; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.inline-warn { background: #fff8e1; border: 1px solid #ffe082; color: #8a6d00;
  padding: 10px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ===========================================================
   印刷書類ビュー（書式 ①〜⑤ の再現）
   画面では拡大縮小して表示、印刷時は A4 にフィット
   =========================================================== */
.doc-toolbar {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.doc-page {
  background: #fff; color: #000; margin: 0 auto 16px;
  width: 210mm; min-height: 297mm; padding: 12mm;
  box-shadow: 0 0 6px rgba(0,0,0,.2);
  font-size: 10.5pt; line-height: 1.45;
}
.doc-scale { transform-origin: top left; }
.doc-page * { box-sizing: border-box; }
.doc-title { text-align: center; font-size: 14pt; font-weight: 700; margin: 0 0 2mm; }
.doc-subtitle { text-align: center; font-size: 10pt; margin: -1mm 0 3mm; }
.doc-page table { border-collapse: collapse; width: 100%; }
.doc-page td, .doc-page th { border: 1px solid #000; padding: 2px 4px; vertical-align: top; font-size: 9.5pt; }
.doc-page .noborder, .doc-page .noborder td { border: none; }
.doc-page .cb { font-family: monospace; }
.doc-row { display: flex; justify-content: space-between; align-items: flex-end; }
.doc-label-line { border-bottom: 1px solid #000; flex: 1; min-height: 1.4em; }
.doc-small { font-size: 8.5pt; }
.doc-section-label { font-size: 9.5pt; margin: 2mm 0 1mm; }
.doc-checks { font-size: 9.5pt; }
.doc-checks span { margin-right: 10px; white-space: nowrap; }

@media print {
  .app-header, .app-nav, .app-footer, .doc-toolbar, #sheetRoot { display: none !important; }
  .app-view { padding: 0; max-width: none; }
  body { background: #fff; }
  .doc-page { box-shadow: none; margin: 0; width: auto; min-height: auto; padding: 8mm;
              page-break-after: always; }
  .doc-scale { transform: none !important; }
}

/* ===== パスキー認証ゲート ===== */
#authGate {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-box {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: 14px; padding: 28px 22px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12); text-align: center;
}
.auth-box h1 { font-size: 20px; color: var(--c-primary-d); margin: 0 0 6px; }
.auth-sub { font-size: 13px; color: var(--c-muted); margin: 0 0 16px; }
.auth-msg { min-height: 18px; font-size: 13px; margin-bottom: 10px; white-space: pre-line; line-height: 1.5; }
.auth-msg.err { color: var(--c-danger); }
.auth-box details { text-align: left; margin-top: 14px; border-top: 1px solid #eee; padding-top: 10px; }
.auth-box summary { cursor: pointer; font-size: 13px; color: var(--c-primary); }
.auth-box details input {
  width: 100%; box-sizing: border-box; margin: 10px 0; padding: 10px;
  border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
.cred-row { display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 6px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
