:root {
  --paper: #F4F5F2;
  --surface: #FFFFFF;
  --ink: #1E2A32;
  --muted: #5D6B74;
  --line: #CDD4D8;
  --steel: #3F5A6C;
  --steel-soft: #E3E9ED;
  --caution: #F2B705;   /* 安全標識の黄色：原価消化バーだけに使う */
  --gain: #2E6B4E;
  --loss: #B4381F;
  --loss-soft: #F8E4DE;
  --focus: #2B6CB0;
  --font: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151B20; --surface: #1D252B; --ink: #E5EAED; --muted: #9AA8B1;
    --line: #34414A; --steel: #8FB0C6; --steel-soft: #26323A;
    --gain: #6FC39A; --loss: #F08A70; --loss-soft: #3A2520; --focus: #7FB3E8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.6; }
.num, td.r, th.r { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
a { color: var(--steel); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; align-items: baseline; gap: 20px; padding: 14px 24px; background: var(--steel); color: #fff; }
@media (prefers-color-scheme: dark) { .topbar { background: #24323C; } }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 17px; }
.toplink { color: #fff; font-size: 14px; text-decoration: none; padding: 2px 10px; border: 1px solid rgba(255,255,255,.5); border-radius: 4px; white-space: nowrap; }
.toplink:hover, .toplink[aria-current="page"] { background: rgba(255,255,255,.15); }
.crumb { color: #D9E3EA; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; }

h1 { font-size: 24px; margin: 0; line-height: 1.3; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.btn { font: inherit; font-size: 14px; padding: 7px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--steel); }
.btn.primary { background: var(--steel); border-color: var(--steel); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10171C; } }
.btn.danger { color: var(--loss); }
.btn.sm { padding: 3px 10px; font-size: 13px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 18px 20px; margin-bottom: 20px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 700; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.sub-total td { font-weight: 700; background: var(--steel-soft); }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: none; }
tr.cat-head td { font-weight: 700; padding-top: 16px; color: var(--steel); border-bottom: 1px solid var(--steel); }
tr.over td { background: var(--loss-soft); }
tr.item td.code { padding-left: 22px; }
.wt-qty { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 12px; font-variant-numeric: tabular-nums; }
.wt-note { font-weight: 400; margin-top: 4px; }
.note { font-size: 12px; color: var(--muted); white-space: pre-wrap; margin-top: 2px; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--steel-soft); }
.gain { color: var(--gain); }
.loss { color: var(--loss); font-weight: 700; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 10px; border: 1px solid var(--chip-line); background: var(--chip-bg); color: var(--chip-ink); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--chip-dot); }
/* 状態ごとの色：予算作成中＝黄、施工中＝青、完了＝緑 */
.chip.planning { --chip-bg: #FFF3CC; --chip-line: #E9C55A; --chip-ink: #6B4E00; --chip-dot: #D9A300; }
.chip.active   { --chip-bg: #DCEBF7; --chip-line: #8DB6D9; --chip-ink: #1D4A73; --chip-dot: #2F74B5; }
.chip.done     { --chip-bg: #DDF0E4; --chip-line: #8CC7A3; --chip-ink: #215C3B; --chip-dot: #2E8B57; }
@media (prefers-color-scheme: dark) {
  .chip.planning { --chip-bg: #3A3016; --chip-line: #8A6D1E; --chip-ink: #F2D27A; --chip-dot: #E6B93A; }
  .chip.active   { --chip-bg: #1C3244; --chip-line: #3E6A90; --chip-ink: #A7CDEE; --chip-dot: #6AA8E0; }
  .chip.done     { --chip-bg: #1B3326; --chip-line: #3D7A56; --chip-ink: #98D8B0; --chip-dot: #5FC08A; }
}

/* 工事ヘッダー */
.phead { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.phead .code { font-size: 14px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 20px; }
.tabs a { padding: 8px 18px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 700; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--steel); }

/* 損益の主要数値 */
.figures { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--surface); border-radius: 4px; margin-bottom: 20px; }
.figures > div { padding: 14px 18px; border-left: 1px solid var(--line); }
.figures > div:first-child { border-left: none; }
.figures dt { font-size: 13px; color: var(--muted); }
.figures dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.figures dd small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
@media (max-width: 760px) { .figures { grid-template-columns: 1fr 1fr; } .figures > div:nth-child(3) { border-left: none; } .figures > div:nth-child(n+3) { border-top: 1px solid var(--line); } }

/* 原価消化 × 進捗：この画面の主役 */
.gauge { margin: 6px 0 4px; }
.gauge-track { position: relative; height: 34px; background: var(--steel-soft); border-radius: 3px; }
.gauge-fill { position: absolute; inset: 0 auto 0 0; background: var(--caution); border-radius: 3px 0 0 3px; }
.gauge-fill.over { background: repeating-linear-gradient(-45deg, var(--caution) 0 10px, #1E2A32 10px 20px); }
.gauge-mark { position: absolute; top: -6px; bottom: -6px; width: 3px; background: var(--ink); }
.gauge-mark span { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font-size: 12px; white-space: nowrap; font-weight: 700; }
.gauge-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 8px; gap: 12px; flex-wrap: wrap; }
.verdict { font-weight: 700; margin: 10px 0 0; }

.minibar { width: 120px; height: 8px; background: var(--steel-soft); border-radius: 2px; display: inline-block; vertical-align: middle; position: relative; overflow: hidden; }
.minibar i { position: absolute; inset: 0 auto 0 0; background: var(--steel); }
.minibar i.over { background: var(--loss); }

.months { display: grid; gap: 6px; }
.month { display: grid; grid-template-columns: 96px 1fr 110px 150px; gap: 10px; align-items: center; font-size: 13px; }
.stack { display: flex; height: 16px; background: var(--steel-soft); border-radius: 2px; overflow: hidden; }
.stack i { background: var(--steel); }
@media (max-width: 600px) { .month { grid-template-columns: 80px 1fr 96px; } .month > :last-child { display: none; } }

/* フォーム */
label.f { display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; font-size: 15px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 6px 9px; min-width: 0; height: 38px; }
textarea { height: auto; }
input.num { text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid2 .full { grid-column: 1 / -1; }
.entry { display: grid; grid-template-columns: 140px minmax(220px, 1.8fr) 1fr 1.2fr 140px auto; gap: 10px; align-items: end; }
@media (max-width: 900px) { .entry { grid-template-columns: 1fr 1fr; } .grid2 { grid-template-columns: 1fr; } }

dialog { border: 1px solid var(--line); border-radius: 6px; padding: 22px; width: min(560px, 94vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(20, 30, 38, .45); }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; }
.err { color: var(--loss); font-size: 14px; margin: 10px 0 0; min-height: 1em; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--paper); padding: 9px 18px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media print { .topbar, .tabs, .btn, .entry { display: none !important; } body { background: #fff; } .panel { border: none; padding: 0; } }
.wt-sub { font-weight: 400; color: var(--ink); font-size: 13px; margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--line); }
input:disabled { background: var(--steel-soft); color: var(--muted); }

.code-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: end; }
.code-row input { font-size: 17px; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.code-hint { font-size: 13px; padding-bottom: 9px; min-height: 1.4em; }
.code-hint.ok { color: var(--gain); }
.code-hint.ng { color: var(--loss); }
td.code { font-variant-numeric: tabular-nums; color: var(--muted); width: 1%; white-space: nowrap; }
.search { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search input[type=search] { width: min(320px, 100%); }

/* 工種の折りたたみ */
tr.cat-head { cursor: pointer; }
tr.cat-head:hover td { background: var(--steel-soft); }
.toggle { font: inherit; font-weight: 700; color: inherit; background: none; border: none; padding: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.chev { width: 0; height: 0; border-left: 6px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; transition: transform .15s; }
.toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
.wt-count { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 10px; }

/* 実行予算一覧：工種の間の余白 */
table.budget tr.gap td { height: 14px; padding: 0; border: none; background: transparent; }
table.budget thead + tbody tr.gap:first-child td { height: 8px; }

/* 工種の範囲を左端の縦線で示す（予算超過の項目がある工種は赤） */
table.budget tr.grp > td:first-child { border-left: 4px solid var(--steel); }
table.budget tr.grp.g-over > td:first-child { border-left-color: var(--loss); }
table.budget tr.cat-head > td { padding-top: 10px; }

/* 当初実行予算の作成日・出力の月度 */
.budget-date { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.budget-date input { height: 34px; }
.budget-date.unset input { border-color: var(--caution); box-shadow: 0 0 0 2px rgba(242, 183, 5, .25); }
.out-month { display: inline-flex; gap: 6px; align-items: center; }
.out-month input { height: 34px; font-size: 14px; }
.outputs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; margin: -6px 0 16px; }
.outputs-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.budget-date { font-weight: 700; color: var(--ink); }

/* 原価取込 */
.topbar .toplink + .toplink { margin-left: -10px; }
.badge { display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--caution); color: #1E2A32; font-size: 12px; font-weight: 700; text-align: center; line-height: 18px; }
.inbox { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.inbox-list { flex: 999 1 560px; min-width: 0; padding: 6px 0; }
.inbox-list tr.selected td { background: var(--steel-soft); }
.inbox-detail { flex: 1 1 440px; min-width: 0; }
.inbox-detail .pdf { width: 100%; height: 380px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); }
.warn-chip { display: inline-block; font-size: 11.5px; font-weight: 700; color: #8A3412; background: #FBE6DC; border: 1px solid #E8A88A; border-radius: 9px; padding: 0 7px; white-space: nowrap; }
.warn { margin: 10px 0 0; padding: 8px 12px; background: #FBE6DC; border: 1px solid #E8A88A; border-radius: 4px; font-size: 13px; color: #6B2A0E; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--steel); }
.link-selects { display: flex; flex-direction: column; gap: 8px; }
.kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 4px 10px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.chip.excluded { --chip-bg: #ECEFF1; --chip-line: #B7C1C7; --chip-ink: #46535B; --chip-dot: #7B8A93; }
.pdf-link { font-size: 12px; margin-left: 4px; }
@media (prefers-color-scheme: dark) {
  .warn-chip, .warn { background: #3A2520; color: #F5B9A0; border-color: #7A4433; }
  .chip.excluded { --chip-bg: #263038; --chip-line: #4A5862; --chip-ink: #B7C3CA; --chip-dot: #8C9AA3; }
}

/* ログイン・権限 */
body.signed-out .toplink, body.signed-out .user-menu, body.signed-out .crumb { display: none !important; }
body.role-viewer .need-editor, body:not(.role-admin) .need-admin { display: none !important; }
.auth-card { max-width: 420px; margin: 56px auto; padding: 28px 30px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.btn.wide { width: 100%; padding: 10px; font-size: 15px; }
.cancel-link { text-align: center; font-size: 14px; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; color: #fff; font-size: 13px; padding: 3px 10px; border-radius: 4px; white-space: nowrap; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: " ▾"; }
.user-menu[open] summary { background: rgba(255,255,255,.15); }
.user-menu-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); min-width: 170px; padding: 6px; display: flex; flex-direction: column; }
.user-menu-body a, .user-menu-body button { font: inherit; font-size: 14px; text-align: left; padding: 8px 10px; border: none; background: none; color: var(--ink); text-decoration: none; border-radius: 4px; cursor: pointer; }
.user-menu-body a:hover, .user-menu-body button:hover { background: var(--steel-soft); }
.audit-detail { font-size: 12.5px; color: var(--muted); word-break: break-all; }

.pdf-none { padding: 18px; margin-bottom: 14px; border: 1px dashed var(--line); border-radius: 4px; background: var(--paper); text-align: center; }
.need-chip { display: inline-block; font-size: 11.5px; font-weight: 700; color: #6B4E00; background: #FFF3CC; border: 1px solid #E9C55A; border-radius: 9px; padding: 0 7px; white-space: nowrap; }
.need-note { margin: 0 0 14px; padding: 8px 12px; background: #FFF3CC; border: 1px solid #E9C55A; border-radius: 4px; font-size: 13px; color: #5A4300; }
@media (prefers-color-scheme: dark) {
  .need-chip, .need-note { background: #3A3016; color: #F2D27A; border-color: #8A6D1E; }
}
