:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #d9d5ca;
  --accent: #1f4e79;
  --accent-ink: #ffffff;
  --danger: #a33a2b;
  --ok: #2e6b3a;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* display 指定のある要素でも hidden を確実に効かせる */

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

button, .btn {
  font: inherit;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: bold; }
button.danger, .btn.danger { color: var(--danger); border-color: #e2b8b1; }
button.active { background: #dce7f2; border-color: var(--accent); color: var(--accent); font-weight: bold; }

input, select {
  font: inherit;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  max-width: 100%;
}

/* ---- ヘッダー ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
}
.app-header .title { font-weight: bold; font-size: 18px; }
.app-header .facility { opacity: .85; font-size: 14px; }
.app-header nav { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.app-header nav a, .app-header nav button {
  color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.5);
  min-height: 36px; padding: 0 12px; border-radius: 8px; text-decoration: none;
  display: inline-flex; align-items: center; font-size: 14px;
}
.app-header nav a.current { background: rgba(255,255,255,.18); }

main { padding: 12px 16px 40px; }

/* ---- 記入画面 ---- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  background: rgba(244, 242, 236, .96);
  border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; gap: 6px; align-items: center; }
.toolbar .spacer { flex: 1; }
.swatch { width: 44px; padding: 0; }
.swatch span { display: block; width: 22px; height: 22px; border-radius: 50%; }

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  max-width: 900px;
  margin: 12px auto;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.keys label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.keys label b { color: var(--danger); font-weight: normal; }
.keys input { width: 100%; }
.keys .hint { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }
.keys .recognize { align-self: end; background: #fff8e6; border-color: #e3c98a; font-weight: bold; }
.keys input.autofilled { background: #fff8d6; }
.keys input.unclear { border: 2px solid var(--danger); }

.sheet {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  aspect-ratio: 210 / 297;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.sheet canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.sheet canvas.ink { touch-action: none; cursor: crosshair; }
.sheet canvas.live { pointer-events: none; }

.status {
  max-width: 900px;
  margin: 8px auto;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: var(--radius);
  background: #222;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  z-index: 100;
  display: none;
}
.toast.show { display: block; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

/* ---- ログイン ---- */
.login-box {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-box h1 { font-size: 22px; margin: 0 0 16px; text-align: center; }
.login-box label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.login-box input { width: 100%; margin-top: 4px; }
.login-box button { width: 100%; margin-top: 8px; }

.flash { max-width: 900px; margin: 8px auto; padding: 10px 14px; border-radius: var(--radius); background: #fff3cd; border: 1px solid #f0d78c; }
.flash.error { background: #f8e1dd; border-color: #e2b8b1; }
.flash.ok { background: #e1f0e3; border-color: #b6d8bc; }

/* ---- 検索・一覧 ---- */
.search-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
  max-width: 1100px;
  margin: 0 auto 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.search-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.search-form input { width: 100%; }
.search-form .actions { display: flex; gap: 8px; }

.results { max-width: 1100px; margin: 0 auto; }
.results .count { font-size: 14px; color: var(--muted); margin: 4px 0 8px; }
.results table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); }
.results th, .results td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.results th { background: #ece8dd; font-size: 13px; }
.results td.ops { white-space: nowrap; }
.results td.ops .btn, .results td.ops button { min-height: 38px; padding: 0 10px; font-size: 14px; }
.results td.ops form { display: inline; }

@media (max-width: 700px) {
  .results thead { display: none; }
  .results table, .results tbody, .results tr, .results td { display: block; width: 100%; }
  .results tr { border-bottom: 2px solid var(--line); padding: 6px 0; }
  .results td { border: none; padding: 4px 10px; }
  .results td[data-label]::before { content: attr(data-label) "："; color: var(--muted); font-size: 13px; }
  .results td.ops { white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; }
}

.pager { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }

/* ---- 設定 ---- */
.panel { max-width: 760px; margin: 0 auto 16px; padding: 16px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { font-size: 18px; margin: 0 0 8px; }
.panel .notes { font-size: 14px; color: var(--muted); padding-left: 20px; }
.status-line b.ok { color: var(--ok); }
.status-line b.ng { color: var(--danger); }
.settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; align-items: end; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

/* ---- カレンダー ---- */
.cal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 900px; margin: 0 auto 10px; }
.cal-head h2 { flex: 1; text-align: center; margin: 0; font-size: 20px; min-width: 160px; }
.cal-head h2 small { font-size: 14px; color: var(--muted); font-weight: normal; }
table.cal { width: 100%; max-width: 900px; margin: 0 auto; border-collapse: collapse; table-layout: fixed; background: var(--panel); }
.cal th { padding: 6px 0; font-size: 13px; background: #ece8dd; border: 1px solid var(--line); }
.cal td { border: 1px solid var(--line); height: 72px; padding: 0; vertical-align: top; }
.cal td a { display: flex; flex-direction: column; height: 100%; padding: 6px; color: var(--ink); text-decoration: none; }
.cal td a:hover { background: #f6f3ea; }
.cal td.other a { color: #b5b1a6; }
.cal td.sun .day { color: #b33a2b; }
.cal td.sat .day { color: #1f4e79; }
.cal td.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .count { margin-top: auto; align-self: flex-end; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 13px; font-weight: bold; }
.cal td.other .count { background: #9fb3c6; }
.cal-note { max-width: 900px; margin: 8px auto; font-size: 13px; color: var(--muted); }
@media (max-width: 600px) { .cal td { height: 56px; } .cal .count { padding: 1px 5px; font-size: 11px; } }

/* ---- 暗号鍵・共通 ---- */
form.inline { display: inline; }
.keygate { max-width: 900px; margin: 12px auto; padding: 12px 16px; border-radius: var(--radius); background: #fdecea; border: 1px solid #e2b8b1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.keygate p { margin: 0; font-weight: bold; color: var(--danger); }
.outbox { max-width: 900px; margin: 8px auto; padding: 10px 14px; border-radius: var(--radius); background: #fff3cd; border: 1px solid #f0d78c; font-size: 14px; }
.warn { color: var(--danger); }
.panel h3 { font-size: 16px; margin: 16px 0 6px; }
.panel details { margin: 10px 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.panel summary { cursor: pointer; font-weight: bold; min-height: 32px; display: flex; align-items: center; }
.settings-form select { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 8px; }
.check input { min-height: auto; width: 20px; height: 20px; }
.recovery { margin-top: 12px; padding: 16px; border: 2px dashed var(--accent); border-radius: var(--radius); background: #f7f9fc; }
.recovery-code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 24px; letter-spacing: 1px; font-weight: bold; word-break: break-all; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.recovery-meta { font-size: 14px; color: var(--muted); }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; border: none; }
  .no-print { display: none; }
}

/* ---- 検索（端末で復号） ---- */
.search-form .inline-check { flex-direction: row; align-items: center; gap: 6px; }
.search-form .inline-check input { min-height: auto; width: auto; }
.results tr.deleted { opacity: .55; }
.results small.sub { color: var(--muted); }
.results .hint { font-size: 12px; color: var(--muted); }
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; flex-direction: column; padding: 12px; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px; background: var(--panel); border-radius: var(--radius) var(--radius) 0 0; }
.viewer-title { flex: 1; font-weight: bold; min-width: 160px; }
.viewer iframe { flex: 1; width: 100%; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }

/* ---- 受付PC ---- */
.rc-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.rc-info { border-collapse: collapse; width: 100%; margin: 8px 0; }
.rc-info th, .rc-info td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.rc-info th { width: 12em; color: var(--muted); font-weight: normal; }
.rc-state.ok { color: var(--ok); font-weight: bold; }
.rc-state.error { color: var(--danger); font-weight: bold; }
.rc-log { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.rc-log li { padding: 3px 0; border-bottom: 1px dotted var(--line); }
.rc-log li.error { color: var(--danger); }
