:root {
  --navy: #0f2a44;
  --navy-2: #173c5f;
  --blue: #2f6fed;
  --green: #1f9d68;
  --orange: #e88b21;
  --red: #d44b4b;
  --bg: #eef3f7;
  --panel: #ffffff;
  --line: #dbe5ef;
  --text: #132238;
  --muted: #66768a;
  --shadow: 0 12px 28px rgba(15, 42, 68, 0.12);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Arial, sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, #0f2a44 0, #0f2a44 178px, var(--bg) 178px);
}

button, input, select {
  font: inherit;
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px 30px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 38px auto 38px;
  gap: 8px;
  align-items: center;
  color: #fff;
  padding: 4px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #8fc7ff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 25px;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
}

.icon-button,
.month-pill,
.primary-button,
.button-row button,
.file-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  font-size: 27px;
  line-height: 1;
}

.month-pill {
  height: 38px;
  border-radius: 999px;
  padding: 0 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.17);
  font-weight: 800;
  white-space: nowrap;
}

main {
  display: grid;
  gap: 14px;
}

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

.metric {
  min-height: 116px;
  padding: 16px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border: 1px solid rgba(219, 229, 239, 0.75);
}

.metric.primary {
  grid-column: 1 / -1;
  min-height: 132px;
  color: #fff;
  background: linear-gradient(135deg, #1f6feb, #1f9d68);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric.primary span,
.metric.primary small {
  color: rgba(255, 255, 255, 0.82);
}

.metric strong {
  display: block;
  margin-top: 9px;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.metric.primary strong {
  font-size: 36px;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.panel {
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border: 1px solid rgba(219, 229, 239, 0.85);
  padding: 16px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.section-heading p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: right;
}

form {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: #edf3f8;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 900;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  font-size: 16px;
}

input:focus, select:focus {
  outline: 2px solid rgba(47, 111, 237, 0.25);
  border-color: var(--blue);
}

.primary-button {
  height: 48px;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  font-size: 16px;
  font-weight: 900;
}

.category-list,
.entry-list {
  display: grid;
  gap: 9px;
}

.category-item {
  display: grid;
  gap: 7px;
}

.category-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  font-weight: 900;
}

.bar {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: #edf3f8;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
}

.entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.entry-title {
  font-weight: 900;
  font-size: 14px;
}

.entry-meta {
  color: var(--muted);
  font-size: 12px;
}

.entry-amount {
  text-align: right;
  font-weight: 900;
}

.entry-amount.income { color: var(--green); }
.entry-amount.expense { color: var(--red); }

.delete-button {
  grid-column: 2;
  justify-self: end;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: #eef3f7;
  padding: 5px 8px;
  font-size: 12px;
}

details summary {
  cursor: pointer;
  font-weight: 900;
}

.setup-note {
  margin-top: 12px;
  padding: 11px 12px;
  border-radius: 6px;
  color: #24415f;
  background: #eef6ff;
  border: 1px solid #cfe2f6;
  font-size: 12px;
  line-height: 1.55;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.button-row button,
.file-button {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 40px;
  border-radius: 6px;
  color: var(--navy);
  background: #edf3f8;
  font-size: 13px;
  font-weight: 900;
}

.file-button input {
  display: none;
}

.backup-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  background: #f6f9fc;
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.45;
}

.backup-status strong {
  color: var(--text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  width: calc(100vw - 28px);
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(15, 42, 68, 0.94);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  font-size: 13px;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty {
  padding: 16px;
  border-radius: 8px;
  color: var(--muted);
  background: #f6f9fc;
  text-align: center;
  font-size: 13px;
}

@media (max-width: 420px) {
  .summary-grid,
  .field-row,
  .settings-grid,
  .button-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: 1fr 34px auto 34px;
  }

  .metric.primary strong {
    font-size: 32px;
  }
}
