:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #f0f7f4;
  --ink: #16211d;
  --muted: #66736e;
  --line: #dfe5df;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --income: #087f5b;
  --expense: #c2410c;
  --shadow: 0 18px 50px rgba(28, 45, 39, 0.12);
  font-family: "Yu Gothic", "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.13), transparent 38%),
    linear-gradient(315deg, rgba(59, 130, 246, 0.08), transparent 35%),
    var(--bg);
  color: var(--ink);
}

body.aco-theme {
  --bg: #fff1f6;
  --surface-strong: #ffe4ee;
  --accent: #db2777;
  --accent-dark: #be185d;
  background:
    linear-gradient(135deg, rgba(219, 39, 119, 0.18), transparent 38%),
    linear-gradient(315deg, rgba(244, 114, 182, 0.12), transparent 35%),
    var(--bg);
}

body.nao-theme {
  --bg: #eef6ff;
  --surface-strong: #dbeafe;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.18), transparent 38%),
    linear-gradient(315deg, rgba(56, 189, 248, 0.12), transparent 35%),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.auth-view {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  gap: 32px;
  align-items: center;
}

.brand-block h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(34px, 6vw, 72px);
  line-height: 1.02;
}

.lead {
  max-width: 560px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.8;
}

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

.auth-panel,
.entry-panel,
.insights-panel,
.history-panel,
.chart-panel,
.metric,
.person-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 28px;
}

h2 {
  margin: 0;
  font-size: 22px;
}

.auth-panel p,
.setup-card p,
.muted {
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 8px;
  color: #26352f;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

textarea {
  resize: vertical;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 78px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  min-width: 58px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef5f2;
  color: var(--accent-dark);
  font-weight: 800;
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.segmented label {
  display: block;
  font-weight: 800;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--accent);
  color: #fff;
}

.primary-button,
.ghost-button,
.icon-button,
.text-button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 12px 16px;
}

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

.ghost-button,
.icon-button {
  background: #eef5f2;
  color: var(--accent-dark);
  padding: 10px 14px;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 22px;
}

.text-button {
  width: 100%;
  margin-top: 14px;
  background: transparent;
  color: var(--accent-dark);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.form-message {
  min-height: 22px;
  margin: 16px 0 0;
  font-weight: 700;
}

.edit-status {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  font-weight: 900;
}

.wallet-view {
  display: grid;
  gap: 20px;
}

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

.topbar h1 {
  font-size: clamp(32px, 5vw, 56px);
}

.topbar-actions,
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 900;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

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

.metric {
  padding: 18px;
  box-shadow: none;
}

.metric span,
.person-card span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.1;
}

.balance-metric {
  background: var(--surface-strong);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.entry-panel,
.insights-panel,
.history-panel,
.chart-panel {
  padding: 20px;
}

.chart-panel {
  box-shadow: none;
}

.money-chart {
  margin-top: 16px;
  min-height: 240px;
  overflow: hidden;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 220px;
}

.chart-axis {
  stroke: #ccd8d2;
  stroke-width: 1.5;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.chart-dot {
  fill: #fff;
  stroke: var(--accent-dark);
  stroke-width: 3;
}

.chart-label {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chart-empty {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed #bac7c1;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

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

.person-card {
  box-shadow: none;
  padding: 18px;
}

.person-card strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

dl {
  display: grid;
  gap: 8px;
  margin: 18px 0 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 900;
}

.history-panel {
  box-shadow: none;
}

.transaction-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.transaction-item {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.transaction-date {
  color: var(--muted);
  font-weight: 800;
}

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

.transaction-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 900;
}

.transaction-memo {
  margin-top: 5px;
  color: var(--muted);
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf2f0;
  color: #41504a;
  font-size: 12px;
  font-weight: 900;
}

.transaction-amount {
  text-align: right;
  font-size: 20px;
  font-weight: 950;
}

.transaction-amount.income {
  color: var(--income);
}

.transaction-amount.expense {
  color: var(--expense);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.small-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 10px;
  color: var(--ink);
  font-weight: 800;
}

.small-button.danger {
  color: var(--expense);
}

.empty-state {
  margin-top: 18px;
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 170px;
  border: 1px dashed #bac7c1;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

@media (max-width: 860px) {
  .auth-view,
  .workspace-grid,
  .summary-grid,
  .person-grid {
    grid-template-columns: 1fr;
  }

  .auth-view {
    align-items: start;
    padding-top: 24px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .filter-row {
    width: 100%;
  }

  .filter-row select {
    flex: 1 1 130px;
  }

  .transaction-item {
    grid-template-columns: 1fr;
  }

  .transaction-amount {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 16px, 1180px);
    padding-top: 12px;
    padding-bottom: 28px;
  }

  .auth-view {
    min-height: auto;
    gap: 18px;
    padding-top: 10px;
  }

  .brand-block h1 {
    font-size: 38px;
  }

  .lead {
    margin-top: 12px;
    font-size: 15px;
    line-height: 1.6;
  }

  .auth-panel,
  .entry-panel,
  .insights-panel,
  .history-panel,
  .chart-panel,
  .metric,
  .person-card {
    padding: 16px;
  }

  .wallet-view {
    gap: 14px;
  }

  .topbar h1 {
    font-size: 32px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .user-pill,
  .sync-status,
  .ghost-button {
    flex: 1 1 auto;
    justify-content: center;
  }

  .summary-grid {
    gap: 8px;
  }

  .money-chart {
    min-height: 190px;
  }

  .chart-svg {
    min-height: 180px;
  }

  .chart-label {
    font-size: 15px;
  }

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

  .metric strong {
    margin-top: 0;
    font-size: 24px;
    text-align: right;
  }

  .person-grid {
    gap: 10px;
  }

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

  .entry-panel .section-heading {
    flex-direction: row;
    align-items: center;
  }
}
