/* ===== 테마 변수 ===== */
:root {
    color-scheme: light;
    --bg: #fff;
    --text: #111;
    --border: #ccc;
    --surface: #eee;
    --accent: #333;
    --accent-text: #fff;
    --error: #d33;
    --overlay: rgba(0,0,0,.4);
    --income: #276749;     /* #2f855a 는 --surface 위 3.9:1 → 5.8:1 */
    --expense: #c53030;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1a1a1a;
    --text: #eee;
    --border: #444;
    --surface: #2a2a2a;
    --accent: #ddd;
    --accent-text: #111;
    --error: #ff6b6b;
    --overlay: rgba(0,0,0,.6);
    --income: #48bb78;     /* 라이트 값은 --surface 위 대비 2.6~3.2:1 이라 다크에서 안 읽힘 → 5.9:1 */
    --expense: #fc8181;
}

body {
    font-family: 'Pretendard', sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: 4px;
}

button:disabled {
    background-color: var(--surface);
    cursor: not-allowed;
}

input, select {
    font-family: inherit;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
}

.form-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
    margin: 40px auto;
    padding: 0 16px;
}

.error-message {
    color: var(--error);
    font-size: 13px;
}

.result-message {
    margin-top: 16px;
    font-weight: bold;
}

.page-container {
    max-width: 500px;
    margin: 40px auto;
    padding: 0 16px;
}

a {
    display: block;
    text-decoration: none;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

.inline-link {
    display: inline;
    padding: 0;
    margin: 0;
    border: none;
    text-decoration: underline;
}

@media (max-width: 480px) {
    .page-container,
    .form-container {
        padding: 0 12px;
    }

    input,
    button {
        font-size: 16px;
    }
}

/* 탭 — button 기본(border none, radius 4px)을 물려받음 */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; padding: 10px; background: var(--surface); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }

/* 모달 */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay);
                 display: flex; align-items: center; justify-content: center; }
.modal-overlay[hidden] { display: none; }
.modal { background: var(--bg); padding: 24px; border-radius: 4px; width: min(90%, 400px); }
.modal .form-container { margin: 0; padding: 0; }

/* 목록 — a 스타일(패딩 12px, 테두리, 마진 8px)과 같은 리듬으로 */
#categoryList { list-style: none; padding: 0; margin: 0; }
.category-item { display: flex; align-items: center; gap: 8px;
                 padding: 12px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 4px; }
.category-item.child { margin-left: 24px; }
.category-item .actions { margin-left: auto; display: flex; gap: 4px; }
/* 개인가계부 하위 네비 */
.sub-nav { display: flex; gap: 8px; margin-bottom: 16px; }
.sub-nav a { flex: 1; text-align: center; margin: 0; }
.sub-nav a.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ── 거래 화면 ───────────────────────────── */

.month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 16px 0;
    font-size: 1.1rem;
}

.summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.transaction-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    list-style: none;
}

.transaction-item .trans-date { width: 48px; opacity: .7; }
.transaction-item .trans-category { width: 120px; }
.transaction-item .trans-memo { flex: 1; opacity: .8; }
.transaction-item .trans-amount { margin-left: auto; font-variant-numeric: tabular-nums; }

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

/* ── 통계 화면 ───────────────────────────── */

/* 요약 4개 — 2×2 격자 */
.stat-summary { display: grid; grid-template-columns: 1fr 1fr; }

/* 봉투 목록 — category-item 과 같은 리듬 */
.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
}
.stat-item.child { margin-left: 24px; opacity: .8; }
.stat-item .stat-name { flex: 1; }
.stat-item .stat-ratio { width: 56px; text-align: right; opacity: .7; }
.stat-item .stat-amount { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.stat-envelope > summary { cursor: pointer; list-style: none; }
.stat-envelope > summary::-webkit-details-marker { display: none; }   /* Safari 는 list-style 로 안 지워짐 */
.stat-envelope > summary::before { content: '▸'; width: 12px; }
.stat-envelope[open] > summary::before { content: '▾'; }

/* 6개월 추이 — CSS 막대. 길이는 6개월 최댓값 기준 */
.trend-item { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.trend-item .trend-label { width: 60px; opacity: .7; }
.trend-item .trend-bars { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.trend-item .bar { display: block; height: 8px; border-radius: 2px; }
.trend-item .bar-income { background: var(--income); }
.trend-item .bar-expense { background: var(--expense); }
.trend-item .trend-balance { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── 메인(홈) 화면 ─────────────────────────
   .home 아래로만 적용 — 전역 a(블록·테두리) 스타일을 홈에서만 덮는다 */
.home { max-width: 880px; margin: 0 auto; padding: 0 16px 64px; }

.home-bar { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid var(--border); }
.home-brand { font-size: 1.2rem; font-weight: 800; letter-spacing: -.02em; }
.home-bar-actions { display: flex; gap: 8px; }
.home-bar-actions button { padding: 8px 12px; background: var(--surface); color: var(--text); }

.home-hero { padding: 56px 0 40px; text-align: center; }
.home-hero h1 { margin: 0 0 12px; font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -.02em; min-height: 1.3em; }
.home-hero p { margin: 0 0 24px; opacity: .75; line-height: 1.6; }
.home a.home-cta { display: inline-block; margin: 0; padding: 12px 28px; border: none; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-weight: 700; }

.home-menu { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.home .home-card { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; transition: transform .15s, border-color .15s; }
.home a.home-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.home-card-icon { font-size: 1.5rem; }
.home-card span:last-child { font-size: 13px; opacity: .7; }
.home-card.is-soon { opacity: .5; border-style: dashed; }

.home-guide { margin-top: 64px; }
.home-guide h2 { margin: 0 0 8px; font-size: 1.4rem; text-align: center; }
.home-step { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: center; padding: 32px 0; border-bottom: 1px solid var(--border); }
.home-step:nth-of-type(even) .home-step-text { order: 2; }   /* 글·화면을 번갈아 배치 */
.home-step-num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 700; }
.home-step h3 { margin: 12px 0 8px; font-size: 1.15rem; }
.home-step p { margin: 0 0 12px; line-height: 1.7; opacity: .8; }

/* 예시 화면 — 이미지 파일이 아니라 실제 화면과 같은 클래스로 그린다 (다크모드·디자인 변경을 그대로 따라온다) */
.home-shot { margin: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); box-shadow: 0 8px 24px var(--overlay); font-size: 14px; pointer-events: none; user-select: none; }
.home-shot-bar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.home-shot-bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.home-shot-bar span { margin-left: 8px; font-size: 12px; opacity: .6; }
.home-shot-body { padding: 12px 16px 16px; }
.home-shot-list { margin: 0; padding: 0; }
.home-shot .month-nav { margin: 4px 0 8px; font-size: 1rem; }
.home-shot .tabs { margin-bottom: 8px; }
.home-shot .tab { text-align: center; padding: 6px; border-radius: 4px; }
.home-shot .category-item { padding: 8px 10px; margin-bottom: 6px; }
.home-shot .stat-item .stat-amount { width: auto; }

.home-note { margin: 24px 0 0; text-align: center; font-size: 13px; opacity: .6; }

@media (max-width: 720px) {
    .home-menu { grid-template-columns: 1fr 1fr; }
    .home-step { grid-template-columns: 1fr; gap: 16px; }
    .home-step:nth-of-type(even) .home-step-text { order: 0; }
    .home-hero { padding: 40px 0 28px; }
}
