/**
 * 医師用アプリ スタイル（PC/タブレット主体。データ表示重視）
 */
/* 閲覧のみロール(施設担当医=マスタ閲覧のみ / 分担研究者=施設・医師権限は閲覧のみ)の入力を読み取り専用に見せる。
   操作ボタンは applyPermissionUi で非表示、保存APIもサーバ側で拒否する。多層防御。
   対象は編集フォーム(#disease-form)内に限定する(#disease-select は表示する疾患を切り替える閲覧用UIのため対象外)。 */
body.ro-masters #disease-form input,
body.ro-masters #disease-form select,
body.ro-masters #disease-form textarea,
body.ro-orgs #panel-orgs input,
body.ro-orgs #panel-orgs select {
    pointer-events: none;
    background: var(--rt-gray-bg);
    color: var(--rt-gray-ink);
}
/* わかばテーマ(全アプリ共通デザイン言語・医師版はゴシックのまま可読性優先)。
   色の値は design/tokens.css だけが持つ(tokens.css を先に読み込む)。
   ここはトークンをこのファイルのローカル名で受ける層。値は書かない。
   角丸・文字サイズ・情報密度は業務UIとして患者アプリとは別に保つ。 */
:root {
    --color-bg: var(--rt-doctor-bg);
    --color-text: var(--rt-doctor-ink);
    --color-text-secondary: var(--rt-ink-soft);
    --color-primary: var(--rt-primary);
    --color-primary-light: var(--rt-primary-light);
    --color-primary-dark: var(--rt-primary-dark);
    --color-white: var(--rt-card);
    --color-border: var(--rt-doctor-line);
    --color-error: var(--rt-error);
    --color-ok: var(--rt-ok);
    --border-radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* hidden 属性を常に最優先で効かせる(display:flex/grid を持つ要素に hidden を付けても確実に隠す) */
[hidden] { display: none !important; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    font-size: 16px; line-height: 1.6; color: var(--color-text); background: var(--color-bg);
}
.muted { color: var(--color-text-secondary); font-size: 14px; }

.screen { display: none; }
.screen.active { display: block; }
#screen-loading.active, #screen-error.active { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.center-box { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px; }
.spinner { width: 44px; height: 44px; border: 5px solid var(--color-primary-light); border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 「読み込み中…」を穏やかに点滅させて目立たせる */
.loading-pulse {
    color: var(--color-primary);
    font-weight: 600;
    animation: rtq-loading-pulse 1.1s ease-in-out infinite;
}
.loading-pulse::before {
    content: '●';
    display: inline-block;
    margin-right: 7px;
    font-size: 0.7em;
    vertical-align: middle;
    animation: rtq-loading-blink 1.1s ease-in-out infinite;
}
@keyframes rtq-loading-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes rtq-loading-blink { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.2; transform: scale(0.7); } }
@media (prefers-reduced-motion: reduce) {
    .loading-pulse, .loading-pulse::before { animation-duration: 0.001s; opacity: 1; }
}

/* トップバー */
.topbar {
    position: sticky; top: 0; z-index: 10;
    background: var(--color-primary); color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px;
}
.topbar-left { display: flex; align-items: center; }
.topbar-right { display: flex; gap: 8px; }
/* 医師名はトップバー右側(再読み込みボタンの左隣)に右揃えで表示 */
.doctor-info { margin-right: 12px; font-size: 14px; opacity: 0.95; align-self: center; text-align: right; }
.btn-mini {
    background: rgba(255,255,255,0.2); color: #fff; border: 1px solid rgba(255,255,255,0.5);
    border-radius: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.btn-mini:hover { background: rgba(255,255,255,0.3); }

/* タブ(フラット1列。グループ分けは廃止) */
.tab-nav {
    position: sticky; top: 50px; z-index: 9;
    display: flex; align-items: stretch; flex-wrap: wrap; gap: 2px;
    background: #fff; border-bottom: 2px solid var(--color-border); padding: 0 12px;
}
.tab {
    background: none; border: none; border-bottom: 3px solid transparent;
    padding: 12px 16px; font-size: 15px; color: var(--color-text-secondary); cursor: pointer;
}
.tab:hover { color: var(--color-primary); }
.tab.active { color: var(--color-primary-dark); border-bottom-color: var(--color-primary); font-weight: 600; }
.tab[hidden] { display: none; }

.tab-panel { display: none; flex-direction: column; gap: 20px; }
.tab-panel.active { display: flex; }

/* [#31] 患者一覧の視認性向上のため表示幅を拡張 */
.content { max-width: 1360px; margin: 0 auto; padding: 20px; }

/* 患者表の行ボタン（トップバーの btn-mini を上書き） */
.btn-edit, .btn-save, .btn-cancel {
    background: var(--color-primary); color: #fff; border: none;
    border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.btn-edit:hover, .btn-save:hover { background: var(--color-primary-dark); }
.btn-cancel { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); margin-left: 6px; }
.btn-save:disabled { background: var(--color-border); cursor: not-allowed; }
/* 配信停止/再開(トップバー用 .btn-mini の白透過が行内で見えなくなるのを明示配色で上書き) */
.btn-stop, .btn-resume {
    border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; margin-left: 6px;
}
.btn-stop { background: #fff; color: var(--rt-error-ink); border: 1px solid var(--rt-error-line); }
.btn-stop:hover { background: var(--rt-error-light); }
.btn-resume { background: #fff; color: var(--color-primary-dark); border: 1px solid var(--rt-primary-muted); }
.btn-resume:hover { background: var(--color-primary-light); }
.btn-stop:disabled, .btn-resume:disabled, .btn-cancel:disabled { opacity: .45; cursor: not-allowed; }
/* 担当外施設(概観)行: 研究ID・施設以外は淡いグレーの「-」。操作対象外 */
.masked-cell { color: var(--rt-ink-faint); }
.masked-row td { background: #FCFBF8; }
/* 行編集の患者ID入力(インライン) */
.rt-pid-edit { display: inline-block; width: 110px; margin-top: 0; font-size: 14px; padding: 6px 8px; border: 2px solid var(--color-border); border-radius: 6px; }

.data-table tr.clickable { cursor: pointer; }
.data-table tr.editing { background: var(--color-primary-light); }
.date-inline { font-size: 14px; padding: 6px; border: 2px solid var(--color-border); border-radius: 6px; }
.edit-actions { white-space: nowrap; }
.row-msg { font-size: 12px; margin-top: 4px; }
.row-msg.err { color: var(--color-error); }
.row-msg.ok { color: var(--color-ok); }
/* 離脱患者の編集行に出す注意書き(照射日を編集しても配信は再開されない) */
.row-msg .row-warn { color: var(--color-error); font-weight: 600; }

/* 登録確認(初回の診察券番号) */
.reg-badge { display: inline-block; margin-left: 6px; font-size: 11px; color: #fff; background: var(--color-error); border-radius: 10px; padding: 1px 8px; font-weight: 600; white-space: nowrap; }
.data-table tr.reg-pending { background: #FDF3F0; }
.rt-pid { display: block; width: 130px; margin-top: 4px; font-size: 14px; padding: 6px 8px; border: 2px solid var(--color-border); border-radius: 6px; }
.btn-confirm-save { background: var(--color-primary); color: #fff; border: none; border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.btn-confirm-save:hover { background: var(--color-primary-dark); }

.card { background: #fff; border: 1px solid var(--color-border); border-radius: var(--border-radius); padding: 20px; box-shadow: 0 1px 6px rgba(0,0,0,0.04); }
.card h2 { font-size: 18px; color: var(--color-primary-dark); margin-bottom: 12px; }

.field-label { font-size: 13px; color: var(--color-text-secondary); font-weight: 600; }
.btn-primary { background: var(--color-primary); color: #fff; border: none; border-radius: 8px; padding: 10px 24px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { background: var(--color-border); cursor: not-allowed; }
.msg { margin-top: 10px; font-size: 14px; }
.msg.ok { color: var(--color-ok); }
.msg.err { color: var(--color-error); }

/* テーブル */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.data-table th { background: var(--color-primary-light); color: var(--color-primary-dark); font-weight: 600; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]:hover { background: var(--color-primary); color: #fff; }
.sort-ind { font-size: 11px; }
.data-table tbody tr { cursor: pointer; }
/* ここから下の淡色（行のホバー・ステータスピル・行の状態色・帯の面色）は医師アプリ固有の
   情報体系で、共有トークン(design/tokens.css)には載せない。docs/design-tokens.md §2 参照。 */
.data-table tbody tr:hover { background: #F7FBF2; } /* ホバーは淡く(選択色より一段薄い) */
.status-pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; background: #EFEDE7; color: var(--color-text-secondary); white-space: nowrap; }
/* 表示状態の色分け(照射開始前/照射中/フォロー中/完了/登録済/離脱)。
   ※ st-before の黄は「照射開始前」という状態区分であり、患者アプリの
     「あなたの回答」の黄(--rt-answer)とは別物。両者が同一画面に並ぶことはない。 */
.status-pill.st-reg    { background: #EFEDE7; color: var(--color-text-secondary); }
.status-pill.st-before { background: #FFF4D6; color: #8a6d1a; }
.status-pill.st-during { background: #DCEBFB; color: #1d5b9c; }
.status-pill.st-follow { background: #E3E0F7; color: #5a4ba8; }
.status-pill.st-done   { background: #DCF0E2; color: #1f7a44; }
.status-pill.st-out    { background: #F3D9D9; color: #9c2b2b; }
.status-pill.st-stop   { background: #E2E2E2; color: #555; }

/* CSVボタン等の「待機中...」点滅(文字のみ。ボタン見た目は維持) */
.btn-blink { display: inline-block; animation: btnTextBlink 1.1s ease-in-out infinite; }
@keyframes btnTextBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .btn-blink { animation: none; } }

/* 患者一覧: 操作列(最終列)を右端に固定し、横スクロールでも隠れないようにする */
.patient-table-wrap th:last-child,
.patient-table-wrap td:last-child {
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.18);
    z-index: 1;
}
.patient-table-wrap thead th:last-child { background: var(--color-primary-light); }
.patient-table-wrap tr.editing td:last-child { background: var(--color-primary-light); }
.patient-table-wrap tr.reg-pending td:last-child { background: #FDF3F0; }
/* [#31] 患者一覧のヘッダを縦スクロールでも固定（表内スクロール＋sticky thead） */
/* 既定は8行分程度の高さ。あとは縦スクロール+右下グリップのドラッグで高さ調整可 */
.patient-table-wrap {
    height: 390px; min-height: 160px; max-height: none;
    overflow: auto; resize: vertical;
    border: 1px solid var(--color-border); border-radius: 8px;
}
/* 選択中の患者行(シングルクリックで選択+詳細読み込み)。従来のホバー色を選択色に昇格 */
.patient-table-wrap tr.row-selected td { background: var(--color-primary-light); }
.patient-table-wrap tr.row-selected td:first-child { box-shadow: inset 3px 0 0 var(--color-primary); }
.patient-table-wrap thead th { position: sticky; top: 0; z-index: 3; box-shadow: 0 2px 0 var(--color-border); }
.patient-table-wrap thead th:last-child { top: 0; right: 0; z-index: 4; }

/* 詳細 */
.detail-head { display: flex; align-items: center; justify-content: space-between; }
.detail-head .btn-mini { background: var(--color-primary); }
.answer-block { border: 1px solid var(--color-border); border-radius: 8px; padding: 14px; margin-top: 14px; }
.answer-block h3 { font-size: 15px; color: var(--color-primary-dark); margin-bottom: 4px; }
.answer-meta { font-size: 13px; color: var(--color-text-secondary); margin-bottom: 10px; }
.qa-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.qa-table td { padding: 8px 10px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.qa-table td.q { color: var(--color-text-secondary); width: 60%; }
.qa-table td.a { font-weight: 600; }

/* フォーム部品(掲示板/疾患区分/ログ 共通) */
.select-field, .num-field, .text-field {
    font: inherit; font-size: 15px; padding: 8px 10px;
    border: 2px solid var(--color-border); border-radius: 8px; background: #fff; color: var(--color-text);
}
.select-field:focus, .num-field:focus, .text-field:focus { outline: none; border-color: var(--color-primary); }

/* 掲示板 */
.board-compose { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.board-compose textarea {
    width: 100%; font: inherit; font-size: 15px; padding: 10px;
    border: 2px solid var(--color-border); border-radius: 8px; resize: vertical; min-height: 64px;
}
.board-compose textarea:focus { outline: none; border-color: var(--color-primary); }
.board-compose-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.board-list { display: flex; flex-direction: column; gap: 10px; }
.board-post { border: 1px solid var(--color-border); border-radius: 8px; padding: 12px 14px; background: #fff; }
.board-post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.board-author { font-weight: 600; color: var(--color-primary-dark); }
.board-date { font-size: 12px; }
.board-del {
    margin-left: auto; background: #fff; color: var(--color-text-secondary);
    border: 1px solid var(--color-border); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.board-del.confirm { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.board-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }

/* 疾患区分編集 */
.disease-select-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.disease-readonly { margin-bottom: 14px; }
.disease-form {
    /* 項目が増えたためボックス幅を約20%縮小(220px→176px)。1行に入る列数も増える */
    display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px;
}
.disease-field { display: flex; flex-direction: column; gap: 4px; }
.disease-field .field-label { font-size: 12px; }
.disease-field input, .disease-field select { width: 100%; }
.disease-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 18px; }

/* ログ */
.logs-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }

/* 送信リンク / QR */
.links-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.links-list { display: flex; flex-direction: column; gap: 18px; }
/* 施設ごとに改行(グループ)。区切り線で施設の境界を示す。グループ内は疾患カードを横並び。 */
.link-facility-group { display: flex; flex-wrap: wrap; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--color-border); }
.link-facility-group:last-child { border-bottom: none; padding-bottom: 0; }
.link-card { border: 1px solid var(--color-border); border-radius: 10px; padding: 14px; background: #fff; width: 260px; }
.link-card-head { margin-bottom: 10px; font-size: 15px; }
.link-url { display: block; width: 100%; margin-bottom: 10px; font-size: 12px; padding: 6px 8px; } /* 画面表示のみ。印刷は print-area(ラベル+QR)だけなので載らない */
/* ポスター印刷=主ボタン(緑)、QRのみ印刷=副ボタン(白地) */
.link-poster { display: block; width: 100%; margin-top: 12px; background: var(--color-primary); color: #fff; border: none; border-radius: 6px; padding: 9px 10px; font-size: 14px; font-weight: 700; cursor: pointer; }
.link-poster:hover { background: var(--color-primary-dark); }
.link-print { display: block; width: 100%; margin-top: 8px; background: #fff; color: var(--color-primary-dark); border: 1px solid var(--color-border); border-radius: 6px; padding: 8px 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.link-print:hover { background: var(--color-primary-light); }
/* QRは可視になってから遅延生成するため、生成前もレイアウトが崩れないよう高さを確保する */
.qr-box { display: flex; justify-content: center; align-items: center; min-height: 180px; }
.qr-box img, .qr-box canvas { display: block; }

/* 設問プレビュー最上部の「動作確認用リンク」ブロック（QR＋直リンク。送信なし） */
.qp-testlink { border: 1px solid var(--color-border); border-left: 4px solid var(--color-primary); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; background: var(--color-primary-light); }
.qp-testlink-head { font-size: 13px; font-weight: 700; color: var(--color-primary-dark); margin-bottom: 8px; }
.qp-testlink-url { display: block; font-size: 12px; word-break: break-all; margin-bottom: 10px; }
.qp-testlink-qr { display: inline-block; background: #fff; padding: 6px; border-radius: 6px; }
.qp-testlink-qr img, .qp-testlink-qr canvas { display: block; }

/* 印刷: 「印刷」ボタンで、ラベル＋QRのみを左上に印刷（QRはA4横幅の約20%＝42mm） */
#print-area { display: none; }
@media print {
  /* margin:0 でブラウザの印刷ヘッダ・フッタ(日時/URL等)を消し、余白は各印刷物の側で確保する */
  @page { margin: 0; }
  body.printing-link > *:not(#print-area),
  body.printing-poster > *:not(#print-area) { display: none !important; }
  /* absolute だと @page 余白を無視するブラウザ/ドライバがあるため通常フローで配置 */
  body.printing-link #print-area,
  body.printing-poster #print-area { display: block; position: static; margin: 0; }
  /* QRラベル印刷: 四方20mmの余白(職場プリンタの印字不可域対策) */
  body.printing-link #print-area { padding: 20mm; }
  #print-area .print-label { font-size: 13pt; font-weight: 700; color: #000; margin-bottom: 5mm; }
  #print-area .print-qr { width: 42mm; }
  #print-area .print-qr img, #print-area .print-qr canvas { width: 42mm !important; height: 42mm !important; display: block; }
  /* ポスター印刷: A4(210×297)に対し左右12mm・上下は残りを等分(≒17mm)して中央配置。
     画像は幅186mm(アスペクト1055:1491で高さ≒263mm)。QRは画像右下の白枠へ、識別文字は右下端に重ねる */
  body.printing-poster .poster-wrap { position: relative; width: 186mm; margin: 17mm auto 0; }
  #print-area .poster-img { display: block; width: 100%; }
  /* QR位置は画像の白枠の実測値(x764-939, y1300-1468 / 1055×1491)の中央に、
     四方に白フチが残る一回り小さいサイズで配置 */
  #print-area .poster-qr { position: absolute; right: 12.3%; bottom: 1.8%; width: 14%; background: #fff; }
  #print-area .poster-qr img, #print-area .poster-qr canvas { width: 100% !important; height: auto !important; display: block; }
  #print-area .poster-id { position: absolute; right: 0.8%; bottom: 0.4%; font-size: 8pt; color: #000; }
}

/* 設問マスタ 閲覧/プレビュー */
.q-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.q-view-toggle { display: inline-flex; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; }
.q-view { background: #fff; border: none; padding: 6px 14px; font-size: 14px; color: var(--color-text-secondary); cursor: pointer; }
.q-view + .q-view { border-left: 1px solid var(--color-border); }
.q-view.active { background: var(--color-primary); color: #fff; font-weight: 600; }
.q-edit-hint { margin-top: 14px; }
#q-list .data-table td { white-space: normal; } /* 設問文は折り返す(他テーブルのnowrapは維持) */
.q-preview { display: flex; flex-direction: column; gap: 12px; }

/* 設問プレビュー: 患者スマホ風（患者アプリと同じ見た目。.phone-screen 配下にスコープ）。
   ★ここは「患者に見えている画面」の再現なので、医師アプリの基調色ではなく
     患者アプリのトークン(--rt-border / --rt-answer / --rt-bg-chat)を使う。
     入口アプリのデモ(.phone)と枠色も揃える。 */
.phone-frame {
    width: 360px; max-width: 100%; margin: 4px auto 0;
    background: var(--rt-device-frame); border-radius: 36px; padding: 14px;
    box-shadow: var(--rt-shadow-device);
}
/* 本文色も患者アプリのインク。医師アプリの --color-text(#423B31)を継がせない */
.phone-screen { background: var(--rt-bg-chat); color: var(--rt-ink); border-radius: 24px; overflow: hidden; height: 560px; display: flex; flex-direction: column; }
.phone-screen .vas-value-input::placeholder { color: var(--rt-ink-faint); }
.qp-header { background: var(--color-primary); color: #fff; padding: 12px 16px; flex-shrink: 0; }
.qp-header-title { font-weight: 700; font-size: 16px; }
.qp-progress-bar { height: 6px; background: rgba(255,255,255,0.3); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.qp-progress-fill { height: 100%; width: 14%; background: #fff; border-radius: 3px; }
.qp-chat { flex: 1; overflow-y: auto; padding: 16px; }
.qp-msg { margin-bottom: 22px; }
.phone-screen .question-bubble {
    background: #fff; border: 1px solid var(--rt-border);
    border-radius: 4px 20px 20px 20px; padding: 12px 16px; max-width: 90%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06); font-size: 16px; line-height: 1.6; color: var(--color-text);
}
.phone-screen .answer-area { margin-top: 10px; padding-left: 4px; }
.phone-screen .options-list { display: flex; flex-direction: column; gap: 8px; }
.phone-screen .option-btn {
    background: #fff; color: var(--rt-ink); border: 2px solid var(--rt-border); border-radius: 26px;
    padding: 11px 16px; min-height: 48px; font-size: 16px; text-align: left; cursor: pointer; width: 100%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.phone-screen .option-btn:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
/* 選択中は本番の .option-btn.selected と同一(黄)。プレビューが本物と違う色にならないようにする。 */
.phone-screen .option-btn.selected { background: var(--rt-answer); color: var(--rt-answer-ink); border-color: var(--rt-answer); }
.phone-screen .vas-area, .phone-screen .text-input-area {
    background: #fff; border: 1px solid var(--rt-border); border-radius: 12px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.phone-screen .vas-value-display { text-align: center; margin-bottom: 12px; }
.phone-screen .vas-value-input {
    font-size: 36px; font-weight: 700; color: var(--color-primary); width: 160px; text-align: center;
    border: 2px solid var(--rt-border); border-radius: 12px; padding: 8px; -moz-appearance: textfield;
}
.phone-screen .vas-value-input::-webkit-outer-spin-button,
.phone-screen .vas-value-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.phone-screen input[type="range"] {
    -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: 7px;
    background: linear-gradient(to right, var(--rt-primary-track) 0%, var(--color-primary) 100%); margin: 12px 0;
    box-shadow: inset 0 0 0 1px rgba(var(--rt-primary-rgb), 0.25);
    cursor: pointer; -webkit-user-select: none; user-select: none;
}
.phone-screen input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 32px; height: 32px; border-radius: 50%;
    background: var(--color-primary-dark); border: 4px solid #fff;
    box-shadow: 0 0 0 3px var(--color-primary-dark), 0 2px 8px rgba(0,0,0,0.25); cursor: grab;
}
.phone-screen input[type="range"]::-moz-range-thumb {
    width: 32px; height: 32px; border-radius: 50%; background: var(--color-primary-dark);
    border: 4px solid #fff;
    box-shadow: 0 0 0 3px var(--color-primary-dark), 0 2px 8px rgba(0,0,0,0.25); cursor: pointer;
}
.phone-screen .vas-scale-numbers { display: flex; justify-content: space-between; font-weight: 700; margin-top: 6px; color: var(--rt-ink); }
.phone-screen .vas-labels { margin-top: 10px; font-size: 13px; color: var(--color-text-secondary); }
.phone-screen .vas-labels div { margin-bottom: 4px; }
.phone-screen .text-input { width: 100%; font: inherit; font-size: 16px; padding: 10px; border: 2px solid var(--rt-border); border-radius: 12px; resize: none; min-height: 90px; }
.phone-screen .vas-confirm-btn, .phone-screen .text-confirm-btn {
    margin-top: 12px; width: 100%; background: var(--color-primary); color: #fff; border: none; border-radius: 26px;
    min-height: 48px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.phone-screen .vas-confirm-btn:hover, .phone-screen .text-confirm-btn:hover { background: var(--color-primary-dark); }

/* 設問マスタ 編集 */
#q-edit-list { display: flex; flex-direction: column; gap: 2px; }
/* 設問の行間・前後に出す「ここに追加」(通常は控えめ、ホバーで強調) */
.q-insert { display: flex; justify-content: center; padding: 2px 0; }
.q-insert-btn {
    background: transparent; border: 1px dashed transparent; color: var(--color-text-secondary);
    font-size: 12px; padding: 3px 12px; border-radius: 14px; cursor: pointer; opacity: 0.45; transition: all 0.12s ease;
}
.q-insert-btn:hover { opacity: 1; border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-light); }
.q-edit-card { border: 1px solid var(--color-border); border-radius: 10px; padding: 14px 16px; background: #fff; }
.q-edit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.q-edit-num { font-weight: 700; color: var(--color-primary-dark); }
.q-edit-tools { display: flex; gap: 6px; }
.q-edit-tools .btn-mini { background: #fff; color: var(--color-text-secondary); border: 1px solid var(--color-border); }
.q-edit-tools .q-del:hover { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.q-edit-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.q-edit-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.q-edit-field > span { font-size: 12px; color: var(--color-text-secondary); font-weight: 600; }
.q-edit-field input, .q-edit-field select, .q-edit-field textarea { width: 100%; }
.q-edit-id { max-width: 160px; }
.q-edit-check { display: flex; align-items: center; gap: 6px; align-self: flex-end; padding-bottom: 8px; white-space: nowrap; }
.q-edit-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
/* 設問アラート設定の枠 */
.q-alert-box { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--color-border); border-radius: 8px; background: #FCFDF9; }
.q-alert-box .q-edit-check { align-self: flex-start; padding-bottom: 6px; white-space: normal; }
.q-alert-note { font-size: 12px; color: var(--color-text-secondary); margin-top: 6px; line-height: 1.5; }
/* 複数選択のトリガ選択肢チェックリスト */
.q-trigger-list { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; }
.q-trigger { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }
.q-edit-actions .btn-primary { margin-left: auto; }
/* 設問ごとの「保存・反映」ボタン(ツールバーの白background btn-mini を上書き) */
.q-edit-tools .q-save-row { background: var(--color-primary); color: #fff; border: none; font-weight: 600; }
.q-edit-tools .q-save-row:hover { background: var(--color-primary-dark); }
/* 削除予定(保存・反映で確定)のグレーアウト */
.q-edit-deleted { opacity: 0.6; background: var(--rt-error-light); }
.q-del-badge { font-size: 12px; color: var(--color-error); border: 1px solid var(--color-error); border-radius: 12px; padding: 2px 10px; font-weight: 600; }

/* 確認ダイアログ */
.modal-overlay { position: fixed; inset: 0; background: var(--rt-scrim-dim); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px 24px; max-width: 440px; width: 100%; box-shadow: 0 10px 34px rgba(0,0,0,0.25); }
.modal-msg { font-size: 15px; line-height: 1.7; margin-bottom: 20px; white-space: pre-wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions .btn-mini { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); padding: 8px 16px; }
.modal-actions .btn-primary { padding: 8px 18px; }

/* CSV エクスポート / インポート */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin-bottom: 0; }
.export-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-head-actions { display: flex; gap: 8px; }
.q-csv-actions { display: inline-flex; gap: 8px; margin-left: auto; }
/* カード内のCSVボタン/ファイルボタン(topbar用 btn-mini の見た目を上書き) */
#btn-export-patients, #btn-export-answers, #btn-export-patient-answers, #q-new-set, #btn-q-export, #btn-disease-export, #org-facility-export, #org-doctor-export, #org-facility-add, #org-doctor-add, .file-btn {
    background: var(--color-primary-light); color: var(--color-primary-dark);
    border: 1px solid var(--color-border); border-radius: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer;
}
#btn-export-patients:hover, #btn-export-answers:hover, #btn-export-patient-answers:hover,
#q-new-set:hover, #btn-q-export:hover, #btn-disease-export:hover,
#org-facility-export:hover, #org-doctor-export:hover, #org-facility-add:hover, #org-doctor-add:hover, .file-btn:hover { background: var(--rt-primary-line); }
.file-btn { display: inline-block; }

/* 施設・医師権限 表編集 */
.org-table td, .org-table th { white-space: nowrap; vertical-align: middle; }
.org-table .org-cell { width: 100%; min-width: 110px; font: inherit; font-size: 14px; padding: 5px 7px; border: 1px solid var(--color-border); border-radius: 6px; background: #fff; }
.org-table .org-cell:focus { outline: none; border-color: var(--color-primary); }
.org-del { background: #fff; color: var(--color-text-secondary); border: 1px solid var(--color-border); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.org-del:hover { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.org-del.confirm { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.org-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.org-actions .btn-primary { margin-left: auto; }

@media (max-width: 600px) {
    .content { padding: 12px; }
    .disease-form { grid-template-columns: 1fr; }
}

/* ============================================================
   [#23/#24/#30/#32] 患者一覧の検索・フィルタ／サマリ帯／通知帯／ログ絞り込み
   ============================================================ */

/* [#24] 登録確認待ちサマリ帯（クリックで確認待ちのみ絞り込み） */
.summary-band {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    background: linear-gradient(90deg, #FDF3F0 0%, #FBEDEA 100%);
    border: 1px solid #EBC7BE; border-left: 5px solid var(--color-error);
    border-radius: var(--border-radius); padding: 12px 16px;
}
.summary-band .sb-count { font-size: 26px; font-weight: 800; color: var(--color-error); line-height: 1; }
.summary-band .sb-count small { font-size: 14px; font-weight: 700; margin-left: 2px; }
.summary-band .sb-text { font-size: 15px; font-weight: 600; color: var(--rt-error-ink); }
.summary-band .sb-sub { font-size: 13px; color: var(--color-text-secondary); }

/* [#30] 担当医通知リンク到達時のお知らせ帯 */
.notify-banner {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--color-primary-light); border: 1px solid var(--color-border);
    border-left: 5px solid var(--color-primary); border-radius: var(--border-radius);
    padding: 12px 16px; font-size: 14px; color: var(--color-text);
}
.notify-banner.warn { background: #FDF3F0; border-color: #EBC7BE; border-left-color: var(--color-error); color: var(--rt-error-ink); }
.notify-banner .nb-close {
    margin-left: auto; background: #fff; color: var(--color-text-secondary);
    border: 1px solid var(--color-border); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.notify-banner .nb-close:hover { background: var(--rt-gray-bg); }

/* [#23] 検索・フィルタバー */
.filter-bar {
    display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap;
    background: var(--color-primary-light); border: 1px solid var(--color-border);
    border-radius: var(--border-radius); padding: 14px 16px; margin-bottom: 4px;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-field .field-label { font-size: 12px; }
.filter-search { min-width: 240px; }
.filter-search .text-field { width: 100%; }
.toggle-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: #fff; color: var(--color-text-secondary);
    border: 2px solid var(--color-border); border-radius: 22px; padding: 7px 14px 7px 12px;
    font-size: 14px; font-weight: 600; cursor: pointer;
}
.toggle-btn .knob { width: 34px; height: 18px; border-radius: 10px; background: var(--color-border); position: relative; transition: background 0.15s; }
.toggle-btn .knob::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle-btn.on { color: var(--color-primary-dark); border-color: var(--color-primary); background: var(--color-primary-light); }
.toggle-btn.on .knob { background: var(--color-primary); }
.toggle-btn.on .knob::after { transform: translateX(16px); }
.filter-reset {
    background: #fff; color: var(--color-text-secondary); border: 1px solid var(--color-border);
    border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.filter-reset:hover { background: var(--rt-gray-bg); }
.filter-summary { font-size: 13px; color: var(--color-text-secondary); margin: 2px 2px 10px; }

/* [#24] 登録確認待ち行のピン留め強調 */
.data-table tr.reg-pending:hover { background: #FBE9E4; }
.data-table tr.reg-pending td:first-child { box-shadow: inset 4px 0 0 var(--color-error); }
.pin-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; color: var(--color-error); margin-left: 6px; }
.pin-tag::before { content: '▲'; font-size: 9px; }

/* [#30] 通知リンクで指定された患者行のハイライト（該当行へ注意を誘導） */
.data-table tr.row-highlight td { animation: rowHighlightFlash 2.2s ease-in-out; }
@keyframes rowHighlightFlash { 0%, 12% { background: #FFE49B; } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) {
    .data-table tr.row-highlight td { animation: none; background: #FFF3C9; }
}

/* [#32] ログの列見出しソート＋テキスト絞り込み */
#logs-head th { cursor: pointer; user-select: none; white-space: nowrap; }
#logs-head th:hover { background: var(--color-primary); color: #fff; }
.logs-controls .text-field { min-width: 200px; }

/* 入力つきモーダル(新規マスタ追加など)の入力欄 */
.modal-input { width: 100%; margin: -6px 0 16px; }

/* [#25] 危険操作（CSV上書き等）の確認ダイアログの主ボタンを危険色に */
.modal-actions .btn-primary.danger { background: var(--color-error); }
.modal-actions .btn-primary.danger:hover { background: var(--rt-error-ink); }

@media (max-width: 720px) {
    .patient-table-wrap { height: 320px; }
    .filter-search { min-width: 180px; }
}
