:root {
  --bg: #f5f6f7; --surface: #fff; --line: #e1e5e8; --line-strong: #c9d0d5;
  --text: #1f2933; --muted: #5d6975; --accent: #1f5c43; --accent-hover: #17483a; --accent-weak: #e7f0ea;
  --danger: #a12a2a; --danger-weak: #fbeeee; --warn: #8a5a00; --warn-weak: #fff6df; --info-weak: #eef3f7;
  --weekend: #f0f2f4; --today: #fff4cf; --sat: #2f5d8a; --sun: #a13a3a;
  --radius: 6px; --sidebar: 224px;
  /* 余白（margin / padding / gap）は、すべて8の倍数（8px グリッド）にそろえる。0 は 8 の倍数として使ってよい。 */
  --s0: 0; --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 40px; --s6: 48px;
  --font: "Yu Gothic UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Meiryo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.6; color: var(--text); background: var(--bg); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 var(--s1); }
h3 { font-size: 14px; margin: 0 0 var(--s1); }
p { margin: var(--s2) 0; }   /* ブラウザ既定の「文字の大きさ×1」の余白をやめ、8の倍数にする */
.notice p, .modal p { margin: var(--s1) 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: var(--s5); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── レイアウト ── */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; transition: grid-template-columns .2s ease; }
/* メニューを閉じた状態（ハンバーガーで切替）。本文が全幅になる */
.shell.nav-closed { grid-template-columns: 0 1fr; }
.shell.nav-closed .sidebar { visibility: hidden; padding-left: 0; padding-right: 0; border-right-width: 0; }
.nav-backdrop { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s1); height: 48px; padding: 0 var(--s2); background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-title { font-weight: 700; color: var(--accent); font-size: 14px; }
@media (min-width: 901px) { .shell:not(.nav-closed) .topbar-title { display: none; } }
.menu-btn { all: unset; box-sizing: border-box; width: 40px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.menu-btn:hover { background: var(--bg); }
.menu-btn:focus-visible { outline: 2px solid #2b7a58; outline-offset: 2px; }
.menu-btn .ico { width: 20px; height: 20px; color: var(--text); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: var(--s2); display: flex; flex-direction: column; gap: var(--s1); position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden; min-width: 0; }
.brand { font-weight: 700; font-size: 15px; padding: var(--s1) var(--s2) var(--s2); color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: var(--s0); }
.nav a { display: flex; align-items: center; gap: var(--s2); min-height: 40px; padding: var(--s1) var(--s2); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--bg); }
.nav a[aria-current="page"] { background: var(--accent-weak); color: var(--accent); font-weight: 700; }
.nav a .ico { flex: none; width: 20px; height: 20px; }
.nav .section { margin: var(--s3) var(--s2) var(--s1); font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.sidebar .grow { flex: 1; }
.userbox { border-top: 1px solid var(--line); padding: var(--s2) var(--s2) var(--s1); font-size: 12px; color: var(--muted); }
.userbox strong { color: var(--text); display: block; font-size: 13px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.envbar { background: var(--warn-weak); color: var(--warn); border-bottom: 1px solid #ead9a8; padding: var(--s1) var(--s3); font-size: 12px; }
.content { padding: var(--s3) var(--s3) var(--s6); max-width: 1400px; width: 100%; }
.content.wide { max-width: none; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); flex-wrap: wrap; }
.pagehead .sub { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap; }

/* ── 部品 ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2); margin-bottom: var(--s2); }
.card > h2:first-child { margin-top: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s1); padding: var(--s1) var(--s2); border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius); cursor: pointer; text-decoration: none; color: var(--text); min-height: 40px; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #d9b4b4; }
.btn.danger:hover { background: var(--danger-weak); }
.btn.small { padding: var(--s0) var(--s1); min-height: 32px; font-size: 13px; }
.btn.link { border: none; background: none; color: var(--accent); padding: var(--s0) var(--s1); min-height: 0; text-decoration: underline; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, .bar:focus-visible { outline: 2px solid #2b7a58; outline-offset: 1px; }
label.field { display: block; font-weight: 600; font-size: 13px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=date], input[type=number], input[type=search], input[type=email], select, textarea {
  width: 100%; padding: var(--s1) var(--s2); border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff; margin-top: var(--s1); min-height: 40px; font-weight: 400;
}
textarea { min-height: 72px; resize: vertical; }
.req::after { content: "必須"; margin-left: var(--s1); font-size: 10px; color: var(--danger); border: 1px solid #dfb7b7; border-radius: 3px; padding: var(--s0) var(--s1); font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--s2); align-items: end; }
.chip { display: inline-block; padding: var(--s0) var(--s1); border-radius: 10px; font-size: 12px; border: 1px solid var(--line-strong); background: var(--bg); white-space: nowrap; }
.chip.inperiod { background: var(--accent-weak); border-color: #b7d3c3; color: var(--accent); font-weight: 700; }
.chip.upcoming { background: var(--info-weak); border-color: #c5d3df; }
.chip.ended { background: #f3f3f3; color: var(--muted); }
.chip.returned { background: var(--accent-weak); border-color: #b7d3c3; color: var(--accent); }
.chip.returned::before { content: "✓ "; }
.chip.return_pending { background: var(--danger-weak); border-color: #e2bcbc; color: var(--danger); font-weight: 700; }
.chip.return_pending::before { content: "⚠ "; }
.chip.cancelled { background: var(--danger-weak); border-color: #dfb7b7; color: var(--danger); text-decoration: line-through; }
.chip.suspended { background: var(--warn-weak); border-color: #ead9a8; color: var(--warn); }
.chip.retired { background: #eee; color: #666; }
.chip.role { background: var(--info-weak); }

table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.tbl th, .tbl td { text-align: left; padding: var(--s1); border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: #f2f4f5; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #fafbfb; }
.tbl tr.clickable { cursor: pointer; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tbl-wrap .tbl th:first-child { border-top-left-radius: var(--radius); }
.empty { padding: var(--s4); text-align: center; color: var(--muted); }
.loading { padding: var(--s4); text-align: center; color: var(--muted); }
.notice { padding: var(--s1) var(--s2); border-radius: var(--radius); border: 1px solid var(--line); background: var(--info-weak); margin-bottom: var(--s2); font-size: 13px; }
.notice.error { background: var(--danger-weak); border-color: #e2bcbc; color: #7d2020; white-space: pre-line; }
.notice.ok { background: var(--accent-weak); border-color: #b7d3c3; }
.notice.warn { background: var(--warn-weak); border-color: #ead9a8; }
.kv { display: grid; grid-template-columns: 128px 1fr; gap: var(--s1) var(--s2); margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: var(--s2); color: var(--muted); }

/* ── トースト・モーダル ── */
.toasts { position: fixed; right: var(--s3); bottom: var(--s3); display: flex; flex-direction: column; gap: var(--s1); z-index: 100; }
.toast { background: #1f2933; color: #fff; padding: var(--s1) var(--s2); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: #7d2020; }
.modal-back { position: fixed; inset: 0; background: rgba(31,41,51,.45); display: flex; align-items: flex-start; justify-content: center; padding: var(--s5) var(--s2); overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 8px; width: 100%; max-width: 760px; box-shadow: 0 8px 28px rgba(0,0,0,.25); }
.modal.narrow { max-width: 520px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: var(--s2) var(--s3); max-height: calc(100vh - 224px); overflow-y: auto; }
.modal-foot { padding: var(--s2) var(--s3); border-top: 1px solid var(--line); display: flex; gap: var(--s1); justify-content: flex-end; background: #fafbfb; border-radius: 0 0 8px 8px; }
.modal-foot .spacer { flex: 1; }

/* ── ログイン ── */
.login { max-width: 420px; margin: 96px auto; padding: var(--s0) var(--s2); }
.login .card { padding: var(--s4); }
.login h1 { margin-bottom: var(--s1); color: var(--accent); }

/* ── ホーム ── */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.home-grid .card { margin: 0; }
.home-grid .full { grid-column: 1 / -1; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { padding: var(--s1) 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: var(--s0) var(--s2); cursor: pointer; }
.mini-list li:last-child { border-bottom: none; }
.mini-list li:hover { background: #fafbfb; }
.mini-list .t { font-weight: 600; }
.mini-list .s { color: var(--muted); font-size: 12px; grid-column: 1 / -1; }
.mini-list .late { color: var(--danger); font-weight: 700; font-size: 12px; grid-column: 1; }
.card.alert { border-color: #e2bcbc; background: #fffafa; }
.card.alert > h2:first-child { color: var(--danger); }
label.check { display: flex; gap: var(--s1); align-items: center; font-weight: 600; margin: var(--s2) 0; cursor: pointer; }
label.check input { margin: var(--s0); width: 18px; height: 18px; }

/* ── 予約フォーム ── */
.reserve-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s2); align-items: start; }
.item-row { display: grid; grid-template-columns: minmax(0, 2fr) 90px minmax(0, 1.6fr) 40px; gap: var(--s1); align-items: start; margin-bottom: var(--s2); }
.item-row .rm { margin-top: var(--s1); }
.avail-panel { position: sticky; top: 64px; }
.avail-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s0) var(--s1); padding: var(--s1) 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.avail-row:last-child { border-bottom: none; }
.avail-row .n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.avail-row.low .n { color: var(--danger); font-weight: 700; }
.avail-row .meter { grid-column: 1 / -1; height: 4px; background: #e7ebee; border-radius: 2px; overflow: hidden; }
.avail-row .meter i { display: block; height: 100%; background: var(--accent); }
.result-list { margin: var(--s1) 0 0; padding-left: var(--s3); }

/* ── カレンダー ── */
.cal-toolbar { display: flex; gap: var(--s1); flex-wrap: wrap; align-items: end; margin-bottom: var(--s2); }
.cal-toolbar .grp { display: flex; gap: var(--s1); align-items: center; }
.cal-title { font-size: 18px; font-weight: 700; min-width: 152px; text-align: center; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: none; background: #fff; padding: var(--s1) var(--s2); cursor: pointer; min-height: 40px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; }
.cal-filter label { font-size: 12px; font-weight: 600; display: block; }
.cal-filter input, .cal-filter select { display: block; margin-top: var(--s1); min-height: 40px; padding: var(--s1); width: 168px; }
.cal-scroll { overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); max-height: calc(100vh - 280px); min-height: 256px; position: relative; }
.cal-inner { position: relative; width: max-content; min-width: 100%; }
.cal-row { display: grid; grid-template-columns: var(--label-w) repeat(var(--days), var(--cell-w)); position: relative; z-index: 1; border-bottom: 1px solid var(--line); height: 34px; }
.cal-row > .lab { position: sticky; left: 0; z-index: 4; background: var(--surface); border-right: 2px solid var(--line-strong); padding: var(--s0) var(--s1); display: flex; align-items: center; gap: var(--s1); overflow: hidden; white-space: nowrap; }
.cal-row > .lab .no { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 34px; }
.cal-row > .lab .nm { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.cal-row.grouprow { background: #f2f4f5; height: 30px; }
.cal-row.grouprow > .lab { background: #f2f4f5; font-weight: 700; cursor: pointer; }
.cal-row.grouprow > .lab button { all: unset; cursor: pointer; display: flex; align-items: center; gap: var(--s1); width: 100%; }
.cal-head { position: sticky; top: 0; z-index: 6; background: var(--surface); }
.cal-head .cal-row { height: 26px; border-bottom: 1px solid var(--line); z-index: 6; background: var(--surface); }
.cal-head .cal-row > .lab { z-index: 7; }
.cal-head .mon { font-weight: 700; font-size: 12px; border-left: 2px solid #6b7782; display: flex; align-items: center; background: #eef1f3; }
.cal-head .mon .monl { position: sticky; left: calc(var(--label-w) + var(--s1)); padding-right: var(--s1); }
.cal-head .day { text-align: center; font-size: 12px; line-height: 1.3; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid var(--line); }
.cal-head .day b { font-variant-numeric: tabular-nums; }
.cal-head .day.sat { color: var(--sat); } .cal-head .day.sun { color: var(--sun); }
.cal-head .day.today { background: var(--today); font-weight: 700; box-shadow: inset 0 -3px 0 #c9971a; }
.cal-head .day.mstart { border-left: 2px solid #6b7782; }
.cal-head .row-days { height: 56px; }
.cal-head .day .tdy { font-size: 11px; font-weight: 700; color: #7a5a00; }
.stripes { position: absolute; top: 0; bottom: 0; left: var(--label-w); right: 0; display: grid; grid-template-columns: repeat(var(--days), var(--cell-w)); z-index: 0; pointer-events: none; }
.stripes i { border-left: 1px solid #eceff1; }
.stripes i.we { background: var(--weekend); }
.stripes i.today { background: var(--today); }
.stripes i.mstart { border-left: 2px solid #6b7782; }
.bar { grid-row: 1; align-self: center; height: 26px; margin: var(--s0); z-index: 3; border: 1px solid #7aa88f; background: #d6e8dd; color: #12301f; border-radius: 4px; padding: var(--s0) var(--s1); text-align: left; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; line-height: 24px; }
.bar:hover { filter: brightness(.96); box-shadow: 0 0 0 1px #1f5c43; }
.bar.t1 { background: #d6e8dd; border-color: #7aa88f; }
.bar.t2 { background: #dbe7f3; border-color: #86a6c6; }
.bar.t3 { background: #f1e6d1; border-color: #c9a96a; }
.bar.t4 { background: #ead9e6; border-color: #b68aab; }
.bar.t5 { background: #e1e8c9; border-color: #a2b362; }
.bar.t6 { background: #d9ecee; border-color: #77b1b7; }
.bar .mk { margin-right: var(--s1); }
.bar.ret { opacity: .55; }
.bar.od { border: 2px solid #b3261e; line-height: 22px; background-image: repeating-linear-gradient(135deg, rgba(179, 38, 30, .10) 0 6px, transparent 6px 12px); }
.bar.cl { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left-style: dashed; }
.bar.cr { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right-style: dashed; }
/* 移動日（前後の予約不可日）: 斜線。帯より下に敷く */
.buf { grid-row: 1; align-self: center; height: 26px; margin: var(--s0); z-index: 2; border-radius: 4px; border: 1px dashed #aab4bc; background: repeating-linear-gradient(135deg, #e3e8ec 0 5px, #f6f8f9 5px 10px); }
.cal-legend i.buf-sample { background: repeating-linear-gradient(135deg, #e3e8ec 0 4px, #f6f8f9 4px 8px); border: 1px dashed #aab4bc; }
.cal-legend { display: flex; gap: var(--s1) var(--s2); flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: var(--s1); align-items: center; }
.cal-legend i { display: inline-block; width: 14px; height: 12px; vertical-align: -2px; margin-right: var(--s1); border: 1px solid var(--line-strong); }

/* ── 履歴 ── */
.hist { border-bottom: 1px solid var(--line); padding: var(--s2) 0; }
.hist:last-child { border-bottom: none; }
.hist .hd { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: baseline; }
.hist .act { font-weight: 700; }
.diff { width: 100%; border-collapse: collapse; margin-top: var(--s1); font-size: 13px; }
.diff th, .diff td { text-align: left; padding: var(--s1); border: 1px solid var(--line); vertical-align: top; }
.diff th { background: #f6f7f8; width: 128px; font-weight: 600; }
.diff .before { background: #fdf3f3; } .diff .after { background: #f1f8f3; }
.diff .arrow { width: 24px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) {
  .reserve-layout { grid-template-columns: 1fr; }
  .avail-panel { position: static; }
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  /* 狭い幅: メニューは本文の上に重ねて表示（既定は閉じる）。ハンバーガーで開く */
  .shell, .shell.nav-closed { grid-template-columns: 1fr; transition: none; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 84vw); height: 100vh; z-index: 60; box-shadow: 4px 0 18px rgba(0, 0, 0, .18); transition: transform .2s ease, visibility .2s; }
  .shell.nav-closed .sidebar { transform: translateX(-100%); padding: var(--s2); border-right-width: 1px; box-shadow: none; }
  .shell:not(.nav-closed) .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(31, 41, 51, .4); }
  .content { padding: var(--s2) var(--s2) var(--s5); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr 80px 1fr 40px; }
}
.sec { margin-top: var(--s3); }

.grid2 + .grid2 { margin-top: var(--s2); }
.card .grid2 + label.field { margin-top: var(--s2); }
.err { color: var(--danger); }
