:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1b2a2f;
  --ink-2: #5b6b70;
  --line: #dfe3df;
  --accent: #0f5c56;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ee;
  --warn: #b4321f;
  --warn-soft: #fbe9e5;
  --amber: #8a5a00;
  --amber-soft: #fbf0d9;
  --track: #e6e9e5;
  --sat: #2b6cb0;
  --radius: 14px;
  --nav-h: 60px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121819;
    --surface: #1b2325;
    --ink: #e8eeed;
    --ink-2: #9eadaf;
    --line: #2c383a;
    --accent: #4fc3b6;
    --accent-ink: #06201d;
    --accent-soft: #17302e;
    --warn: #ff8f7a;
    --warn-soft: #3a1f1a;
    --amber: #f1c36a;
    --amber-soft: #33290f;
    --track: #2a3436;
    --sat: #8fc0f5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.loading { padding: 48px 16px; text-align: center; color: var(--ink-2); }

/* ---- 枠 ---- */
.shell { max-width: 720px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 20px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; margin: -6px 0; border: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center; font-size: 30px; line-height: 1;
  color: inherit; text-decoration: none; flex: none; margin-left: -10px;
}
.icon-btn:active { background: var(--track); }
main { padding: 4px 16px 16px; }
section + section { margin-top: 24px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 8px; letter-spacing: .04em; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav ul { max-width: 720px; margin: 0 auto; display: flex; height: var(--nav-h); }
.bottom-nav li { flex: 1; }
.bottom-nav a {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); text-decoration: none; font-size: 11px; font-weight: 600;
}
.bottom-nav a[aria-current="page"] { color: var(--accent); }
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- 部品 ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-list { display: grid; gap: 10px; }
.project-card { display: block; width: 100%; text-align: left; padding: 14px 16px; text-decoration: none; color: inherit; }
.project-card:active { background: var(--accent-soft); }
.project-head { display: flex; align-items: flex-start; gap: 8px; }
.project-name { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.project-sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.bar { flex: 1; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--track); color: var(--ink-2); }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }

.btn {
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.danger { border-color: transparent; background: transparent; color: var(--warn); padding: 0 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.fab {
  position: fixed; z-index: 7; right: max(16px, calc(50vw - 344px)); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgb(0 0 0 / .22);
}

.search { width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 12px; scrollbar-width: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.tabs { display: flex; border-bottom: 1px solid var(--line); margin: 0 -16px 16px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; padding: 0 10px; white-space: nowrap; font-size: 15px; min-height: 44px; border: 0; background: none; font-weight: 700; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { padding: 14px 16px; }
.metric-label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.metric-value { font-size: 28px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.metric-value small { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-left: 2px; }
.metric-note { font-size: 12px; color: var(--ink-2); }
.metric .bar { margin-top: 6px; }
.metric.is-warn .metric-value { color: var(--warn); }
.metric.is-off .metric-value { color: var(--ink-2); font-size: 18px; line-height: 2.05; }
.judge { margin-top: 10px; padding: 10px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.judge.late { background: var(--warn-soft); color: var(--warn); }

.task-list { overflow: hidden; }
.task { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.check {
  flex: none; width: 52px; border: 0; background: none; display: grid; place-items: center;
}
.check > span {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--ink-2);
  display: grid; place-items: center; font-size: 14px; font-weight: 700; color: var(--accent-ink);
}
.task.is-done .check > span { background: var(--accent); border-color: var(--accent); }
.task-body { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 11px 14px 11px 0; }
.task-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.task.is-done .task-title { color: var(--ink-2); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 18px 0 8px; }
.group-title:first-child { margin-top: 0; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; text-decoration: none; color: inherit; }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.row.is-off .row-title { color: var(--ink-2); }
.chev { color: var(--ink-2); }

.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); font-size: 14px; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; padding: 14px 16px; font-size: 15px; }
.facts { padding: 4px 16px; }
.facts div { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.facts div:first-child { border-top: 0; }
.facts dt { width: 5em; flex: none; color: var(--ink-2); font-size: 13px; padding-top: 2px; }
.facts dd { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
dl { margin: 0; }

/* ---- ログイン ---- */
.auth { max-width: 400px; margin: 0 auto; padding: 16vh 20px 40px; }
.auth h1 { font-size: 26px; margin-bottom: 4px; }
.auth .lead { color: var(--ink-2); font-size: 14px; margin-bottom: 24px; }

/* ---- フォーム ---- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  min-width: 0; max-width: 100%;
}
.field input[type="date"] { -webkit-appearance: none; appearance: none; padding-right: 8px; }
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field { min-width: 0; }
.form-error { color: var(--warn); font-size: 14px; font-weight: 600; margin: 0 0 12px; }

dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); }
dialog.sheet form { padding: 20px 20px calc(env(safe-area-inset-bottom) + 16px); }
dialog.sheet h2 { font-size: 18px; margin-bottom: 16px; }
.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px); transform: translateX(-50%);
  z-index: 20; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* ---- 予定・カレンダー(フェーズ2) ---- */
.when { flex: none; width: 96px; white-space: nowrap; display: flex; flex-direction: column; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.when b { color: var(--ink); font-weight: 700; }
.cal { padding: 8px 8px 10px; }
.cal-head { display: flex; align-items: center; gap: 2px; padding: 0 4px 6px; }
.cal-head h2 { font-size: 17px; min-width: 7em; text-align: center; }
.cal-head .icon-btn { margin: 0; }
.cal-today { margin-left: auto; min-height: 36px; padding: 0 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--ink-2); padding: 4px 0; }
.cal-day { border: 0; background: none; min-height: 50px; padding: 4px 0; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cal-num { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal .is-sun { color: var(--warn); }
.cal .is-sat { color: var(--sat); }
.cal-day.is-other { opacity: .38; }
.cal-day.is-today .cal-num { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.is-selected .cal-num { background: var(--accent); color: var(--accent-ink); }
.cal-dots { height: 6px; display: flex; gap: 3px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.ev { background: var(--accent); }
.dot.tk { background: var(--amber); }
.cal-legend { display: flex; align-items: center; gap: 6px; padding: 6px 8px 0; font-size: 12px; color: var(--ink-2); }
.cal-legend .dot.tk { margin-left: 8px; }

/* ---- 写真(フェーズ2) ---- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.photo-grid.is-strip { grid-template-columns: repeat(4, 1fr); }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(4, 1fr); } }
.photo-grid button { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--track); }
.photo-grid img { display: block; width: 100%; height: 100%; object-fit: cover; }
dialog.viewer > img { display: block; width: 100%; max-height: 62dvh; object-fit: contain; background: #000; }
.viewer-body { padding: 14px 20px calc(env(safe-area-inset-bottom) + 16px); }
.viewer-caption { white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 4px; }
.viewer-body .sheet-actions { margin-top: 14px; }
.menu-body { padding: 20px 20px calc(env(safe-area-inset-bottom) + 12px); }
.menu-body .card { margin-bottom: 8px; }

/* ---- 見積・支払い(フェーズ3) ---- */
.amount { flex: none; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount small { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); }
.metric-value.money { font-size: 22px; line-height: 1.6; overflow-wrap: anywhere; }
.sum-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.sum-table th, .sum-table td { padding: 9px 14px; border-top: 1px solid var(--line); text-align: right; }
.sum-table th { border-top: 0; font-size: 12px; color: var(--ink-2); }
.sum-table th:first-child, .sum-table td:first-child { text-align: left; }
.sum-table tr.total td { font-weight: 700; }
.items { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 10px; }
.items summary { padding: 10px 12px; font-size: 13px; font-weight: 700; color: var(--ink-2); cursor: pointer; }
.items-scroll { overflow-x: auto; max-height: 240px; overflow-y: auto; border-top: 1px solid var(--line); }
.items table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.items th, .items td { padding: 6px 10px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
.items th { border-top: 0; color: var(--ink-2); font-size: 12px; }
.items th:first-child, .items td:first-child { text-align: left; white-space: normal; min-width: 9em; }
.doc-link { font-size: 13px; color: var(--ink-2); margin: -4px 0 14px; }
.doc-link a { color: var(--accent); font-weight: 700; }
.ocr-note { font-size: 13px; padding: 9px 12px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.month-bars { padding: 8px 16px; }
.month-bars .mb { display: grid; grid-template-columns: 4.5em minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.month-bars .mb b { font-weight: 700; }
dialog.sheet.busy { max-width: 320px; }
.busy-body { display: flex; align-items: center; gap: 14px; padding: 24px 22px calc(env(safe-area-inset-bottom) + 24px); font-weight: 600; }
.spinner { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
