/* KY ミニアプリ。iPhone (WebKit) で崩れない書き方:
   - 割合の高さを flex:1 の中で使わない / 枠の大きさを中身から推し量らせない
   - figure と img の間に改行を入れない (JS で組むので入らない)。figure は line-height:0 */
:root {
  --ink: #1b2a3a;
  --ink-2: #4a5868;
  --muted: #7a8794;
  --line: #e2e6ea;
  --bg: #f3f5f7;
  --card: #ffffff;
  --brand: #1b2a3a;
  --accent: #f5b301;      /* 安全黄 */
  --primary: #0b8a4a;     /* ヨシ! の緑 */
  --primary-dark: #08703c;
  --high: #d93025;
  --mid: #e8890c;
  --low: #2f7dd1;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
  border-bottom: 4px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; }
.brand-mark { display: inline-block; background: var(--accent); color: var(--brand); font-weight: 900; padding: 2px 8px; border-radius: 6px; letter-spacing: .05em; }
.user { font-size: 13px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }

.app { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 16px 0; margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.page-title { font-size: 20px; margin: 4px 0 12px; }

/* ホーム */
.hero {
  background: linear-gradient(135deg, #24384d, #1b2a3a); color: #fff;
  border-radius: var(--radius); padding: 18px 16px 16px; margin-bottom: 18px;
}
.hero-date { margin: 0; font-size: 14px; opacity: .85; }
.hero-greet { margin: 2px 0 14px; font-size: 19px; font-weight: 700; }
.block { margin-bottom: 20px; }
.block-title { font-size: 16px; margin: 0 0 8px; padding-left: 10px; border-left: 4px solid var(--accent); }
.block-title.attention { border-left-color: var(--high); color: var(--high); }
.list { display: grid; gap: 10px; }

.kycard {
  display: block; text-decoration: none; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.kycard:active { background: #f8fafb; }
.kycard-head, .sheet-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kycard-date { font-weight: 700; font-size: 14px; color: var(--ink-2); }
.kycard-site { margin: 4px 0 0; font-weight: 700; font-size: 17px; }
.kycard-work { margin: 2px 0 8px; color: var(--ink-2); font-size: 14px; }
.kycard-foot { display: flex; gap: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.kycard-foot .done { color: var(--primary); font-weight: 700; }
.kycard-foot .need { color: #fff; background: var(--high); border-radius: 999px; padding: 0 8px; font-weight: 700; }
.chip-mini { font-size: 12px; background: #eef1f4; color: var(--ink-2); border-radius: 999px; padding: 1px 8px; }
.lv { font-size: 12px; font-weight: 700; color: #fff; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.lv-high { background: var(--high); }
.lv-mid { background: var(--mid); }
.lv-low { background: var(--low); }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-style: dashed; border-color: #b9c2cb; color: var(--ink-2); width: 100%; margin-top: 8px; }
.btn-big { width: 100%; min-height: 54px; font-size: 18px; }
.btn-small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.link-btn { background: none; border: 0; color: var(--low); font: inherit; font-size: 14px; padding: 4px; cursor: pointer; }
.link-btn.danger { color: var(--high); }

/* フォーム */
.form { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-title { font-size: 16px; margin: 0 0 8px; }
.card label { display: block; font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 10px 0 4px; }
.card label.sub { font-weight: 600; margin-top: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
input[type="text"], input[type="date"], input[type="search"], textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px 未満だと iPhone が拡大する */
  padding: 10px 12px; border: 1px solid #cbd3db; border-radius: 10px; background: #fff; color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
input[type="date"] { min-height: 46px; }
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  min-height: 40px; padding: 4px 14px; border-radius: 999px; border: 1px solid #cbd3db; background: #fff;
  font: inherit; font-size: 15px; color: var(--ink-2); cursor: pointer;
}
.seg-btn.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 700; }
.seg-level .seg-btn { min-width: 64px; }
.seg-level .lvbtn-high.on { background: var(--high); border-color: var(--high); }
.seg-level .lvbtn-mid.on { background: var(--mid); border-color: var(--mid); }
.seg-level .lvbtn-low.on { background: var(--low); border-color: var(--low); }

.hazards { display: grid; gap: 10px; }
.hazard { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; background: #fffdf5; }
.hazard-head { display: flex; justify-content: space-between; align-items: center; }
.hazard-no { font-weight: 800; font-size: 14px; color: var(--ink); }

.examples { margin-bottom: 10px; }
.examples summary { cursor: pointer; color: var(--low); font-size: 14px; font-weight: 700; padding: 4px 0; }
.example-list { display: grid; gap: 6px; margin-top: 6px; }
.example {
  display: flex; align-items: flex-start; gap: 8px; text-align: left;
  background: #f7f9fb; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font: inherit; font-size: 14px; color: var(--ink); cursor: pointer;
}

.goal-row { display: flex; align-items: center; gap: 8px; }
.goal-row input { flex: 1 1 auto; min-width: 0; }
.yoshi { font-weight: 900; color: var(--primary); font-size: 18px; white-space: nowrap; }

.members { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip { display: inline-flex; align-items: center; gap: 2px; background: #e8f5ee; color: var(--primary-dark); border-radius: 999px; padding: 3px 4px 3px 12px; font-size: 14px; font-weight: 600; }
.mchip.self { padding-right: 12px; background: var(--ink); color: #fff; }
.mchip.outside { background: #eef1f4; color: var(--ink-2); }
.mchip-x { background: none; border: 0; font: inherit; font-size: 16px; color: inherit; width: 28px; height: 28px; cursor: pointer; }
.inline { display: flex; gap: 8px; margin-top: 8px; }
.inline input { flex: 1 1 auto; min-width: 0; }

.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-actions .btn-ghost { margin-top: 0; }
.photo-actions .btn-ghost:nth-child(3) { grid-column: 1 / -1; }
.photo-preview { margin-top: 8px; }
.thumb, .photo { margin: 0; line-height: 0; }
.thumb img { display: block; width: 100%; height: auto; max-height: 280px; object-fit: contain; background: #eef1f4; border-radius: 10px; }
.photo img { display: block; width: 100%; height: auto; border-radius: 10px; }

.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.actions .btn-ghost { margin-top: 0; border-style: solid; }
.actions .btn-big { font-size: 17px; }

/* 選ぶシート (下から出る) */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 32, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  background: #fff; width: 100%; max-width: 640px; border-radius: 16px 16px 0 0;
  padding: 14px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
  height: 80vh; display: flex; flex-direction: column; gap: 10px;
}
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head strong { font-size: 17px; }
.sheet-head .btn { margin-left: auto; }
.picker-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; border-top: 1px solid var(--line); }
.pick {
  display: grid; grid-template-columns: 32px 1fr; grid-template-areas: "c n" "c o"; align-items: center; column-gap: 8px;
  width: 100%; text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 4px; font: inherit; color: var(--ink); cursor: pointer;
}
.pick-check { grid-area: c; width: 26px; height: 26px; border: 2px solid #b9c2cb; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 900; color: #fff; }
.pick.on .pick-check { background: var(--primary); border-color: var(--primary); }
.pick-name { grid-area: n; font-weight: 700; }
.pick-org { grid-area: o; font-size: 13px; color: var(--muted); }

/* カメラ */
.camera { position: fixed; inset: 0; z-index: 40; background: #000; }
.camera video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; padding-bottom: max(18px, env(safe-area-inset-bottom)); background: rgba(0, 0, 0, .4);
}
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: rgba(255, 255, 255, .25); cursor: pointer; }
.cam-space { width: 72px; }
.cam-cancel { background: transparent; color: #fff; border-color: #fff; }

/* 詳細 */
.back { display: inline-block; text-decoration: none; color: var(--low); margin-bottom: 8px; font-weight: 700; }
.detail-site { font-size: 21px; margin: 6px 0 8px; }
.kv { display: grid; grid-template-columns: 5.5em 1fr; gap: 4px 8px; margin: 0; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sheet-card { border-top: 4px solid var(--accent); }
.sheet-card, .card + .card { margin-bottom: 12px; }
.app > .card, .app > .goal-banner { margin-bottom: 12px; }
.hz-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.hz { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.hz-head { display: flex; align-items: center; gap: 8px; }
.hz-danger { margin: 6px 0 4px; font-weight: 700; }
.hz-measure { margin: 0; color: var(--ink-2); display: flex; gap: 8px; align-items: baseline; }
.arrow { flex: 0 0 auto; font-size: 12px; font-weight: 800; color: #fff; background: var(--primary); border-radius: 6px; padding: 0 6px; }
.goal-banner { background: var(--accent); border-radius: var(--radius); padding: 12px 16px; }
.goal-label { font-size: 13px; font-weight: 700; color: #5b4500; }
.goal-banner p { margin: 2px 0 0; font-size: 20px; font-weight: 900; }
.mlist { list-style: none; padding: 0; margin: 0; }
.mlist li { display: grid; grid-template-columns: 24px 1fr auto; gap: 6px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mlist li:last-child { border-bottom: 0; }
.mstate { color: var(--muted); font-weight: 900; text-align: center; }
.mlist li.ok .mstate { color: var(--primary); }
.mwhen { font-size: 13px; color: var(--muted); }
.mlist li.ok .mwhen { color: var(--primary); }
.confirm-area { margin: 16px 0; }
.btn-yoshi { font-size: 19px; box-shadow: 0 3px 0 var(--primary-dark); }
.confirmed-note { text-align: center; color: var(--primary); font-weight: 800; margin: 0; padding: 12px; background: #e8f5ee; border-radius: var(--radius); }
.danger-zone { text-align: center; }

.error-card h1 { font-size: 18px; margin: 0 0 6px; color: var(--high); }
.diag { margin-top: 10px; font-size: 13px; }
.diag dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.diag dd { margin: 0; word-break: break-all; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 50; margin: 0 auto; width: fit-content;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: calc(100% - 32px); text-align: center;
}
.toast.warn { background: #8a5a00; }
.toast.err { background: var(--high); }
