:root {
  --primary: #3C3838;      /* Malme ウォームチャコール */
  --accent: #C2706B;       /* ダスティローズ */
  --accent-light: #E8B4B0;
  --bg: #FAF8F8;
  --card: #FFFFFF;
  --line: #E4DCDC;
  --text: #333333;
  --muted: #8A7C7C;
  --ok: #4A7C59;
  --warn-a: #B7791F;
  --warn-b: #C2706B;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Hiragino Sans", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
}

/* header */
.app-header {
  background: var(--card); border-bottom: 3px solid var(--accent);
  padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 12px; height: 40px; background: linear-gradient(180deg, var(--accent), var(--accent-light)); border-radius: 3px; }
.app-header h1 { font-size: 18px; color: var(--primary); font-weight: 700; }
.phase { white-space: nowrap; font-size: 12px; color: #fff; background: var(--primary); border-radius: 12px; padding: 2px 10px; vertical-align: 2px; margin-left: 6px; font-weight: 600; }
.breadcrumb { font-size: 12px; color: var(--muted); }
.header-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 12px; background: #F5F0F0; border-radius: 14px; padding: 4px 12px; color: var(--primary); white-space: nowrap; }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 12px 24px 0; background: var(--bg); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); border-bottom: none; background: #F1ECEC; color: var(--muted);
  padding: 10px 18px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab.active { background: var(--card); color: var(--primary); border-color: var(--line); box-shadow: 0 -2px 0 var(--accent) inset; }
.tab-badge { display: inline-block; min-width: 18px; margin-left: 6px; background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 5px; }
.tab-badge:empty { display: none; }

/* panels */
main { padding: 20px 24px 40px; max-width: 1240px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 14px; flex-wrap: wrap; }
h2 { font-size: 16px; color: var(--primary); margin-bottom: 4px; }
.sub { font-size: 13px; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* stats */
.stat-row { display: flex; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; text-align: center; min-width: 96px; }
.stat .num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 11px; color: var(--muted); }
.stat.alert .num { color: var(--accent); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { background: var(--primary); color: #fff; padding: 8px 10px; text-align: left; font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.flagged { background: #FBF3F2; }
tr.resolved { background: #F3F7F4; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-err { color: var(--accent); font-weight: 700; }

/* badges & findings */
.badge { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; border-radius: 4px; padding: 1px 7px; margin-right: 4px; }
.badge-a { background: var(--warn-a); }
.badge-b { background: var(--warn-b); }
.badge-ok { background: var(--ok); }
.finding { margin-bottom: 4px; }
.finding .rule { font-weight: 600; color: var(--primary); }
.finding .detail { color: var(--muted); font-size: 12px; }

/* judgement buttons */
.judge { display: flex; flex-direction: column; gap: 4px; min-width: 128px; }
.jbtn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--text); text-align: left; }
.jbtn:hover { border-color: var(--accent); }
.jbtn.sel-adopt { background: var(--ok); color: #fff; border-color: var(--ok); }
.jbtn.sel-fix { background: var(--primary); color: #fff; border-color: var(--primary); }
.jbtn.sel-ask { background: var(--accent); color: #fff; border-color: var(--accent); }
.judged-label { font-size: 12px; font-weight: 700; }

/* buttons */
.btn { border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); white-space: nowrap; }
.btn-outline { background: #fff; color: var(--primary); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(0.95); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* aggregation tab */
.agg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(480px, 100%), 1fr)); gap: 18px; }
.agg-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.agg-card h3 { font-size: 15px; color: var(--primary); margin-bottom: 2px; }
.agg-sub { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.agg-stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.agg-stat { background: #F5F0F0; border-radius: 8px; padding: 6px 12px; font-size: 12px; }
.agg-stat b { display: block; font-size: 16px; color: var(--primary); font-variant-numeric: tabular-nums; }
.agg-stat.hl b { color: var(--accent); }
tr.outlier td { background: #FBEDEC; }
tr.rejected td { color: #B9AFAF; text-decoration: line-through; background: #F7F4F4; }
tr.rejected td .badge { text-decoration: none; }
.toggle { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 2px 12px; font-size: 12px; }
.toggle.rej { background: var(--primary); color: #fff; border-color: var(--primary); }
.chart { margin-top: 10px; width: 100%; }

/* band tab */
.band-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 18px 8px; }
.band-scale { position: relative; height: 22px; margin-left: 220px; margin-bottom: 6px; }
.band-scale span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--muted); }
.band-row { display: flex; align-items: center; margin-bottom: 14px; }
.band-label { width: 220px; padding-right: 12px; }
.band-label b { display: block; color: var(--primary); font-size: 13px; }
.band-label small { color: var(--muted); font-size: 11px; line-height: 1.3; display: block; }
.band-track { position: relative; flex: 1; height: 26px; background: repeating-linear-gradient(90deg, #F5F0F0 0, #F5F0F0 calc(100%/12 - 1px), #E4DCDC calc(100%/12 - 1px), #E4DCDC calc(100%/12)); border-radius: 6px; }
.band-seg { position: absolute; top: 3px; bottom: 3px; background: linear-gradient(180deg, var(--accent), #A85B56); border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.band-seg .seg-time { position: absolute; top: -16px; left: 2px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.band-total { width: 90px; text-align: right; font-size: 12px; color: var(--primary); font-weight: 700; padding-left: 8px; white-space: nowrap; }
.band-facts { display: flex; gap: 14px; margin: 16px 0; flex-wrap: wrap; }
.fact { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 18px; flex: 1; min-width: 180px; }
.fact-num { font-size: 18px; font-weight: 700; color: var(--primary); }
.fact-label { font-size: 12px; color: var(--muted); }
.callout { background: #F5F0F0; border-radius: 10px; padding: 12px 16px; font-size: 13px; }

/* output tab */
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-top: 8px; }
.sheet h3 { font-size: 14px; color: var(--primary); margin-bottom: 10px; }
.empty-msg { color: var(--muted); font-size: 13px; padding: 12px 0; }
.draft { font-size: 12px; color: var(--muted); }

/* toast */
.toast { position: fixed; top: 76px; right: 24px; background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.hidden { display: none; }

/* footer */
.app-footer { border-top: 1px solid var(--line); background: var(--card); padding: 12px 24px; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.disclaimer { color: var(--accent); font-weight: 600; }

@media (max-width: 760px) {
  .agg-grid { grid-template-columns: 1fr; }
  .band-card { overflow-x: auto; }
  .band-scale, .band-row { min-width: 640px; }
  .band-seg .seg-time { display: none; }
}

/* ===== ワークフローステッパー ===== */
.stepper { display: flex; gap: 6px; padding: 14px 24px 0; background: var(--bg); flex-wrap: wrap; }
.step {
  flex: 1 1 0; min-width: 150px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border: 1px solid var(--line); background: #F1ECEC; border-radius: 10px 10px 0 0; border-bottom: none;
  padding: 10px 14px; cursor: pointer; text-align: left;
}
.step.active { background: var(--card); box-shadow: 0 -3px 0 var(--accent) inset; }
.step-no {
  display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center;
  background: var(--primary); color: #fff; border-radius: 50%; font-size: 11px; font-weight: 700;
}
.step.active .step-no { background: var(--accent); }
.step-ttl { font-size: 13px; font-weight: 700; color: var(--primary); }
.gate { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; background: #fff; }
.gate.done { color: #fff; background: var(--ok); border-color: var(--ok); }

/* ===== 工種スイッチャー ===== */
.kind-bar { display: flex; align-items: center; gap: 10px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; visibility: hidden; }
.kind-lbl { font-size: 12px; color: var(--muted); }
.kind-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 16px;
  font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; text-align: left;
}
.kind-btn small { display: block; font-weight: 400; font-size: 11px; }
.kind-btn.active { border-color: var(--accent); color: var(--primary); background: #FBF3F2; }

/* ===== ステップ1 ファイルカード ===== */
.file-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 16px; }
.file-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.file-card.confirmed { border-color: var(--ok); }
.file-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--primary); }
.file-icon { font-size: 20px; }
.detect-tbl { margin-bottom: 12px; font-size: 13px; }
.detect-tbl th { background: #F5F0F0; color: var(--primary); width: 84px; white-space: nowrap; position: static; }
.detect-tbl td.small { font-size: 12px; color: var(--muted); }
.conf-bar { display: inline-block; width: 120px; height: 8px; background: #EEE7E7; border-radius: 4px; vertical-align: middle; overflow: hidden; }
.conf-bar span { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.btn-done { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ===== ステップ2 ===== */
.gate-btn { align-self: flex-start; white-space: nowrap; }
.day-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.day-tab { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--muted); font-weight: 600; }
.day-tab.active { border-color: var(--accent); color: var(--primary); background: #FBF3F2; }
.mini-h { font-size: 14px; color: var(--primary); margin: 16px 0 8px; }

/* ===== ステップ3 ===== */
.rule { font-weight: 600; color: var(--primary); }
.dim { color: var(--muted); font-size: 12px; }

/* ===== ステップ4 項目リスト ===== */
.agg-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.item-list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-height: 640px; overflow-y: auto; }
.item-head { font-size: 12px; font-weight: 700; color: var(--primary); margin: 4px 4px 10px; }
.item-note { font-size: 11px; color: var(--muted); margin: 8px 4px 0; }
.item-btn {
  display: block; width: 100%; text-align: left; border: 1px solid transparent; background: none;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--text); cursor: pointer; line-height: 1.5;
}
.item-btn small { display: block; color: var(--muted); font-size: 10px; }
.item-btn .item-code { display: inline-block; min-width: 34px; font-weight: 700; color: var(--muted); }
.item-btn.active { background: #FBF3F2; border-color: var(--accent); color: var(--primary); font-weight: 700; }
.item-btn.disabled { color: #B9AFAF; cursor: not-allowed; }
.agg-main { min-width: 0; }

@media (max-width: 900px) {
  .agg-layout { grid-template-columns: 1fr; }
  .item-list { max-height: 240px; }
}

/* ===== ステップ1: ドロップゾーン・工種選択 ===== */
.dropzone {
  grid-column: 1 / -1; background: var(--card); border: 2px dashed var(--line);
  border-radius: 14px; padding: 44px 24px; text-align: center; cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); }
.dz-icon { font-size: 34px; margin-bottom: 6px; }
.dz-sub { font-size: 12px; color: var(--muted); margin: 4px 0 14px; }
.detect-q { font-size: 13px; color: var(--muted); margin: 6px 0; }
.detect-cand { font-size: 15px; font-weight: 700; color: var(--primary); margin: 0 0 12px; }
.detect-cand small { font-weight: 400; color: var(--muted); }
.detect-cand.ok { color: var(--ok); }
.koushu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin-bottom: 10px; }
.koushu-btn {
  text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; color: var(--text); line-height: 1.4;
}
.koushu-btn:hover { border-color: var(--accent); background: #FBF3F2; }
.koushu-btn.cand { border-color: var(--accent-light); background: #FBF3F2; }
.link-btn { border: none; background: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 2px 0; text-decoration: underline; }

/* ===== デモ注入の明示 ===== */
.demo-callout {
  background: #FFF8E7; border: 1px solid #E8D9B0; border-left: 4px solid var(--warn-a);
  border-radius: 10px; padding: 10px 16px; font-size: 13px; margin-bottom: 12px;
}
tr.demo-row td { background: #FFFBEF; }
.demo-cell { font-size: 11px; color: var(--warn-a); max-width: 180px; }
.demo-cell small { color: var(--muted); }

/* ===== ステップ確認済み✓・ステップ2編集 ===== */
.step.done .step-ttl::after { content: " ✓"; color: var(--ok); font-weight: 900; }
.edit-in { width: 44px; border: 1px solid var(--accent); border-radius: 4px; padding: 2px 4px; font-size: 12px; margin: 0 1px; }
tr.editing td { background: #FFF4E5; }
.btn-xs { padding: 3px 10px; font-size: 12px; }
.fixed-note { color: var(--ok); font-weight: 700; font-size: 11px; }

/* ===== ステップ2 様式ミラー表示・ステップ4 比較表 ===== */
.form-mirror .sub-kubun { color: var(--muted); font-size: 11px; white-space: nowrap; background: #FAF7F7; }
.num { text-align: right; }
.cmp-h { font-size: 13px; color: var(--primary); margin: 14px 0 6px; }
.cmp-table th, .cmp-table td { padding: 6px 12px; }
.cmp-table tr.row-cmp-em td { background: #FBF3F2; font-weight: 700; }
.cmp-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ===== 棄却3色の凡例 ===== */
.badge-shukan { background: #7C5295; }   /* 紫=主観棄却 */
.badge-sg { background: #4A6FA5; }       /* 青=SG検定（Phase-2） */
tr.rejected td { background: #F3EEF7; color: #9A8FA5; }
.legend-note { font-size: 11px; color: var(--muted); margin-top: 8px; }
