:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-soft: #f9fbf8;
  --line: #dce4da;
  --line-strong: #b9c8b6;
  --text: #1d2b27;
  --muted: #65746f;
  --green: #2f6f5e;
  --green-dark: #17463b;
  --amber: #c7832b;
  --red: #b94b48;
  --blue: #426f8f;
  --ink: #17221f;
  --shadow: 0 10px 30px rgba(23, 70, 59, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Yu Gothic UI", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: #183c34;
  color: #f7fbf3;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
}

.brand-sub {
  margin-top: 2px;
  color: #c8d7cf;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: #e7f0eb;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-item span {
  width: 22px;
  color: #d79a4b;
  font-weight: 800;
  text-align: center;
}

.nav-item b {
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
}

.side-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.side-label {
  color: #c8d7cf;
  font-size: 11px;
  font-weight: 700;
}

.side-panel strong {
  display: block;
  margin-top: 5px;
}

.side-note {
  margin-top: 10px;
  color: #dce8e1;
  font-size: 12px;
  line-height: 1.6;
}

.main {
  min-width: 0;
  padding: 22px 24px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.25;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search {
  width: min(420px, 42vw);
  min-width: 260px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.icon-button,
.primary-button,
.secondary-button,
.small-button {
  border: 0;
  border-radius: 8px;
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--green-dark);
  font-size: 18px;
}

.primary-button {
  height: 40px;
  padding: 0 16px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

.secondary-button {
  height: 36px;
  padding: 0 13px;
  background: #eef4ed;
  color: var(--green-dark);
  border: 1px solid var(--line-strong);
  font-weight: 700;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  background: #eef4ed;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.toast {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #e8f4ed;
  border: 1px solid #b9dac6;
  color: var(--green-dark);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.kpi-value {
  margin-top: 10px;
  font-size: 24px;
  font-weight: 900;
}

.kpi-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.split,
.two-column,
.reports-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(330px, 0.6fr);
  gap: 14px;
}

.split.bottom {
  margin-top: 14px;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
}

.two-column {
  grid-template-columns: minmax(420px, 0.9fr) minmax(0, 1.1fr);
}

.reports-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel.wide {
  min-width: 0;
}

.panel-head {
  min-height: 70px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.compact-select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #e8eee6;
  vertical-align: top;
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 900;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: #f8fbf5;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef4ed;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
}

.badge.warn {
  background: #fff2d8;
  color: #8d5d18;
}

.badge.red {
  background: #fae6e4;
  color: var(--red);
}

.badge.blue {
  background: #e7f0f6;
  color: var(--blue);
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: #e6ece4;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.queue,
.checklist,
.project-list,
.document-list,
.stack-list,
.report-menu,
.roadmap {
  padding: 14px;
}

.queue-item,
.check-item,
.project-card,
.document-card,
.stack-item,
.report-item,
.roadmap-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.queue-item,
.check-item,
.document-card,
.stack-item,
.report-item {
  padding: 12px;
}

.queue {
  display: grid;
  gap: 10px;
}

.queue-item {
  display: grid;
  gap: 8px;
}

.queue-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.queue-meta {
  color: var(--muted);
  font-size: 12px;
}

.checklist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.check-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.check-symbol {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e2efe6;
  color: var(--green-dark);
  font-weight: 900;
}

.bar-chart {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 98px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e6ece4;
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.bar-track .sales {
  background: var(--green);
}

.bar-track .receipts {
  background: var(--amber);
}

.workbench {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.project-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.project-card {
  padding: 12px;
  cursor: pointer;
}

.project-card.active,
.project-card:hover {
  border-color: var(--green);
  background: #f5fbf6;
}

.project-card strong {
  display: block;
  font-size: 14px;
}

.project-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  min-height: 620px;
}

.detail-body {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.detail-hero h2 {
  margin-top: 4px;
  font-size: 22px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.meta-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.meta-box span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meta-box strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
}

.form {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.field textarea {
  min-height: 72px;
  resize: vertical;
}

.line-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.line-editor table {
  min-width: 680px;
}

.line-editor input {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
}

.form-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: #f1f7f0;
  font-weight: 900;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.document-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.document-card {
  display: grid;
  gap: 9px;
}

.doc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.doc-head strong {
  font-size: 14px;
}

.doc-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stack-list {
  display: grid;
  gap: 10px;
}

.stack-item {
  display: grid;
  gap: 8px;
}

.stack-head {
  display: flex;
  justify-content: space-between;
  font-weight: 900;
}

.print-sheet {
  margin: 16px;
  padding: 22px;
  min-height: 640px;
  border: 1px solid #cfd8cd;
  background: #fff;
}

.print-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.print-title h2 {
  font-size: 22px;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}

.print-cell {
  border: 1px solid #cfd8cd;
  padding: 8px;
  min-height: 54px;
}

.print-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.print-cell strong {
  display: block;
  margin-top: 5px;
}

.report-menu {
  display: grid;
  gap: 10px;
}

.report-item {
  display: grid;
  gap: 5px;
}

.report-item strong {
  font-size: 14px;
}

.report-item span {
  color: var(--muted);
  font-size: 12px;
}

.roadmap {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.roadmap-card {
  padding: 16px;
}

.roadmap-card h3 {
  font-size: 16px;
}

.roadmap-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.roadmap-row {
  display: grid;
  grid-template-columns: 112px 1fr 82px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.dialog::backdrop {
  background: rgba(22, 34, 31, 0.35);
}

.dialog-head {
  height: 58px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#dialogBody {
  padding: 18px;
  overflow: auto;
}

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 82px 1fr;
  }

  .brand {
    justify-content: center;
    padding: 4px 0 12px;
  }

  .brand div,
  .nav-item b,
  .side-panel {
    display: none;
  }

  .nav-item {
    justify-content: center;
  }

  .nav-item span {
    width: auto;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .two-column,
  .reports-grid,
  .workbench {
    grid-template-columns: 1fr;
  }

  .project-list,
  .document-list {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .brand {
    justify-content: flex-start;
  }

  .brand div,
  .nav-item b {
    display: block;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 16px 12px 28px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
    min-width: 0;
  }

  .kpi-grid,
  .checklist,
  .meta-grid,
  .form-grid,
  .roadmap,
  .print-grid {
    grid-template-columns: 1fr;
  }

  .detail-hero {
    grid-template-columns: 1fr;
  }
}

/* 多段承認ステッパー */
.approval-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 4px;
  margin: 8px 0 4px;
}

.astep {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  line-height: 1;
  padding: 4px 8px 4px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-soft);
}

.astep i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}

.astep.done {
  color: var(--green-dark);
  border-color: rgba(47, 111, 94, 0.4);
  background: rgba(47, 111, 94, 0.1);
}

.astep.done i {
  background: var(--green);
}

.astep.current {
  color: #6a4a12;
  border-color: rgba(199, 131, 43, 0.5);
  background: rgba(199, 131, 43, 0.14);
  font-weight: 700;
}

.astep.current i {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(199, 131, 43, 0.2);
}

.astep.returned {
  color: #7a2e2c;
  border-color: rgba(185, 75, 72, 0.5);
  background: rgba(185, 75, 72, 0.12);
  font-weight: 700;
}

.astep.returned i {
  background: var(--red);
}

/* 承認履歴 */
.history-block {
  margin-top: 14px;
}

.history-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 12px;
}

/* 注文要求の予算ボックス */
.budget-box {
  margin: 4px 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.budget-box.over {
  border-color: rgba(185, 75, 72, 0.55);
  background: rgba(185, 75, 72, 0.07);
}

.budget-cells {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.budget-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.budget-cell span {
  font-size: 10.5px;
  color: var(--muted);
}

.budget-cell strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.budget-cell.pos strong {
  color: var(--green);
}

.budget-cell.neg strong {
  color: var(--red);
}

.budget-progress {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.budget-progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
}

.budget-box.over .budget-progress span {
  background: var(--red);
}

.budget-warn {
  margin-top: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #7a2e2c;
  background: rgba(185, 75, 72, 0.12);
}

.budget-ok {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--muted);
}

/* 原価計算書の集計行 */
.report-sub td {
  background: var(--surface-soft);
  font-weight: 600;
}

.report-grand td {
  background: rgba(47, 111, 94, 0.1);
  border-top: 2px solid var(--line-strong);
}

.print-note {
  margin-top: 10px;
  font-size: 11px;
}

@media (max-width: 1080px) {
  .budget-cells {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 製作No 親データへのリンク・親子ツリー */
.parent-link {
  color: var(--green);
  font-weight: 600;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

.parent-link:hover {
  text-decoration: underline;
}

.parent-link.inline {
  font-weight: 600;
}

.parent-link-row {
  margin: 4px 0 10px;
}

.doc-foot {
  border-top: 1px dashed var(--line);
  padding-top: 7px;
}

.document-tree {
  display: grid;
  gap: 14px;
}

.slip-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-soft);
  display: grid;
  gap: 10px;
}

.slip-children {
  border-left: 2px solid var(--line-strong);
  margin-left: 6px;
  padding-left: 12px;
  display: grid;
  gap: 8px;
}

.slip-children-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.orphan-block {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.list-filter {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 2px 10px;
}

.list-filter a {
  color: var(--green);
  cursor: pointer;
}

.empty.small {
  padding: 10px;
  font-size: 12px;
}

/* 入金・出金 登録と割り当て */
.panel-head.sub {
  margin-top: 18px;
}

.panel-head.sub h3 {
  margin: 0;
  font-size: 13px;
}

.alloc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.alloc-table th,
.alloc-table td {
  font-size: 12px;
}

.alloc-table .alloc-input {
  width: 100%;
  min-width: 90px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  text-align: right;
}

.alloc-foot {
  display: flex;
  gap: 18px;
  justify-content: flex-end;
  padding: 10px 2px 4px;
  font-size: 12px;
  color: var(--muted);
}

.alloc-foot strong {
  color: var(--text);
}

.alloc-foot .neg {
  color: var(--red);
}

.document-list.compact {
  max-height: 240px;
}

/* 残高表のグルーピング・小計・合計・符号付き残高 */
td.num.neg {
  color: var(--red);
}

.group-row td {
  background: var(--surface-soft);
  font-weight: 700;
  font-size: 12px;
  color: var(--green-dark);
}

.subtotal-row td {
  border-top: 1px solid var(--line);
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}

.total-row td {
  border-top: 2px solid var(--line-strong);
  font-weight: 700;
}

.total-row.sub td {
  border-top: none;
  font-weight: 600;
  color: var(--muted);
}
