/* 高齢の患者が迷わず使えることを最優先にしています。
   文字は大きく、押す場所は広く、色数は抑えます。 */

:root {
  --bg: #ffffff;
  --panel: #f3f6f4;
  --ink: #1b211d;
  --ink-sub: #57615a;
  --rule: #ccd5cf;
  --accent: #10645c;      /* 操作できる場所を示す色 */
  --accent-ink: #ffffff;
  --alert: #93362a;       /* 満員・エラーなど、止まってほしい場所 */
  --ok-bg: #e7f0ec;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", "Yu Gothic",
               "Noto Sans JP", Meiryo, sans-serif;
  font-size: 18px;
  line-height: 1.75;
}

body.staff { font-size: 15px; line-height: 1.6; }

.wrap { max-width: 42rem; margin: 0 auto; padding: 0 1rem 4rem; }
body.staff .wrap { max-width: 72rem; }

/* 見出し帯 */
.masthead {
  border-bottom: 3px solid var(--accent);
  padding: 1rem 0 0.75rem;
  margin-bottom: 1.5rem;
}
.masthead a { color: inherit; text-decoration: none; }
.masthead h1 { font-size: 1.25rem; margin: 0; font-weight: 600; letter-spacing: 0.02em; }
body.staff .masthead { border-bottom-width: 2px; }
/* 患者向けはすぐ下にメニューが来るため、見出し帯の線は省きます */
.masthead.plain { border-bottom: none; padding-bottom: 0.25rem; margin-bottom: 0; }

h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; font-weight: 600; }
h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; font-weight: 600; }
p  { margin: 0.5rem 0 1rem; }

a { color: var(--accent); }

.lead { color: var(--ink-sub); }
.note { color: var(--ink-sub); font-size: 0.9em; }

/* 案内・エラー */
.errors, .flash {
  border-left: 5px solid var(--alert);
  background: #fbf0ee;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}
.flash { border-left-color: var(--accent); background: var(--ok-bg); }
.errors ul { margin: 0; padding-left: 1.2rem; }

/* 日付ごとの空き状況 */
.day {
  border: 1px solid var(--rule);
  border-radius: 6px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.day > .date {
  background: var(--panel);
  padding: 0.6rem 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--rule);
}
.slots { display: flex; flex-wrap: wrap; gap: 0.6rem; padding: 1rem; }

.slot {
  display: block;
  min-width: 9.5rem;
  min-height: 3.5rem;
  padding: 0.5rem 0.9rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  background: #fff;
  text-decoration: none;
  text-align: center;
  font-weight: 600;
}
.slot:hover { background: var(--ok-bg); }
.slot .left { display: block; font-size: 0.85em; font-weight: 400; }
.slot.full,
.slot.closed {
  border-color: var(--rule);
  color: var(--ink-sub);
  background: var(--panel);
  cursor: default;
  pointer-events: none;
}
/* 締切後の枠。枠数は読めるように残しつつ、押せないことを見た目で示します */
.slot.closed {
  border-style: dashed;
  opacity: 0.75;
}
.day > .date.closed { color: var(--ink-sub); }

/* フォーム */
.field { margin: 1.25rem 0; }
.field label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.field .hint { display: block; font-weight: 400; color: var(--ink-sub); font-size: 0.85em; }

input[type=text], input[type=tel], input[type=email], input[type=password],
input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { min-height: 4rem; }

button, .btn {
  display: inline-block;
  min-height: 3rem;
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
}
button.sub, .btn.sub { background: #fff; color: var(--accent); }
button.danger { background: var(--alert); border-color: var(--alert); }
button.small, .btn.small { min-height: 2.2rem; padding: 0.2rem 0.7rem; font-size: 0.85rem; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

/* 確認・完了 */
.summary { border: 2px solid var(--rule); border-radius: 6px; }
.summary div { display: flex; border-top: 1px solid var(--rule); }
.summary div:first-child { border-top: none; }
.summary dt { flex: 0 0 9rem; background: var(--panel); padding: 0.6rem 0.8rem; margin: 0; font-weight: 600; }
.summary dd { flex: 1; padding: 0.6rem 0.8rem; margin: 0; }

.code {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-align: center;
  padding: 1rem;
  border: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--ok-bg);
}

/* 職員画面 */
.nav { display: flex; flex-wrap: wrap; gap: 1rem; padding: 0.5rem 0; font-size: 0.95rem; }
.nav a { text-decoration: none; font-weight: 600; }
.nav .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { border-bottom: 1px solid var(--rule); padding: 0.45rem 0.5rem; text-align: left; vertical-align: top; }
th { background: var(--panel); font-weight: 600; white-space: nowrap; }
tr.done td { color: var(--ink-sub); }
tr.dup td { background: #fdf6e8; }
td.num { text-align: right; white-space: nowrap; }

.tag { display: inline-block; padding: 0 0.4rem; border-radius: 3px; font-size: 0.8em; border: 1px solid var(--rule); }
.tag.warn { border-color: var(--alert); color: var(--alert); }

.filter { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; background: var(--panel); padding: 1rem; border-radius: 6px; }
.filter .field { margin: 0; }
.filter input, .filter select { width: auto; min-width: 8rem; }
.filter input[type=checkbox], .filter input[type=radio] { min-width: 0; }

.scroll { overflow-x: auto; }

/* 印刷時は操作部分を省きます */
@media print {
  .noprint, .nav, .masthead { display: none; }
  body { font-size: 12pt; }
  .code { border-width: 2px; }
}

@media (max-width: 30rem) {
  body { font-size: 17px; }
  .summary div { flex-direction: column; }
  .summary dt { flex: none; }
  .slot { min-width: 100%; }
}

/* --- 患者向けの共通メニュー ---
   どの画面からも同じ位置に出します。現在いる画面は下線と文字色で示します。 */
.pnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 3px solid var(--rule);
  margin-bottom: 1.5rem;
}
.pnav a {
  display: flex;
  align-items: center;
  min-height: 3rem;
  padding: 0.5rem 1.1rem;
  text-decoration: none;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
}
.pnav a:hover { background: var(--ok-bg); }
.pnav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.pnav a:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }

@media (max-width: 30rem) {
  .pnav a { flex: 1 1 auto; justify-content: center; padding: 0.5rem 0.6rem; }
}

@media print {
  .pnav { display: none; }
}

/* --- 週・月の切り替え --- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.5rem 0;
  padding: 0.75rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.pager .range { font-weight: 600; }
.pager .off {
  border-color: var(--rule);
  color: var(--ink-sub);
  background: var(--panel);
  cursor: default;
}

/* --- 月間カレンダー ---
   記号と残数を併記します。色だけで区別すると見分けられない方がいるためです。 */
table.cal { table-layout: fixed; border: 1px solid var(--rule); }
table.cal th {
  text-align: center;
  padding: 0.4rem 0;
  font-size: 0.9rem;
  border: 1px solid var(--rule);
}
table.cal th.sun { color: var(--alert); }
table.cal th.sat { color: #2a5d93; }
table.cal td {
  height: 4.5rem;
  padding: 0;
  text-align: center;
  vertical-align: top;
  border: 1px solid var(--rule);
}
table.cal td a,
table.cal td > span.d {
  display: block;
  padding: 0.3rem 0.1rem;
  text-decoration: none;
  color: inherit;
}
table.cal td a { color: var(--accent); }
/* 押せる範囲をマス全体に広げます。
   a の高さは中身の分しかないため（td の高さに対する height: 100% はブラウザによって効きません）、
   透明な ::after を td いっぱいに重ねて、マスのどこを押しても移れるようにします。 */
table.cal td { position: relative; }
table.cal td a::after {
  content: "";
  position: absolute;
  inset: 0;
}
table.cal td:has(> a) { cursor: pointer; }
table.cal td:has(> a:hover) { background: var(--ok-bg); }
table.cal td a:focus-visible { outline: none; }
table.cal td a:focus-visible::after { outline: 3px solid var(--ink); outline-offset: -3px; }
table.cal .d { display: block; font-size: 0.85rem; color: var(--ink-sub); }
table.cal .m { display: block; font-size: 1.5rem; line-height: 1.2; font-weight: 700; }
table.cal .r { display: block; font-size: 0.75rem; }

table.cal td.c-open  { background: #fff; }
table.cal td.c-few   { background: #fdf6e8; }
table.cal td.c-full   { background: var(--panel); color: var(--ink-sub); }
table.cal td.c-closed { background: var(--panel); color: var(--ink-sub); opacity: 0.8; }
table.cal td.c-none   { background: var(--panel); color: var(--rule); }
table.cal td.c-today { outline: 3px solid var(--accent); outline-offset: -3px; }

/* 選べない日はマス全体を静かにします */
table.cal td.c-full .m,
table.cal td.c-closed .m,
table.cal td.c-none .m { font-weight: 400; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  font-size: 0.9rem;
  color: var(--ink-sub);
}
.legend .m { font-weight: 700; color: var(--ink); }

@media (max-width: 30rem) {
  table.cal td { height: 3.8rem; }
  table.cal .m { font-size: 1.2rem; }
  table.cal .r { font-size: 0.65rem; }
  .pager .range { width: 100%; text-align: center; order: -1; }
}

/* --- 選択肢 --- */
.choices { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 3rem;
  padding: 0.4rem 1rem;
  border: 2px solid var(--rule);
  border-radius: 6px;
  font-weight: 400;
  cursor: pointer;
}
.choice input { width: auto; min-width: 0; margin: 0; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--ok-bg); }
.choice:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }

/* JavaScript が動く環境では、対象年齢のときだけ接種回数を出します */
.dose-hidden { display: none; }

/* --- 患者自身によるキャンセル --- */
.cancelbox {
  border: 2px solid var(--rule);
  border-radius: 6px;
  padding: 0 1rem 1rem;
  margin: 1rem 0 2rem;
  background: var(--panel);
}
.cancelbox h3 { margin-top: 1rem; }

/* --- 接種の種類を選ぶ画面 --- */
.typecards { display: flex; flex-direction: column; gap: 1rem; margin: 1.5rem 0; }
.typecard {
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 1rem 1.25rem 1.25rem;
}
.typecard.empty { border-color: var(--rule); background: var(--panel); }
.typecard h3 { margin-top: 0.25rem; }
.typecard .meta { margin: 0.5rem 0; }
.typecard .meta div { display: flex; gap: 0.5rem; }
.typecard .meta dt {
  flex: 0 0 5.5rem;
  margin: 0;
  font-weight: 600;
  color: var(--ink-sub);
  font-size: 0.9em;
}
.typecard .meta dd { margin: 0; }
.typecard .avail { font-weight: 600; color: var(--accent); margin-bottom: 0.5rem; }
.typecard .avail.none { color: var(--ink-sub); font-weight: 400; }

/* --- 種別の切り替え --- */
.typebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1.25rem;
  background: var(--panel);
  border-radius: 6px;
}
.typebar .label { font-size: 0.85rem; color: var(--ink-sub); margin-right: 0.25rem; }
.typebar .tab {
  display: inline-flex;
  align-items: center;
  min-height: 2.6rem;
  padding: 0.3rem 0.9rem;
  border: 2px solid var(--rule);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
.typebar .tab.on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.typebar .tab:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

@media (max-width: 30rem) {
  .typebar .label { width: 100%; }
  .typebar .tab { flex: 1 1 auto; justify-content: center; }
}

/* --- 共通の小物 ---
   CSP で style 属性を禁止している（style-src 'self'）ため、
   テンプレートに style="..." を書いても効きません。見た目は必ずここにクラスで書いてください。 */
form.inline { display: inline; }
form.narrow { max-width: 24rem; }
form.rowform { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
form.rowform input { width: auto; flex: 1 1 10rem; }
.flash .actions { margin-top: 0.6rem; align-items: center; }
.sitefoot { margin-top: 3rem; border-top: 1px solid var(--rule); padding-top: 1rem; }
.nowrap { white-space: nowrap; }
th.c, td.c { text-align: center; }
th.num { text-align: right; }

/* --- 種別の色分け ---
   並び順（models.go の SlotTypes）で tc0〜tc5 を割り当てます。7 種類目からは色が循環します。 */
.tc0 { --tc: #2f6ea8; --tc-bg: #e8f1fa; }
.tc1 { --tc: #b8661d; --tc-bg: #fcf0e3; }
.tc2 { --tc: #7550a6; --tc-bg: #f2ecf9; }
.tc3 { --tc: #4d7f33; --tc-bg: #e9f3e4; }
.tc4 { --tc: #a8436a; --tc-bg: #fbeaf0; }
.tc5 { --tc: #857a26; --tc-bg: #f5f2dc; }
.tc-unknown { --tc: #777; --tc-bg: #f0f0f0; }
.tt-key {
  display: inline-block;
  width: 0.8em; height: 0.8em;
  margin-right: 0.3em;
  border-radius: 2px;
  background: var(--tc, var(--rule));
  vertical-align: -0.05em;
}

/* --- 予約枠の一覧 --- */
.slotday { margin: 1.75rem 0; }
.slotday-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1rem; }
.slotday-head h3 { margin: 0; }
.daysum { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
table.slottable { margin: 0.5rem 0 0; }
table.slottable th, table.slottable td { vertical-align: middle; padding: 0.35rem 0.6rem; }
table.slottable input.capinput { width: 5.5rem; padding: 0.3rem 0.4rem; }
table.slottable input[type=checkbox] { width: 1.15rem; height: 1.15rem; margin: 0; }
table.slottable tr.row-hidden td { background: var(--panel); color: var(--ink-sub); }
table.slottable tbody tr:hover td { background: var(--ok-bg); }
.ops { display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.ops form { margin: 0; }
button.danger-text { color: var(--alert); border-color: var(--alert); }

/* --- 時間割 ---
   行が種別、列が時間。枠は colspan で横に伸ばし、縦にそろえて重なりを見せます。 */
.tt-day { margin: 1.5rem 0 2rem; }
.tt-day h3 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 1rem; }
table.tt {
  width: auto;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
table.tt th, table.tt td {
  border-bottom: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  padding: 0;
  vertical-align: middle;
  text-align: center;
}
table.tt thead th { padding: 0.3rem 0.4rem; min-width: 4.2rem; font-weight: 600; border-top: 1px solid var(--rule); }
table.tt th.tt-gap, table.tt td.tt-gap { min-width: 2.5rem; }
table.tt .tt-head {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 7.5rem;
  padding: 0.35rem 0.6rem;
  text-align: left;
  background: var(--panel);
  border-left: 1px solid var(--rule);
  white-space: nowrap;
}
table.tt th.tt-head[class*="tc"] { border-left: 5px solid var(--tc); }
.tt-type { display: block; font-weight: 700; }
table.tt .tt-head .note { display: block; }
table.tt .tt-head .tag { margin-top: 0.2rem; }

td.tt-cell { position: relative; background: var(--tc-bg); box-shadow: inset 4px 0 0 var(--tc); }
/* 行の高さがそろわないとマスの下に押せない部分ができるため、カレンダーと同じくマス全体に広げます */
td.tt-cell a::after { content: ""; position: absolute; inset: 0; }
td.tt-cell a:focus-visible { outline: none; }
td.tt-cell a:focus-visible::after { outline: 3px solid var(--ink); outline-offset: -3px; }
td.tt-cell a {
  display: block;
  padding: 0.3rem 0.4rem 0.3rem 0.6rem;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.3;
}
td.tt-cell:has(a:hover) { background-color: #fff; }
.tt-num { display: block; font-weight: 700; font-size: 1.05rem; }
.tt-num small { font-weight: 400; color: var(--ink-sub); font-size: 0.8em; margin-left: 0.1em; }
.tt-time { display: block; font-size: 0.75rem; color: var(--ink-sub); white-space: nowrap; }
.tt-flag {
  display: inline-block;
  margin-top: 0.15rem;
  padding: 0 0.3rem;
  font-size: 0.7rem;
  border: 1px solid var(--ink-sub);
  border-radius: 3px;
  color: var(--ink-sub);
  background: #fff;
}
td.tt-cell.st-zero .tt-num { color: var(--ink-sub); font-weight: 400; }
td.tt-cell.st-full { box-shadow: inset 4px 0 0 var(--tc), inset 0 0 0 2px var(--alert); }
td.tt-cell.st-full .tt-num { color: var(--alert); }
td.tt-cell.st-over { background: #f9ddd8; box-shadow: inset 4px 0 0 var(--tc), inset 0 0 0 2px var(--alert); }
td.tt-cell.st-over .tt-num { color: var(--alert); }
td.tt-cell.st-hidden {
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,0.7) 0 6px, transparent 6px 12px);
}
td.tt-cell.st-hidden a { opacity: 0.8; }
td.tt-empty, th.tt-gap { background: #fafbfa; }
th.tt-gap, td.tt-empty.tt-gap {
  background-image: repeating-linear-gradient(135deg, var(--panel) 0 4px, transparent 4px 8px);
}
table.tt tfoot td.tt-total { background: var(--panel); padding: 0.3rem 0.4rem; }
table.tt tfoot td.tt-total.multi { background: #fdf3de; box-shadow: inset 0 -3px 0 #d9b36c; }
table.tt tfoot th, table.tt tfoot td { border-top: 2px solid var(--ink-sub); }

.tt-legend { margin: 0.5rem 0 0; }
.tt-key.st-full { background: #fff; box-shadow: inset 0 0 0 2px var(--alert); }
.tt-key.st-over { background: #f9ddd8; box-shadow: inset 0 0 0 2px var(--alert); }
.tt-key.st-hidden {
  background: #c9d3dc repeating-linear-gradient(135deg, #fff 0 2px, transparent 2px 4px);
  box-shadow: inset 0 0 0 1px var(--ink-sub);
}
.tt-key.tt-multi { background: #fdf3de; box-shadow: inset 0 0 0 1px #d9b36c; }

@media print {
  table.tt .tt-head { position: static; }
  td.tt-cell a { padding: 0.2rem; }
}

/* --- 予約の手続き（メールアドレスの確認） --- */
.startbox {
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 0 1rem 1rem;
  margin: 1rem 0 2rem;
  background: var(--ok-bg);
}
.startbox h3 { margin-top: 1rem; }
.steps { margin: 0.5rem 0 0; padding-left: 1.5rem; }
.steps li { margin: 0.2rem 0; }
.sessionbar {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.9rem;
  border-left: 5px solid var(--accent);
  background: var(--ok-bg);
  font-size: 0.9em;
}
/* 確認画面で診察券番号を目立たせます（打ち間違いに気付いてもらうため） */
.summary div.em dd { background: #fdf6e8; }
.summary .big { font-size: 1.4em; letter-spacing: 0.08em; }

/* --- 並べ替えのできる列見出し（予約一覧） --- */
th.sortable { padding: 0; }
th.sortable a {
  display: block;
  padding: 0.45rem 0.5rem;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
th.sortable a:hover { background: var(--ok-bg); }
th.sortable .sortmark { margin-left: 0.25em; font-size: 0.8em; color: var(--rule); }
th.sortable.sorted { background: var(--ok-bg); }
th.sortable.sorted .sortmark { color: var(--accent); }
@media print { th.sortable .sortmark { display: none; } }

/* --- CSV の取り込み --- */
.importsum { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; list-style: none; padding: 0; margin: 0.5rem 0; }
.importsum .bad strong { color: var(--alert); }
.importsum .good strong { color: var(--accent); }
table.importtable td { vertical-align: top; }
table.importtable tr.ng td { background: #fbf0ee; }
.rowerr { color: var(--alert); font-weight: 600; }
.commitbox {
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 0 1rem 1rem;
  margin: 1.5rem 0;
  background: var(--ok-bg);
}
.commitbox h3 { margin-top: 1rem; }
input[type=file] { font-size: 1rem; }
table.importtable td:last-child { min-width: 16rem; }
