:root {
  --bg: #f6f3ed;
  --ink: #19202a;
  --muted: #68717f;
  --line: #d8d0c3;
  --panel: #fffdf8;
  --income: #176b50;
  --income-soft: #dff2ea;
  --expense: #ad3d34;
  --expense-soft: #fae3de;
  --warn: #b77612;
  --warn-soft: #fff0c9;
  --accent: #245c8f;
  --accent-soft: #dcebf7;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px;
  border-right: 1px solid var(--line);
  background: #ebe3d6;
}

.brand h1,
.toolbar h2,
.panel h2,
.ledger-section h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 28px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel h2 {
  margin-bottom: 14px;
  font-size: 16px;
}

.panel.compact p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.storage-status,
.storage-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.storage-status {
  min-height: 20px;
  margin-bottom: 10px;
  color: var(--income);
  font-weight: 700;
}

.storage-status.is-error {
  color: var(--expense);
}

.storage-note {
  margin-top: 10px;
}

.data-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.entry-form,
.field {
  display: grid;
  gap: 8px;
}

.entry-form {
  gap: 12px;
}

.entry-panel.is-editing {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.entry-panel.is-editing .form-actions {
  grid-template-columns: 1fr 1fr;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #c7bdad;
  border-radius: 6px;
  background: white;
  color: var(--ink);
}

.primary-button,
.ghost-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

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

.ghost-button {
  padding: 0 14px;
  color: var(--accent);
  background: var(--accent-soft);
}

.main {
  display: grid;
  gap: 22px;
  align-content: start;
  padding: 28px;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.toolbar h2 {
  font-size: 26px;
}

.month-heading {
  display: grid;
  gap: 8px;
}

.month-navigation {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-navigation .eyebrow {
  min-width: 150px;
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
  text-align: center;
}

.month-button {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid #9eb3c2;
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.month-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
}

.summary div {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary strong {
  font-size: 20px;
}

.calendar-wrap {
  overflow: hidden;
  border: 1px solid #9eb3c2;
  border-radius: 8px;
  background: var(--panel);
}

.weekdays,
.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
}

.weekdays span {
  padding: 10px;
  border-right: 1px solid #9eb3c2;
  background: #dfeef5;
  color: #36546b;
  font-weight: 700;
  text-align: center;
}

.weekdays span:first-child {
  background: #f3dede;
  color: #8d3c4d;
}

.weekdays span:last-child {
  border-right: 0;
}

.day {
  min-height: 142px;
  padding: 9px;
  border-top: 1px solid #9eb3c2;
  border-right: 1px solid #9eb3c2;
  background: #fffefb;
}

.day.week-end {
  border-right: 0;
}

.day.is-sunday,
.day.is-blank {
  background: #fbf6f2;
}

.day.is-sunday .date,
.day.is-blank {
  color: #8d3c4d;
}

.day.is-today {
  box-shadow: inset 0 0 0 3px var(--accent);
  background: #f1f7fb;
}

.day.is-today .date::after {
  content: "今日";
  display: inline-block;
  margin-left: 6px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  vertical-align: middle;
}

.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
}

.date {
  font-weight: 800;
}

.balance {
  padding: 3px 7px;
  border: 1px solid #a8b4bd;
  border-radius: 999px;
  color: #36546b;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.balance.low {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: #704600;
}

.events {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.event {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 6px 7px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.35;
}

.event strong {
  overflow-wrap: anywhere;
}

.event.income {
  background: var(--income-soft);
  color: var(--income);
}

.event.expense {
  background: var(--expense-soft);
  color: var(--expense);
}

.event .amount {
  font-weight: 800;
  white-space: nowrap;
}

.ledger-section {
  display: grid;
  gap: 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ledger {
  display: grid;
  gap: 8px;
}

.ledger-row {
  display: grid;
  grid-template-columns: 58px 84px minmax(160px, 1fr) 120px 96px 96px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.income {
  background: var(--income-soft);
  color: var(--income);
}

.badge.expense {
  background: var(--expense-soft);
  color: var(--expense);
}

.edit-button,
.delete-button {
  height: 34px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.edit-button {
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.delete-button {
  width: 34px;
  background: #f0ede7;
  color: var(--muted);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .weekdays,
  .calendar {
    grid-template-columns: repeat(7, minmax(104px, 1fr));
  }

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

@media (max-width: 720px) {
  .sidebar,
  .main {
    padding: 18px;
  }

  .toolbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .summary,
  .form-row {
    grid-template-columns: 1fr;
  }

  .ledger-row {
    grid-template-columns: 52px 76px 1fr;
  }

  .ledger-row .amount-cell,
  .ledger-row .balance-cell,
  .ledger-row .row-actions {
    justify-self: start;
  }
}
