/* 우리집 자산 스타일
   순서: 1 토큰 → 2 테마(토큰 덮어쓰기) → 3 기본 → 4 레이아웃(l-) → 5 컴포넌트(c-) → 6 유틸(u-) → 7 반응형(@container)
   - 새 화면은 l-/c- 조합으로 만든다. 색·간격은 반드시 토큰(var(--…))으로
   - 선택·현재 상태는 클래스 대신 aria-pressed / aria-selected / aria-current 로 꾸민다
   - 다크 모드는 2번에 [data-theme=dark] 토큰 묶음만 추가하면 된다 */

/* 1 토큰 */
:root {
  --font: 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  --font-display: var(--font);
  --r-lg: 16px; --r-md: 12px; --r-sm: 8px;
  --sp1: 4px; --sp2: 8px; --sp3: 12px; --sp4: 16px; --sp5: 20px; --sp6: 24px; --sp8: 32px;
  --dur: .16s; --ease: cubic-bezier(.2, .6, .2, 1);
  --pop: 0 8px 24px rgba(15, 23, 42, .18);
  --sheet: 0 -8px 32px rgba(15, 23, 42, .18);
}

/* 2 테마 */
:root, [data-theme=light] {
  --bg: #FFFFFF; --surface-2: #F9FAFB; --muted: #F2F4F6; --line: #F2F4F6; --line-2: #E5E8EB;
  --text: #191F28; --text-2: #4E5968; --text-3: #6B7684;
  --accent: #2563EB; --accent-soft: #EEF4FF; --on-accent: #FFFFFF;
  --up: #E42939; --up-soft: #FEECEC; --down: #2563EB; --down-soft: #EEF4FF;
  --warn: #B54708; --warn-soft: #FFF4E5; --ok: #12B76A;
  --scrim: rgba(15, 23, 42, .4);
  --c1: #2563EB; --c2: #60A5FA; --c3: #93C5FD; --c4: #F59E0B; --c5: #14B8A6; --c6: #FB923C; --c7: #A78BFA; --c8: #CBD5E1;
}

/* 3 기본 */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
body.has-sheet { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { opacity: .5; cursor: default; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font: inherit; color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: -.2px; }
.h { font-family: var(--font-display); font-weight: 700; margin: 0; }
.app { container: app / inline-size; min-height: 100vh; display: flex; flex-direction: column; }

/* 4 레이아웃 */
.l-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--sp6); height: 60px; padding: 0 var(--sp6); background: var(--bg); border-bottom: 1px solid var(--line); }
.l-shell { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 320px 64px; width: 100%; max-width: 1680px; margin: 0 auto; }
.l-shell--full { grid-template-columns: minmax(0, 1fr); max-width: 1080px; }
.l-main { min-width: 0; padding: var(--sp5) var(--sp6) var(--sp8); display: flex; flex-direction: column; gap: var(--sp5); }
.l-side { border-left: 1px solid var(--line); padding: var(--sp5) var(--sp4); display: flex; flex-direction: column; gap: var(--sp4); }
.l-rail { border-left: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: var(--sp2); padding: var(--sp4) 0; }
.l-summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr) minmax(0, 1fr); gap: var(--sp6); align-items: start; }
.l-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.l-board { display: grid; grid-template-columns: minmax(0, 1fr) 340px; border-top: 1px solid var(--line); }
.l-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp5); align-items: start; }
.l-stack { display: flex; flex-direction: column; gap: var(--sp4); }

/* 5 컴포넌트 */
.c-brand { display: flex; align-items: center; gap: var(--sp2); font-weight: 800; font-size: 17px; white-space: nowrap; }
.c-nav { display: flex; gap: var(--sp1); }
.c-nav a { padding: 6px 10px; border-radius: var(--r-sm); color: var(--text-2); transition: background var(--dur) var(--ease); }
.c-nav a:hover { background: var(--muted); }
.c-nav a[aria-current=page] { color: var(--text); font-weight: 700; }
.c-top-actions { margin-left: auto; display: flex; gap: var(--sp2); align-items: center; }

.c-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 var(--sp4); border-radius: var(--r-md); font-weight: 700; white-space: nowrap; transition: filter var(--dur) var(--ease), background var(--dur) var(--ease); }
.c-btn--primary { background: var(--accent); color: var(--on-accent); }
.c-btn--primary:hover { filter: brightness(1.08); }
.c-btn--ghost { border: 1px solid var(--line-2); }
.c-btn--ghost:hover { background: var(--muted); }
.c-btn--soft { background: var(--accent-soft); color: var(--accent); }
.c-btn--sm { height: 32px; padding: 0 var(--sp3); font-size: 13px; }
.c-btn--block { width: 100%; }
.c-icon-btn { width: 36px; height: 36px; border-radius: var(--r-md); display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); flex-shrink: 0; }
.c-icon-btn:hover { background: var(--muted); }
.c-link { color: var(--accent); font-weight: 700; }

.c-select { height: 32px; padding: 0 var(--sp3); border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--bg); font-size: 13px; }

.c-notice { display: flex; align-items: center; justify-content: center; gap: var(--sp3); padding: 10px var(--sp6); border-bottom: 1px solid var(--line); font-weight: 500; flex-wrap: wrap; }
.c-notice__ico { width: 28px; height: 28px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); display: inline-flex; align-items: center; justify-content: center; }

.c-status { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp5); color: var(--text-2); }
.c-status > span { display: inline-flex; align-items: center; gap: 6px; }
.c-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.c-dot--warn { background: var(--warn); }

.c-hero__label { display: flex; align-items: center; gap: var(--sp2); font-weight: 700; }
.c-tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--muted); color: var(--text-2); }
.c-hero__value { font-size: 30px; margin-top: var(--sp1); line-height: 1.3; }
.c-hero__split { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp2); margin-top: var(--sp3); font-size: 12px; color: var(--text-3); }

.c-kpi { display: flex; gap: var(--sp3); align-items: center; padding: var(--sp3) var(--sp4); border-left: 1px solid var(--line); transition: background var(--dur) var(--ease); min-width: 0; }
.c-kpi:hover { background: var(--surface-2); }
.c-kpi__label { font-size: 12px; color: var(--text-2); }
.c-kpi__value { font-size: 16px; }

.c-up { color: var(--up); } .c-down { color: var(--down); } .c-warn { color: var(--warn); } .c-muted { color: var(--text-3); }
.c-sub { color: var(--text-3); font-size: 12px; }

.c-panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp4) var(--sp5); }
.c-panel__head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp2); font-weight: 700; margin-bottom: var(--sp2); }
.c-card { border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: var(--sp5); background: var(--bg); }
.c-section-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp3); flex-wrap: wrap; }
.c-section-head h2 { font-size: 18px; }

.c-todo { display: flex; gap: var(--sp3); padding: var(--sp2) 0; align-items: flex-start; width: 100%; text-align: left; border-radius: var(--r-sm); }
.c-todo:hover { background: var(--muted); }
.c-todo__when { min-width: 40px; font-size: 12px; font-weight: 700; color: var(--accent); padding-left: 2px; }

.c-tabs { display: flex; gap: var(--sp5); align-items: center; border-bottom: 1px solid var(--line); overflow-x: auto; }
.c-tab { padding: var(--sp3) 0; color: var(--text-3); font-size: 15px; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color var(--dur) var(--ease); }
.c-tab:hover { color: var(--text); }
.c-tab[aria-selected=true] { color: var(--text); font-weight: 700; border-color: var(--text); }

.c-filters { display: flex; flex-wrap: wrap; gap: var(--sp2); align-items: center; padding: var(--sp3) 0; }
.c-chip { height: 32px; padding: 0 var(--sp3); border-radius: var(--r-sm); border: 1px solid var(--line-2); color: var(--text-2); font-size: 13px; transition: all var(--dur) var(--ease); }
.c-chip:hover { background: var(--muted); }
.c-chip[aria-pressed=true] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 700; }

.c-grid { position: relative; min-width: 0; }
.c-row { display: grid; grid-template-columns: var(--cols, minmax(150px, 1.4fr) 1fr .7fr .6fr minmax(110px, 1.2fr) .8fr 1.4fr); gap: var(--sp3); align-items: center; padding: var(--sp3) var(--sp2); border-bottom: 1px solid var(--line); transition: background var(--dur) var(--ease); min-height: 56px; }
.c-row:hover { background: var(--surface-2); }
.c-row--head { color: var(--text-3); font-size: 12px; min-height: 40px; }
.c-row--head:hover { background: none; }
button.c-row { width: 100%; text-align: left; }
.u-right { text-align: right; }
.c-name { display: flex; align-items: center; gap: var(--sp3); font-weight: 500; min-width: 0; }
.c-name > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.c-ico { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #FFFFFF; font-style: normal; }

.c-meter { position: relative; display: block; height: 6px; border-radius: 3px; background: var(--muted); }
.c-meter__fill { display: block; height: 6px; border-radius: 3px; background: var(--accent); max-width: 100%; }
.c-meter__goal { position: absolute; left: 50%; top: -4px; width: 2px; height: 14px; background: var(--text); border-radius: 1px; }
.c-progress { height: 8px; border-radius: 4px; background: var(--muted); overflow: hidden; }
.c-progress > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.c-badge { display: inline-flex; align-items: center; height: 24px; padding: 0 var(--sp2); border-radius: 6px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.c-badge--ok { background: var(--muted); color: var(--text-2); }
.c-badge--over { background: var(--up-soft); color: var(--up); }
.c-badge--under { background: var(--warn-soft); color: var(--warn); }
.c-badge--accent { background: var(--accent-soft); color: var(--accent); }

.c-pop { position: absolute; left: 24px; top: 52px; z-index: 3; width: 300px; padding: var(--sp4); border-radius: var(--r-md); background: var(--accent); color: var(--on-accent); box-shadow: var(--pop); animation: popin .24s var(--ease); }
.c-pop::before { content: ''; position: absolute; top: -6px; left: 28px; width: 12px; height: 12px; background: var(--accent); transform: rotate(45deg); }
@keyframes popin { from { opacity: 0; transform: translateY(-4px); } }

.c-chartpane { border-left: 1px solid var(--line); padding: var(--sp5); min-width: 0; }
.c-seg { display: inline-flex; padding: 3px; border-radius: var(--r-sm); background: var(--muted); }
.c-seg button { height: 28px; padding: 0 var(--sp3); border-radius: 6px; font-size: 12px; color: var(--text-3); }
.c-seg button[aria-pressed=true] { background: var(--bg); color: var(--text); font-weight: 700; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.c-stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--muted); }
.c-stack > i { display: block; height: 10px; }
.c-asset { display: flex; align-items: center; gap: var(--sp3); padding: 10px var(--sp2); margin: 0 calc(var(--sp2) * -1); border-radius: var(--r-md); transition: background var(--dur) var(--ease); width: calc(100% + var(--sp4)); text-align: left; }
.c-asset:hover { background: var(--muted); }
.c-asset__tile { width: 36px; height: 36px; border-radius: var(--r-md); flex-shrink: 0; }

.c-rail-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 52px; padding: var(--sp2) 0; border-radius: var(--r-md); font-size: 11px; color: var(--text-3); }
.c-rail-btn:hover { background: var(--muted); }
.c-rail-btn[aria-current=page] { color: var(--text); }

.c-tabbar { display: none; position: sticky; bottom: 0; z-index: 20; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 6px 4px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.c-tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; justify-content: center; font-size: 11px; color: var(--text-3); }
.c-tabbar a[aria-current=page] { color: var(--accent); font-weight: 700; }
.c-fab { display: none; position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 21; width: 56px; height: 56px; border-radius: 28px; background: var(--accent); color: var(--on-accent); box-shadow: var(--pop); align-items: center; justify-content: center; }

.c-empty { padding: var(--sp6); text-align: center; color: var(--text-3); border: 1px dashed var(--line-2); border-radius: var(--r-lg); }
.c-list { display: flex; flex-direction: column; }
.c-item { display: flex; align-items: center; gap: var(--sp3); padding: var(--sp3) 0; border-bottom: 1px solid var(--line); }
.c-item:last-child { border-bottom: 0; }
.c-item__main { flex: 1; min-width: 0; }
.c-kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp1) var(--sp4); font-size: 13px; }
.c-kv dt { color: var(--text-3); } .c-kv dd { margin: 0; text-align: right; }

/* 폼과 시트 */
.c-form { display: flex; flex-direction: column; gap: var(--sp4); }
.c-field { display: flex; flex-direction: column; gap: 6px; }
.c-field > label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.c-field > label i { color: var(--up); font-style: normal; }
.c-field input:not([type=checkbox]), .c-field select { height: 44px; padding: 0 var(--sp3); border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--bg); width: 100%; transition: border-color var(--dur) var(--ease); }
.c-field input:focus, .c-field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.c-field small { color: var(--text-3); font-size: 12px; }
.c-field--check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--sp2); font-weight: 500; }
.c-field--check input { width: 18px; height: 18px; accent-color: var(--accent); }
.c-field--check small { flex-basis: 100%; padding-left: 26px; }
.c-money { position: relative; }
.c-money input { padding-right: 36px !important; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.c-money span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.c-form__err { color: var(--up); font-size: 13px; white-space: pre-line; min-height: 0; }
.c-form__err:empty { display: none; }
.c-form__actions { display: flex; gap: var(--sp2); justify-content: flex-end; position: sticky; bottom: 0; background: var(--bg); padding-top: var(--sp2); }
.c-form__actions .c-btn { min-width: 96px; }
.c-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp3); }

.c-sheet-wrap { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: var(--sp6); animation: fade .16s var(--ease); }
.c-sheet { width: min(560px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--bg); border-radius: var(--r-lg); box-shadow: var(--pop); animation: rise .22s var(--ease); }
.c-sheet__head { display: flex; justify-content: space-between; align-items: center; padding: var(--sp4) var(--sp5); border-bottom: 1px solid var(--line); }
.c-sheet__head .h { font-size: 17px; }
.c-sheet__body { padding: var(--sp5); overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.c-toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px var(--sp4); border-radius: var(--r-md); font-weight: 500; box-shadow: var(--pop); transition: opacity .3s; max-width: calc(100% - 32px); }
.c-toast.is-out { opacity: 0; }
.c-toast.error { background: var(--up); color: #FFFFFF; }

/* 로그인·처음 설정 */
.c-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp6); background: var(--surface-2); }
.c-login__card { width: min(400px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: var(--sp8) var(--sp6); display: flex; flex-direction: column; gap: var(--sp4); text-align: center; }
.c-google { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp2); height: 48px; border-radius: var(--r-md); border: 1px solid var(--line-2); font-weight: 700; }
.c-google:hover { background: var(--muted); }
.c-alert { padding: var(--sp3) var(--sp4); border-radius: var(--r-md); background: var(--warn-soft); color: var(--warn); font-size: 13px; text-align: left; }
.c-steps { display: flex; gap: var(--sp2); flex-wrap: wrap; }
.c-step { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--sp3); border-radius: 16px; background: var(--muted); color: var(--text-3); font-size: 13px; }
.c-step b { width: 20px; height: 20px; border-radius: 10px; background: var(--line-2); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-2); }
.c-step[aria-current=step] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.c-step[aria-current=step] b { background: var(--accent); color: var(--on-accent); }
.c-step.is-done b { background: var(--ok); color: #FFFFFF; }

/* 6 유틸 */
.u-row { display: flex; gap: var(--sp2); align-items: center; flex-wrap: wrap; }
.u-grow { flex: 1; min-width: 0; }
.u-gap { gap: var(--sp4); }
.u-center { text-align: center; }

/* 7 반응형 (앱 영역의 폭 기준) */
@container app (max-width: 1280px) { .l-shell { grid-template-columns: minmax(0, 1fr) 300px; } .l-rail { display: none; } }
@container app (max-width: 1120px) { .l-summary { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); } .c-panel--todo { grid-column: 1 / -1; } .l-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container app (max-width: 960px) {
  .l-shell { grid-template-columns: minmax(0, 1fr); }
  .l-side { border-left: 0; border-top: 1px solid var(--line); }
  .l-board { grid-template-columns: minmax(0, 1fr); }
  .c-chartpane { border-left: 0; border-top: 1px solid var(--line); padding: var(--sp5) 0; }
  .l-cols { grid-template-columns: minmax(0, 1fr); }
}
@container app (max-width: 640px) {
  .l-top { gap: var(--sp2); padding: 0 var(--sp4); height: 56px; }
  .c-nav, .u-hide-sm, .col-opt { display: none !important; }
  .l-main { padding: var(--sp4); gap: var(--sp4); }
  .l-summary { grid-template-columns: minmax(0, 1fr); gap: var(--sp4); }
  .l-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp2); }
  .c-kpi { border: 1px solid var(--line); border-radius: var(--r-md); flex-direction: column; align-items: flex-start; gap: var(--sp1); }
  .c-row { --cols: minmax(0, 1fr) auto auto !important; }
  .c-notice { justify-content: flex-start; padding: 10px var(--sp4); }
  .c-pop { display: none; }
  .c-tabbar { display: grid; }
  .c-fab { display: inline-flex; }
  .c-tabs { gap: var(--sp4); }
  .c-form-grid { grid-template-columns: minmax(0, 1fr); }
}
/* 시트·토스트는 앱 영역 밖(body)에 붙으므로 화면 폭 기준으로 */
@media (max-width: 640px) {
  .c-sheet-wrap { align-items: flex-end; padding: 0; }
  .c-sheet { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; box-shadow: var(--sheet); }
  .c-sheet .c-form-grid { grid-template-columns: minmax(0, 1fr); }
  .c-toast { bottom: 140px; }
}
