:root {
  --c-primary: #1B4D3E;
  --c-primary-2: #246653;
  --c-base: #F0F2F5;
  --c-surface: #FFFFFF;
  --c-surface-soft: #FAFAF8;
  --c-border: #D7DDE2;
  --c-border-soft: #E8ECEF;
  --c-text: #111111;
  --c-text-sub: #4F5653;
  --c-muted: #7A807D;
  --c-accent: #F28C28;
  --c-good: #1B4D3E;
  --c-warn: #F28C28;
  --c-bad: #B8392B;
  --shadow: 0 10px 28px rgba(27, 77, 62, 0.08);
  --shadow-soft: 0 1px 2px rgba(17, 17, 17, 0.04);
  --ff-gothic: "BIZ UDPGothic", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  --ff-mincho: "BIZ UDPMincho", "Yu Mincho", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--ff-gothic);
  background:
    linear-gradient(126deg, rgba(255,255,255,0.78) 0 38%, transparent 38%),
    linear-gradient(90deg, rgba(27,77,62,0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(27,77,62,0.035) 1px, transparent 1px),
    var(--c-base);
  background-size: auto, 32px 32px, 32px 32px, auto;
  color: var(--c-text);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }
.num { font-variant-numeric: tabular-nums; }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
}
.boot__eyebrow {
  color: var(--c-primary);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.boot__text { color: var(--c-muted); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--c-primary);
  color: #fff;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 1px 0 0 rgba(255,255,255,0.08) inset;
}
.brand {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.11), rgba(255,255,255,0.035)),
    rgba(5, 27, 22, 0.16);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 4px;
  padding: 10px 11px 9px;
  display: grid;
  gap: 6px;
  max-width: 214px;
  box-shadow: none;
}
.brand__logo {
  width: 100%;
  height: 28px;
  object-fit: contain;
  object-position: left center;
  display: block;
  filter: brightness(0) invert(1);
  opacity: 0.94;
}
.brand__sub {
  color: rgba(255,255,255,0.66);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}
.side__rule {
  height: 1px;
  background: rgba(255,255,255,0.18);
  margin: 18px 0;
}
.nav {
  display: grid;
  gap: 6px;
}
.nav button {
  color: rgba(255,255,255,0.82);
  background: transparent;
  text-align: left;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
}
.nav button.is-active {
  color: #fff;
  background: rgba(255,255,255,0.13);
  border-color: rgba(255,255,255,0.16);
}
.side__meta {
  margin-top: auto;
  color: rgba(255,255,255,0.66);
  font-size: 12px;
  line-height: 1.7;
}

.main {
  min-width: 0;
  padding: 24px 28px 42px;
}
.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 24px;
  align-items: start;
  padding-bottom: 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--c-border);
}
.eyebrow {
  color: var(--c-accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  line-height: 1.2;
}
h1 {
  margin: 7px 0 8px;
  color: var(--c-primary);
  font-size: clamp(30px, 3.2vw, 44px);
  line-height: 1.12;
  font-weight: 700;
}
.lead {
  margin: 0;
  color: var(--c-text-sub);
  line-height: 1.55;
  max-width: 760px;
}
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 4px;
  background: var(--c-surface);
  color: var(--c-primary);
  border: 1px solid var(--c-border);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn:disabled {
  cursor: progress;
  opacity: 0.72;
}
.btn--primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
  box-shadow: 0 8px 18px rgba(27, 77, 62, 0.16);
}
.filters {
  background: rgba(255,255,255,0.86);
  border: 1px solid var(--c-border);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px 160px;
  gap: 10px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-soft);
}
.field {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--c-text);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 13px 14px 12px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--c-primary);
}
.kpi__label {
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.3;
}
.kpi__value {
  margin-top: 6px;
  font-size: clamp(20px, 1.65vw, 24px);
  font-weight: 700;
  color: var(--c-primary);
  white-space: nowrap;
  line-height: 1.12;
}
.kpi__note {
  margin-top: 6px;
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi__value.is-warn { color: var(--c-accent); }
.kpi__value.is-bad { color: var(--c-bad); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}
.panel {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel__head {
  min-height: 66px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--c-border);
  background: linear-gradient(180deg, #fff, #FAFAF8);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.panel__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.35;
}
.panel__note {
  margin-top: 3px;
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.45;
}
.chart {
  padding: 18px 20px 22px;
  min-height: 250px;
}
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  color: var(--c-text-sub);
  font-size: 12px;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend i {
  width: 18px;
  height: 8px;
  display: inline-block;
}
.legend__invoice { background: var(--c-primary); }
.legend__paid { background: #8BC34A; }
.legend__open { background: var(--c-accent); }
.bars {
  display: grid;
  gap: 18px;
}
.bar-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 76px;
  gap: 14px;
  align-items: center;
}
.bar-row__month {
  color: var(--c-text-sub);
  font-size: 13px;
  font-weight: 700;
}
.bar-series {
  display: grid;
  gap: 5px;
}
.bar-meter {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
.bar-meter__label {
  color: var(--c-muted);
  font-size: 11px;
  line-height: 1;
}
.bar-meter__track {
  height: 9px;
  background: #F0F2F5;
  border: 1px solid var(--c-border);
  overflow: hidden;
}
.bar-meter__fill {
  display: block;
  height: 100%;
}
.bar-meter__fill--invoice { background: var(--c-primary); }
.bar-meter__fill--paid { background: #8BC34A; }
.bar-meter__fill--open { background: var(--c-accent); }
.bar-row__value {
  text-align: right;
  font-size: 13px;
  color: var(--c-text-sub);
  font-weight: 700;
}

.table-wrap { overflow: auto; max-height: calc(100vh - 430px); }
.table-wrap--ledger {
  max-height: calc(100vh - 470px);
  border-top: 1px solid var(--c-border-soft);
}
.table-note {
  padding: 10px 16px;
  border-top: 1px solid var(--c-border-soft);
  color: var(--c-muted);
  font-size: 12px;
}
table { width: 100%; border-collapse: collapse; min-width: 1080px; }
.customer-table { min-width: 1040px; }
.ledger-table {
  min-width: 1380px;
  font-size: 13px;
}
th, td {
  padding: 15px 14px;
  border-bottom: 1px solid var(--c-border-soft);
  text-align: left;
  white-space: nowrap;
  line-height: 1.4;
}
.ledger-table th,
.ledger-table td {
  padding: 10px 10px;
}
th {
  position: sticky;
  top: 0;
  background: #FAFAF8;
  z-index: 1;
  color: var(--c-muted);
  font-size: 12px;
  font-weight: 700;
}
td { vertical-align: middle; }
tr { cursor: pointer; }
tr:hover td { background: #FAFBFC; }
tr.is-selected td { background: rgba(27,77,62,0.06); }
.right { text-align: right; }
.customer {
  display: grid;
  gap: 5px;
  white-space: normal;
  min-width: 150px;
  line-height: 1.35;
}
.customer b { color: var(--c-primary); }
.customer span {
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.35;
}
.ledger-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background:
    linear-gradient(90deg, rgba(27,77,62,0.08), transparent 42%),
    #fff;
}
.ledger-head__title {
  color: var(--c-primary);
  font-weight: 700;
}
.ledger-head__note {
  color: var(--c-muted);
  font-size: 12px;
  text-align: right;
}
.ledger-customer {
  min-width: 260px;
  max-width: 340px;
  white-space: normal;
  color: var(--c-primary);
  font-weight: 700;
  line-height: 1.45;
}
.ledger-open {
  color: var(--c-accent);
  font-weight: 700;
}
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--c-border);
  background: #fff;
}
.status--回収済 { color: var(--c-good); border-color: rgba(27,77,62,0.22); background: rgba(27,77,62,0.06); }
.status--一部入金 { color: var(--c-accent); border-color: rgba(242,140,40,0.28); background: rgba(242,140,40,0.08); }
.status--未入金, .status--遅延 { color: var(--c-bad); border-color: rgba(184,57,43,0.22); background: rgba(184,57,43,0.06); }
.status--過入金, .status--要確認 { color: #6F4E00; border-color: rgba(242,140,40,0.36); background: rgba(242,140,40,0.13); }
.rate {
  height: 8px;
  border: 1px solid var(--c-border-soft);
  background: var(--c-base);
  overflow: hidden;
  min-width: 86px;
}
.rate span {
  display: block;
  height: 100%;
  background: var(--c-primary);
}
.rate__label {
  margin-top: 4px;
  color: var(--c-muted);
  font-size: 12px;
}
.risk-list {
  border-top: 1px solid var(--c-border-soft);
  padding: 12px 16px 16px;
  display: grid;
  gap: 8px;
}
.risk {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 220px) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-border-soft);
}
.risk:last-child { border-bottom: 0; }
.risk b {
  display: block;
  color: var(--c-primary);
}
.risk span {
  display: block;
  margin-top: 3px;
  color: var(--c-muted);
  font-size: 12px;
}
.risk__bar {
  height: 10px;
  background: var(--c-base);
  border: 1px solid var(--c-border-soft);
}
.risk__bar span {
  display: block;
  height: 100%;
  background: var(--c-accent);
}
.risk strong {
  color: var(--c-primary);
}

.detail {
  position: sticky;
  top: 22px;
}
.detail__body {
  padding: 18px 20px 20px;
  display: grid;
  gap: 18px;
}
.detail__name {
  font-size: 20px;
  line-height: 1.45;
  color: var(--c-primary);
  font-weight: 700;
}
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--c-border);
}
.metric {
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-border-soft);
  min-height: 68px;
}
.metric:nth-child(odd) { border-right: 1px solid var(--c-border-soft); }
.metric:nth-last-child(-n+2) { border-bottom: 0; }
.metric span {
  display: block;
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.35;
  margin-bottom: 6px;
}
.metric b {
  color: var(--c-primary);
  line-height: 1.25;
}
.payment-list {
  display: grid;
  gap: 8px;
}
.payment {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 10px;
  padding: 12px;
  background: var(--c-surface-soft);
  border: 1px solid var(--c-border-soft);
  border-radius: 6px;
  align-items: center;
  line-height: 1.4;
}
.payment span { color: var(--c-muted); font-size: 12px; }
.empty {
  padding: 28px 16px;
  color: var(--c-muted);
  text-align: center;
}
.error {
  background: #fff;
  border: 1px solid rgba(184,57,43,0.28);
  color: var(--c-bad);
  padding: 16px;
  border-radius: 8px;
  margin: 20px;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    padding: 14px 18px;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
  }
  .brand { max-width: 220px; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .side__rule, .side__meta { display: none; }
  .grid { grid-template-columns: 1fr; }
  .detail { position: static; }
}
@media (max-width: 760px) {
  .main { padding: 18px 14px 28px; }
  .topbar { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
  .filters { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi__value { font-size: 20px; }
  .side { grid-template-columns: 1fr; }
  .brand { max-width: 210px; }
  .nav { grid-template-columns: 1fr; }
  .table-wrap { max-height: none; }
  .risk { grid-template-columns: 1fr; }
}
