:root {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-2: #0b0e13;
  --surface: #161b22;
  --surface-2: #1c232d;
  --line: #262d39;
  --ink: #e8ebf1;
  --muted: #8d97a8;
  --faint: #5b6575;
  --accent: #6c7bff;
  --accent-2: #a855f7;
  --income: #2dd4a7;
  --income-soft: rgba(45, 212, 167, 0.14);
  --expense: #fb6f86;
  --expense-soft: rgba(251, 111, 134, 0.14);
  --gold: #f0b429;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --grad: linear-gradient(135deg, #5b5bff 0%, #7c5cff 48%, #b15cf0 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(45, 212, 167, 0.08), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", "Pretendard", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3, p { margin: 0; }

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

/* 상단바 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 800; color: #fff;
  background: var(--grad);
  box-shadow: 0 8px 22px rgba(124, 92, 255, 0.4);
}
.brand-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: var(--accent); }
.brand h1 { font-size: 21px; font-weight: 800; line-height: 1.1; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 18px;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  transition: transform .12s, background .12s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-1px); }

/* 인증 */
.auth-card {
  display: none;
  flex-direction: column; align-items: center; gap: 16px;
  padding: 34px 20px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.auth-card.is-visible { display: flex; }
.auth-illu {
  width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center;
  font-size: 28px; background: var(--surface-2); border: 1px solid var(--line);
}
.auth-form { width: min(420px, 100%); }
.auth-form label { display: block; margin-bottom: 10px; color: var(--muted); font-weight: 600; text-align: center; }
.auth-row { display: flex; gap: 8px; }
.auth-row input { flex: 1; }
input, .search-box {
  height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--ink);
}
input::placeholder { color: var(--faint); }
input:focus { outline: none; border-color: var(--accent); }
.btn-primary {
  height: 44px; padding: 0 20px; border-radius: 12px; font-weight: 700; color: #fff;
  background: var(--grad); box-shadow: 0 8px 20px rgba(124, 92, 255, 0.32);
  transition: transform .12s, filter .12s;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-primary.compact { padding: 0 16px; height: 40px; }
.form-error { min-height: 18px; margin-top: 10px; color: var(--expense); font-weight: 600; text-align: center; font-size: 13px; }

/* 대시보드 숨김 처리(잠금 시) */
#dashboard.locked { display: none; }

/* 월 네비 */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 14px; }
.month-step {
  width: 36px; height: 36px; border-radius: 10px; font-size: 20px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
}
.month-step:disabled { opacity: .3; cursor: default; }
.month-label { font-size: 17px; font-weight: 800; min-width: 110px; text-align: center; letter-spacing: .5px; }
.month-select {
  height: 40px; min-width: 130px; text-align: center; text-align-last: center;
  font-size: 16px; font-weight: 800; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.quick-row { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.quick-btn {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.quick-btn:hover { color: var(--ink); background: var(--surface-2); }
.quick-btn.reset { color: var(--accent); border-color: rgba(108,123,255,0.4); background: rgba(108,123,255,0.12); }

/* 히어로 */
.hero {
  position: relative; overflow: hidden;
  padding: 22px; margin-bottom: 14px; border-radius: var(--radius);
  background: var(--grad); color: #fff;
  box-shadow: 0 18px 44px rgba(108, 76, 220, 0.36);
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(420px 220px at 90% -30%, rgba(255,255,255,0.28), transparent 60%);
  pointer-events: none;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; position: relative; }
.hero-eyebrow { font-size: 12px; font-weight: 600; opacity: .85; }
.hero-amount { font-size: 36px; font-weight: 800; line-height: 1.05; margin-top: 6px; letter-spacing: -.5px; }
.hero-delta { margin-top: 8px; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.hero-delta .pill {
  padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,0.18); backdrop-filter: blur(4px);
}
.hero-spark { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.hero-spark svg { width: 130px; height: 50px; }
.hero-spark-label { font-size: 10px; opacity: .8; }
.hero-sub {
  position: relative; display: flex; align-items: center; gap: 16px;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.2);
}
.hero-sub-item { flex: 1; }
.hero-sub-item span { display: block; font-size: 12px; opacity: .85; }
.hero-sub-item strong { font-size: 18px; font-weight: 800; margin-top: 2px; display: block; }
.hero-sub-divider { width: 1px; align-self: stretch; background: rgba(255,255,255,0.2); }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { padding: 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); }
.kpi p { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi strong { display: block; font-size: 21px; font-weight: 800; margin-top: 6px; letter-spacing: -.3px; }
.kpi span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi-up { color: var(--income) !important; }
.kpi-down { color: var(--expense) !important; }

/* 카드 공통 */
.card { padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-head h3 { font-size: 15px; font-weight: 800; }
.card-sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.link-btn { color: var(--accent); font-size: 13px; font-weight: 700; }

/* 예산 */
.budget-card { margin-bottom: 14px; }
.budget-bar { position: relative; height: 14px; border-radius: 999px; background: var(--bg-2); overflow: hidden; border: 1px solid var(--line); }
.budget-bar span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 999px; background: var(--grad); transition: width .5s ease; }
.budget-bar span.over { background: linear-gradient(135deg, #fb6f86, #f0426a); }
.budget-pace { position: absolute; top: -3px; bottom: -3px; width: 2px; background: rgba(255,255,255,0.55); }
.budget-meta { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; font-weight: 700; }
.budget-left { color: var(--income); }
.budget-left.over { color: var(--expense); }
.budget-note { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.budget-form { display: flex; gap: 8px; margin-top: 12px; }
.budget-form input { flex: 1; }

/* 그리드 */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }

/* 차트 */
.legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.dot-bar { background: var(--accent); }
.dot-line { background: var(--gold); border-radius: 999px; }
.chart-wrap { width: 100%; position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap svg rect[data-day] { cursor: pointer; transition: opacity .1s; }
.chart-wrap svg rect[data-day]:hover { opacity: .82; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; transform: translate(-50%, -100%);
  padding: 6px 9px; border-radius: 9px; font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: #0b0e13; border: 1px solid var(--line); color: var(--ink); box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}
.chart-tip b { color: var(--accent); }
.chart-hint { margin-top: 8px; font-size: 11px; color: var(--faint); text-align: center; }

/* 드릴다운 필터 칩 */
.ledger-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ledger-filters[hidden] { display: none; }
.fchip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; color: var(--ink);
  background: rgba(108,123,255,0.16); border: 1px solid rgba(108,123,255,0.4);
}
.fchip button { color: var(--muted); font-size: 14px; line-height: 1; }
.fchip button:hover { color: var(--ink); }

/* 선택 강조 */
.cat-item { cursor: pointer; padding: 4px; margin: -4px; border-radius: 10px; transition: background .1s; }
.cat-item:hover { background: var(--bg-2); }
.cat-item.sel { background: rgba(108,123,255,0.12); }
#categoryDonut circle[data-cat] { cursor: pointer; }

/* 도넛 */
.donut-wrap { position: relative; width: 150px; height: 150px; margin: 4px auto 14px; }
.donut-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut-center span { font-size: 11px; color: var(--muted); }
.donut-center strong { font-size: 17px; font-weight: 800; display: block; margin-top: 2px; }

/* 분류 리스트 */
.category-list { display: grid; gap: 11px; }
.cat-item { display: grid; gap: 6px; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.cat-name { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.cat-name i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.cat-name b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-pct { color: var(--faint); font-weight: 600; font-size: 12px; }
.cat-amt { font-weight: 800; white-space: nowrap; }
.cat-bar { height: 7px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.cat-bar span { display: block; height: 100%; border-radius: inherit; }

/* 인사이트 */
.insight { padding: 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); }
.insight p { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.insight strong { display: block; font-size: 16px; font-weight: 800; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insight span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

/* 거래 */
.ledger-toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.ledger-toolbar h3 { font-size: 15px; font-weight: 800; }
.ledger-count { color: var(--muted); font-weight: 600; font-size: 13px; margin-left: 4px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 150px; padding: 0 12px; color: var(--muted); }
.search-box input { height: 40px; border: 0; background: none; padding: 0; flex: 1; }
.search-box input:focus { outline: none; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg button.active { background: var(--surface-2); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

.ledger-list { display: grid; gap: 8px; }
.tx {
  display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius-sm); background: var(--bg-2); border: 1px solid var(--line);
}
.tx-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 16px; font-weight: 800; }
.tx-icon.card { background: rgba(108,123,255,0.16); color: #9aa6ff; }
.tx-icon.bank { background: var(--income-soft); color: var(--income); }
.tx-icon.manual { background: rgba(240, 180, 41, 0.16); color: var(--gold); }
.tx-main { min-width: 0; }
.tx-title { font-size: 14.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { margin-top: 4px; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag { padding: 2px 7px; border-radius: 6px; background: var(--surface-2); font-size: 10.5px; font-weight: 700; color: var(--muted); }
.tx-right { text-align: right; }
.tx-amt { font-size: 15px; font-weight: 800; white-space: nowrap; }
.tx-amt.expense { color: var(--expense); }
.tx-amt.income { color: var(--income); }
.tx-amt.refund { color: var(--gold); }
.tx-bal { font-size: 11px; color: var(--faint); margin-top: 3px; white-space: nowrap; }

/* 메모 (형광녹색, 인라인 편집) */
.tx { grid-template-areas: "icon main right" "memo memo memo"; }
.tx-icon { grid-area: icon; } .tx-main { grid-area: main; } .tx-right { grid-area: right; }
.tx-memo-row { grid-area: memo; margin-top: 8px; display: flex; align-items: flex-start; gap: 6px; }
.tx-memo-row .pencil { flex: none; color: var(--faint); font-size: 12px; line-height: 1.5; }
.tx-memo {
  flex: 1; min-width: 0; height: auto; font-size: 12.5px; font-weight: 700; line-height: 1.5;
  color: #7CFC00; /* 형광녹색 */ text-shadow: 0 0 8px rgba(124,252,0,0.25);
  background: transparent; outline: none; border-radius: 6px; padding: 3px 6px; border: 1px dashed transparent;
}
.tx-memo::placeholder { color: var(--faint); text-shadow: none; font-weight: 600; }
.tx-memo:hover { border-color: var(--line); }
.tx-memo:focus { border-color: #7CFC00; background: rgba(124,252,0,0.06); }

/* 분류 태그(클릭 편집) + 선택 버튼 */
.tag-edit { cursor: pointer; border: 1px solid transparent; }
.tag-edit:hover { border-color: var(--line); color: var(--ink); }
.cat-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-opt { padding: 13px 8px; border-radius: 12px; font-size: 13.5px; font-weight: 700; color: var(--ink); background: var(--bg-2); border: 1px solid var(--line); }
.cat-opt:hover { background: var(--surface-2); }
.cat-opt.auto { grid-column: 1 / -1; color: var(--muted); }
.cat-opt.del-mode { color: var(--expense); border-color: rgba(251,111,134,0.4); background: rgba(251,111,134,0.1); }
.cat-opt.del-mode .del { margin-left: 4px; opacity: .8; }
.cat-opt.locked { color: var(--faint); background: var(--bg-2); cursor: default; }
.cat-manage { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.cat-add { display: flex; gap: 8px; margin-top: 10px; }
.cat-add[hidden] { display: none; }
.cat-add input { flex: 1; }

/* 이체 카드 */
.card-note { font-size: 11.5px; color: var(--muted); margin: -6px 0 12px; line-height: 1.5; }
.transfer-card .tx-amt.income { color: var(--income); }
.transfer-card .tx-amt.expense { color: #38bdf8; }

/* 수동 입력 FAB + 시트 */
.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; font-size: 30px; font-weight: 300; color: #fff; line-height: 1;
  background: var(--grad); box-shadow: 0 12px 30px rgba(124, 92, 255, 0.5); z-index: 30;
  transition: transform .14s;
}
.fab:hover { transform: translateY(-2px) scale(1.04); }
#dashboard.locked ~ .fab { display: none; }
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); }
.sheet-card {
  position: relative; width: min(440px, 100%); max-height: 90vh; overflow-y: auto;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
  animation: sheetUp .22s ease;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 560px) { .sheet { align-items: center; } .sheet-card { border-radius: 22px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 17px; font-weight: 800; }
.seg-block { display: flex; width: 100%; margin-bottom: 14px; }
.seg-block button { flex: 1; padding: 9px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.field input, .field select { width: 100%; }
select { height: 44px; padding: 0 12px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); color: var(--ink); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-primary.block { width: 100%; margin-top: 6px; }

.empty { padding: 30px 14px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius-sm); background: var(--bg-2); }
.foot { margin-top: 20px; text-align: center; color: var(--faint); font-size: 12px; }

/* 데스크톱 */
@media (min-width: 720px) {
  .kpi-row { grid-template-columns: repeat(4, 1fr); }
  .grid-2 { grid-template-columns: 1.5fr 1fr; }
  .hero-amount { font-size: 42px; }
  .ledger-toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
  .filters { flex-wrap: nowrap; }
}
@media (max-width: 460px) {
  .grid-3 { grid-template-columns: 1fr; }
  .hero-spark svg { width: 104px; }
}
