:root {
  /* 八王子総合クリニック ブランドカラー（文字・ボタンはコントラスト比4.5:1以上の濃い緑を使用） */
  --brand: #3f9e5e;
  --brand-strong: #2e7d46;
  --brand-deep: #17512c;
  --brand-soft: #e8f2eb;
  --brand-softer: #f4f9f5;
  --bg: #f4f9f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #4d4d4d;
  --line: #d6dcd8;
  --control: #8a8a8a;
  --primary: #2e7d46;
  --primary-ink: #ffffff;
  --primary-soft: #e8f2eb;
  --danger: #ce0000;
  --danger-soft: #fdeeee;
  --warn: #8a5300;
  --warn-soft: #fff4e0;
  --caution: #f5c400; /* 注意が必要な回答（黄色）。文字は --text を重ねる（白文字にしない） */
  --caution-soft: #fff8d9; /* 注意が必要な回答の背景 */
  --ok: #2e7d46;
  --ok-soft: #e8f2eb;
  --focus: #17512c; /* フォーカスの輪（= --brand-deep） */
  --focus-gap: #ffffff; /* 輪と部品の間の白い隙間 */
  --radius: 8px;
  /* 余白: 8px を基本単位とした段階だけを使う（docs/development/ui.md 3.） */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
  --sp-6: 40px;
  --sp-7: 56px;
  --shadow: 0 1px 2px rgba(23, 81, 44, 0.06), 0 2px 8px rgba(23, 81, 44, 0.06);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    16px/1.7 'Noto Sans JP',
    'Hiragino Sans',
    'Hiragino Kaku Gothic ProN',
    system-ui,
    -apple-system,
    Meiryo,
    sans-serif;
}
h1,
h2,
h3 {
  line-height: 1.35;
  margin: 0 0 0.5em;
}
h1 {
  font-size: 1.35rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 1rem;
}
p {
  margin: 0 0 0.75em;
}
a {
  color: var(--primary);
}
[hidden] {
  display: none !important;
}
.offscreen {
  position: fixed;
  top: -1000px;
  left: 0;
  opacity: 0;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.spacer {
  flex: 1;
}
.stack > * + * {
  margin-top: 1rem;
}

/* ---------- ボタン ---------- */
button,
.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 1rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-decoration: none;
}
button:hover {
  border-color: #b5c2c7;
}
/* フォーカス表示: 濃い緑の輪＋白い隙間の二重リング
   デジタル庁デザインシステムの既定（黄色＋黒）から、ブランドに合わせて変更。
   輪と背景のコントラスト比は8:1以上。白い隙間で、緑のボタンや「選択中」の枠とも見分けられる */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
.choice:has(input:focus-visible),
.pt-dept:has(input:focus-visible),
.pt-consent:has(input:focus-visible),
.photo-add:has(+ .photo-input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--focus-gap);
}
/* カード型の選択肢は、カードにだけ輪を出す（中のチェックボックスと二重にしない） */
/* （:has() に対応していない古いブラウザでは、チェックボックス側の輪を残す） */
@supports selector(:has(*)) {
  .choice input:focus-visible,
  .pt-dept input:focus-visible,
  .pt-consent input:focus-visible,
  .photo-input:focus-visible {
    outline: none;
    box-shadow: none;
  }
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--brand-deep);
  border-color: var(--brand-deep);
}
.btn-danger {
  color: var(--danger);
  border-color: #f1b8b2;
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
}
.btn-sm {
  min-height: 34px;
  padding: 0.25rem 0.65rem;
  font-size: 0.9rem;
}
.btn-lg {
  min-height: 54px;
  font-size: 1.05rem;
  padding: 0.75rem 1.5rem;
}
.btn-block {
  width: 100%;
}

/* ---------- フォーム ---------- */
input[type='text'],
input[type='email'],
input[type='tel'],
input[type='number'],
input[type='date'],
input[type='password'],
textarea,
select {
  font: inherit;
  width: 100%;
  border: 1px solid #c3cfd3;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  background: #fff;
  color: var(--text);
  min-height: 46px;
}
textarea {
  resize: vertical;
  min-height: 96px;
}
label.field {
  display: block;
}
label.field > span {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

/* ---------- 設問 ---------- */
.q {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}
.q:last-child {
  border-bottom: 0;
}
.q-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.q-help {
  font-size: 0.9rem;
  color: var(--muted);
  margin: -0.25rem 0 0.5rem;
}
.q-error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0.4rem 0 0;
}
.q.has-error input,
.q.has-error textarea,
.q.has-error .choice {
  border-color: var(--danger);
}
.q.info {
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  border: 0;
  margin: 0.5rem 0;
}
.req,
.opt {
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  margin-left: 0.5rem;
  vertical-align: 2px;
}
.req {
  background: var(--danger);
  color: #fff;
}
.opt {
  background: #e8edef;
  color: var(--muted);
}

.choices {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.choices.row {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid #c3cfd3;
  border-radius: 10px;
  background: #fff;
  padding: 0.65rem 0.8rem;
  min-height: 50px;
  cursor: pointer;
  user-select: none;
}
.choice input {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  accent-color: var(--primary);
  flex: none;
}
.choice.checked {
  border-color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}
.other-input {
  margin-top: 0.5rem;
}

.scale-row {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 4px;
}
.scale-btn {
  padding: 0;
  min-height: 46px;
  font-weight: 600;
  border-radius: 8px;
}
.scale-btn.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.scale-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.with-unit {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 240px;
}
.unit {
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- 通知 ---------- */
.alert {
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
}
.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f5c2bd;
}
.alert-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #f3d29a;
}
.alert-ok {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #b8e0c0;
}
.alert-info {
  background: var(--primary-soft);
  color: var(--brand-deep);
  border: 1px solid #bcdcc6;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #e8edef;
  color: var(--muted);
  white-space: nowrap;
}
.badge-new {
  background: #fde7e7;
  color: var(--danger);
}
.badge-reviewed {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge-done {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge-alert {
  background: var(--danger);
  color: #fff;
}
/* 注意が必要な回答: エラー（赤）と区別するため黄色にする。「⚠」と文言を付け、色だけに頼らない */
.badge-caution {
  background: var(--caution);
  color: var(--text);
  font-weight: 700;
}
.alert-caution {
  background: var(--caution-soft);
  color: var(--text);
  border: 1px solid var(--caution);
  border-left-width: 6px;
}
.badge-deep {
  background: #e9e5fb;
  color: #4b3aa8;
}
.badge-basic {
  background: var(--primary-soft);
  color: var(--brand-deep);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  transform: translate(-50%, 120px);
  background: #1c2529;
  color: #fff;
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  transition: transform 0.2s;
  z-index: 100;
  max-width: calc(100vw - 32px);
  visibility: hidden;
  pointer-events: none;
}
.toast.show {
  transform: translate(-50%, 0);
  visibility: visible;
  pointer-events: auto;
}
.toast.error {
  background: var(--danger);
}

/* ---------- 院内画面の共通レイアウト ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 1rem;
}
.topbar .brand {
  font-weight: 700;
  color: var(--primary);
}
.topbar nav {
  display: flex;
  gap: 0.25rem;
}
.topbar nav a {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.topbar nav a.active {
  background: var(--primary-soft);
  color: var(--brand-deep);
  font-weight: 600;
}
/* 大きな分類のメニュー（問診結果の確認／問診の編集／その他） */
.topbar .main-nav {
  gap: 0.25rem;
}
.topbar .main-nav a {
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
}
.topbar .main-nav a.active {
  background: var(--primary-soft);
  border-bottom-color: var(--brand-strong);
}
/* 分類の中の項目（上部のメニューと一緒に画面の上に固定する） */
.subnav {
  position: sticky;
  top: var(--topbar-h, 0);
  z-index: 9;
  display: flex;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  overflow-x: auto;
  background: var(--brand-softer);
  border-bottom: 1px solid var(--line);
}
.subnav a {
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--surface);
}
.subnav a.active {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
  color: #fff;
  font-weight: 600;
}
/* 問診票の編集画面: 「各科の問診票」は1つ上の場所（押すと一覧に戻る）として枠だけにし、横に今の問診票の名前を出す */
.subnav a.active.parent {
  background: var(--surface);
  color: var(--brand-strong);
}
.subnav-crumb {
  align-self: center;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
  padding: 0 0.25rem;
}
.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
table.tbl th,
table.tbl td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.tbl th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfb;
}
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

pre.copybox {
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font:
    14px/1.6 ui-monospace,
    'SF Mono',
    Menlo,
    Consolas,
    'Hiragino Sans',
    monospace;
  margin: 0;
  max-height: 60vh;
  overflow: auto;
}

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop {
  background: rgba(16, 24, 40, 0.45);
}

/* ---------- タッチ端末向け ---------- */
button,
.btn,
.choice,
a,
select,
input,
textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:active,
.btn:active {
  transform: translateY(1px);
}
.choice:active {
  background: var(--primary-soft);
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.bd-selects {
  display: grid;
  grid-template-columns: 2.2fr 1fr 1fr;
  gap: 0.5rem;
}
.choices {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}
@media (max-width: 480px) {
  .scale-row {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }
  .scale-btn {
    min-height: 48px;
  }
}
