:root {
  --navy: #1F3864;
  --green: #4CAF50;
  --orange: #FF9800;
  --red: #e53935;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d8e0eb;
  --shadow: 0 8px 24px rgba(31, 56, 100, 0.08);
  --radius: 12px;
  --safe-bottom: max(env(safe-area-inset-bottom), 12px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
}
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(31, 56, 100, 0.14);
  border-color: var(--navy);
}
input.invalid, textarea.invalid, select.invalid, .signature-wrap.invalid {
  border-color: var(--red) !important;
  box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.14);
}
/* 入力済みのinput/textarea/selectには薄い緑背景でフィードバック */
input.filled, textarea.filled, select.filled {
  background: #F0F9F0 !important;
  border-color: rgba(76, 175, 80, 0.55) !important;
}
.app-header {
  background: linear-gradient(180deg, var(--navy), #2b4a7f);
  color: #fff;
  padding: 14px 16px 12px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.2);
}
/* 会社情報ヘッダー (新規) */
.company-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 6px;
}
.company-logo {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  background: #ffffff;
  border-radius: 10px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.company-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.company-info {
  flex: 1 1 auto;
  min-width: 0;
}
.company-name {
  font-size: 19px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.company-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}
.company-staff {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.92);
}
.company-tel {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  background: rgba(76, 175, 80, 0.22);
  border: 1px solid rgba(76, 175, 80, 0.55);
  border-radius: 999px;
  padding: 4px 12px;
  text-decoration: none;
  min-height: 32px;
  transition: background 0.15s ease, transform 0.05s ease;
}
.company-tel:hover { background: rgba(76, 175, 80, 0.35); }
.company-tel:active { transform: scale(0.97); }
.header-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  margin: 8px 0 10px;
}
.report-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.title-icon { margin-right: 4px; }
h1 { margin: 0; font-size: 22px; }
.subtitle { margin: 4px 0 0; color: rgba(255,255,255,0.88); font-size: 12px; }
.header-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
/* ログイン画面の会社情報カード */
.login-welcome-card {
  background: linear-gradient(180deg, #ffffff, #f3f6fc);
  border: 1px solid rgba(31, 56, 100, 0.18);
  border-left: 4px solid var(--navy);
  margin-bottom: 12px;
  padding: 14px 16px;
}
.login-welcome-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--navy);
}
.login-welcome-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.02em;
}
.app-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}
.view { display: none; }
.view.active { display: block; }
.stack { display: flex; flex-direction: column; }
.gap16 { gap: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.info-card {
  border: 1px solid rgba(76, 175, 80, 0.35);
  background: linear-gradient(180deg, #ffffff, #f8fff9);
}
.card-title, .subsection-title {
  font-weight: 700;
  color: var(--navy);
}
.card-title {
  font-size: 17px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: linear-gradient(90deg, var(--navy) 0%, #2b4a7f 100%);
  color: #ffffff;
  border-radius: 8px;
  letter-spacing: 0.02em;
  margin-left: -14px;
  margin-right: -14px;
  margin-top: -4px;
  padding-left: 14px;
  padding-right: 14px;
  box-shadow: 0 2px 6px rgba(31, 56, 100, 0.18);
}
.card-title-row .card-title,
.modal-title-row .card-title,
.card-title-row + .card-title {
  margin: 0;
}
.card-title-row, .modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.subsection-title {
  font-size: 15px;
  margin: 18px 0 10px;
  font-weight: 700;
  color: var(--navy);
}
/* ==============================================
   ラベルと入力欄の視覚的区別 (新規)
   - ラベル: グレー背景 + ネイビー太字 + ▶マーク
   - 入力欄: 白背景 + 左ボーダー + プレースホルダー
   ============================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.field > span.field-label,
.field span {
  display: inline-block;
  background: #F2F2F2;
  border-left: 3px solid var(--navy);
  color: var(--navy);
  font-size: 14px;
  font-weight: 700;
  padding: 6px 12px 6px 10px;
  border-radius: 6px;
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  letter-spacing: 0.02em;
}
.field > span::before {
  content: '▶ ';
  color: var(--navy);
  margin-right: 2px;
  font-size: 11px;
}
.required-field > span::after {
  content: ' *';
  color: var(--red);
  font-weight: 800;
  margin-left: 2px;
}
/* 入力欄: 白背景 + 左ボーダー 3px ネイビー */
.field input,
.field textarea,
.field select {
  background: #ffffff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--navy);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.2s ease;
  min-height: 48px;
}
.field input::placeholder,
.field textarea::placeholder {
  color: #999999;
  font-size: 14px;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--navy);
  border-left-width: 4px;
  border-left-color: var(--green);
  box-shadow: 0 2px 8px rgba(31, 56, 100, 0.18);
  background: #ffffff;
}
/* 入力済み: 薄い緑背景 */
.field input.filled,
.field textarea.filled,
.field select.filled {
  background: #F0F9F0 !important;
  border-left-color: var(--green) !important;
}
@media (max-width: 480px) {
  .field > span { font-size: 13px; padding: 6px 10px; }
  .field input, .field textarea, .field select { font-size: 16px; }
}
.grid {
  display: grid;
  gap: 12px;
}
.grid.two { grid-template-columns: 1fr 1fr; }
.btn {
  min-height: 48px;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.secondary { background: #e8eef7; color: var(--navy); }
.btn.ghost { background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.24); }
#reportView .btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn.full { width: 100%; }
.btn.large { min-height: 54px; font-size: 17px; }
.mini-badge, .demo-badge, .count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}
.demo-badge { background: rgba(255, 152, 0, 0.18); color: #fff3e0; border: 1px solid rgba(255,255,255,0.22); }
.mini-badge { background: #fff4e5; color: #9a5a00; }
.count-pill { background: #e8eef7; color: var(--navy); }
.period-display, .info-strip, .modal-note {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  margin-bottom: 12px;
}
.info-strip.success { color: #1b5e20; background: #edf7ed; border-color: rgba(76, 175, 80, 0.4); }
.account-list { display: grid; gap: 10px; }
.account-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
}
.account-item span { color: var(--muted); }
.error-text { color: var(--red); font-size: 14px; min-height: 20px; }
.worker-notes {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.worker-note {
  padding: 12px;
  border-radius: 10px;
  background: #fff8e8;
  border: 1px solid #ffd89b;
  color: #8a4b00;
  font-weight: 700;
  line-height: 1.5;
}
.workers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.worker-total-summary {
  margin-top: 12px;
  font-size: 15px;
  font-weight: 800;
}
.worker-total-summary.warn {
  color: #b42318;
  background: #fff5f5;
  border-color: rgba(229, 57, 53, 0.35);
}
.worker-total-summary.ok {
  color: #1b5e20;
  background: #edf7ed;
  border-color: rgba(76, 175, 80, 0.35);
}
/* ==============================================
   安全管理ブロック(高所作業/ヘルメット)
   ============================================== */
.safety-block {
  margin-top: -6px;
  margin-bottom: 14px;
  padding: 12px 12px 10px;
  border: 1px dashed rgba(31, 56, 100, 0.35);
  border-radius: 10px;
  background: #f9fbff;
}
.safety-block.is-active {
  border-style: solid;
  border-color: rgba(255, 152, 0, 0.55);
  background: #fffaf0;
}
.safety-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.safety-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  background: #F2F2F2;
  border-left: 3px solid var(--green);
  padding: 6px 10px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.segmented {
  display: inline-flex;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg-item {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.seg-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}
.seg-item span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.seg-item input:checked + span,
.seg-item.active span {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 4px rgba(31, 56, 100, 0.25);
}
.seg-item[data-height="yes"] input:checked + span {
  background: var(--orange);
}
.helmet-row {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  cursor: pointer;
  min-height: 44px;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}
.helmet-row.is-shown {
  display: flex;
}
.helmet-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-height: auto;
  accent-color: var(--green);
}
.helmet-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.helmet-icon {
  font-size: 18px;
}
.worker-card .safety-block {
  margin-top: -8px;
}
.worker-safety-wrap {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease;
}
.worker-safety-wrap.is-visible {
  max-height: 220px;
  opacity: 1;
}
.worker-safety-wrap .safety-block {
  margin-top: -8px;
}
/* 安全管理サマリ */
.safety-summary {
  margin-top: 10px;
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  gap: 6px;
}
.safety-summary.is-all-ok {
  background: #edf7ed;
  border-color: rgba(76, 175, 80, 0.45);
}
.safety-summary.is-warn {
  background: #fff5f5;
  border-color: rgba(229, 57, 53, 0.45);
}
.safety-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}
.safety-summary-label {
  font-weight: 700;
  color: var(--navy);
}
.safety-summary.is-all-ok .safety-summary-label,
.safety-summary.is-all-ok .safety-summary-value {
  color: #1b5e20;
}
.safety-summary.is-warn .safety-summary-label,
.safety-summary.is-warn .safety-summary-value {
  color: #b42318;
}
.safety-summary-value {
  font-size: 15px;
  font-size: 15px;
  font-weight: 800;
}
.safety-summary-note {
  font-size: 13px;
  margin-top: 4px;
  color: #b42318;
  font-weight: 700;
}
.safety-banner {
  background: #fff5f5;
  border: 1px solid rgba(229, 57, 53, 0.55);
  border-radius: 10px;
  padding: 12px;
  color: #b42318;
  font-weight: 700;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.safety-banner .warn-icon {
  font-size: 20px;
  flex: 0 0 auto;
}
.field.has-warn input,
.field.has-warn textarea,
.field.has-warn select {
  border-color: var(--red) !important;
  box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.12);
}
@media (max-width: 480px) {
  .seg-item span { min-height: 34px; padding: 5px 10px; font-size: 13px; }
  .helmet-row { font-size: 13px; }
}
.checklist { display: grid; gap: 10px; }
.checklist-required-note {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(229, 57, 53, 0.35);
  background: #fff5f5;
  color: #b42318;
  font-weight: 800;
  line-height: 1.5;
}
.checklist-validation-message {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(229, 57, 53, 0.45);
  background: #fff1f1;
  color: #8f1d1d;
  line-height: 1.6;
}
.checklist-validation-message ul {
  margin: 8px 0 8px 18px;
  padding: 0;
}
.checklist-warning-title {
  font-weight: 800;
  margin-bottom: 4px;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  transition: all 0.2s ease;
}
.check-item.checked {
  background: #eef8ef;
  border-color: rgba(76, 175, 80, 0.45);
}
.check-item.invalid {
  border-color: rgba(229, 57, 53, 0.7) !important;
  box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.14);
  background: #fff5f5;
}
.check-item input {
  width: 24px;
  height: 24px;
  min-height: auto;
  accent-color: var(--green);
}
.file-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 2px dashed #b8c8df;
  border-radius: 12px;
  background: #f8fbff;
  color: var(--navy);
  font-weight: 700;
  margin-bottom: 12px;
}
.file-picker input { display: none; }
.photo-preview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.photo-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #e5e7eb;
  aspect-ratio: 1 / 1;
}
.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-card button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 18px;
}
.signature-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
#signatureCanvas {
  width: 100%;
  height: 180px;
  display: block;
  touch-action: none;
  background: linear-gradient(180deg, #ffffff, #fbfbfb);
}
.signature-help {
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  color: var(--navy);
  font-weight: 700;
  line-height: 1.5;
}
.signature-preview img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mail-preview {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  line-height: 1.6;
}
.toggle-field {
  justify-content: flex-end;
}
.toggle-field input {
  width: 24px;
  height: 24px;
  align-self: flex-start;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.summary-item {
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.summary-item strong {
  display: block;
  font-size: 22px;
  color: var(--navy);
  margin-top: 6px;
}
.admin-list, .history-list { display: grid; gap: 12px; }
.list-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}
.list-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.list-title { font-weight: 700; color: var(--navy); }
.list-meta { color: var(--muted); font-size: 13px; }
.list-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tag {
  font-size: 12px;
  background: #eef3f9;
  color: var(--navy);
  padding: 4px 8px;
  border-radius: 999px;
}
.tag.ok { background: #edf7ed; color: #1b5e20; }
.tag.warn { background: #fff4e5; color: #a05a00; }
.modal, .overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  z-index: 100;
}
.hidden { display: none !important; }
.modal-card, .loader-card, .success-card {
  width: min(100%, 720px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.25);
  padding: 18px;
}
.modal-card.large { max-height: 84vh; overflow: auto; }
.modal-title { font-size: 18px; font-weight: 800; color: var(--navy); margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.confirm-summary { max-height: 42vh; overflow: auto; font-size: 14px; }
.detail-content {
  display: grid;
  gap: 10px;
}
.detail-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #f9fbfd;
}
.detail-block h4 {
  margin: 0 0 8px;
  color: var(--navy);
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: #eef3f9;
  color: var(--navy);
  font-size: 18px;
}
.loader-card, .success-card {
  width: min(100%, 320px);
  text-align: center;
}
.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border: 4px solid #d7dfec;
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.success-card { position: relative; z-index: 2; }
.success-check { font-size: 48px; }
.success-title { font-size: 22px; font-weight: 800; color: var(--navy); margin-top: 8px; }
.success-text { margin-top: 8px; font-weight: 700; }
.success-subtext { margin-top: 6px; color: var(--muted); font-size: 13px; }
#confettiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.submit-bar {
  width: min(100%, 600px);
  margin: 0 auto 24px;
  padding: 10px 16px calc(var(--safe-bottom) + 6px);
}
.submit-bar .btn {
  background: linear-gradient(180deg, var(--navy), #2b4a7f);
  box-shadow: 0 10px 24px rgba(31, 56, 100, 0.18);
}
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 20px 0;
}
@media (max-width: 640px) {
  .grid.two, .summary-grid { grid-template-columns: 1fr; }
  .account-item, .list-top, .modal-actions { flex-direction: column; }
  .workers-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 768px) {
  .photo-preview { grid-template-columns: repeat(4, 1fr); }
}
