:root {
  color-scheme: light;
  --ink: #10202b;
  --muted: #586979;
  --line: #c7d3dc;
  --page: #eef4f6;
  --panel: #ffffff;
  --panel-tint: #f7fafb;
  --consume: #155ca8;
  --consume-soft: #e2effb;
  --waste: #b93632;
  --waste-soft: #fbe6e4;
  --invest: #1f7a52;
  --invest-soft: #e2f4ea;
  --accent: #0f5560;
  --accent-soft: #e4f1f3;
  --accent-hover: #0a3e47;
  font-family:
    "Hiragino Sans", "Yu Gothic", "YuGothic", "Noto Sans JP", system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #dbe9ed 0, rgba(219, 233, 237, 0) 420px),
    linear-gradient(120deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0)),
    var(--page);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.summary-band {
  display: block;
  padding: 28px 0 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.15rem, 5vw, 4.2rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.lead {
  max-width: 36rem;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.8;
}

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

.metric {
  min-height: 106px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 28px rgba(18, 42, 56, 0.1);
}

.metric span {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.05;
}

.metric.consume {
  border-color: #97bee5;
  background: var(--consume-soft);
}

.metric.waste {
  border-color: #e3a29c;
  background: var(--waste-soft);
}

.metric.invest {
  border-color: #9cd3b8;
  background: var(--invest-soft);
}

.workspace,
.bottom-summary,
.insight-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(18, 42, 56, 0.12);
}

.bottom-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 14px;
  align-items: stretch;
  margin-top: 18px;
  padding: 16px;
}

.bottom-summary .summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.bottom-summary-actions {
  display: flex;
  align-items: stretch;
}

.bottom-summary-actions .button {
  width: 100%;
  justify-content: center;
}

.toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.toolbar-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.usage-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 14px 20px 16px 38px;
  border-bottom: 1px solid var(--line);
  color: #3f5060;
  font-size: 0.92rem;
  line-height: 1.6;
  background: var(--accent-soft);
}

.usage-list li::marker {
  color: var(--accent);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #aebcc7;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button:hover {
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-hover);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  color: #263846;
  font-size: 0.84rem;
  white-space: nowrap;
  background: #e8f0f3;
}

.expense-row {
  background: #ffffff;
}

.expense-row:hover {
  background: #f5f9fb;
}

th:nth-child(1) {
  width: 15%;
}

th:nth-child(2) {
  width: 20%;
}

th:nth-child(3) {
  width: 13%;
}

th:nth-child(4) {
  width: 24%;
}

th:nth-child(5) {
  width: 16%;
}

.action-heading {
  width: 150px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfd9e2;
  border-radius: 8px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--ink);
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 85, 96, 0.18);
}

input[readonly] {
  background: #edf4f6;
  color: #334653;
}

.amount-field {
  display: flex;
  align-items: center;
  min-width: 130px;
}

.amount-field span {
  margin-right: 6px;
  color: var(--muted);
  font-weight: 700;
}

.amount-input {
  text-align: right;
}

.rating-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(62px, 1fr));
  gap: 6px;
}

.rating {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid #b9c6d0;
  border-radius: 8px;
  background: #fff;
  color: #3f4f5d;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.rating input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.rating:has(input:checked).consume {
  border-color: #6da9df;
  background: var(--consume-soft);
  color: var(--consume);
}

.rating:has(input:checked).waste {
  border-color: #dc8780;
  background: var(--waste-soft);
  color: var(--waste);
}

.rating:has(input:checked).invest {
  border-color: #7ec79f;
  background: var(--invest-soft);
  color: var(--invest);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid #b9c6d0;
  border-radius: 8px;
  background: #fff;
  color: #536474;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--waste);
  color: var(--waste);
}

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.subitem-button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #9ebac2;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.subitem-button:hover {
  border-color: var(--accent);
}

.point-row td {
  padding: 0 12px 10px;
  background: var(--panel-tint);
}

.point-shell {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid #d4e0e6;
  border-radius: 8px;
  background: #ffffff;
}

.point-shell span {
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.point-text {
  margin: 0;
  color: #43505d;
  font-size: 0.92rem;
  line-height: 1.7;
}

.subitems-row td {
  padding: 0 12px 14px;
  background: var(--panel-tint);
}

.subitems-shell {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid #d4e0e6;
  border-radius: 8px;
  background: #fff;
}

.subitems-title {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  padding-top: 10px;
}

.subitems-list {
  display: grid;
  gap: 8px;
}

.subitem {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(130px, 180px) 36px;
  gap: 8px;
  align-items: center;
}

.subitem-amount-field {
  min-width: 0;
}

.insights {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.insight-panel {
  padding: 18px 20px;
}

.bar-track {
  display: flex;
  overflow: hidden;
  height: 18px;
  margin: 18px 0 12px;
  border-radius: 8px;
  background: #d9e3e9;
}

.bar {
  width: 0;
  transition: width 180ms ease;
}

.bar.consume {
  background: var(--consume);
}

.bar.waste {
  background: var(--waste);
}

.bar.invest {
  background: var(--invest);
}

#balanceText {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.review-list {
  display: grid;
  gap: 8px;
  min-height: 92px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.review-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: #34414e;
}

.review-list span:last-child {
  color: var(--waste);
  font-weight: 800;
  white-space: nowrap;
}

.print-report {
  display: none;
}

@media (max-width: 900px) {
  .summary-band,
  .bottom-summary,
  .insights {
    grid-template-columns: 1fr;
  }

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

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

  .metric {
    min-height: 92px;
  }

  table {
    min-width: 1040px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  .summary-band {
    padding-top: 14px;
  }

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

  .bottom-summary {
    padding: 12px;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .usage-list {
    padding: 12px 14px 14px 30px;
  }

  .toolbar-actions,
  .button {
    width: 100%;
  }

  .button {
    justify-content: center;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tr {
    padding: 14px;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 6rem minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
  }

  td[data-label="操作"] {
    grid-template-columns: 1fr;
  }

  td[data-label="操作"]::before {
    display: none;
  }

  .icon-button {
    width: 100%;
  }

  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .subitem-button {
    width: 100%;
  }

  .subitems-row {
    padding-top: 0;
  }

  .point-row {
    padding-top: 0;
  }

  .point-row td,
  .subitems-row td {
    display: block;
    padding: 0;
  }

  .point-row td::before,
  .subitems-row td::before {
    display: none;
  }

  .point-shell {
    grid-template-columns: 1fr;
    gap: 4px;
    margin-top: -4px;
  }

  .subitems-shell {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: -4px;
  }

  .subitems-title {
    padding-top: 0;
  }

  .subitem {
    grid-template-columns: 1fr;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .rating-control {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 4mm;
  }

  html,
  #root,
  body {
    width: 297mm !important;
    height: 210mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #eef4f6;
    color: #10202b;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  * {
    box-sizing: border-box;
    break-before: avoid !important;
    break-after: avoid !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
  }

  body {
    position: relative;
  }

  body * {
    visibility: hidden;
  }

  .print-page {
    box-sizing: border-box;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 289mm !important;
    height: 202mm !important;
    max-height: 202mm !important;
    max-width: none;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    transform: none !important;
    transform-origin: top left;
    visibility: visible;
    zoom: 0.72;
    break-before: avoid !important;
    break-after: avoid !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
  }

  .print-page * {
    box-sizing: border-box;
    visibility: visible;
  }

  .print-page::after {
    display: none !important;
  }

  .print-report {
    display: none !important;
  }

  .summary-band {
    padding: 0 0 2px;
  }

  h1 {
    margin-bottom: 1px;
    font-size: 17px;
  }

  h2 {
    font-size: 8px;
  }

  .eyebrow,
  .lead,
  .usage-list,
  .toolbar-actions,
  .row-actions,
  .bottom-summary-actions,
  button,
  .no-print {
    display: none !important;
  }

  .workspace,
  .bottom-summary,
  .insight-panel {
    box-shadow: none;
  }

  .toolbar {
    padding: 3px 5px;
  }

  .toolbar-title p {
    margin-top: 1px;
    font-size: 6px;
  }

  table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    font-size: 5px;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  tr,
  td,
  th {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  th,
  td {
    padding: 1px 1.5px;
  }

  th:nth-child(1) {
    width: 12%;
  }

  th:nth-child(2) {
    width: 22%;
  }

  th:nth-child(3) {
    width: 10%;
  }

  th:nth-child(4) {
    width: 20%;
  }

  th:nth-child(5) {
    width: 36%;
  }

  .action-heading,
  td[data-label="操作"] {
    display: none;
  }

  .table-wrap {
    overflow: visible;
  }

  .print-page input,
  .print-page select,
  .print-page textarea,
  input[type="text"],
  input[type="number"] {
    height: 12px !important;
    min-height: 12px !important;
    padding: 1px 2px !important;
    border-color: #c7d3dc;
    border-radius: 3px;
    font-size: 7px !important;
  }

  .amount-field {
    min-width: 0;
  }

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

  .rating {
    min-height: 13px;
    border-radius: 3px;
    font-size: 4.6px;
  }

  .point-row td,
  .subitems-row td {
    padding: 0 1.5px 1px;
  }

  .point-shell,
  .subitems-shell {
    gap: 1.5px;
    padding: 1.5px 2px;
    border-radius: 3px;
  }

  .point-shell {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .subitems-shell {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .point-shell span,
  .subitems-title,
  .point-text {
    font-size: 4.7px;
    line-height: 1.02;
  }

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

  .subitem {
    grid-template-columns: minmax(0, 1fr) 40px 0;
    gap: 1px;
  }

  .delete-subitem {
    display: none;
  }

  .insights,
  .bottom-summary {
    gap: 2px;
    margin-top: 2px;
  }

  .insight-panel,
  .bottom-summary {
    padding: 3px;
  }

  .bar-track {
    height: 4px;
    margin: 2px 0 1px;
  }

  #balanceText,
  .review-list,
  .review-list li {
    font-size: 4.8px;
    line-height: 1.02;
  }

  .review-list {
    min-height: 0;
    margin-top: 2px;
  }

  .review-list li {
    padding: 1px 0;
  }

  .bottom-summary {
    grid-template-columns: 1fr;
  }

  .bottom-summary .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric {
    min-height: 20px;
    padding: 2px 3px;
    border-radius: 3px;
    box-shadow: none;
  }

  .metric span {
    margin-bottom: 1px;
    font-size: 4.8px;
  }

  .metric strong {
    font-size: 7px;
  }
}
