/* この画面固有のレイアウト（色・罫線・部品は base.css のトークンだけを使う） */

/* ---------- 上部バー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  min-height: 3rem; padding: 0.35rem 0.75rem;
  background: var(--card); border-bottom: 1px solid var(--grid-strong); border-top: 3px solid var(--primary);
}
.brand { font-size: 1.05rem; font-weight: 700; white-space: nowrap; color: var(--primary); }
.seg { display: inline-flex; border: 1px solid var(--input); background: var(--card); }
.seg button { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.35rem; height: 2.25rem; padding: 0 0.8rem; font-size: 0.85rem; font-weight: 700; border-right: 1px solid var(--input); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed='true'] { background: var(--primary); color: #fff; }
.seg-sm button { height: 1.75rem; padding: 0 0.5rem; font-size: 0.75rem; }
.topbar .spacer { flex: 1; }

/* ---------- 左のメニューと本文 ---------- */
.office { display: grid; grid-template-columns: 14.5rem minmax(0, 1fr); min-height: calc(100vh - 3rem); }
.side { background: var(--chrome); border-right: 1px solid var(--grid-strong); padding: 0.4rem; }
.side .grp { padding: 0.75rem 0.75rem 0.25rem; font-size: 0.72rem; font-weight: 700; color: var(--muted-foreground); letter-spacing: 0.05em; }
.nav { display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.5rem 0.75rem; font-size: 0.95rem; text-align: left; border-left: 3px solid transparent; }
.nav .i { font-size: 1.15rem; }
.nav:hover { background: var(--accent); }
.nav[aria-current='page'] { border-left-color: var(--primary); background: var(--accent); font-weight: 700; color: var(--primary); }
.nav .count { margin-left: auto; min-width: 1.4rem; padding: 0 0.35rem; text-align: center; font-size: 0.72rem; font-weight: 700; background: var(--warn); color: var(--warn-foreground); }
.nav.soon { color: rgb(90 90 90 / 0.75); font-size: 0.85rem; cursor: default; }
.nav.soon:hover { background: transparent; }
.nav.soon .tag { margin-left: auto; font-size: 0.65rem; border: 1px solid currentColor; padding: 0 0.3rem; white-space: nowrap; }
.fields.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.main { padding: 0.75rem; min-width: 0; }
.main > .section + .section, .main > * + .section, .main > .grid2 + .section { margin-top: 0.75rem; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.75rem; margin-top: 0.75rem; align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; }
.toolbar .select { width: auto; min-width: 12rem; }
.legend { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.8rem; color: var(--muted-foreground); }
.linklike { color: var(--info); text-decoration: underline; cursor: pointer; }
.btn:not(.btn-primary):not(.btn-ghost) { border: 1.5px solid var(--primary); color: var(--primary); }
.btn.btn-danger { border-color: var(--destructive); color: var(--destructive); }
table.ruled.compact { font-size: 0.8rem; }
.ruled td.wrap-cell { white-space: normal; min-width: 9rem; }
.ruled.compact th, .ruled.compact td { padding: 0.25rem 0.4rem; }
.ruled td.center { text-align: center; }
.ruled tr.retired td { color: var(--muted-foreground); }
td.cell-btn { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
td.cell-btn:hover { background: var(--accent); }
td.cell-edit { cursor: pointer; color: var(--info); }
td.cell-edit:hover { background: var(--accent); text-decoration: underline; }
td.cell-edit .i { font-size: 0.85em; vertical-align: -0.1em; }
.ruled tr.add-row td { background: #fbfbfe; padding: 0.1rem 0.25rem; }
.neg { color: var(--destructive); font-weight: 700; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 0.55rem 0.75rem; border-top: 1px solid var(--border); font-size: 0.9rem; }
.list-plain li:first-child { border-top: 0; }
.modal-wide { width: min(94vw, 56rem); }
.sub-title { margin: 1rem 0 0.4rem; font-size: 0.85rem; font-weight: 700; }

/* ---------- 共通ヘッダー：流れ（どこまで進んだか）＋ 共通の数字。押すとそのタブへ ---------- */
.stepper { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.25rem; margin-bottom: 0.5rem; }
.step { display: flex; gap: 0.4rem; align-items: flex-start; text-align: left; padding: 0.35rem 0.5rem; background: var(--card); border: 1px solid var(--border); border-top: 3px solid var(--border); font-size: 0.78rem; }
.step b { display: block; font-size: 0.82rem; }
.step .no { flex-shrink: 0; width: 1.3rem; height: 1.3rem; display: grid; place-items: center; border-radius: 999px; background: var(--muted); font-weight: 700; font-size: 0.72rem; }
.step.done { border-top-color: var(--primary); }
.step.done .no { background: var(--primary); color: #fff; }
.step.now { border-top-color: #d9a300; background: #fffdf0; }
.step.now .no { background: #d9a300; color: #fff; }
.step.alert { border-top-color: var(--destructive); background: #fff6f7; }
.step.alert .no { background: var(--destructive); color: #fff; }
.step.on { outline: 2px solid var(--primary); outline-offset: -2px; }
button.step:hover, button.kpi:hover { background: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); margin-bottom: 0.75rem; }
.kpi { display: grid; gap: 0.15rem; align-content: start; text-align: left; padding: 0.45rem 0.7rem; background: var(--card); }
.kpi .label { font-size: 0.72rem; color: var(--muted-foreground); }
.kpi .value { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) { .stepper, .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; } }

/* ---------- 入力欄の並び（灰色のラベル・白い値・1px の罫線） ---------- */
.form-grid { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.form-grid.two { grid-template-columns: 8rem minmax(0, 1fr) 8rem minmax(0, 1fr); border: 0; }
.form-grid > .lab { background: var(--muted); padding: 0.55rem 0.75rem; font-size: 0.85rem; font-weight: 700; }
.form-grid > .val { background: var(--card); padding: 0.45rem 0.6rem; }
.form-grid .input, .form-grid .select { max-width: 26rem; }

/* ---------- 見積の明細（表の中で直接入力。数字はその場で計算） ---------- */
.est-t .input.cell, .est-t .select.cell { height: 1.85rem; padding: 0 0.35rem; font-size: 0.8rem; }
.est-t .w-name { min-width: 9rem; }
.est-t .w-spec { min-width: 8rem; }
.est-t .w-num { width: 4.2rem; }
.est-t .w-unit { width: 3.6rem; }
.est-t .w-price { width: 6.2rem; }
.est-t .w-group { max-width: 22rem; font-weight: 700; }
.est-t .select.cell { width: 4.6rem; }
.est-t td { vertical-align: middle; }
.est-t.editing td { padding: 0.15rem 0.25rem; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input.w-num { width: 5rem; display: inline-block; }
.input.w-price { width: 8rem; display: inline-block; }
.input.need { background: #ffff99; }
.est-t tfoot tr.total td, .est-t tfoot tr.grand td { font-weight: 700; }
.est-t tfoot td { border: 1px solid var(--border); }
.est-t tfoot tr.grand td { background: var(--accent); border-top: 2px solid var(--primary); }

/* 工事台帳と同じ並びの収支表 */
.ledger-t td:first-child { width: 2rem; }

/* ---------- 帳票（紙と同じく黒の細罫） ---------- */
.sheet-scroll { overflow-x: auto; background: #fff; }
table.sheet { width: 100%; border-collapse: collapse; background: #fff; font-size: 0.72rem; line-height: 1.3; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { border: 1px solid #555; padding: 0.2rem 0.3rem; white-space: nowrap; }
.sheet thead th { background: #e4e5ef; font-weight: 700; text-align: center; }
.sheet .n { text-align: right; }
.sheet .center { text-align: center; }
.sheet .right { text-align: right; }
.sheet tr.cat td { background: #f2f2f2; font-weight: 700; }
.sheet tr.grand td { background: #fff2cc; font-weight: 700; border-top: 2px solid #222; }
.tracer { font-size: 0.7rem; }

/* 見積書（印刷用・A4 縦）。様式は仮 */
.quote { width: 50rem; max-width: 100%; margin: 0 auto; background: #fff; border: 1px solid var(--grid-strong); padding: 1.4rem 1.6rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.9rem; }
.q-head { display: flex; justify-content: space-between; align-items: flex-end; }
.q-head h2 { font-size: 1.5rem; letter-spacing: 0.35em; border-bottom: 3px double #222; padding: 0 0.6rem 0.2rem; margin: 0 auto; }
.q-parties { display: flex; justify-content: space-between; gap: 1.2rem; flex-wrap: wrap; align-items: flex-start; }
.q-to { flex: 1 1 18rem; min-width: 0; display: grid; gap: 0.5rem; }
.q-client { font-size: 1.1rem; font-weight: 700; border-bottom: 1px solid #222; padding-bottom: 0.15rem; }
.q-kv th { width: 6rem; text-align: left; background: #f2f2f2; }
.q-kv td { white-space: normal; }
.q-total { display: flex; align-items: baseline; gap: 0.8rem; border-bottom: 2px solid #222; padding: 0.3rem 0; }
.q-total b { font-size: 1.4rem; }
.q-from { text-align: right; line-height: 1.6; }
.q-stamps { display: flex; justify-content: flex-end; margin-top: 0.5rem; }
.q-stamps span { width: 3.4rem; height: 3.4rem; border: 1px solid #555; margin-left: -1px; font-size: 0.65rem; text-align: center; padding-top: 0.1rem; }
.q-table td:nth-child(2), .q-table td:nth-child(3) { white-space: normal; }

/* ---------- 請求管理 ---------- */
.notice.stage { margin-bottom: 0.75rem; align-items: center; }
.notice.stage .badge { flex-shrink: 0; }
.stage-tag { margin-left: 0.5rem; font-size: 0.7rem; vertical-align: 0.1em; }
.section-head .stage-tag { background: #fff; color: var(--primary); }
.asks { margin-top: 0.75rem; padding: 0.6rem 0.8rem; background: var(--card); border: 1px dashed var(--grid-strong); font-size: 0.8rem; }
.asks b { display: flex; align-items: center; gap: 0.35rem; }
.asks ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }
.flow4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; margin-bottom: 0.75rem; }
.flow4 > div { display: grid; gap: 0.2rem; align-content: start; padding: 0.5rem 0.7rem; font-size: 0.78rem; background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--primary); }
.flow4 b { font-size: 0.88rem; }
.pu-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 0.75rem; align-items: start; }
.pu-grid > div > .section + .section { margin-top: 0.75rem; }
.vinv { background: #fff; border: 1px solid var(--grid-strong); padding: 0.8rem; display: grid; gap: 0.5rem; font-size: 0.8rem; }
.vinv-title { font-size: 1.05rem; letter-spacing: 0.3em; border-bottom: 3px double #222; }
.vinv .sheet td.wrap { white-space: normal; }
.alloc-t .select.cell, .alloc-t .input.cell { height: 1.85rem; padding: 0 0.35rem; font-size: 0.78rem; max-width: 14rem; }
.alloc-t .select.cell { min-width: 12rem; }
.alloc-t .input.w-price { width: 7rem; }
.select.need { background: #ffff99; }
.ruled tr.mine td { background: #eef2ff; }
.alloc-sum { padding: 0.45rem 0.6rem; font-weight: 700; font-size: 0.85rem; text-align: right; border-top: 2px solid var(--grid-strong); }
.kv { display: grid; grid-template-columns: 8rem 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); font-size: 0.85rem; }
.kv > div { background: var(--card); padding: 0.35rem 0.6rem; }
.kv > div:nth-child(odd) { background: var(--muted); font-weight: 700; font-size: 0.78rem; }
.quote.bill { width: 60rem; }
.bill-grid { display: grid; grid-template-columns: minmax(0, 1fr) 15rem; gap: 1rem; align-items: start; }
.bill-side .sheet th { text-align: left; background: #f2f2f2; width: 6rem; }
.bill .sheet td.wrap { white-space: normal; }
/* 請求書と割り当ては、広い画面だけ横に並べる（割り当ての表の列を削らない） */
@media (max-width: 1500px) { .pu-grid { grid-template-columns: minmax(0, 1fr); } .vinv { max-width: 46rem; } }
@media (max-width: 1100px) { .bill-grid { grid-template-columns: minmax(0, 1fr); } .flow4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* 今入れた行をしばらく光らせる */
.flash td, .flash { animation: flash 2.4s ease-out 2; }
@keyframes flash { 0%, 40% { background: #fff3b0; } 100% { background: inherit; } }

@media (max-width: 900px) {
  .office { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; min-width: 0; border-right: 0; border-bottom: 1px solid var(--grid-strong); padding: 0; }
  .side .grp, .nav.soon { display: none; }
  .nav { width: auto; white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; }
  .nav[aria-current='page'] { border-bottom-color: var(--primary); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .fields.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .stepper, .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .quote { padding: 0.8rem; }
  .topbar { flex-wrap: nowrap; overflow-x: auto; gap: 0.4rem; }
  .brand, .topbar .size-label, .topbar .seg-sm, .topbar .hide-sm { display: none; }
}

@media print {
  .topbar, .side, .page-header .row, .sheet-tabs, .toolbar, .legend, .stepper, .kpis { display: none !important; }
  .office { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .quote { border: 0; width: 100%; padding: 0; }
}
