/* デザインシステム 2026-11-29 版。tokens/tokens.json から生成(手で編集しない) */
:root {
  color-scheme: light;
  --page: #faf9f5;
  --surface: #ffffff;
  --surface-alt: #f5f4ee;
  --text-primary: #141413;
  --text-secondary: #3d3d3a;
  --text-muted: #85837c;
  --grid: #ebe9e0;
  --baseline: #d6d3c7;
  --border: rgba(20, 20, 19, 0.10);
  --accent: #c96442;
  --accent-soft: rgba(201, 100, 66, 0.10);
  --on-accent: #ffffff;
  --good: #2f7d43;
  --warning: #b8892e;
  --critical: #bf4d43;
  --info: #2b6fd9;
  --good-soft: rgba(47, 125, 67, 0.11);
  --warning-soft: rgba(184, 137, 46, 0.14);
  --critical-soft: rgba(191, 77, 67, 0.11);
  --info-soft: rgba(43, 111, 217, 0.11);
  --scrim: rgba(20, 20, 19, 0.45);
  --s0: #c96442;
  --s1: #2b6fd9;
  --s2: #0f9960;
  --s3: #9b5cc7;
  --s4: #b8892e;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.05);
  --shadow-menu: 0 8px 28px rgba(20, 20, 19, 0.16);
  --shadow-sheet: 0 -4px 20px rgba(20, 20, 19, 0.16);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Noto Sans Mono CJK JP", monospace;
  --fs-2xs: 0.6875rem;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.875rem;
  --fs-base: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.625rem;
  --lh-tight: 1.4;
  --lh-ui: 1.5;
  --lh-body: 1.8;
  --fw-regular: 400;
  --fw-semibold: 600;
  --fw-bold: 700;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-12: 48px;
  --sp-16: 64px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;
  --tap: 44px;
  --control-h: 38px;
  --appbar-h: 48px;
  --tabbar-h: 52px;
  --measure: 44rem;
  --dur-fast: 0.15s;
  --dur: 0.2s;
  --ease: ease;
  --z-bar: 30;
  --z-overlay: 1000;
  --z-toast: 1100;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #1f1e1d;
    --surface: #262624;
    --surface-alt: #30302e;
    --text-primary: #f5f4ef;
    --text-secondary: #c2c0b6;
    --text-muted: #91918d;
    --grid: #35342f;
    --baseline: #4a4843;
    --border: rgba(245, 244, 239, 0.11);
    --accent: #d5714f;
    --accent-soft: rgba(213, 113, 79, 0.16);
    --on-accent: #ffffff;
    --good: #4caf6a;
    --warning: #d4a441;
    --critical: #e0655a;
    --info: #5a92e0;
    --good-soft: rgba(76, 175, 106, 0.15);
    --warning-soft: rgba(212, 164, 65, 0.16);
    --critical-soft: rgba(224, 101, 90, 0.15);
    --info-soft: rgba(90, 146, 224, 0.16);
    --scrim: rgba(0, 0, 0, 0.55);
    --s0: #d5714f;
    --s1: #5a92e0;
    --s2: #22a173;
    --s3: #a878d4;
    --s4: #bb851f;
    --shadow: none;
    --shadow-menu: 0 8px 28px rgba(0, 0, 0, 0.5);
    --shadow-sheet: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1f1e1d;
  --surface: #262624;
  --surface-alt: #30302e;
  --text-primary: #f5f4ef;
  --text-secondary: #c2c0b6;
  --text-muted: #91918d;
  --grid: #35342f;
  --baseline: #4a4843;
  --border: rgba(245, 244, 239, 0.11);
  --accent: #d5714f;
  --accent-soft: rgba(213, 113, 79, 0.16);
  --on-accent: #ffffff;
  --good: #4caf6a;
  --warning: #d4a441;
  --critical: #e0655a;
  --info: #5a92e0;
  --good-soft: rgba(76, 175, 106, 0.15);
  --warning-soft: rgba(212, 164, 65, 0.16);
  --critical-soft: rgba(224, 101, 90, 0.15);
  --info-soft: rgba(90, 146, 224, 0.16);
  --scrim: rgba(0, 0, 0, 0.55);
  --s0: #d5714f;
  --s1: #5a92e0;
  --s2: #22a173;
  --s3: #a878d4;
  --s4: #bb851f;
  --shadow: none;
  --shadow-menu: 0 8px 28px rgba(0, 0, 0, 0.5);
  --shadow-sheet: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

/* 土台。トークン(dist/tokens.css)の後、部品(components.css)の前に読む。色は直書きしない */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
}
/* 文書型の画面は、地を面の色にする(線だけで区切るので、面を重ねない) */
body.doc { background: var(--surface); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
code, pre, kbd { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* 部品。色・文字・余白はすべてトークンから取る。
   体裁の決まり: 枠と影のあるカードを作らない / 区切りは線 / 見出しは下線 / 囲みは薄い背景色だけ(左の縦線なし)/ 飾りの絵文字なし */

/* ---- 見出し ---- */
.page-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: .01em; margin: 0 0 var(--sp-1); overflow-wrap: anywhere; text-wrap: balance; }
.page-sub { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.7; margin: 0 0 var(--sp-4); }
.group-title { font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: var(--lh-tight); margin: var(--sp-8) 0 var(--sp-2); padding-bottom: 6px; border-bottom: 2px solid var(--baseline); }
.sec-title { font-size: var(--fs-base); font-weight: var(--fw-bold); line-height: var(--lh-tight); margin: var(--sp-6) 0 var(--sp-2); padding-bottom: 4px; border-bottom: 1px solid var(--baseline); }
.label-title { font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted); letter-spacing: .05em; margin: var(--sp-5) 0 var(--sp-1); }

/* ---- 本文 ---- */
.prose { max-width: var(--measure); overflow-wrap: anywhere; }
.prose p { margin: 0 0 1.1em; }
.prose ul, .prose ol { margin: 0 0 1.1em; padding-left: 1.5em; }
.prose li { margin: .25em 0; }
.prose blockquote { margin: 0 0 1.1em; padding: .3em 1em; background: var(--surface-alt); border-radius: var(--radius-sm); color: var(--text-secondary); }
.prose code { font-size: .88em; background: var(--surface-alt); padding: .1em .35em; border-radius: 4px; }
.prose pre { margin: 0 0 1.2em; padding: 12px 14px; background: var(--surface-alt); border-radius: var(--radius-sm); overflow-x: auto; font-size: var(--fs-sm); line-height: 1.55; }
.prose pre code { background: none; padding: 0; font-size: inherit; }
.note-line { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.7; margin: var(--sp-2) 0 var(--sp-3); }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--control-h); padding: 0 14px;
  font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.3; white-space: nowrap; text-decoration: none;
  color: var(--text-primary); background: var(--surface); border: 1px solid var(--baseline); border-radius: var(--radius-sm); cursor: pointer;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(.94); }
.btn-danger { color: var(--critical); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (pointer: coarse) { .btn { min-height: var(--tap); } .btn-sm { min-height: 36px; } }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font-size: var(--fs-sm); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { flex: none; display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; background: none; border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer; }
.icon-btn:hover { background: var(--surface-alt); }
.icon { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---- 入力 ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 var(--sp-4); }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.6; }
.field-error { font-size: var(--fs-xs); color: var(--critical); line-height: 1.6; }
.input, .select, .textarea {
  width: 100%; min-width: 0; min-height: var(--control-h); padding: 6px 10px;
  font-size: var(--fs-base); /* 16px 未満にしない(iPhone で入力時に画面が拡大される) */
  line-height: var(--lh-ui); color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--baseline); border-radius: var(--radius-sm);
}
.textarea { min-height: 76px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--critical); }
@media (pointer: coarse) { .input, .select { min-height: var(--tap); } }
.check { display: flex; align-items: center; gap: var(--sp-2); min-height: 32px; font-size: var(--fs-md); color: var(--text-secondary); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---- 切り替え(下線のタブ) ---- */
.seg { display: flex; gap: 18px; max-width: 100%; overflow-x: auto; scrollbar-width: none; box-shadow: inset 0 -1px 0 var(--baseline); }
.seg::-webkit-scrollbar { display: none; }
.seg-btn { flex: none; padding: 8px 0; border: 0; border-bottom: 2px solid transparent; background: none; font-size: var(--fs-md); color: var(--text-muted); white-space: nowrap; cursor: pointer; }
.seg-btn:hover { color: var(--text-primary); }
.seg-btn[aria-selected="true"] { color: var(--text-primary); font-weight: var(--fw-bold); border-bottom-color: var(--accent); }

/* ---- チップ(絞り込み) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border: 1px solid var(--baseline); border-radius: var(--radius-full); background: var(--surface); color: var(--text-secondary); font-size: var(--fs-sm); line-height: 1.3; white-space: nowrap; cursor: pointer; }
.chip:hover { background: var(--surface-alt); }
.chip[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: transparent; font-weight: var(--fw-bold); }

/* ---- バッジ(印)。細い枠の小さな丸。意味のある印だけ薄い色を付ける ---- */
.badge { display: inline-block; padding: 0 8px; border: 1px solid var(--baseline); border-radius: var(--radius-full); font-size: var(--fs-2xs); line-height: 1.6; color: var(--text-muted); white-space: nowrap; vertical-align: middle; }
.badge-neutral { color: var(--text-secondary); background: var(--surface-alt); border-color: transparent; }
.badge-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; font-weight: var(--fw-bold); }
.badge-good { color: var(--good); background: var(--good-soft); border-color: transparent; font-weight: var(--fw-bold); }
.badge-warning { color: var(--warning); background: var(--warning-soft); border-color: transparent; font-weight: var(--fw-bold); }
.badge-critical { color: var(--critical); background: var(--critical-soft); border-color: transparent; font-weight: var(--fw-bold); }
.badge-info { color: var(--info); background: var(--info-soft); border-color: transparent; font-weight: var(--fw-bold); }

/* ---- 行の一覧。カードにせず、点線で区切る ---- */
.rows { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.row { padding: 10px 0; border-bottom: 1px dotted var(--baseline); }
.row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: var(--fs-sm); color: var(--text-secondary); }
.row-title { font-size: var(--fs-base); font-weight: var(--fw-bold); line-height: 1.55; margin: 2px 0 0; overflow-wrap: anywhere; }
.row-sub { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.6; margin: 2px 0 0; overflow-wrap: anywhere; }
.row-btn { display: block; width: 100%; padding: 2px 0; border: 0; border-radius: var(--radius-sm); background: none; color: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.row-btn:hover { background: var(--surface-alt); text-decoration: none; }

/* ---- 項目と値 ---- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; margin: 0; font-size: var(--fs-md); }
.kv dt { padding-top: 1px; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: var(--sp-2); } }

/* ---- 数字 ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px 16px; margin: 0; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: var(--fs-xs); color: var(--text-muted); }
.stat-num { font-size: var(--fs-2xl); font-weight: var(--fw-bold); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- 囲み。薄い背景色だけ。左の縦線は付けない ---- */
.callout { margin: var(--sp-4) 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-alt); font-size: var(--fs-md); line-height: 1.7; color: var(--text-secondary); }
.callout > :last-child { margin-bottom: 0; }
.callout p { margin: 0 0 .5em; }
.callout-title { margin: 0 0 2px; font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-secondary); }
.callout-key { background: var(--accent-soft); }
.callout-key .callout-title { color: var(--accent); }
.callout-warning { background: var(--warning-soft); }
.callout-warning .callout-title { color: var(--warning); }
.callout-critical { background: var(--critical-soft); }
.callout-critical .callout-title { color: var(--critical); }

/* ---- 表。横線だけ。数字は右揃えの等幅 ---- */
.table-wrap { overflow-x: auto; margin: 0 0 var(--sp-4); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); line-height: 1.55; }
.table th, .table td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--grid); }
.table th { font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted); white-space: nowrap; border-bottom-color: var(--baseline); }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .num { text-align: right; white-space: nowrap; }

/* ---- 開閉 ---- */
.fold { border-bottom: 1px solid var(--grid); }
.fold > summary { display: flex; align-items: baseline; gap: var(--sp-2); padding: 10px 0; list-style: none; font-weight: var(--fw-bold); cursor: pointer; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "▸"; flex: none; color: var(--text-muted); font-size: .8em; transition: transform var(--dur-fast) var(--ease); }
.fold[open] > summary::before { transform: rotate(90deg); }
.fold-body { padding: 0 0 12px 1.3em; font-size: var(--fs-md); color: var(--text-secondary); }

/* ---- 空の状態 ---- */
.empty { padding: 18px 4px; font-size: var(--fs-md); line-height: 1.7; color: var(--text-muted); }
.empty .btn { margin-top: var(--sp-3); }

/* ---- 進み具合 ---- */
.progress { height: 8px; border-radius: 4px; background: var(--surface-alt); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

/* ---- パネル。グラフや数字をまとめるダッシュボード型の画面でだけ使う(影なし) ---- */
.panel { padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* ---- トースト。下に固定する部品は --bottom-inset(下のタブバーの高さ)を空ける ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-inset, env(safe-area-inset-bottom, 0px)) + 16px); transform: translateX(-50%); z-index: var(--z-toast);
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: var(--radius-md);
  background: var(--text-primary); color: var(--page); font-size: var(--fs-md); line-height: var(--lh-ui); box-shadow: var(--shadow-menu);
}
.toast-error { background: var(--critical); color: var(--on-accent); }

/* ---- ダイアログ。狭い画面では下から出るシートになる ---- */
.dialog { width: min(560px, 100%); max-height: 88vh; margin: auto; padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow-menu); }
.dialog::backdrop { background: var(--scrim); }
.dialog-body { padding: var(--sp-5); }
.dialog-title { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
.dialog-text { margin: 0; font-size: var(--fs-md); line-height: 1.7; color: var(--text-secondary); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-5); }
@media (max-width: 700px) {
  .dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 14px 14px 0 0; box-shadow: var(--shadow-sheet); }
  .dialog-body { padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px)); }
  .dialog-actions .btn { flex: 1; }
}

/* ---- 上のバー ---- */
.appbar {
  position: sticky; top: 0; z-index: var(--z-bar); display: flex; align-items: center; gap: var(--sp-1);
  height: calc(var(--appbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-bottom: 1px solid var(--baseline);
}
.appbar-title { min-width: 0; margin: 0 0 0 var(--sp-1); font-size: var(--fs-base); font-weight: var(--fw-bold); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-end { display: flex; align-items: center; gap: var(--sp-1); margin-left: auto; }

/* ---- 下のタブバー。画面の下に固定するときは .tabbar-fixed を足す ---- */
.tabbar { display: flex; justify-content: center; height: var(--tabbar-h); background: var(--surface); border-top: 1px solid var(--border); }
.tabbar a { flex: 1 1 0; min-width: 0; max-width: 128px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-muted); font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1.2; text-decoration: none; -webkit-tap-highlight-color: transparent; user-select: none; }
.tabbar a:hover { color: var(--text-secondary); text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: var(--fw-bold); }
.tabbar-fixed { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-bar); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); }

/* ---- テーマの切り替え(自動 / ライト / ダーク)。動きは js/theme.js ---- */
.theme-switch { display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--surface-alt); }
.theme-switch button { padding: 4px 9px; border: 0; border-radius: 7px; background: none; font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; cursor: pointer; }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text-primary); font-weight: var(--fw-bold); box-shadow: 0 0 0 1px var(--border); }
