:root {
  --bg: #f6f3ed;
  --ink: #19202a;
  --muted: #68717f;
  --line: #d8d0c3;
  --panel: #fffdf8;
  --income: #176b50;
  --income-soft: #dff2ea;
  --expense: #245c8f;
  --expense-soft: #e3effa;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --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-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.app-header {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 16px;
  text-align: center;
}

.app-header .brand {
  grid-column: 1;
  min-width: 0;
  text-align: left;
}

.overview-controls {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
  text-align: left;
}

.app-actions .summary {
  flex: 0 0 360px;
  max-width: none;
  margin-left: auto;
}

.app-header .app-actions {
  grid-column: 3;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start;
}

.app-actions {
  justify-content: flex-end;
  gap: 8px;
}

.app-actions .primary-button,
.app-actions .ghost-button {
  flex-shrink: 0;
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

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

.brand h1 {
  overflow-wrap: anywhere;
  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(--danger);
}

.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;
}

.app-dialog {
  width: min(440px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow-y: auto;
  color: var(--ink);
  box-shadow: 0 12px 36px rgb(25 32 42 / 24%);
}

.app-dialog::backdrop {
  background: rgb(25 32 42 / 48%);
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.help-section {
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.8;
}

.help-section summary {
  cursor: pointer;
  font-weight: 700;
}

.help-section p {
  margin: 8px 0 0;
}

.delete-details {
  overflow-wrap: anywhere;
}

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

.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;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  align-content: start;
  padding: 28px;
  padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px));
}

.add-entry-fab {
  position: fixed;
  right: calc(24px + env(safe-area-inset-right, 0px));
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgb(25 32 42 / 28%);
  cursor: pointer;
}

.add-entry-fab span {
  font-size: 34px;
  line-height: 1;
}

.add-entry-fab:hover {
  filter: brightness(1.1);
}

.add-entry-fab:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 4px;
}

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

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

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

.period-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.unit-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.unit-control legend {
  float: left;
  padding: 0;
  margin-right: 10px;
  color: var(--muted);
  font-size: 13px;
}

.label-limit-control legend {
  float: none;
  margin: 0 0 6px;
}

.unit-options {
  display: inline-grid;
  grid-template-columns: repeat(2, 64px);
}

.unit-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
}

.unit-options label {
  padding: 7px 10px;
  border: 1px solid #9eb3c2;
  background: var(--panel);
  text-align: center;
  font-size: 13px;
  cursor: pointer;
}

.unit-options input:checked + label {
  background: var(--accent);
  color: white;
}

.unit-options input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.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(0, 1fr));
  width: 360px;
  max-width: 100%;
  justify-self: start;
  gap: 6px;
  min-width: 0;
  text-align: left;
}

.summary div {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  line-height: 1.3;
  background: var(--panel);
}

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

.summary strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.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.is-sunday {
  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: var(--ink);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.balance.low,
.balance-cell.low,
.summary-balance.low {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: #854600;
}

.balance.negative,
.balance-cell.negative,
.summary-balance.negative {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: inset 0 0 0 2px var(--danger);
}

.balance.negative {
  border-color: var(--danger);
}

.balance-cell,
.summary-balance {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 5px;
  overflow-wrap: anywhere;
}

.summary-balance {
  display: block;
}

.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;
}

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

.unit-yen .weekdays,
.unit-yen .calendar {
  grid-template-columns: repeat(7, minmax(160px, 1fr));
  min-width: 1120px;
}

.unit-yen .date-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.unit-yen .balance {
  justify-self: end;
  max-width: 100%;
  text-align: right;
}

.unit-yen .event {
  grid-template-columns: minmax(0, 1fr) fit-content(65%);
}

.unit-yen .event .amount {
  text-align: right;
}

.unit-yen .event .amount,
.unit-yen .balance {
  white-space: normal;
  overflow-wrap: anywhere;
}

.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 160px 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;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

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

.edit-button {
  background: var(--accent-soft);
  color: var(--accent);
}

.delete-button {
  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) {
  .weekdays,
  .calendar {
    grid-template-columns: repeat(7, minmax(104px, 1fr));
  }

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

@media (max-width: 720px) {
  .app-header {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-header .brand,
  .app-header .overview-controls,
  .app-header .app-actions {
    grid-column: 1;
  }

  .main {
    padding: 18px;
    padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px));
  }

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

  .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;
  }

  .ledger-row .balance-cell {
    grid-column: 2 / -1;
    justify-self: stretch;
    min-width: 0;
  }
}
