:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --text: #1c2833;
  --muted: #5d6d7e;
  --line: #d5dde5;
  --primary: #1f5f8b;
  --primary-ink: #ffffff;
  --danger: #c0392b;
  --ok: #1e8449;
  --accent: #e67e22;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  background: var(--primary); color: var(--primary-ink);
  padding: 10px 16px;
}
.app-header .brand { font-weight: 700; }
.app-header .nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.app-header .nav a {
  color: var(--primary-ink); text-decoration: none; padding: 6px 12px; border-radius: 6px; opacity: .85;
}
.app-header .nav a.active, .app-header .nav a:hover { background: rgba(255,255,255,.18); opacity: 1; }
.app-header .user { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.app-header .btn.ghost { color: var(--primary-ink); border-color: rgba(255,255,255,.6); background: transparent; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.lead { margin: 0 0 12px; }
.note { color: var(--muted); font-size: 15px; }
.error { color: var(--danger); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 8px 18px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  user-select: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.huge { min-height: 64px; min-width: 220px; font-size: 22px; }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 14px; }

.steps {
  display: flex; list-style: none; margin: 0; padding: 0 16px; gap: 4px;
  max-width: 1100px; margin: 12px auto 0; counter-reset: s;
}
.steps li {
  flex: 1; text-align: center; padding: 6px 4px; font-size: 15px;
  background: #e5ebf0; color: var(--muted); border-radius: 6px; counter-increment: s;
}
.steps li::before { content: counter(s) ". "; }
.steps li.current { background: var(--primary); color: #fff; font-weight: 700; }
.steps li.done { background: #d4e6f1; color: var(--primary); }

/* カメラ */
.camera-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.camera-wrap video { display: block; width: 100%; max-height: 72vh; object-fit: contain; background: #000; }
.a4-guide {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  height: 88%; aspect-ratio: 210 / 297; max-width: 92%;
  border: 3px dashed rgba(255,255,255,.8); border-radius: 6px; pointer-events: none;
}
.camera-hint {
  position: absolute; left: 0; right: 0; bottom: 8px; margin: 0; text-align: center;
  color: #fff; text-shadow: 0 1px 3px #000; font-size: 16px;
}
.fallback { margin-top: 16px; }
.fallback summary { cursor: pointer; color: var(--muted); }

/* キャンバス */
.canvas-holder canvas { display: block; width: 100%; height: auto; border-radius: 6px; background: #222; }
.edit-canvas { touch-action: none; }
.review-canvas { touch-action: auto; border: 1px solid var(--line); }
.review-canvas.drawing { touch-action: none; outline: 4px solid var(--accent); }
.zoom-box { background: var(--surface); border: 2px solid var(--danger); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; }
.zoom-box canvas { max-height: 40vh; width: auto; max-width: 100%; margin: 0 auto; }
.zoom-title { font-weight: 700; color: var(--danger); margin-bottom: 4px; }
.sticky-tools { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; margin: 0; }
.confirm-check {
  display: flex; align-items: center; gap: 12px; margin: 16px 0; padding: 14px;
  background: #fef5e7; border: 2px solid var(--accent); border-radius: var(--radius); font-weight: 700;
}
.confirm-check input { width: 32px; height: 32px; }

/* フォーム */
.form label { display: block; margin-bottom: 14px; font-weight: 600; }
.form input, .form select {
  display: block; width: 100%; margin-top: 4px; min-height: 52px; padding: 8px 12px;
  font: inherit; font-size: 22px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
.form.compact input, .form.compact select { font-size: 18px; min-height: 44px; }
.done { text-align: center; }
.done h2 { color: var(--ok); }

/* ログイン */
.login-box { max-width: 420px; margin: 8vh auto; }
.login-box h1 { font-size: 22px; text-align: center; }

/* 一覧 */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: 14px; font-weight: 600; }
.filters input, .filters select { min-height: 44px; font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
.layout-2 { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
@media (max-width: 760px) { .layout-2 { grid-template-columns: 1fr; } }
.patient-list { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow: auto; }
.patient-list li button {
  width: 100%; text-align: left; padding: 8px 10px; border: none; border-bottom: 1px solid var(--line);
  background: none; font: inherit; cursor: pointer; display: flex; justify-content: space-between;
}
.patient-list li button.active { background: #d4e6f1; font-weight: 700; }
.date-group h3 { margin: 18px 0 8px; font-size: 17px; border-bottom: 2px solid var(--line); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.thumb-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  cursor: pointer; text-align: left; font: inherit; font-size: 14px;
}
.thumb-card img { width: 100%; aspect-ratio: 210/297; object-fit: cover; background: #eee; border-radius: 4px; display: block; }
.thumb-card .pno { font-weight: 700; font-size: 16px; }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th, table.list td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 15px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 13px; background: #e5ebf0; }
.badge.admin { background: #fdebd0; }
.badge.off { background: #f5b7b1; }

/* モーダル */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; max-width: 560px; width: 100%; }
.modal-msg { white-space: pre-wrap; font-size: 18px; }
.viewer { max-width: 900px; max-height: 95vh; overflow: auto; }
.viewer img { width: 100%; display: block; }

.busy {
  position: fixed; inset: 0; background: rgba(255,255,255,.75); z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.spinner { width: 56px; height: 56px; border: 6px solid #d4e6f1; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.mask-values { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
