/* 우리집 앱 - 밝고 깔끔한 모바일 스타일 (항상 라이트 모드) */
:root {
  --bg: #f3f4f6;          /* 바탕: 아주 옅은 회색 */
  --card: #ffffff;        /* 카드: 흰색 */
  --soft: #f7f8fa;        /* 카드 안 칸 */
  --text: #191f28;        /* 본문 */
  --sub: #4e5968;         /* 보조 글자 */
  --muted: #8b95a1;       /* 흐린 글자 */
  --line: #eef0f3;        /* 구분선 */
  --brand: #f2683c;       /* 포인트 (따뜻한 코랄) */
  --brand-weak: #fff1eb;
  --ok: #12a150;
  --warn: #e08a00;
  --danger: #e5484d;
  --info: #3182f6;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 4px 16px rgba(17, 24, 39, .04);
  --nav-h: 62px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
               "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px; line-height: 1.5; letter-spacing: -0.01em;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 20px);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; }
code { background: var(--soft); padding: 1px 5px; border-radius: 6px; font-size: .92em; }
.wrap {
  max-width: 640px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* 헤더 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(243, 244, 246, .92);
  -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
  padding-top: calc(env(safe-area-inset-top, 0px) + 14px); padding-bottom: 10px;
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar .who {
  font-size: 12px; color: var(--sub); background: var(--card); padding: 4px 10px; border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 600;
}

.reload {
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--card); color: var(--sub);
  display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow); cursor: pointer; padding: 0;
}
.reload svg { width: 16px; height: 16px; }
.reload:active { transform: rotate(-90deg); transition: transform .2s ease; }

/* 하단 탭 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(255, 255, 255, .96);
  -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
  box-shadow: 0 -1px 0 var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.tabbar ul { display: flex; max-width: 640px; margin: 0 auto; padding: 0; list-style: none; }
.tabbar li { flex: 1; }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--nav-h); font-size: 11px; color: #b0b8c1; gap: 3px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--text); }
.tabbar a.on svg { color: var(--brand); }

/* 카드 */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin: 12px 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.card-head a.more { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 380px) { .grid4 { grid-template-columns: repeat(2, 1fr); } }
.grid2 > *, .grid3 > *, .grid4 > * { min-width: 0; }

.stat { background: var(--soft); border-radius: 14px; padding: 12px; display: block; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 17px; font-weight: 700; white-space: nowrap; letter-spacing: -0.02em; margin-top: 2px; }
.big { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* 리스트 */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; padding-bottom: 2px; }
.list > li:first-child { padding-top: 2px; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.badge {
  display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--soft); color: var(--sub); font-weight: 700; white-space: nowrap;
}
.badge.ok { background: #e8f7ee; color: #0b7a3b; }
.badge.warn { background: #fff4e0; color: #a35f00; }
.badge.danger { background: #ffeceb; color: #c4252b; }
.badge.info { background: #e8f2ff; color: #1b64da; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 14px; border: 0;
  background: var(--soft); color: var(--sub); font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: #eef0f3; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #e55a2e; }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.97); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.icon-btn { min-width: 36px; padding: 0; }
.fab {
  position: fixed; right: max(18px, calc(env(safe-area-inset-right, 0px) + 18px));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 300;
  box-shadow: 0 8px 20px rgba(242, 104, 60, .35);
}
.fab.sub { background: var(--card); color: var(--sub); box-shadow: 0 4px 14px rgba(17, 24, 39, .12); width: 48px; height: 48px; right: max(22px, calc(env(safe-area-inset-right, 0px) + 22px)); font-size: 24px; }
.fab svg { width: 26px; height: 26px; }
.scan-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(17, 24, 39, .55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.scan-box { background: var(--card); border-radius: 20px; padding: 24px 28px; text-align: center; max-width: 300px; }
.scan-box b { display: block; font-size: 17px; margin-top: 12px; }
.scan-box p { margin: 4px 0 0; font-size: 13px; color: var(--sub); }
.scan-spin { width: 36px; height: 36px; margin: 0 auto; border-radius: 50%; border: 4px solid var(--soft); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick form { margin: 0; }
.quick button, .quick a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px; width: 100%; border-radius: 16px; border: 0; background: var(--soft);
  font-size: 13px; font-weight: 700; color: var(--sub); cursor: pointer; font-family: inherit;
  transition: transform .08s ease;
}
.quick button:active, .quick a:active { transform: scale(.96); }
.quick .ico { font-size: 24px; line-height: 1; }
.quick .on { background: var(--brand-weak); color: var(--brand); }

/* 폼 */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid transparent;
  background: var(--soft); color: var(--text); font-size: 16px; font-family: inherit;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); background: #fff; }
input::placeholder, textarea::placeholder { color: #b0b8c1; }
textarea { min-height: 88px; resize: vertical; }
input[type=checkbox], input[type=radio] {
  width: 20px; min-height: 20px; height: 20px; padding: 0; accent-color: var(--brand); flex: none;
}
input[type=color] { padding: 3px; width: 48px; min-height: 40px; background: var(--soft); }
input[type=file] { padding: 10px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; margin: 10px 0; color: var(--sub); }
.seg { display: flex; background: var(--soft); border-radius: 14px; padding: 4px; gap: 4px; }
.seg label { flex: 1; }
.seg input { display: none; }
.seg span {
  display: block; text-align: center; padding: 10px 6px; border-radius: 10px; font-weight: 700; font-size: 14px;
  color: var(--muted); cursor: pointer; transition: background .15s ease;
}
.seg input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(17, 24, 39, .08); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }
.form-actions .btn { flex: 1; }

/* 알림 메시지 */
.flash { padding: 12px 16px; border-radius: 14px; margin: 8px 0; font-size: 14px; font-weight: 600; }
.flash.ok { background: #e8f7ee; color: #0b7a3b; }
.flash.error { background: #ffeceb; color: #c4252b; }
.tip { padding: 12px 14px; background: var(--soft); border-radius: 14px; margin: 8px 0; position: relative; }
.tip b { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.tip b::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.tip p { margin: 3px 0 0 12px; font-size: 13px; color: var(--sub); }
.tip.danger { background: #fff4f3; } .tip.danger b::before { background: var(--danger); }
.tip.warn { background: #fff8eb; }   .tip.warn b::before { background: var(--warn); }
.tip.info { background: #f0f6ff; }   .tip.info b::before { background: var(--info); }
.tip.ok { background: #effaf3; }     .tip.ok b::before { background: var(--ok); }

/* 진행 막대 */
.bar { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.over > i { background: var(--danger); }

/* 월 이동 */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; }
.month-nav a {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--sub); background: var(--card); box-shadow: var(--shadow);
}
.month-nav strong { font-size: 18px; letter-spacing: -0.02em; }

/* 캘린더 */
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { font-size: 12px; color: var(--muted); padding: 4px 0 8px; font-weight: 600; }
.cal th:first-child, .cal td:first-child .n { color: var(--danger); }
.cal th:last-child, .cal td:last-child .n { color: var(--info); }
.cal td { vertical-align: top; height: 62px; padding: 1px; }
.cal td a { display: block; height: 100%; border-radius: 12px; padding: 4px 3px; text-align: center; }
.cal td.other { opacity: .3; }
.cal td.sel a { background: var(--brand-weak); }
.cal .n { font-size: 14px; font-weight: 600; display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; }
.cal td.today .n { background: var(--brand); color: #fff !important; border-radius: 50%; }
.cal .ev { display: block; font-size: 10px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; padding: 0 3px; margin-top: 2px; color: #fff; text-align: left; }
.cal .bd { display: block; font-size: 10px; line-height: 1.2; }

/* 테이블 */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.scroll-x { overflow-x: auto; }

.chart-box { position: relative; height: 220px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; font-size: 14px; }
.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--card); color: var(--sub); white-space: nowrap; box-shadow: var(--shadow);
}
.chips a.on { background: var(--text); color: #fff; }
.inline-form { display: inline; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; color: var(--sub); list-style-position: inside; }
.amount-in { color: var(--ok); }
.login-box { max-width: 380px; margin: 12vh auto 0; }

/* 화면 돌아왔을 때 새로고침 표시 */
.refreshing::after {
  content: "새로고침 중…"; position: fixed; top: calc(env(safe-area-inset-top, 0px) + 10px); left: 50%;
  transform: translateX(-50%); background: var(--text); color: #fff; font-size: 12px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; z-index: 40;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active, .quick button:active, .quick a:active { transform: none; }
}
