:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --ink: #1b1b1a;
  --ink2: #55544f;
  --muted: #86857f;
  --line: #e3e2dc;
  --line2: #efeee9;
  --accent: #f07408;
  --accent-tint: #fff6ec;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --crit: #d03b3b;   --crit-bg: #fdeeee;
  --serious: #c2531f; --serious-bg: #fdf0e9;
  --warn: #8a6100;   --warn-bg: #fdf4d8;
  --good: #0a7d0a;   --good-bg: #e9f6e9;
  --over: #5a50a8;   --over-bg: #efedfa;
  --r: 8px;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--ink); font: 14px/1.6 "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", Meiryo, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
.zh { font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Hiragino Sans", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
[hidden] { display: none !important; }

/* 骨組み */
.app { display: flex; min-height: 100vh; }
.side { width: 216px; flex: 0 0 216px; background: #1d1d1b; color: #cfcec8; padding: 22px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 0 8px 22px; }
.brand strong { display: block; color: #fff; font-size: 15px; letter-spacing: .02em; }
.brand span { font-size: 11px; color: #8f8e88; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--r); color: #cfcec8; font-weight: 600; }
.nav a:hover { background: #2b2b28; text-decoration: none; }
.nav a.on { background: #33332f; color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav small { font-size: 11px; font-weight: 400; color: #8f8e88; }
.nav em { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--crit); color: #fff; font: 700 11px/20px system-ui; text-align: center; }
.nav em:empty { display: none; }
.demo-note { margin-top: auto; padding: 10px; border: 1px solid #3a3a36; border-radius: var(--r); font-size: 11px; line-height: 1.5; color: #a09f99; }
.main { flex: 1; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 19px; }
.sync { display: flex; align-items: center; gap: 16px; }
.sync dl { display: flex; gap: 20px; font-size: 12px; }
.sync dt { color: var(--muted); }
.sync dd { font-weight: 600; }
.view { padding: 22px 28px 60px; max-width: 1500px; }

/* 部品 */
.btn { height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b9b8b1; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .6; cursor: default; }
.link { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.link:hover { color: var(--crit); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card > header, .memo > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
h2 { font-size: 15px; }
h2 small, h3 small { margin-left: 10px; font-size: 12px; font-weight: 400; color: var(--muted); }
.meta, .muted { font-size: 12px; color: var(--muted); }
.lead { margin-bottom: 14px; color: var(--ink2); max-width: 900px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: 12px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip i { font-style: normal; font-size: 10px; }
.chip.crit { background: var(--crit-bg); color: var(--crit); }
.chip.serious { background: var(--serious-bg); color: var(--serious); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.over { background: var(--over-bg); color: var(--over); }

/* 表 */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line2); vertical-align: middle; }
thead th { font-size: 12px; font-weight: 600; color: var(--ink2); background: #faf9f6; border-bottom: 1px solid var(--line); white-space: nowrap; line-height: 1.35; }
thead th small { display: block; font-weight: 400; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.r { text-align: right; }
td b + code { display: block; }
td.strong { font-weight: 700; font-size: 14px; }
.neg { color: var(--crit); font-weight: 700; }
tr.row { cursor: pointer; }
tr.row:hover td, tr.row.open td { background: #faf9f6; }
tr.group td { background: #f1f0eb; padding: 8px 12px; border-bottom: 1px solid var(--line); }
tr.group b { margin-right: 12px; }
tr.group span { font-size: 12px; color: var(--ink2); }
tr.group em { float: right; font-style: normal; font-size: 12px; color: var(--muted); }
tr.detail td { background: #faf9f6; padding: 14px 20px 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.detail-grid h4 { font-size: 12px; color: var(--ink2); margin-bottom: 6px; }
.detail-grid li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.detail-grid .btn { margin-top: 10px; }
td.empty, li.empty { color: var(--muted); text-align: center; padding: 24px; }
small.late { display: block; color: var(--crit); font-size: 11px; font-weight: 700; }

/* ホーム */
.memo { background: var(--accent-tint); border: 1.5px solid var(--accent); border-radius: var(--r); padding: 16px 20px; margin-bottom: 16px; }
.memo-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.memo-input textarea { width: 100%; padding: 10px 12px; border: 1px solid #e6c9a8; border-radius: var(--r); background: #fff; resize: vertical; }
.memo-input div { display: flex; gap: 8px; margin-top: 8px; }
.memo-list li { display: flex; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid #f1dcc3; }
.memo-list li:last-child { border-bottom: 0; }
.memo-list time { flex: 0 0 38px; font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.memo-list p { flex: 1; }
.alert { display: flex; align-items: center; gap: 14px; padding: 12px 16px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--crit); border-radius: var(--r); }
.alert p { flex: 1; font-weight: 600; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 18px; align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi span { display: block; font-size: 12px; color: var(--ink2); }
.kpi b { display: block; font-size: 30px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi b small { margin-left: 4px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.kpi em { display: block; font-style: normal; font-size: 11px; color: var(--muted); line-height: 1.45; }
.props { display: grid; gap: 12px; }
.prop { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; cursor: pointer; }
.prop:hover { border-color: #b9b8b1; }
.prop header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.prop h3 { font-size: 15px; }
.mini { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.mini div { background: #faf9f6; border-radius: 6px; padding: 7px 10px; }
.mini dt { font-size: 11px; color: var(--muted); }
.mini dd { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.why { color: var(--ink2); font-size: 13px; line-height: 1.75; }
.why.big { color: var(--ink); font-size: 14px; background: #faf9f6; border-radius: var(--r); padding: 12px 14px; }

/* AI アシスタント */
.chat { position: sticky; top: 78px; display: flex; flex-direction: column; height: calc(100vh - 100px); min-height: 460px; padding: 16px; margin-bottom: 0; }
.chat > header { margin-bottom: 10px; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.7; }
.msg.ai { background: #f3f2ee; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.qs { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line2); }
.qs button { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.qs button:hover { border-color: var(--accent); }
.ask { display: flex; gap: 8px; }
.ask input { flex: 1; min-width: 0; height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r); }

/* 絞り込み */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.seg.wrap { flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; font-weight: 600; color: var(--ink2); border-right: 1px solid var(--line2); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: #fff; }
.filters input[type=search], .filters select, .card header select { height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.filters input[type=search] { width: 280px; max-width: 100%; }
.addform { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line2); }
.addform label { display: grid; gap: 4px; font-size: 12px; color: var(--ink2); }
.addform input, .addform select { height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; max-width: 260px; }
.addform input[name=qty] { width: 90px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--ink2); font-size: 12px; }

/* グラフ */
.chart { position: relative; }
.plot { position: relative; }
.chart svg { display: block; max-width: 100%; }
.chart .grid { stroke: var(--line2); stroke-width: 1; }
.chart .grid.zero { stroke: #b9b8b1; }
.chart .tick { font-size: 11px; fill: var(--muted); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .endlabel { font-size: 12px; fill: var(--ink2); font-weight: 600; }
.chart .cross { stroke: #9a9993; stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .mark { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .mark.out { stroke: var(--crit); }
.chart .marklabel { font-size: 11px; fill: var(--ink2); font-weight: 600; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink2); margin-bottom: 4px; }
.legend i, .tip i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.tip { position: absolute; z-index: 2; min-width: 150px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 4px 14px rgba(0, 0, 0, .1); font-size: 12px; pointer-events: none; }
.tip b { display: block; margin-bottom: 2px; }
.tip div { display: flex; align-items: center; color: var(--ink2); }
.tip strong { margin-left: auto; padding-left: 12px; color: var(--ink); font-variant-numeric: tabular-nums; }
.bars li { display: grid; grid-template-columns: 150px minmax(0, 1fr) 48px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bars div { height: 14px; }
.bars i { display: block; height: 100%; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bars b { text-align: right; font-variant-numeric: tabular-nums; }

/* 詳細パネル */
.drawer-mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .28); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 21; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .14); }
.drawer > header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer > header h2 { font-size: 18px; margin: 6px 0 2px; }
.drawer-body { padding: 4px 22px 40px; overflow-y: auto; }
.drawer-body h3 { font-size: 13px; margin: 20px 0 8px; }
.calc li { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line2); font-size: 13px; }
.calc span { color: var(--ink2); }
.calc b { font-weight: 600; }
table.psi th:first-child { white-space: nowrap; font-weight: 600; }
table.psi tr.sub th, table.psi tr.sub td { color: var(--muted); font-size: 12px; font-weight: 400; padding-top: 4px; padding-bottom: 4px; }
table.psi tr.total th, table.psi tr.total td { font-weight: 700; background: #faf9f6; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r); z-index: 30; font-size: 13px; max-width: 90vw; }

@media (max-width: 1180px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .chat { position: static; height: 520px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app { display: block; }
  .side { position: static; width: auto; height: auto; padding: 12px 12px 8px; }
  .brand { padding: 0 4px 8px; }
  .nav { display: flex; overflow-x: auto; }
  .nav a { white-space: nowrap; padding: 8px 12px; }
  .nav a.on { box-shadow: inset 0 -3px 0 var(--accent); }
  .demo-note { display: none; }
  .top { position: static; flex-direction: column; align-items: flex-start; padding: 12px 16px; }
  .sync { flex-wrap: wrap; }
  .sync dl { flex-wrap: wrap; gap: 8px 16px; }
  .view { padding: 16px 16px 48px; }
  .memo-body, .two, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .mini { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alert { flex-direction: column; align-items: flex-start; }
  .bars li { grid-template-columns: 110px minmax(0, 1fr) 40px; }
  table { min-width: 640px; }
}
