:root {
  --bg: #faf9f6;
  --card: #ffffff;
  --ink: #1f2937;
  --sub: #6b7280;
  --line: #e5e7eb;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --changed-bg: #fef3c7;
  --changed-border: #f59e0b;
  --ok: #15803d;
  --ng: #dc2626;
  --na: #6b7280;
  --danger: #b91c1c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 17px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  line-height: 1.5;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

main { max-width: 640px; margin: 0 auto; }

/* ---------- ヘッダー ---------- */
#app-header {
  background: var(--accent);
  color: var(--accent-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
#hd-title { margin: 0; font-size: 1.1rem; font-weight: 700; }
#hd-sub { font-size: 0.85rem; opacity: 0.95; overflow-wrap: anywhere; }

/* ---------- 読み込み画面 ---------- */
#screen-load { padding: 24px 16px; text-align: center; }
.guide { color: var(--sub); font-size: 1rem; }
.error { color: var(--danger); font-weight: 600; overflow-wrap: anywhere; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-secondary { border-color: var(--accent); color: var(--accent); }
.btn-ghost { border: none; background: none; color: var(--accent); min-height: 44px; }
.btn-danger-ghost { border-color: var(--danger); color: var(--danger); background: none; width: 100%; margin-top: 12px; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn-file { position: relative; overflow: hidden; }
.btn-file input[type="file"] { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

/* ---------- タブ ---------- */
#tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
}
.tab.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab .badge {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--changed-border);
  color: #fff;
  font-size: 0.8rem;
  text-align: center;
}
.tab .badge:empty { display: none; }

/* ---------- 行一覧 ---------- */
#rows { padding: 8px 16px 16px; }
.section-head {
  margin: 14px 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--sub);
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 8px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.row.changed {
  background: var(--changed-bg);
  border-left: 6px solid var(--changed-border);
}
.judge-badge {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  font-size: 1.3rem;
  font-weight: 700;
  background: #fff;
}
.judge-badge.j-ok { color: var(--ok); border-color: var(--ok); }
.judge-badge.j-ng { color: var(--ng); border-color: var(--ng); }
.judge-badge.j-na { color: var(--na); }
.judge-badge.j-none { color: var(--line); }
.row-text { min-width: 0; }
.row-item { font-weight: 700; overflow-wrap: anywhere; }
.row-value { font-size: 0.9rem; color: var(--sub); overflow-wrap: anywhere; }
.row-sub { font-size: 0.9rem; color: var(--ink); overflow-wrap: anywhere; }
.row-diff { font-size: 0.85rem; color: #92400e; font-weight: 700; }

/* ---------- 下部バー ---------- */
#bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
#change-count { font-weight: 700; }

/* ---------- シート ---------- */
#overlay {
  position: fixed; inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.35);
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .sheet { max-width: 640px; margin: 0 auto; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.sheet-title { font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; }
.prev-value { font-size: 0.9rem; color: var(--sub); overflow-wrap: anywhere; }

.field { margin-top: 16px; }
.field-label { font-size: 0.9rem; font-weight: 700; color: var(--sub); margin-bottom: 6px; }
.from-note { font-size: 0.85rem; color: var(--sub); margin-top: 4px; }

input, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1.05rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row input { flex: 1 1 auto; min-width: 0; }
.input-row .btn { flex: 0 0 auto; white-space: nowrap; }

/* 判定ボタン */
.judge-btns { display: flex; gap: 12px; }
.judge-btn {
  flex: 1 1 0;
  min-height: 64px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
}
.judge-btn.j-ok { color: var(--ok); }
.judge-btn.j-ng { color: var(--ng); }
.judge-btn.j-na { color: var(--na); }
.judge-btn.sel { border-width: 3px; background: var(--changed-bg); }
.judge-btn.j-ok.sel { border-color: var(--ok); }
.judge-btn.j-ng.sel { border-color: var(--ng); }
.judge-btn.j-na.sel { border-color: var(--na); }

/* 写真 */
.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.photo-item { width: 96px; text-align: center; font-size: 0.75rem; color: var(--sub); }
.photo-item img {
  width: 96px; height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.photo-item button {
  margin-top: 4px;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--danger);
  font-size: 0.85rem;
  cursor: pointer;
}

/* 書き出し */
.summary {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 0.95rem;
  white-space: pre-wrap;
}
#btn-export { margin-top: 12px; }
.export-photos { display: flex; flex-direction: column; gap: 8px; }
.export-photo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.9rem;
}
.export-photo-row .pname { font-weight: 700; }
.export-photo-row .pwhere { color: var(--sub); overflow-wrap: anywhere; }

/* クラウド送信 */
#btn-send, #btn-resend { margin-top: 10px; }
.send-status { margin-top: 8px; font-size: 0.9rem; font-weight: 600; color: var(--ok); overflow-wrap: anywhere; }
.send-status:empty { display: none; }
.outbox-badge {
  padding: 3px 10px;
  border: 1px solid var(--changed-border);
  border-radius: 999px;
  background: var(--changed-bg);
  color: #92400e;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
#cloud-settings {
  margin-top: 20px;
  padding: 4px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
#cloud-settings summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
  color: var(--sub);
  cursor: pointer;
}

hr { border: none; border-top: 1px solid var(--line); margin: 20px 0 12px; }

/* トースト */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: 90vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.92);
  color: #fff;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#toast.show { opacity: 1; }
