:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #edf3ee;
  --ink: #1c2520;
  --muted: #66706a;
  --line: #d9dfd8;
  --green: #1f7a56;
  --green-dark: #155b40;
  --gold: #b7791f;
  --red: #c93535;
  --red-soft: #fff0ef;
  --shadow: 0 18px 40px rgba(31, 51, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-header,
.section-heading,
.month-switcher,
.history-item,
.history-actions,
.bottom-nav {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 38px);
}

h2 {
  font-size: 20px;
}

.month-switcher {
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.icon-button,
.month-button,
.text-button,
.ghost-button,
.submit-button {
  border: 0;
  border-radius: 8px;
}

.icon-button {
  width: 38px;
  height: 38px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}

.month-button {
  min-width: 132px;
  height: 38px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

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

.summary-card {
  min-height: 118px;
  padding: 20px;
}

.summary-card span,
.dialog-summary span,
label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(26px, 4vw, 38px);
}

.summary-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.summary-card.primary {
  background: var(--green-dark);
  color: white;
}

.summary-card.primary span,
.summary-card.primary small {
  color: rgba(255, 255, 255, 0.78);
}

.summary-card.over {
  background: var(--red);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
}

.section-heading {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.carryover-setting {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin: -2px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.carryover-setting label {
  width: 180px;
  flex-shrink: 0;
}

.carryover-setting p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.text-button,
.ghost-button {
  padding: 10px 14px;
  color: var(--green-dark);
  background: var(--surface-soft);
  font-weight: 700;
}

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

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

tr[data-category] {
  cursor: pointer;
}

tr[data-category]:hover {
  background: #f8faf8;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-width: 70px;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.over,
.amount-over {
  color: var(--red);
}

.status-pill.over {
  background: var(--red-soft);
}

.mobile-card-list {
  display: none;
}

.expense-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}

input:focus,
select:focus {
  outline: 3px solid rgba(31, 122, 86, 0.18);
  border-color: var(--green);
}

.submit-button {
  min-height: 48px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

.quick-categories {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.quick-categories button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.history-panel {
  margin-top: 16px;
}

.history-count {
  color: var(--muted);
  font-weight: 700;
}

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

.history-item {
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-main {
  min-width: 0;
}

.history-main strong,
.history-main span {
  display: inline-block;
  margin-right: 8px;
}

.history-main p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.history-actions {
  gap: 6px;
  flex-shrink: 0;
}

.history-actions button {
  min-width: 54px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 700;
}

.history-actions .delete-button {
  color: var(--red);
  background: var(--red-soft);
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none;
}

.bottom-nav {
  position: fixed;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 10;
  display: none;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.bottom-nav a,
.bottom-nav button {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface-soft);
  font-weight: 800;
  text-decoration: none;
}

.bottom-nav button {
  background: var(--green);
  color: #fff;
}

.category-dialog {
  width: min(720px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

.category-dialog::backdrop {
  background: rgba(23, 33, 28, 0.45);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.dialog-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.dialog-summary div {
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.dialog-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

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

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .month-switcher {
    justify-content: space-between;
  }

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

  .summary-card {
    min-height: 98px;
  }

  .desktop-table {
    display: none;
  }

  .mobile-card-list {
    display: grid;
    gap: 10px;
  }

  .carryover-setting {
    align-items: stretch;
    flex-direction: column;
  }

  .carryover-setting label {
    width: 100%;
  }

  .budget-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .budget-card-header,
  .budget-card-values {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .budget-card-header strong {
    font-size: 17px;
  }

  .budget-card-values span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .budget-card-values strong {
    display: block;
    margin-top: 3px;
  }

  .form-panel {
    scroll-margin-top: 12px;
  }

  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .history-actions {
    justify-content: flex-end;
  }

  .bottom-nav {
    display: grid;
  }
}

@media (max-width: 520px) {
  .summary-grid {
    gap: 10px;
  }

  .summary-card {
    padding: 16px;
  }

  .panel {
    padding: 14px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .text-button {
    padding: 9px 11px;
  }

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