* { box-sizing: border-box; }
:root {
  --bg: #f6f4ef; --card: #ffffff; --ink: #22302c; --muted: #71807a;
  --line: #ddd8cc; --accent: #0e5f56; --warn: #e07b24; --free: #eef6f2;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.danger { color: #b03030; }
.error { color: #b03030; font-size: 14px; min-height: 1.2em; margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; }

/* ログイン / セットアップ */
.auth-wrap { max-width: 420px; margin: 8vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.auth-wrap h1 { font-size: 22px; margin: 0 0 6px; }
.staff-pick { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.staff-pick button { border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px; }
.staff-pick button.sel { border-color: var(--accent); background: var(--free); font-weight: 700; }
.setup-row { border-top: 1px solid var(--line); padding: 10px 0; }
.setup-row .nm { font-weight: 700; }
.setup-done { color: var(--accent); font-size: 13px; }

/* ヘッダー */
header.top { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 14px; position: sticky; top: 0; z-index: 20; }
.top-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top-row .title { font-size: 19px; font-weight: 800; margin-right: auto; }
.top-row .title small { font-size: 12px; color: var(--muted); font-weight: 400; }
.date-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.date-nav .cur { font-size: 17px; font-weight: 800; min-width: 9.5em; text-align: center; }
.week-strip { display: flex; gap: 4px; margin-top: 8px; overflow-x: auto; }
.week-strip .day { flex: 1; min-width: 64px; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 2px; background: #fff; font-size: 12px; }
.week-strip .day.sel { border-color: var(--accent); background: var(--free); font-weight: 700; }
.week-strip .day.closed { background: #eceae4; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-top: 10px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 16px; }
.tabs button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 13px; margin: 4px 0 10px; }
.legend .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.legend .spacer { margin-left: auto; display: flex; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; }
.seg button.sel { background: var(--accent); color: #fff; }
.closed-banner { background: #eceae4; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.absence-bar { border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #fff; }

/* 予約表 */
.board-timeline { display: flex; flex-direction: column; gap: 4px; }
.board-timeline.wide { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.board-timeline.wide .col { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: stretch; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; min-height: 52px; }
.row .time { width: 46px; flex: none; font-weight: 700; font-size: 14px; padding-top: 4px; }
.board-timeline.wide .row .time { width: 42px; }
.row.cont { min-height: 30px; align-items: center; color: var(--muted); font-size: 13px; }
.row.free { background: var(--free); border-style: dashed; align-items: center; cursor: pointer; }
.row.free .free-label { color: var(--accent); font-weight: 700; }
.row .bar { width: 6px; border-radius: 3px; flex: none; }
.row .main { flex: 1; min-width: 0; cursor: pointer; }
.row .kana { font-size: 10px; color: var(--muted); line-height: 1.1; }
.row .pname { font-size: 16px; font-weight: 700; line-height: 1.25; }
.row .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-new { background: var(--warn); color: #fff; font-size: 11px; border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.mark-caution { color: var(--warn); font-weight: 900; margin-left: 5px; }
.row .status-btns { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.status-badge { font-size: 11px; border-radius: 6px; padding: 1px 7px; background: #eee; color: #555; }
.status-badge.done { background: #dcefe6; color: var(--accent); }

/* モーダル */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,27,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px; }
@media (min-width: 768px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal .close-row { display: flex; justify-content: space-between; align-items: center; }
.kv { font-size: 14px; margin: 6px 0; }
.kv b { display: inline-block; min-width: 5.5em; color: var(--muted); font-weight: 600; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.chips button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.avail-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 6px; }
.avail-grid button { border: 1px solid var(--line); border-radius: 7px; padding: 5px 0; font-size: 12px; background: var(--free); }
.avail-grid button.booked { background: #f3e2e2; color: #a05555; }
.avail-grid button.absent { background: #fdf0dd; color: #a06a1c; }
.avail-grid button.closed { background: #eceae4; color: var(--muted); }
.avail-grid button.sel { outline: 2px solid var(--accent); font-weight: 800; }
.candidates { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 6px; }
.candidates button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 9px 12px; }
.candidates button:last-child { border-bottom: 0; }
.panel { background: var(--free); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.preview { background: #fbf8f1; border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-top: 8px; }

/* 患者 */
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.patient-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 768px) { .patient-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .patient-grid { grid-template-columns: 1fr 1fr 1fr; } }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; }
.pcard .pname { font-size: 16px; font-weight: 700; }
.record-item { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.weekday-checks { display: flex; gap: 8px; flex-wrap: wrap; }
.weekday-checks label { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ink); margin: 0; }
.weekday-checks input { width: auto; }
.abs-item { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; }

/* 印刷シート */
#print-sheet { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-sheet, #print-sheet * { visibility: visible; }
  #print-sheet { display: block; position: absolute; inset: 0; padding: 10px; }
  #print-sheet table { width: 100%; border-collapse: collapse; font-size: 12px; }
  #print-sheet th, #print-sheet td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  #print-sheet .kana { font-size: 9px; color: #444; }
  #print-sheet h2 { font-size: 16px; margin: 0 0 8px; }
}
