:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --line: #dfe3df;
  --text: #1f2a2a;
  --muted: #5f6b6b;
  --primary: #0f7a70;
  --primary-soft: #e3f3f0;
  --high: #c0392b;
  --high-soft: #fbeae7;
  --mid: #a86400;
  --mid-soft: #fdf1dc;
  --ok: #2f7d3a;
  --c-mood: #0f8a7e;
  --c-fatigue: #d9730d;
  --c-amount: #5b6b9c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.4; margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

/* ヘッダー */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; color: var(--primary); }
.brand small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.mode-switch { margin-left: auto; display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.mode-switch button { border: 0; background: transparent; padding: 6px 16px; }
.mode-switch button.on { background: var(--primary); color: #fff; }

.layout { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 53px); }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; }
.nav button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
}
.nav button:hover { background: var(--bg); }
.nav button.on { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.main { padding: 24px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.lead { color: var(--muted); margin: 4px 0 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card > h3 { margin-bottom: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; line-height: 1.3; }
.stat .value small { font-size: 14px; font-weight: 400; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.high { background: var(--high-soft); color: var(--high); }
.badge.mid { background: var(--mid-soft); color: var(--mid); }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.gray { background: #eceeec; color: var(--muted); }
.avatar { display: inline-flex; width: 28px; height: 28px; border-radius: 50%; color: #fff; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; margin-right: 8px; vertical-align: middle; }

.alert { border-left: 4px solid var(--mid); background: var(--mid-soft); border-radius: 6px; padding: 10px 14px; margin-bottom: 8px; }
.alert.high { border-color: var(--high); background: var(--high-soft); }
.alert .who { font-weight: 700; }
.alert .action { color: var(--muted); font-size: 13px; }
.notice { background: var(--primary-soft); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.notice.warn { background: var(--mid-soft); }

/* 操作の手がかり */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.is-busy, .is-busy button { cursor: progress; }
.is-busy::before { content: ""; position: fixed; top: 0; left: 0; height: 3px; width: 40%; background: var(--primary); z-index: 30; animation: slide 1s ease-in-out infinite; }
@keyframes slide { from { left: -40%; } to { left: 100%; } }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); z-index: 20; display: grid; gap: 8px; pointer-events: none; }
.toasts .notice { margin: 0; padding: 12px 16px; font-size: 14px; box-shadow: 0 4px 18px rgba(0, 0, 0, .16); border: 1px solid var(--primary); pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; }
.toasts .notice:not(.error) { animation: toast-out .4s ease 5s forwards; }
.toasts .notice.error { border-color: var(--high); }
.toasts .close { margin-left: auto; border: 0; background: transparent; color: inherit; font-size: 18px; line-height: 1; padding: 2px 4px; }
@keyframes toast-out { to { opacity: 0; visibility: hidden; } }
#rec-form:has(input[name="attend"][value="欠席"]:checked) .when-present { display: none; }
.doc-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); margin-top: 16px; }
.stat .value .btn { vertical-align: middle; font-weight: 400; }

/* 初期設定・ログイン */
.gate { max-width: 420px; margin: 0 auto; padding: 60px 18px; }
.gate-title { color: var(--primary); font-size: 28px; }
.stack { display: grid; gap: 14px; }
.stack label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input { font-size: 16px; padding: 10px 12px; }
.notice.error { background: var(--high-soft); color: var(--high); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { border-color: var(--high); color: var(--high); }
.busy { text-align: center; padding: 48px 18px; }
.spinner { width: 36px; height: 36px; margin: 0 auto 16px; border: 4px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 4s; } }

/* フォーム */
.form-grid { display: grid; grid-template-columns: 130px 1fr; gap: 12px 14px; align-items: start; }
.form-grid > label { color: var(--muted); font-size: 13px; padding-top: 6px; }
input[type=text], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; max-width: 100%;
}
textarea { width: 100%; resize: vertical; line-height: 1.7; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; background: #fff; }
.chips input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* グラフ */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 6px; }
.legend i.dash { border-top-style: dashed; }

/* 書類エディタ */
.doc-section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; margin-bottom: 12px; }
.doc-section.confirmed { border-color: var(--primary); }
.doc-section header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.doc-section header h3 { flex: 1; }
.doc-section details { margin-top: 8px; font-size: 13px; color: var(--muted); }
.doc-section details ul { margin: 6px 0 0; padding-left: 20px; }
.doc-section summary { cursor: pointer; }
.confirm { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.confirm input { width: 18px; height: 18px; }
.progress { height: 8px; background: #e6e9e6; border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress div { height: 100%; background: var(--primary); }

/* 利用者モード */
.user-mode { max-width: 640px; margin: 0 auto; padding: 28px 18px 60px; text-align: center; }
.user-mode h2 { font-size: 26px; margin: 18px 0 22px; }
.user-mode .step { color: var(--muted); font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile, .choice {
  border: 2px solid var(--line); background: var(--surface); border-radius: 16px;
  padding: 18px 12px; font-size: 20px; min-height: 76px; width: 100%;
}
.tile:hover, .choice:hover { border-color: var(--primary); }
.tile.done { background: var(--primary-soft); border-color: var(--primary); }
.tile small { display: block; font-size: 13px; color: var(--muted); }
.avatar.big { display: flex; width: 44px; height: 44px; font-size: 20px; margin: 0 auto 6px; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 10px 0 0; }
.dots i { width: 28px; height: 6px; border-radius: 999px; background: var(--line); }
.dots i.on { background: var(--primary); }
.choice:active, .tile:active { transform: scale(.98); background: var(--primary-soft); }
.choices { display: grid; gap: 10px; }
.choice { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 20px; }
.choice .face { font-size: 30px; line-height: 1; }
.choice.on { background: var(--primary-soft); border-color: var(--primary); }
.choices.multi { grid-template-columns: repeat(2, 1fr); }
.hard-btn { margin-top: 22px; border: 0; background: transparent; color: var(--muted); text-decoration: underline; font-size: 16px; padding: 12px; }
.big-btn { margin-top: 18px; width: 100%; border: 0; border-radius: 16px; background: var(--primary); color: #fff; font-size: 20px; padding: 16px; }
.done-mark { font-size: 64px; line-height: 1; }

.print-only { display: none; }
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .nav { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .nav button { white-space: nowrap; width: auto; }
  .main { padding: 16px; }
  .grid3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .form-grid > label { padding-top: 10px; }
  .form-grid > label br { display: none; }
  .wide { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .choices.multi { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .nav, .no-print { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; font-size: 12pt; }
  .print-only { display: block; }
  .print-doc h2 { text-align: center; margin-bottom: 12pt; }
  .print-doc h3 { border-bottom: 1px solid #333; margin: 14pt 0 4pt; }
  .print-doc p { margin: 0; white-space: pre-wrap; }
}
