:root {
  --ink: #12211c;
  --muted: #5b6f68;
  --line: #d8e4de;
  --panel: #ffffff;
  --bg: #eef6f2;
  --green: #15835d;
  --blue: #1677a6;
  --gold: #b8892f;
  --red: #ca3b3b;
  --shadow: 0 14px 34px rgba(20, 54, 43, .1);
  font-family: "Noto Sans JP", "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eaf6f0 0%, #f8fbf9 52%, #eef7fb 100%);
  color: var(--ink);
  letter-spacing: 0;
  line-height: 1.48;
}

button,
input {
  font: inherit;
}

button,
.home-link {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(21, 131, 93, .18);
}

.secondary-action {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .24);
  box-shadow: none;
}

.finance-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 34px);
  background: #0f2f27;
  color: #f7fffb;
}

.finance-header h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
}

.finance-header p {
  margin: 8px 0 0;
  color: #cfe6dd;
  max-width: 860px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #69cba8;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.finance-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 14px clamp(8px, 2.4vw, 24px) 30px;
}

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

.summary-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
}

.summary-card span,
.flow-row span,
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-card strong {
  min-width: 0;
  font-size: 21px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.summary-card small {
  color: var(--muted);
  font-size: 11px;
}

.summary-card.cash {
  border-top: 4px solid var(--green);
}

.summary-card.payment {
  border-top: 4px solid var(--red);
}

.summary-card.asset {
  border-top: 4px solid var(--blue);
}

.summary-card.expense {
  border-top: 4px solid var(--gold);
}

.summary-card.debt {
  border-top: 4px solid #6f8bd6;
}

.finance-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 12px 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 8px 22px rgba(20, 54, 43, .08);
}

.tab-btn {
  flex: 0 0 auto;
  min-height: 34px;
  background: #eef6f2;
  color: var(--ink);
  box-shadow: none;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 12px;
}

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

.finance-layout.three {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(280px, .8fr);
}

.panel {
  min-width: 0;
  padding: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.22;
}

.status-pill {
  border-radius: 999px;
  background: #e9f7ef;
  color: #116948;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
}

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

.period-grid > div,
.connector-list span,
.loan-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfefd;
}

.period-grid > div {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.period-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.period-grid strong {
  font-size: 15px;
}

.period-result {
  border-color: rgba(21, 131, 93, .34);
  background: #effaf4;
}

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

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

.compact-table table {
  min-width: 420px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 6px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: #eef8f2;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

td input,
.loan-card input {
  width: 100%;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 7px;
  background: transparent;
  color: var(--ink);
}

td input:focus,
.loan-card input:focus {
  border-color: rgba(22, 119, 166, .35);
  outline: 0;
  background: #fff;
}

.progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1e9e5;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.connector-list {
  display: grid;
  gap: 7px;
}

.connector-list span {
  padding: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.loan-card {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.loan-card strong {
  font-size: 15px;
}

.loan-card label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 999px;
  background: #0f2f27;
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .summary-card.cash {
    grid-column: 1 / -1;
  }

  .finance-layout,
  .finance-layout.three,
  .loan-grid,
  .period-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .finance-header {
    padding: 12px 9px;
  }

  .finance-header p {
    display: none;
  }

  .finance-header h1 {
    font-size: 25px;
  }

  .header-actions {
    align-content: flex-start;
    gap: 5px;
  }

  .header-actions button,
  .header-actions a {
    min-height: 32px;
    padding: 6px 8px;
    border-radius: 7px;
    font-size: 11px;
  }

  .finance-shell {
    padding: 8px 7px 22px;
  }

  .summary-grid {
    gap: 7px;
  }

  .summary-card {
    padding: 9px;
  }

  .summary-card strong {
    font-size: 18px;
  }

  .finance-tabs {
    margin: 8px 0;
    padding: 5px;
  }

  .tab-btn {
    min-height: 31px;
    padding: 6px 9px;
    font-size: 12px;
  }

  .panel {
    padding: 9px;
  }

  .panel-head {
    align-items: flex-start;
    margin-bottom: 8px;
  }

  .panel-head h2 {
    font-size: 16px;
  }

  .panel-head button {
    min-height: 31px;
    padding: 6px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  .period-grid > div {
    padding: 8px;
  }

  th,
  td {
    padding: 5px;
  }

  td input,
  .loan-card input {
    min-height: 30px;
    padding: 4px 6px;
    font-size: 12px;
  }
}
