/* QRカルテ 共通スタイル(SORAMORIと共通のデザイン:仕様書9章) */

:root {
  --bg: #eef4f8;
  --card: #ffffff;
  --navy: #15324a;
  --text: #172b3d;
  --label: #243649;
  --muted: #425267;
  --sub-bg: #e5edf4;
  --sub-text: #29445a;
  --outline: #315580;
  --input-border: #c7d4df;
  --green: #087f69;
  --topbar: #0f172a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
}

button, input, select, textarea { font: inherit; }

/* ---------- ログイン・権限選択のカード ---------- */

.authPage {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.authCard {
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.authCard.wide { width: min(760px, 100%); }

.authIcon { display: block; width: 44px; height: 44px; margin: 0 auto 6px; }

.authTitle {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  text-align: center;
}

.authSubTitle {
  margin-top: 6px;
  margin-bottom: 20px;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}

.authHeading {
  margin: 0 0 14px;
  color: var(--navy);
  font-size: 22px;
  font-weight: 800;
}

.authModeSwitch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.authModeButton,
.authPrimaryButton,
.authSecondaryButton {
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.authModeButton {
  min-height: 40px;
  padding: 10px 12px;
  background: var(--sub-bg);
  color: var(--sub-text);
}

.authModeButton.active { background: var(--navy); color: #fff; }

.authSharedNote {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.authLabel {
  display: block;
  margin-top: 12px;
  color: var(--label);
  font-size: 14px;
  font-weight: 700;
}

.authInput {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: 12px;
  background: #fff;
  color: var(--navy);
  font-size: 16px;
}

.authInput:focus { border-color: #2563eb; outline: 2px solid rgba(37, 99, 235, 0.18); outline-offset: 1px; }

.authPrimaryButton {
  width: 100%;
  min-height: 44px;
  margin-top: 18px;
  padding: 13px 16px;
  background: var(--navy);
  color: #fff;
  font-size: 16px;
}

.authSecondaryButton {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  padding: 10px 16px;
  background: var(--sub-bg);
  color: var(--sub-text);
}

.authPrimaryButton:disabled,
.authSecondaryButton:disabled { opacity: 0.6; cursor: not-allowed; }

.authLink {
  display: block;
  margin: 14px auto 0;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--outline);
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

.authMessage {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 14px;
  line-height: 1.6;
}

.authMessage { white-space: pre-line; }
.authMessage.info { background: #e6f4f1; color: #075e4f; }
.authMessage:empty { display: none; }

.authNote {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* 利用規約 */
.termsPreview { margin-top: 14px; }
.termsPreview summary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  color: var(--navy);
  cursor: pointer;
  list-style: none;
}
.termsPreview summary::-webkit-details-marker { display: none; }
.termsPreview summary:focus-visible { outline: 3px solid #6393c8; outline-offset: 2px; }
.termsBody {
  margin-top: 12px;
  padding: 16px;
  max-height: 55vh;
  overflow: auto;
  overflow-wrap: anywhere;
  border: 1px solid #ccd9e4;
  border-radius: 8px;
  color: var(--navy);
  background: #fff;
  font-size: 14px;
  line-height: 1.8;
}
.termsBody h1 { font-size: 22px; }
.termsBody h2 { font-size: 17px; margin-top: 24px; }
.termsBody ol { padding-left: 1.6em; }
.termsBody li { margin-bottom: 8px; }
.termsCheckbox {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  margin: 14px 0 0;
  color: var(--navy);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.termsCheckbox input { flex: 0 0 20px; width: 20px; height: 20px; margin: 0; }
.termsStatus { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.termsStatus:empty { display: none; }
body > .termsDocument { max-width: 760px; margin: 24px auto; padding: 0 16px; color: var(--navy); line-height: 1.8; }
.termsDocument { overflow-wrap: anywhere; }

/* 利用権限の選択 */
.roleList { display: grid; gap: 12px; margin-top: 4px; }
.roleButton {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: center;
  cursor: pointer;
}
.roleButton:hover { border-color: var(--outline); background: #f5f8fb; }
.roleButton:disabled { color: #8a99a8; background: #f1f5f9; cursor: not-allowed; }
.roleButton small { display: block; color: #9a3412; font-size: 12px; }
.roleEmail { margin: -6px 0 14px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- ログイン後の画面 ---------- */

.appShell { min-height: 100vh; padding-top: 56px; }

.topBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  min-height: 56px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--navy);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 800; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }

.contextBadge {
  min-width: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contextBadge.owner { background: #f2b233; color: #3d2a00; font-weight: 700; }

.topSpacer { flex: 1 1 auto; }

.userButton {
  min-width: 0;
  max-width: min(32vw, 300px);
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.userButton:hover, .userButton:focus-visible { background: rgba(255, 255, 255, 0.14); outline: none; }

.logoutButton, .roleMenuButton {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.logoutButton { border: 0; background: #fff; color: var(--navy); }
.roleMenuButton { border: 1px solid #5b7590; background: #26425c; color: #fff; }

.roleMenu {
  position: absolute;
  top: calc(100% + 4px);
  right: 12px;
  width: min(320px, calc(100vw - 24px));
  padding: 14px;
  border-radius: 12px;
  background: #18243a;
  color: #fff;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.38);
  display: grid;
  gap: 8px;
}
.roleMenuTitle { font-size: 14px; font-weight: 700; }
.roleMenuCurrent { font-size: 13px; color: #c9d7e4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roleMenuOption {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid #3a4a63;
  border-radius: 10px;
  background: #1f2d45;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.roleMenuOption:hover { background: #334155; }
.roleMenuOption.active { border-color: #4a78e0; background: #2456c8; }
.roleMenuOption:disabled { opacity: 0.55; cursor: not-allowed; }

.page { max-width: 1200px; margin: 0 auto; padding: 24px; display: grid; gap: 24px; }

.panel { background: var(--card); border-radius: 18px; padding: 24px; }
.panel h2 { margin: 0 0 12px; color: var(--navy); font-size: 18px; }
.panel p { margin: 6px 0; line-height: 1.7; }
.muted { color: var(--muted); }

.permList { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; padding: 0; list-style: none; }
.permList li { padding: 4px 12px; border-radius: 999px; font-size: 13px; }
.permList li.on { background: #e6f4f1; color: #075e4f; font-weight: 700; }
.permList li.off { background: #f1f5f9; color: #8a99a8; text-decoration: line-through; }

/* パスワード変更 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.58);
}
.dialog { width: min(420px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; border-radius: 18px; background: #fff; padding: 22px; }
.dialogTitle { color: var(--navy); font-size: 21px; font-weight: 800; text-align: center; }
.dialogSub { margin: 6px 0 12px; color: var(--muted); font-size: 13px; text-align: center; overflow-wrap: anywhere; }
.dialogActions { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialogActions .authPrimaryButton, .dialogActions .authSecondaryButton { margin-top: 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 300;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
  pointer-events: none; /* お知らせの下のボタンも押せるように */
}

@media (max-width: 640px) {
  .authPage { padding: 16px; align-items: flex-start; }
  .authCard { margin-top: 24px; padding: 20px; }
  .topBar { gap: 6px; padding: 6px 8px; }
  .brand { font-size: 15px; }
  .brand img { width: 24px; height: 24px; }
  .contextBadge { font-size: 11px; padding: 3px 8px; max-width: 34vw; }
  .userButton { display: none; }
  .logoutButton, .roleMenuButton { min-height: 36px; padding: 0 10px; font-size: 13px; }
  .page { padding: 12px; gap: 12px; }
  .panel { padding: 16px; }
}

/* ---------- 段階3〜8の画面部品 ---------- */

h3 { margin: 16px 0 8px; color: var(--navy); font-size: 16px; }
a { color: var(--outline); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; }
.errorText { color: #9a3412; }
.dangerText { color: #b42318 !important; }
.lateText { color: #8f1d14; font-weight: 700; }
.fieldHint { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.notice { margin: 8px 0; padding: 10px 12px; border-radius: 12px; background: #eef4f8; color: var(--sub-text); font-size: 14px; }
.dialogMessage { margin: 0 0 8px; line-height: 1.7; }
.codeText { font-family: Consolas, "Courier New", monospace; font-weight: 700; letter-spacing: 0.02em; overflow-wrap: anywhere; }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px;
  background: var(--card);
  border-radius: 14px;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--sub-text);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover { background: var(--sub-bg); }
.tab.active { background: var(--navy); color: #fff; }
#view { display: grid; gap: 24px; }

.panelHead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panelHead h2 { margin: 0; }

.pillButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.pillButton.sub { background: var(--sub-bg); color: var(--sub-text); }
.pillButton:disabled { opacity: 0.6; cursor: not-allowed; }
.authPrimaryButton.danger { background: #b42318; }
.authPrimaryButton.slim, .authSecondaryButton.slim { width: auto; min-height: 40px; margin-top: 0; padding: 8px 18px; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.linkButton {
  padding: 6px 8px;
  border: 0;
  background: none;
  color: var(--outline);
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.quickRow, .buttonRow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.buttonRow { margin-top: 14px; }

.inlineForm { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.inlineForm .authLabel { margin-top: 0; }
.inlineForm .pillButton { margin-bottom: 1px; }
.grow { flex: 1 1 200px; }
.grow2 { flex: 2 1 260px; }

.filterRow { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.filterRow .authLabel { margin-top: 0; }

.formGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.formActions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
textarea.authInput { resize: vertical; line-height: 1.6; }
.checkRow { display: flex; align-items: center; gap: 10px; min-height: 40px; margin-top: 8px; font-size: 14px; color: var(--label); }
.checkRow input { width: 20px; height: 20px; margin: 0; flex: 0 0 20px; }
.checkRow small { color: var(--muted); }
.checkRow.locked { color: #8a99a8; }
.choice { margin: 0 0 8px; padding: 0; border: 0; }
.choice legend { color: var(--label); font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.issueRow { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.colorInput { height: 48px; padding: 4px; }

.tableWrap { overflow-x: auto; margin-top: 8px; }
.dataTable { width: 100%; border-collapse: collapse; font-size: 14px; }
.dataTable th, .dataTable td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e3eaf0; vertical-align: top; }
.dataTable th { font-size: 13px; color: var(--muted); font-weight: 700; background: #f5f8fb; white-space: nowrap; }
.dataTable td.actions { white-space: nowrap; text-align: right; }
.rowLink { cursor: pointer; }
.rowLink:hover { background: #f5f8fb; }
.inlineSelect { margin-top: 0; padding: 6px 8px; font-size: 13px; width: auto; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--sub-bg); color: var(--sub-text); font-size: 12px; font-weight: 700; white-space: nowrap; }
.tag.ok { background: #e6f4f1; color: #075e4f; }
.tag.stop { background: #fdecea; color: #8f1d14; }
.tag.wait { background: #fff4d6; color: #6b4600; }
.stepTag {
  --step: #5b7590;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--step);
  color: var(--step);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.kvList { display: grid; gap: 2px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #eef2f6; font-size: 14px; }
.kv > span:first-child { color: var(--muted); flex: 0 0 auto; }
.kv > span:last-child { text-align: right; overflow-wrap: anywhere; }

.timeline { display: grid; gap: 10px; }
.timelineItem { display: block; padding: 10px 12px; border: 1px solid #e3eaf0; border-radius: 12px; color: inherit; text-decoration: none; }
.timelineItem:hover { border-color: var(--outline); }
.timelineItem.inherited { background: #f5f8fb; border-style: dashed; }
.timelineHead { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; }
.timelineTitle { margin-top: 4px; font-weight: 700; }

.countGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.countGrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.countCard { display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--bg); color: var(--navy); text-decoration: none; border: 1px solid transparent; }
.countCard:hover { border-color: var(--outline); }
.countCard span { font-size: 13px; font-weight: 700; }
.countCard strong { font-size: 28px; font-weight: 800; line-height: 1.1; }
.countCard small { font-size: 12px; color: var(--muted); }
.countCard.over { background: #fdecea; color: #8f1d14; }
.countCard.soon { background: #fff4d6; color: #6b4600; }
.countCard.step { background: #fff; border-color: #e3eaf0; }
.warnBox { margin: 8px 0 12px; padding: 12px 14px; border-radius: 12px; background: #fff4d6; color: #6b4600; font-size: 14px; display: grid; gap: 4px; }
.warnBox ul { margin: 4px 0 0; padding-left: 1.2em; }

.deadlineList { display: grid; gap: 8px; }
.deadline { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: #f5f8fb; }
.deadline.over { background: #fdecea; }
.deadline.soon { background: #fff4d6; }
.deadline.done { background: #f1f5f9; color: #8a99a8; }
.deadlineType { font-size: 13px; font-weight: 700; color: var(--sub-text); }
.deadline.over .deadlineType, .deadline.over .deadlineDate { color: #8f1d14; }
.deadline.soon .deadlineType, .deadline.soon .deadlineDate { color: #6b4600; }
.deadlineDate { font-weight: 800; }
.deadlineState { margin-left: 8px; font-size: 12px; font-weight: 700; }
.deadlineActions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px; }

.photoGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo { margin: 0; }
.photoOpen { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 1px solid #e3eaf0; border-radius: 10px; overflow: hidden; background: #f1f5f9; cursor: zoom-in; }
.photoOpen img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo figcaption { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.photoAdd { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 12px; }
.photoAdd .authLabel { margin-top: 0; }
.fileButton { cursor: pointer; }
.fileButton.busy { opacity: 0.6; pointer-events: none; }
.photoViewer { flex-direction: column; gap: 12px; }
.photoViewer img { max-width: 100%; max-height: calc(100dvh - 120px); border-radius: 12px; }

.scanBox { position: relative; width: min(520px, 100%); aspect-ratio: 4 / 3; margin: 0 auto; border-radius: 16px; overflow: hidden; background: #0e1a26; }
.scanBox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanFrame { position: absolute; inset: 18% 22%; border: 3px solid #f2b233; border-radius: 16px; pointer-events: none; }
.scanMessage { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 10px; background: rgba(14, 26, 38, 0.7); color: #fff; font-size: 14px; text-align: center; }
.zoomLabel { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--label); }
.scanResult { margin-top: 14px; padding: 14px; border-radius: 12px; background: #f5f8fb; display: grid; gap: 8px; justify-items: start; }
.manualForm { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px; }
.manualForm .authLabel { flex: 1 1 240px; margin-top: 0; }

.permChecks { display: grid; gap: 2px; margin-top: 10px; }
.selCol { width: 36px; }
.selCol input { width: 20px; height: 20px; }
.listTools { margin: 0 0 4px; }
.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 640px) {
  #view { gap: 12px; }
  .formGrid { grid-template-columns: 1fr; }
  .countGrid.three { gap: 6px; }
  .countCard { padding: 10px; }
  .countCard strong { font-size: 22px; }
  /* 表は、スマホでは1行をカードのように縦に並べる */
  .dataTable thead { display: none; }
  .dataTable, .dataTable tbody, .dataTable tr, .dataTable td { display: block; width: 100%; }
  .dataTable tr { padding: 8px 0; border-bottom: 1px solid #e3eaf0; }
  .dataTable td { border: 0; padding: 3px 4px; display: flex; justify-content: space-between; gap: 10px; }
  .dataTable td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; flex: 0 0 auto; }
  .dataTable td.actions { justify-content: flex-end; }
  .deadline { flex-direction: column; align-items: stretch; }
  .formActions { justify-content: stretch; }
  .formActions > * { flex: 1; }
}

/* 移管(仕様書 7章) */
.transferRecord { margin: 0 0 12px; padding: 12px 14px; border: 1px solid #e3eaf0; border-radius: 12px; display: grid; gap: 8px; }
.transferCard { padding: 14px 0; border-bottom: 1px solid #e3eaf0; display: grid; gap: 8px; }
.transferCard:last-child { border-bottom: 0; }
