/* 屋外・手袋での利用前提：高コントラスト、押せる所は高さ52px以上 */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --bg: #eef0f3;
  --fg: #111;
  --muted: #474f5c;
  --line: #aab1bc;
  --primary: #1f4fd6;
  --bar: #1c2430;
  --danger: #c01e1e;
  --warn: #b45f00;
  --ok: #1b7a31;
  --yellow: #ffd400;
  font-size: 20px;
  -webkit-text-size-adjust: 100%;
}
:root[data-fs="m"] { font-size: 17px; }
:root[data-fs="xl"] { font-size: 23px; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .55; }

/* ---------- 上部バー ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  min-height: 64px; padding: 6px 10px;
  background: var(--bar); color: #fff;
}
.top h1 { flex: 1; margin: 0; font-size: 1.05rem; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  min-width: 52px; min-height: 52px;
  border: 0; border-radius: 12px; background: transparent;
  font-size: 1.3rem; color: inherit; text-decoration: none;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.icon-btn.on { background: rgba(255, 212, 0, .4); }
.icon-btn.small { min-width: 44px; min-height: 44px; font-size: 1rem; }
.site-sel {
  flex: 1; min-width: 0; min-height: 52px; padding: 0 12px;
  border: 2px solid #56627a; border-radius: 12px;
  background: #2a3444; color: #fff; font-size: 1.05rem; font-weight: 800;
}

.meta-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 12px; background: #fff; border-bottom: 2px solid var(--line);
  font-weight: 700;
}
.chip-btn {
  min-height: 44px; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 999px; background: #fff; font-weight: 800;
}
.offline {
  display: none; padding: 2px 12px; border: 2px solid #b45309; border-radius: 999px;
  background: #fde68a; color: #7c2d12; font-size: .85rem; font-weight: 800;
}
body.is-offline .offline { display: inline-block; }
.wx-pick { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px 12px; background: #fff; border-bottom: 2px solid var(--line); }

/* ---------- ボタン類 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 56px; padding: 0 18px;
  border: 2px solid var(--line); border-radius: 14px; background: #fff;
  font-weight: 800; font-size: 1rem; text-decoration: none; text-align: center;
}
.btn:active { filter: brightness(.9); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.mic { background: var(--yellow); border-color: var(--yellow); color: #111; }
.btn.big { width: 100%; min-height: 64px; margin-top: 20px; font-size: 1.1rem; }
.btn.small { min-height: 48px; padding: 0 14px; flex: none; }
.btn.lock { flex: 1; background: var(--bar); border-color: var(--bar); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: #fff; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button, .wx-pick button {
  min-height: 52px; min-width: 64px; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 800;
}
.seg button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.status button { flex: 1; }
.status .s-0.on { background: var(--danger); border-color: var(--danger); }
.status .s-1.on { background: var(--warn); border-color: var(--warn); }
.status .s-2.on { background: var(--ok); border-color: var(--ok); }

/* ---------- ホーム ---------- */
.search { padding: 10px 12px 0; }
.search input {
  width: 100%; min-height: 52px; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
/* 横スクロールだと右端のボタンに気づけないので、入りきらなければ折り返す */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; min-height: 46px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: 999px; background: #fff; font-weight: 800;
}
.filters button.on { background: var(--fg); border-color: var(--fg); color: #fff; }

#list { padding: 0 12px calc(100px + env(safe-area-inset-bottom)); }
.group-h { margin: 12px 2px 8px; font-size: .9rem; font-weight: 800; color: var(--muted); }
.cards { columns: 2; column-gap: 10px; }
@media (min-width: 720px) { .cards { columns: 3; } }
@media (min-width: 1080px) { .cards { columns: 4; } }
.card {
  display: block; break-inside: avoid; margin: 0 0 10px; padding: 12px;
  border: 2px solid rgba(0, 0, 0, .2); border-radius: 14px;
  background: var(--c, #fff); color: inherit; text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.card:active { filter: brightness(.94); }
.card-head { display: flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 800; }
.tag { flex: 1; }
.card-title { margin-top: 4px; font-weight: 800; word-break: break-word; }
.card-body {
  margin-top: 4px; font-size: .88rem; white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.card-body:empty { display: none; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; font-size: .75rem; font-weight: 700; color: #2b2f36; }
.badge { padding: 1px 8px; border-radius: 999px; color: #fff; font-weight: 800; }
.badge.b-0 { background: var(--danger); }
.badge.b-1 { background: var(--warn); }
.badge.b-2 { background: var(--ok); }
.due.over { color: var(--danger); font-weight: 900; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); font-weight: 700; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bar);
}
.bottom-bar .btn { flex: 1; min-width: 0; min-height: 66px; padding: 0 8px; font-size: 1rem; }
.bottom-bar .btn.photo { background: #fff; border-color: #fff; }
.card-img {
  display: block; width: calc(100% + 24px); margin: -12px -12px 8px;
  aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px 12px 0 0;
}

/* ---------- テンプレート選択 ---------- */
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; max-width: 760px; margin: 0 auto; }
.tpl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 116px; border: 2px solid rgba(0, 0, 0, .22); border-radius: 16px;
  background: var(--c); font-size: 1.05rem; font-weight: 800;
}
.tpl:active { filter: brightness(.92); }
.tpl-icon { font-size: 2rem; line-height: 1; }

/* ---------- 共通フォーム ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 12px; }
.field { display: block; margin: 16px 0; }
.field > span { display: block; margin-bottom: 6px; font-size: .9rem; font-weight: 800; }
.page input:not([type="file"]), .page select, .page textarea {
  width: 100%; min-height: 52px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.page textarea { min-height: 96px; resize: vertical; }
.page input:focus, .page select:focus, .page textarea:focus { outline: 3px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.page input:disabled, .page select:disabled, .page textarea:disabled {
  background: rgba(255, 255, 255, .55); color: #111; -webkit-text-fill-color: #111; opacity: 1;
}
/* 確定後の空欄に入力例が出ると、入力済みの値に見えてしまう */
.page input:disabled::placeholder, .page textarea:disabled::placeholder { -webkit-text-fill-color: transparent; color: transparent; }
.hint { margin: 6px 0; font-size: .85rem; color: var(--muted); }

/* ---------- 初回設定 ---------- */
.setup { padding-top: 40px; }
.setup-title { margin: 0 0 8px; font-size: 1.6rem; }
.lead { color: var(--muted); font-weight: 700; }

/* ---------- メモ編集 ---------- */
.note-page { min-height: 100vh; background: var(--c); }
.note-page .top { background: var(--bar); }
.meta-edit { margin-bottom: 8px; border: 2px solid rgba(0, 0, 0, .18); border-radius: 12px; background: rgba(255, 255, 255, .7); }
.meta-edit summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  min-height: 52px; padding: 8px 12px; font-size: .85rem; font-weight: 800; list-style: none; cursor: pointer;
}
.meta-edit summary::-webkit-details-marker { display: none; }
.meta-edit .edit-hint { margin-left: auto; color: var(--primary); }
.meta-edit[open] .edit-hint { visibility: hidden; }
.meta-edit > .field { margin: 12px; }
.page .title-input { margin-top: 8px; font-size: 1.15rem; font-weight: 800; }
.locked-banner { margin: 10px 0; padding: 10px 14px; border-radius: 12px; background: var(--bar); color: #fff; font-weight: 800; }
.locked-banner small { display: block; font-weight: 600; opacity: .85; }

.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.colors button { width: 48px; height: 48px; border: 2px solid #666; border-radius: 50%; background: var(--c); }
.colors button.on { outline: 4px solid var(--fg); outline-offset: 2px; }

.item { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-bottom: 8px; padding: 8px; border: 2px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .75); }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button {
  flex: none; min-width: 52px; min-height: 52px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 1.3rem; font-weight: 900;
}
.page .qty input { width: 4.2em; flex: none; padding: 0 4px; text-align: center; font-weight: 800; }
.page .qty select { flex: 1; width: auto; min-width: 3.5em; }
.qty .it-del { color: var(--danger); font-size: 1rem; }
.add-row { width: 100%; }
/* 材料手配：Keep風の箇条書きチェックリスト */
.checklist { overflow: hidden; border: 2px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .85); }
.li { display: flex; align-items: center; gap: 2px; padding: 2px 4px; border-bottom: 1px solid #d5d9df; }
.li:last-child { border-bottom: 0; }
.it-check { display: grid; place-items: center; flex: none; width: 52px; height: 52px; cursor: pointer; }
.page .it-check input { width: 28px; height: 28px; min-height: 0; margin: 0; padding: 0; accent-color: var(--ok); cursor: pointer; }
.page .li input[data-ik="name"] { flex: 1; min-width: 0; min-height: 52px; padding: 6px 4px; border: 0; border-radius: 0; background: transparent; }
.page .li input[data-ik="name"]:focus { outline: none; box-shadow: inset 0 -3px 0 var(--primary); }
.li-del { flex: none; width: 48px; height: 48px; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; }
.li.done { background: rgba(0, 0, 0, .04); }
.page .li.done input[data-ik="name"] { text-decoration: line-through; color: var(--muted); -webkit-text-fill-color: var(--muted); }
/* 材料名をなるべく広く見せるため、数量・単位は小さめ */
.page .li .li-qty { flex: none; width: 3em; min-height: 44px; padding: 4px; font-size: .95rem; text-align: right; font-weight: 800; }
.page .li .li-unit {
  flex: none; width: 2.6em; min-height: 44px; padding: 4px 0; font-size: .95rem; text-align: center;
  -webkit-appearance: none; appearance: none;
}
.li .it-check { width: 44px; }
.li-del { width: 40px; }

.picker { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 10px; padding: 12px; border: 2px solid var(--primary); border-radius: 12px; background: #fff; }
.pk-title { font-size: .9rem; }
.pk-row { display: flex; gap: 8px; }
.page .pk-row > select { flex: 1; min-width: 0; }
.pk-row .qty { flex: 1; min-width: 0; }
.page .pk-row .qty input { flex: 1; width: auto; min-width: 0; }
.page .pk-row > .pk-unit { flex: none; width: 4.6em; }
.pk-preview { font-size: .85rem; color: var(--muted); }
.pk-preview b { color: var(--fg); font-size: 1rem; }
.picker .add-row { margin: 0; }
.li-add {
  display: block; width: 100%; min-height: 52px; margin-top: 8px; padding: 0 16px;
  border: 2px dashed var(--line); border-radius: 12px; background: transparent;
  color: var(--muted); font-weight: 800; text-align: left;
}
.task.today { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.task-dates, .task-meta { display: flex; align-items: center; gap: 6px; }
.page .task-dates input, .page .task-meta input { flex: 1; min-width: 0; }
.page .task-meta select { flex: none; width: auto; }
.task-meta .it-del {
  flex: none; min-width: 52px; min-height: 52px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--danger);
}

.att-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.att {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  aspect-ratio: 1; padding: 0; overflow: hidden;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.att img { width: 100%; height: 100%; object-fit: cover; }
.att-icon { font-size: 2rem; line-height: 1; }
.att-name {
  padding: 0 6px; font-size: .7rem; font-weight: 700; word-break: break-all;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.att-add { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.att-add .btn { padding: 0 8px; }
.att-add .btn:last-child { grid-column: 1 / -1; }

.viewer { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: #000; color: #fff; }
.viewer .top h1 { overflow: hidden; font-size: .9rem; white-space: nowrap; text-overflow: ellipsis; }
.viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-doc { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 420px; padding: 24px; text-align: center; word-break: break-all; }
.viewer-icon { font-size: 4rem; line-height: 1; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bar); }
.viewer-bar small { flex: 1; min-width: 0; }
.viewer-bar .btn { color: var(--fg); }
.viewer-bar .btn.danger-outline { color: var(--danger); }

.corr { margin-bottom: 8px; padding: 8px 12px; border-left: 5px solid var(--warn); border-radius: 8px; background: rgba(255, 255, 255, .8); }
.corr b { font-size: .8rem; }
.corr p { margin: 2px 0 0; white-space: pre-wrap; }
.corrections .btn { width: 100%; margin-top: 8px; }

.history { margin-top: 16px; }
.history summary { min-height: 48px; padding: 10px 0; font-weight: 800; cursor: pointer; }
.history ul { margin: 0; padding-left: 1.2em; font-size: .85rem; }
.history li { margin: 4px 0; }
.note-actions { display: flex; gap: 10px; margin: 20px 0 8px; }

/* ---------- 設定 ---------- */
.settings section { margin: 0 0 12px; padding: 4px 14px 14px; border: 2px solid var(--line); border-radius: 14px; background: #fff; }
.settings h2 { margin: 12px 0 10px; font-size: 1rem; }
.settings .row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.settings .row.mat { justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #e3e6ea; }
.settings .row.mat .icon-btn { color: var(--danger); }
.settings small { color: var(--muted); }
.btn-col { display: grid; gap: 10px; }
.version { text-align: center; font-size: .8rem; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 90vw; padding: 12px 20px; transform: translateX(-50%);
  border-radius: 12px; background: #111; color: #fff; font-weight: 800;
}
