/* 용돈기입장 — mobile first */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #191f28;
  --text-strong: #0b1016;
  --muted: #8b95a1;
  --muted-2: #b0b8c1;
  --line: #e8eaee;
  --accent: #3182f6;
  --accent-2: #1b64da;
  --accent-soft: #e8f1ff;
  --expense: #f04452;
  --expense-soft: #ffeaec;
  --income: #3182f6;
  --income-soft: #e8f1ff;
  --danger: #f04452;
  --card-shadow: 0 1px 2px rgba(16, 24, 40, 0.03), 0 10px 30px rgba(16, 24, 40, 0.05);
  --radius: 22px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #191c22;
    --surface-2: #21252d;
    --text: #e8ebef;
    --text-strong: #ffffff;
    --muted: #8f98a3;
    --muted-2: #636b76;
    --line: #272b33;
    --accent: #4b8ef8;
    --accent-2: #6aa2ff;
    --accent-soft: #1c2a42;
    --expense: #ff6571;
    --expense-soft: #3a2024;
    --income: #5b97ff;
    --income-soft: #1c2a42;
    --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ */
/* 스플래시                                                            */
/* ------------------------------------------------------------------ */

.splash {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity 0.25s ease;
}

.splash img {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(49, 130, 246, 0.28);
  animation: pulse 1.2s ease-in-out infinite;
}

.splash.fade {
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* 로그인                                                              */
/* ------------------------------------------------------------------ */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(49, 130, 246, 0.16), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.login-logo {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  box-shadow: 0 12px 30px rgba(49, 130, 246, 0.28);
}

.login-card h1 {
  margin: 18px 0 4px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text-strong);
}

.login-sub {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 15px;
}

.pin-field {
  position: relative;
  margin-bottom: 10px;
}

.pin-field input {
  width: 100%;
  height: 58px;
  padding: 0 66px 0 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  font-size: 22px;
  letter-spacing: 0.35em;
  text-align: center;
  outline: none;
  box-shadow: var(--card-shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pin-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.pin-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.login-error {
  min-height: 20px;
  margin: 4px 0 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.shake {
  animation: shake 0.35s;
}

.login-foot {
  margin: 26px 0 0;
  color: var(--muted-2);
  font-size: 12px;
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------------ */
/* 공통 버튼 / 입력                                                     */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 50px;
  padding: 0 20px;
  border-radius: 15px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.975);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(49, 130, 246, 0.22);
}

.btn-primary:active {
  background: var(--accent-2);
}

.btn-block {
  width: 100%;
}

.btn-grow {
  flex: 1;
}

.btn-sm {
  height: 44px;
  padding: 0 16px;
  border-radius: 13px;
  font-size: 14px;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}

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

.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.text-input {
  width: 100%;
  height: 50px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* iOS 자동 확대 방지 */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.text-input::placeholder {
  color: var(--muted-2);
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="date"].text-input {
  min-width: 0;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.inline-form .text-input {
  flex: 1;
  min-width: 0;
}

.inline-form.compact {
  margin-top: 8px;
}

.stack-form {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.card {
  margin-bottom: 14px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.card-desc {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.card-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.card-note code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  font-size: 11px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot.income {
  background: var(--income);
}

.dot.expense {
  background: var(--expense);
}

/* ------------------------------------------------------------------ */
/* 앱 레이아웃                                                         */
/* ------------------------------------------------------------------ */

.app {
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 40px);
}

@media (min-width: 560px) {
  body {
    background: #e9ebef;
  }
  @media (prefers-color-scheme: dark) {
    body {
      background: #08090b;
    }
  }
  .app {
    background: var(--bg);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 30px 80px rgba(15, 23, 42, 0.12);
    min-height: 100dvh;
  }
}

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(10px + var(--safe-top)) 20px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
}

@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .header {
    background: var(--bg);
  }
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: linear-gradient(135deg, #4b8ef8, #1b64da);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

.month-btn {
  width: 42px;
  height: 38px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  font-weight: 500;
}

.month-btn:active {
  background: var(--surface-2);
}

.month-label {
  min-width: 148px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text-strong);
}

.main {
  padding: 4px 16px 0;
}

/* ------------------------------------------------------------------ */
/* 요약 카드                                                           */
/* ------------------------------------------------------------------ */

.summary {
  position: relative;
  overflow: hidden;
  margin: 4px 0 16px;
  padding: 24px 22px 20px;
  border-radius: 26px;
  background:
    radial-gradient(90% 120% at 100% 0%, rgba(75, 142, 248, 0.5), transparent 55%),
    linear-gradient(145deg, #232b36, #11151b 70%);
  color: #fff;
  box-shadow: 0 20px 40px rgba(17, 24, 39, 0.24);
}

@media (prefers-color-scheme: dark) {
  .summary {
    background:
      radial-gradient(90% 120% at 100% 0%, rgba(75, 142, 248, 0.4), transparent 55%),
      linear-gradient(145deg, #1d222b, #0d1015 70%);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  }
}

.summary-glow {
  position: absolute;
  top: -70px;
  right: -50px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(84, 152, 255, 0.5), transparent 65%);
  filter: blur(6px);
  pointer-events: none;
}

.summary-caption {
  position: relative;
  margin: 0;
  color: rgba(255, 255, 255, 0.62);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.summary-balance {
  position: relative;
  margin: 5px 0 20px;
  font-size: clamp(30px, 9vw, 38px);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.summary-balance.negative {
  color: #ff9ba3;
}

.summary-split {
  position: relative;
  display: flex;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.summary-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.summary-key {
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
}

.summary-item strong {
  margin-left: auto;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.budget {
  position: relative;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.budget-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.budget-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.budget-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #69a5ff, #a8c8ff);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.budget-track i.over {
  background: linear-gradient(90deg, #ff8a93, #ff5c68);
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 13px 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.banner span {
  flex: 1;
}

.banner button {
  flex: none;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

@media (prefers-color-scheme: dark) {
  .banner {
    color: #9ec3ff;
  }
}

/* ------------------------------------------------------------------ */
/* 내역                                                                */
/* ------------------------------------------------------------------ */

.view {
  animation: fade 0.25s ease;
}

.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 4px 10px;
}

.view-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text-strong);
}

.count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.day-group {
  margin-bottom: 12px;
  padding: 6px 6px 4px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.day-head .day-net {
  font-variant-numeric: tabular-nums;
}

.day-net.income {
  color: var(--income);
}

.day-net.expense {
  color: var(--expense);
}

.entry {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  text-align: left;
  transition: background 0.12s;
}

.entry:active {
  background: var(--surface-2);
}

.entry-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 20px;
}

.entry-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.entry-memo {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.entry-amount {
  flex: none;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

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

.empty {
  padding: 54px 20px 40px;
  text-align: center;
}

.empty-emoji {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 14px;
  filter: saturate(0.9);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.empty-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* ------------------------------------------------------------------ */
/* 통계                                                                */
/* ------------------------------------------------------------------ */

.stats-hero {
  margin-bottom: 14px;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

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

.stats-amount {
  margin: 4px 0 16px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.045em;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.stats-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.stats-meta div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stats-meta span {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.stats-meta strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.panel {
  margin-bottom: 14px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.panel-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.cat-row {
  margin-bottom: 14px;
}

.cat-row:last-child {
  margin-bottom: 0;
}

.cat-row-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 7px;
  font-size: 13px;
}

.cat-row-name {
  font-weight: 600;
  color: var(--text);
}

.cat-row-pct {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.cat-row-amount {
  margin-left: auto;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.cat-track {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}

.cat-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.mini-empty {
  padding: 18px 0 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.trend {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 132px;
  padding-top: 18px;
}

.trend-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex: 1;
  height: 100%;
  min-width: 0;
}

.trend-bar-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.trend-bar {
  width: 100%;
  max-width: 30px;
  min-height: 3px;
  border-radius: 7px 7px 4px 4px;
  background: var(--accent-soft);
  transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.trend-col.current .trend-bar {
  background: linear-gradient(180deg, #6aa2ff, #3182f6);
}

.trend-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.trend-col.current .trend-label {
  color: var(--accent);
  font-weight: 800;
}

/* ------------------------------------------------------------------ */
/* 설정                                                                */
/* ------------------------------------------------------------------ */

.cat-editor {
  margin-top: 4px;
}

.cat-group {
  margin-top: 18px;
}

.cat-group h4 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.chip:active {
  background: var(--surface-2);
}

.chip.selected {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.chip .remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  margin-right: -3px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}

.link-list {
  margin-top: 12px;
  border-radius: 15px;
  background: var(--surface-2);
  overflow: hidden;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}

.link-row:last-child {
  border-bottom: 0;
}

.link-row:active {
  background: var(--line);
}

.link-row > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.link-row strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.link-row small {
  color: var(--muted);
  font-size: 11.5px;
}

.chev {
  color: var(--muted-2);
  font-size: 20px;
}

.info-list {
  margin: 12px 0 0;
}

.info-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.info-list div:last-child {
  border-bottom: 0;
}

.info-list dt {
  color: var(--muted);
  flex: none;
}

.info-list dd {
  margin: 0;
  text-align: right;
  color: var(--text);
}

.footer-note {
  margin: 22px 0 4px;
  color: var(--muted-2);
  font-size: 11px;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* 탭바 / FAB                                                          */
/* ------------------------------------------------------------------ */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  max-width: 520px;
  margin: 0 auto;
  padding: 6px 12px calc(6px + var(--safe-bottom));
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .tabbar {
    background: var(--surface);
  }
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: 50px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  transition: color 0.15s;
}

.tab.active {
  color: var(--accent);
}

.tab:active {
  background: var(--surface-2);
}

.fab {
  position: fixed;
  z-index: 31;
  right: max(18px, calc((100vw - 520px) / 2 + 18px));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(145deg, #4b8ef8, #1b64da);
  color: #fff;
  box-shadow: 0 12px 26px rgba(27, 100, 218, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 6px 16px rgba(27, 100, 218, 0.35);
}

/* ------------------------------------------------------------------ */
/* 입력 시트                                                           */
/* ------------------------------------------------------------------ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(9, 12, 18, 0.48);
  opacity: 0;
  transition: opacity 0.25s ease;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.sheet-backdrop.open {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 520px;
  max-height: 92vh;
  max-height: 92dvh;
  margin: 0 auto;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--bg);
  box-shadow: 0 -20px 60px rgba(9, 12, 18, 0.24);
  transform: translateY(104%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 2px auto 10px;
  border-radius: 99px;
  background: var(--muted-2);
  opacity: 0.5;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text-strong);
}

.entry-form {
  display: block;
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.seg {
  flex: 1;
  height: 42px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg.active {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.09);
}

.seg[data-type="expense"].active {
  color: var(--expense);
}

.seg[data-type="income"].active {
  color: var(--income);
}

.amount-field {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 10px 0 4px;
  padding: 10px 6px 14px;
  border-bottom: 1px solid var(--line);
}

.amount-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text-strong);
  font-size: clamp(30px, 10vw, 40px);
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.amount-input::placeholder {
  color: var(--muted-2);
  font-weight: 700;
}

.amount-unit {
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-top: 16px;
}

.field-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.entry-chips {
  margin-top: 0;
}

.entry-chips .chip {
  height: 38px;
  padding: 0 13px;
  border-radius: 12px;
  background: var(--surface);
}

.entry-chips .chip.selected {
  background: var(--accent);
}

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

.receipt-box {
  margin-top: 12px;
}

.receipt-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 13px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  text-align: left;
}

.receipt-pick:active {
  background: var(--surface-2);
}

.receipt-pick-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--accent-soft);
  font-size: 20px;
}

.receipt-pick-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.receipt-pick-text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
}

.receipt-pick-text small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-pick .chev {
  flex: none;
}

.receipt-file {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.receipt-thumb-btn {
  flex: none;
  width: 54px;
  height: 54px;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-2);
}

.receipt-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.receipt-file-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.receipt-status {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 700;
}

.receipt-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.receipt-progress {
  height: 4px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.receipt-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.18s ease;
}

.receipt-remove {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 99px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.receipt-remove:active {
  background: var(--surface-2);
}

.entry-receipt {
  font-size: 11px;
  vertical-align: 1px;
}

.entry-auto {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--income, #2e7d32);
  background: rgba(46, 125, 50, 0.12);
  border-radius: 999px;
  vertical-align: 1px;
}

.form-error {
  min-height: 18px;
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.sheet-actions {
  display: flex;
  gap: 9px;
  margin-top: 8px;
}

.sheet-actions .btn {
  height: 54px;
  border-radius: 16px;
  font-size: 16px;
}

#deleteBtn {
  flex: none;
  padding: 0 20px;
}

body.sheet-open {
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* 토스트 / 기타                                                       */
/* ------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 84px);
  z-index: 60;
  max-width: calc(100vw - 48px);
  padding: 11px 18px;
  border-radius: 99px;
  background: rgba(23, 28, 36, 0.94);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

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

.noscript {
  position: fixed;
  inset: auto 20px 20px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  text-align: center;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
