:root {
    /* 아이콘(파스텔 피치)에 맞춘 따뜻한 색. 대비를 재서 고른 값이라 임의로 밝히면 글자가 안 보인다 */
    --bg: #fbf6f2;
    --card: #ffffff;
    --text: #2b2320;
    --text-sub: #6b5c55;
    --muted: #7d6e66;
    --line: #f5ede7;
    --line-strong: #e9ded6;

    /* 브랜드: 버튼·활성 탭 (흰 글씨 대비 4.8) / soft는 아이콘·막대용 */
    --primary: #b85338;
    --primary-soft: #e8836a;
    --primary-weak: #fceae1;

    /* 금액 4종 — 흰 배경에서 4.5 이상, 서로 색상이 충분히 벌어지게 */
    --income: #2f74b0;
    --income-weak: #e9f1f8;
    --expense: #c93b52;
    --expense-weak: #fbeaee;
    --invest: #6f5fc4;
    --invest-weak: #efecfb;
    --good: #358066;
    --good-weak: #e7f3ee;
    --planned: #8f5e10;
    --planned-weak: #fbf1df;

    /* 분석 카드 보조색 */
    --teal: #3e8f8c;
    --slate: #6e6259;

    --radius: 20px;
    --shadow: 0 1px 4px rgba(64, 42, 32, 0.04), 0 8px 24px rgba(64, 42, 32, 0.07);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
        "Apple SD Gothic Neo", "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.brand-font {
    font-family: "Jua", "Pretendard Variable", Pretendard, sans-serif;
    font-weight: 400;
}

.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* ===== 내비게이션 ===== */
.nav {
    background: rgba(255, 252, 250, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line-strong);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-inner {
    max-width: 920px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-inner::-webkit-scrollbar {
    display: none;
}

.nav-brand {
    font-size: 20px;
    color: var(--primary);
    text-decoration: none;
    margin-right: 12px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.nav a.nav-link {
    color: var(--text-sub);
    text-decoration: none;
    padding: 7px 12px;
    border-radius: 10px;
    white-space: nowrap;
    font-weight: 500;
    font-size: 14px;
}

.nav a.nav-link:hover {
    background: var(--bg);
}

.nav a.nav-link.active {
    color: var(--primary);
    background: var(--primary-weak);
    font-weight: 700;
}

.nav .spacer {
    flex: 1;
    min-width: 8px;
}

.nav form {
    margin: 0;
}

/* ===== 카드 ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin: 0 0 16px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.card h2 .sub {
    font-size: 13px;
    color: var(--muted);
    font-weight: 400;
    margin-left: 8px;
}

/* ===== 요약 그리드 ===== */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
}

.summary-item .label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 2px;
}

.summary-item .value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.hero-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    margin: 4px 0 2px;
}

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

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

.amount-planned {
    color: var(--planned);
}

.amount-invest {
    color: var(--invest);
}

.amount-withdraw {
    color: var(--good);
}

/* 거래 내역 테이블은 정보 밀도가 높아 한 단계 작게 */
table.compact {
    font-size: 13px;
}

table.compact td {
    padding: 8px 10px;
}

table.compact .badge {
    font-size: 11px;
    padding: 1px 7px;
}

.amount-good {
    color: var(--good);
}

/* ===== 월 이동 ===== */
.month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 4px 0 20px;
}

.month-nav a {
    color: var(--text-sub);
    text-decoration: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 13px;
}

.month-nav .current {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

/* ===== 막대 그래프 ===== */
.bar-row {
    display: grid;
    /* 금액 칸은 글자 길이에 맞춘다. 고정 폭으로 두면 10자리 금액이 칸을 넘어 카드 밖으로 삐져나온다.
       대신 막대가 줄어들고, 이름은 말줄임으로 접힌다 */
    grid-template-columns: minmax(0, auto) minmax(32px, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
}

.bar-row .bar-label {
    font-size: 14px;
    color: var(--text-sub);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-track {
    background: var(--bg);
    border-radius: 6px;
    height: 12px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
    background: var(--primary-soft);
    min-width: 2px;
}

.bar-fill.expense {
    background: var(--expense);
    opacity: 0.85;
}

.bar-row .bar-amount {
    font-size: 14px;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}

/* ===== 테이블 ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--line-strong);
    white-space: nowrap;
}

td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

td.num, th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ===== 배지 ===== */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--primary-weak);
    color: var(--primary);
}

.badge.planned {
    background: var(--planned-weak);
    color: var(--planned);
}

.badge.gray {
    background: var(--bg);
    color: var(--text-sub);
}

.badge.expense {
    background: var(--expense-weak);
    color: var(--expense);
}

.badge.good {
    background: var(--good-weak);
    color: var(--good);
}

/* ===== 초대 코드 (가리고 눌러서 보기) ===== */
.invite-code {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 6px;
    filter: blur(4px);
    cursor: pointer;
    transition: filter 0.15s;
}

.invite-code:hover, .invite-code:active, .invite-code:focus {
    filter: none;
}

.mode-switch {
    display: flex;
    gap: 14px;
    font-size: 14px;
    color: var(--text-sub);
}

.mode-switch input {
    width: auto;
    margin-right: 4px;
    accent-color: var(--primary);
}

/* ===== 자산 행: 수정 모드 토글 ===== */
.asset-row .edit {
    display: none;
}

.asset-row.editing .edit {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.asset-row.editing .view,
.asset-row.editing .js-edit {
    display: none;
}

td a.plain {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

td a.plain:hover {
    color: var(--primary);
}

.back {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.delta-up {
    color: var(--good);
}

.delta-down {
    color: var(--expense);
}

/* ===== 카테고리 칩 (카테고리 = 채움, 소분류 = 외곽선) ===== */
.chip {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    background: var(--line-strong);
    color: var(--text-sub);
    vertical-align: middle;
    white-space: nowrap;
}

.chip.sub {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--muted);
    font-weight: 500;
    margin-left: 4px;
}

/* ===== 폼 ===== */
form.stack {
    display: grid;
    gap: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    /* 칸마다 설명 줄 수가 달라 한 줄의 높이가 들쭉날쭉하다.
       start 가 없으면 짧은 칸(선택 상자)이 옆 칸 높이에 맞춰 늘어나 찌그러져 보인다 */
    align-items: start;
}

/* 칸 안의 긴 안내문·placeholder가 열 폭을 밀어내지 않게 (분석 기준 폼에서 "무엇을 위해" 칸이 혼자 넓어졌다) */
.form-row > * { min-width: 0; }

label.field {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--text-sub);
    font-weight: 500;
}

input, select, textarea {
    padding: 11px 14px;
    border: 1.5px solid var(--line-strong);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    width: 100%;
    min-width: 0;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="file"] {
    padding: 10px;
    background: var(--bg);
    border-style: dashed;
}

button {
    padding: 12px 18px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.15s;
}

button:hover {
    filter: brightness(1.06);
}

button.ghost {
    background: var(--bg);
    color: var(--text-sub);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
}

button.danger {
    background: var(--expense-weak);
    color: var(--expense);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
}

button.small {
    padding: 6px 12px;
    font-size: 13px;
}

/* ===== 플래시 ===== */
.flash {
    padding: 13px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}

.flash.success {
    background: var(--good-weak);
    color: var(--good);
}

.flash.error {
    background: var(--expense-weak);
    color: var(--expense);
}

/* ===== 인증 화면 ===== */
.auth-wrap {
    max-width: 400px;
    margin: 0 auto;
    padding: 10vh 20px 40px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 28px;
}

.auth-brand .logo {
    font-size: 44px;
    color: var(--primary);
    letter-spacing: -1px;
    line-height: 1.2;
}

.auth-brand .tagline {
    color: var(--muted);
    font-size: 14px;
    margin-top: 4px;
}

.auth-wrap .card {
    padding: 28px 24px;
}

.auth-wrap button[type="submit"] {
    margin-top: 4px;
    padding: 14px;
    font-size: 16px;
}

/* ===== 조언 카드 ===== */
.advice {
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 12px;
    background: var(--bg);
}

.advice.warn {
    background: var(--planned-weak);
}

.advice.good {
    background: var(--good-weak);
}



/* ===== 기타 ===== */
.muted {
    color: var(--muted);
    font-size: 13px;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 28px 0;
    font-size: 14px;
}

.inline-form {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.inline-form input {
    width: 130px;
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
}

/* 긴 입력칸: 160px를 기준 폭으로 쓰되 좁은 화면에선 줄어들어야 옆 버튼이 밖으로 밀리지 않는다 */
.inline-form input.wide {
    flex: 1 1 160px;
    width: auto;
    min-width: 0;
}

a {
    color: var(--primary);
}

/* ===== 거래 모바일 카드 리스트 ===== */
.tx-cards {
    display: none;
}

.tx-card {
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    padding: 12px 14px;
    min-width: 0;
    overflow: hidden;
}

.tx-card .top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

/* flex 항목은 min-width:0 없으면 내용 폭 이하로 줄어들지 않아 말줄임이 동작하지 않음 */
.tx-card .title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tx-card .title .date {
    color: var(--muted);
    font-size: 12px;
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}

.tx-card .title .cat {
    font-weight: 600;
}

.tx-card .amt {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.tx-card .memo {
    color: var(--text-sub);
    font-size: 13px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tx-card .meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.tx-card .meta .badge {
    font-size: 11px;
    padding: 1px 7px;
}

.tx-card .meta .spacer {
    flex: 1;
}

.tx-card .meta form {
    margin: 0;
}

.tx-card .meta button {
    padding: 4px 10px;
    font-size: 12px;
}

@media (max-width: 640px) {
    .tx-table {
        display: none;
    }

    .tx-cards {
        display: grid;
        gap: 10px;
    }
}

@media (max-width: 560px) {
    .card {
        padding: 18px;
        border-radius: 16px;
    }

    .hero-value {
        font-size: 26px;
    }

    .summary-item .value {
        font-size: 18px;
    }

    .bar-row {
        grid-template-columns: minmax(0, auto) minmax(24px, 1fr) auto;
        gap: 8px;
    }

    /* 폰에서는 이름을 더 줄여서라도 금액이 다 보이게 */
    .bar-row .bar-label { max-width: 84px; }
}

/* ===== 반응형 내비: 데스크톱 상단 / 모바일 하단 탭 ===== */
.nav-user {
    color: var(--text-sub);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 10px;
    white-space: nowrap;
}

.nav-user:hover {
    background: var(--bg);
}

.tabbar {
    display: none;
}

@media (max-width: 640px) {
    .nav .nav-link, .nav form {
        display: none;
    }

    .nav-inner {
        justify-content: space-between;
    }

    body {
        padding-bottom: 76px;
    }

    .tabbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--line-strong);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        z-index: 20;
    }

    .tabbar a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        text-decoration: none;
        color: var(--muted);
        font-size: 11px;
        font-weight: 600;
        padding: 4px 0;
    }

    .tabbar a .ico {
        font-size: 20px;
        line-height: 1;
    }

    .tabbar a.active {
        color: var(--primary);
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }

    .container {
        padding: 14px 12px 60px;
    }
}

/* ===== 모달(dialog) ===== */
dialog.modal {
    border: none;
    border-radius: 20px;
    padding: 0;
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100vh - 40px);
    box-shadow: 0 24px 60px rgba(64, 42, 32, 0.25);
    background: var(--card);
    color: var(--text);
}

dialog.modal::backdrop {
    background: rgba(64, 42, 32, 0.45);
    backdrop-filter: blur(2px);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px 0;
}

.modal-head h2 {
    margin: 0;
    font-size: 17px;
}

.modal-body {
    padding: 14px 20px 20px;
}

.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.modal-actions .right {
    display: flex;
    gap: 8px;
}

.btn-close {
    background: var(--bg);
    color: var(--text-sub);
    padding: 6px 10px;
    font-size: 13px;
}

.btn-add {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    font-size: 14px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.section-head h2 {
    margin: 0;
}

@media (max-width: 640px) {
    .fab {
        position: fixed;
        right: 16px;
        bottom: calc(84px + env(safe-area-inset-bottom));
        width: 56px;
        height: 56px;
        border-radius: 50%;
        font-size: 28px;
        line-height: 1;
        padding: 0;                 /* 좌우 패딩 때문에 ＋가 왼쫫으로 치우치던 문제 */
        justify-content: center;
        padding: 0;
        box-shadow: 0 10px 24px rgba(49, 130, 246, 0.4);
        z-index: 21;
    }

    .fab-label {
        display: none;
    }
}

/* ===== 날짜별 묶음 ===== */
.day-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 2px 6px;
    margin-top: 6px;
    border-bottom: 1px solid var(--line-strong);
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.day-head .sums {
    display: flex;
    gap: 10px;
    font-variant-numeric: tabular-nums;
}

.day-head .sums span {
    font-weight: 700;
}

.tx-list .tx-card {
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 10px 2px;
}

.tx-list .tx-card:last-child {
    border-bottom: none;
}

tr.day-row td {
    background: var(--bg);
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 10px;
}

/* ===== 접이식 카드 ===== */
details.card > summary {
    cursor: pointer;
    list-style: none;
    font-size: 17px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

/* 제목이 줄어들 수 있어야 오른쪽 화살표 자리가 남는다 (없으면 제목이 화살표를 밀어낸다) */
details.card > summary > * { min-width: 0; }

details.card > summary::after { flex: none; }

details.card > summary::-webkit-details-marker {
    display: none;
}

details.card > summary::after {
    content: "▾";
    color: var(--muted);
    font-size: 14px;
    transition: transform 0.15s;
    /* 회전(rotate)했을 때 글자 박스가 밖으로 삐져나가지 않도록 정사각형으로 고정 */
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1em;
    text-align: center;
}

details.card:not([open]) > summary::after {
    transform: rotate(-90deg);
}

details.card > summary .sub {
    font-size: 13px;
    color: var(--muted);
    font-weight: 400;
    margin-left: 8px;
}

details.card[open] > summary {
    margin-bottom: 14px;
}

/* ===== 마이페이지 ===== */
.family-list {
    display: grid;
    gap: 10px;
}

.family-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
}

.family-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-weak);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    flex: none;
}

.family-item .avatar.child {
    background: var(--planned-weak);
    color: var(--planned);
}

.family-item .info {
    flex: 1;
    min-width: 0;
}

.family-item .info .n {
    font-weight: 700;
}

.family-item .info .s {
    font-size: 13px;
    color: var(--muted);
}

.tool-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.tool-links a {
    display: block;
    padding: 14px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
}

.tool-links a small {
    display: block;
    color: var(--muted);
    font-weight: 400;
    font-size: 12.5px;
    margin-top: 2px;
}

/* ===== 모바일 마무리: 말줄임·접이식 제목 줄바꿈 ===== */
.tx-card .top .title {
    min-width: 0;
    flex: 1;
}

details.card > summary {
    flex-wrap: wrap;
    row-gap: 4px;
}

@media (max-width: 640px) {
    details.card > summary .sub {
        flex-basis: 100%;
        margin-left: 0;
    }

    .day-head {
        position: sticky;
        top: 56px;
        background: var(--card);
        z-index: 1;
    }
}

/* 긴 메모가 카드 폭을 밀어내지 않도록 (grid/flex 항목 min-width:auto 방지) */
.tx-cards {
    grid-template-columns: minmax(0, 1fr);
}

.tx-cards > *,
.tx-list,
.tx-card,
.tx-card .top,
.tx-card .meta {
    min-width: 0;
}

.tx-card .meta {
    flex-wrap: wrap;
}

/* Turbo 진행 표시줄 */
.turbo-progress-bar {
    height: 3px;
    background: var(--primary);
}

.badge.invest {
    background: var(--invest-weak);
    color: var(--invest);
}

/* 접이식 제목의 합계는 오른쪽 정렬 (숫자 우측 정렬 원칙) */
details.card > summary .sub {
    margin-left: auto;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

details.card > summary .sub b {
    font-weight: 700;
}

@media (max-width: 640px) {
    details.card > summary .sub {
        flex-basis: 100%;
        text-align: right;
    }
}

/* 가계부 카드 금액: 제목과 같은 크기로 (색으로 이미 구분되므로 크기 강조는 불필요) */
.tx-card .amt {
    font-size: 15px;
    font-weight: 700;
}

.day-head .sums {
    font-size: 12.5px;
}

/* ===== 페이지 가로 스크롤 금지 + 행동 버튼 줄바꿈 보장 ===== */
/* 가로 넘침은 clip으로 자른다. hidden을 쓰면 사파리가 body를 스크롤 상자로 취급해
   상단바의 position: sticky가 동작하지 않는다 (크롬은 뷰포트로 넘겨 멀쩡해서 개발 중엔 안 보였다) */
html, body {
    overflow-x: clip;
}

.container {
    overflow-x: clip;
}

.tx-card .meta {
    flex-wrap: wrap;
    row-gap: 6px;
}

.tx-card .meta form,
.tx-card .meta > button {
    flex: none;
}

@media (max-width: 640px) {
    /* 폰: 확정·수정 버튼은 항상 오른쪽 아래에 한 줄로 */
    .tx-card .meta .spacer {
        flex-basis: 100%;
        height: 0;
    }

    .tx-card .meta form,
    .tx-card .meta > button {
        margin-left: auto;
    }

    .tx-card .meta form + button {
        margin-left: 6px;
    }
}

/* ===== 탭바 라인 아이콘 ===== */
.tabbar a .ico svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tabbar a .ico {
    display: block;
    height: 22px;
}

/* ===== 모바일: 표 대신 카드, 남는 표는 줄바꿈 (가로 스크롤 0) ===== */
.asset-cards, .rule-cards {
    display: none;
}

.asset-card, .rule-card {
    border-bottom: 1px solid var(--line);
    padding: 10px 2px;
    min-width: 0;
}

.asset-card:last-child, .rule-card:last-child {
    border-bottom: none;
}

.asset-card .top, .rule-card .top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.asset-card .top a.plain, .rule-card .title {
    flex: 1;
    min-width: 0;
    font-weight: 700;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.asset-card .amt, .rule-card .amt {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.asset-card .meta, .rule-card .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
    min-width: 0;
}

.asset-card .editing-row {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
}

.asset-card.editing .editing-row {
    display: flex;
}

.asset-card.editing .js-edit {
    display: none;
}

@media (max-width: 640px) {
    .asset-table, .rule-table {
        display: none;
    }

    .asset-cards, .rule-cards {
        display: block;
    }

    .hide-m {
        display: none !important;
    }

    .table-wrap {
        overflow-x: visible;
    }

    td, th {
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: anywhere; /* 띄어쓰기 없는 긴 이름도 카드 폭 안에서 줄바꿈 */
        padding: 9px 6px;
        font-size: 13px;
    }

    td.num, th.num,
    td:first-child, th:first-child, /* 날짜 열 */
    td .badge {
        white-space: nowrap;
        overflow-wrap: normal;
    }

    table.compact td {
        padding: 8px 6px;
        font-size: 13px;
    }

    .tx-table {
        display: none;
    }
}

/* ===== 최신 앱 스타일 폴리시 ===== */
button {
    white-space: nowrap;
}

.asset-card .top a.plain {
    color: var(--text);
    text-decoration: none;
}

.asset-card .top a.plain:active {
    color: var(--primary);
}

/* 홈 히어로 */
.card.hero .label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.card.hero .hero-value {
    font-size: 34px;
    margin: 2px 0 0;
}

.chips {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 16px;
}

.chip {
    background: var(--bg);
    border-radius: 12px;
    padding: 10px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chip .k {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.chip .v {
    font-size: 14px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 접이식 제목 구조: 제목 | ▾  /  합계(오른쪽) */
details.card > summary {
    align-items: center;
}

details.card > summary .t {
    flex: 1;
    min-width: 0;
}

details.card > summary .t .hint {
    display: block;
    font-size: 12px;
    color: var(--muted);
    font-weight: 400;
}

details.card > summary::after {
    order: 1;
    margin-left: 8px;
}

details.card > summary .sub {
    order: 2;
    flex-basis: 100%;
    margin-left: 0;
    margin-top: 6px;
    text-align: right;
    font-size: 13px;
}

/* 상단 아바타 */
.avatar-sm {
    display: inline-flex;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-weak);
    color: var(--primary);
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    margin-right: 6px;
    vertical-align: middle;
}

.nav-user {
    display: inline-flex;
    align-items: center;
}

/* 정기 항목·자산 카드: 행동 버튼은 폰에서 오른쪽 한 줄 */
.rule-card .meta form,
.rule-card .meta > button,
.asset-card .meta > button {
    flex: none;
}

@media (max-width: 640px) {
    .nav-user-text {
        display: none;
    }

    .avatar-sm {
        margin-right: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--line-strong);
        border-radius: 16px;
        padding: 16px;
        margin-bottom: 12px;
    }

    .card.hero {
        border: none;
        background: linear-gradient(160deg, #ffffff 0%, #fff7f2 100%);
        box-shadow: var(--shadow);
    }

    .chips {
        grid-template-columns: repeat(2, 1fr);
    }

    .month-nav {
        margin: 2px 0 14px;
    }

    .rule-card .meta .spacer,
    .asset-card .meta .spacer {
        flex-basis: 100%;
        height: 0;
    }

    .rule-card .meta > button,
    .rule-card .meta form,
    .asset-card .meta > button {
        margin-left: auto;
    }

    .rule-card .meta > button + form {
        margin-left: 6px;
    }

    /* 모달 → 바텀시트 */
    dialog.modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 92vh;
        margin: auto 0 0;
        border-radius: 20px 20px 0 0;
        animation: sheet-up 0.22s ease-out;
    }

    dialog.modal .modal-body {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
        max-height: calc(92vh - 60px);
        overflow-y: auto;
    }

    dialog.modal .modal-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    dialog.modal .modal-actions .right {
        flex-direction: column-reverse;
    }

    dialog.modal .modal-actions button {
        width: 100%;
        padding: 13px;
    }

    @keyframes sheet-up {
        from { transform: translateY(24px); opacity: 0.6; }
        to { transform: translateY(0); opacity: 1; }
    }
}

@media (prefers-reduced-motion: reduce) {
    dialog.modal { animation: none; }
}

/* 카드 meta의 spacer: 데스크톱은 밀어내기, 폰은 줄바꿈 */
.tx-card .meta .spacer,
.rule-card .meta .spacer,
.asset-card .meta .spacer {
    flex: 1 1 auto;
}

@media (max-width: 640px) {
    .tx-card .meta .spacer,
    .rule-card .meta .spacer,
    .asset-card .meta .spacer {
        flex: 1 1 100%;
        height: 0;
    }
}

/* 접이식 제목 합계: 항목별 줄바꿈 (폭 넘침 방지) */
details.card > summary .sub.totals {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 2px 12px;
    white-space: nowrap;
}

details.card > summary .sub.totals .tot b {
    font-variant-numeric: tabular-nums;
}

/* 가계부 카드: 카테고리 라벨 */
.tx-card .meta .cat {
    color: var(--text-sub);
    font-weight: 600;
    background: var(--bg);
    border-radius: 6px;
    padding: 1px 7px;
    font-size: 12px;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 데스크톱 거래 표: 날짜 행은 한 칸으로(금액 열 폭을 키우지 않게), 내용 열은 남는 폭만 쓰고 말줄임 */
.tx-table tr.day-row .day-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.tx-table tr.day-row .sums {
    display: flex;
    gap: 10px;
    font-variant-numeric: tabular-nums;
}

.tx-table td.memo-cell {
    max-width: 0;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 중지된 정기 항목: 목록에는 남기되 흐리게 */
.rule-card.inactive .title, .rule-card.inactive .amt, .rule-card.inactive .meta > span,
.rule-table tr.inactive td { opacity: .55; }
.rule-card.inactive .badge, .rule-card.inactive .meta button, .rule-card.inactive .meta form { opacity: 1; }
button.ghost.primary { color: var(--primary); border-color: var(--primary); }

/* AI 재무 분석 */
.ai-card .ai-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.ai-card .ai-head h2 { margin: 0; }
.ai-card .ai-head form { margin: 0; }
.ai-sections { display: grid; gap: 10px; margin-top: 10px; }
@media (min-width: 761px) {
    .ai-sections { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
    .check-list { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
    /* 총평·실행 항목, 그리고 홀수로 남는 마지막 하나는 두 칸을 다 쓴다 (빈칸 방지) */
    .ai-section.wide, .check-item.wide { grid-column: 1 / -1; }
}
.ai-section, .check-item { border-radius: 14px; padding: 14px 16px; background: var(--bg); border: 1px solid transparent; min-width: 0; }
.ai-section.summary { background: linear-gradient(135deg, rgba(184, 83, 56, 0.09), rgba(184, 83, 56, 0.03)); border-color: rgba(184, 83, 56, 0.22); }
.ai-section.good { background: rgba(53, 128, 102, 0.08); border-color: rgba(53, 128, 102, 0.24); }
.ai-section.warn { background: rgba(176, 118, 26, 0.09); border-color: rgba(176, 118, 26, 0.26); }
.ai-section.todo { background: var(--card); border-color: var(--line); }
.ai-section.goal { background: rgba(111, 95, 196, 0.07); border-color: rgba(111, 95, 196, 0.24); }
.ai-section-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14.5px; margin-bottom: 8px; letter-spacing: -0.2px; }
.ai-icon { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 800; color: #fff; background: var(--muted); flex: none; }
.ai-section.summary .ai-icon { background: var(--primary); }
.ai-section.good .ai-icon { background: var(--good); }
.ai-section.warn .ai-icon { background: var(--planned); }
.ai-section.todo .ai-icon { background: var(--text); }
.ai-section.goal .ai-icon { background: var(--invest); }
.ai-p { margin: 0; font-size: 14px; line-height: 1.65; color: var(--text); }
.ai-p + .ai-p, .ai-p + .ai-list { margin-top: 6px; }
.ai-section.summary .ai-p { font-weight: 700; }
.ai-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 6px; }
.ai-list li { position: relative; padding-left: 16px; font-size: 14px; line-height: 1.65; color: var(--text); }
.ai-list li::before { content: ""; position: absolute; left: 2px; top: 10px; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .45; }
.ai-list.numbered { counter-reset: step; }
.ai-list.numbered li { padding-left: 30px; }
.ai-list.numbered li::before { content: counter(step); counter-increment: step; width: 22px; height: 22px; top: 2px; left: 0; border-radius: 50%; background: var(--text); color: #fff; opacity: 1; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* 월말 마감 루틴 알림 */
.card.reminder { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    border: 1px solid rgba(49, 130, 246, 0.35); background: rgba(49, 130, 246, 0.06); }
.reminder-text { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.reminder-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-link { display: inline-block; padding: 8px 14px; border-radius: 10px; background: var(--primary); color: #fff;
    font-weight: 700; font-size: 13.5px; text-decoration: none; }
.btn-link.done { background: var(--bg); color: var(--text-sub); }

/* 사진 인식 진행률 */
.ocr-actions { display: flex; align-items: center; gap: 12px; min-height: 42px; }
.progress-wrap { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.progress-bar { flex: 1; height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress-text { font-size: 13px; color: var(--text-sub); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 자산 갱신 미리보기(바텀시트 카드) */
dialog.modal.wide { width: min(760px, calc(100vw - 24px)); max-width: 760px; }
.sync-cards { display: grid; gap: 10px; }
@media (min-width: 641px) { .sync-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.sync-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.sync-card.changed { border-color: rgba(49, 130, 246, 0.5); background: rgba(49, 130, 246, 0.04); }
.sync-card.unchanged { opacity: .7; }
.sync-card .top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sync-card .top .pick { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.sync-card .top .title { flex: 1; font-weight: 700; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-card .line { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; min-width: 0; }
.sync-card .line .k { color: var(--muted); flex: none; width: 52px; }
.sync-card .line .v { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sync-card .link-select { width: 100%; font-size: 13px; padding: 6px 8px; }
.sync-card .amt-input { width: 130px; text-align: right; font-size: 14px; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.sync-card select.mini { font-size: 13px; padding: 6px 8px; flex: 1; min-width: 0; }

/* 미리보기 시트: hidden 우선, 헤더·하단 버튼 고정 */
.sync-card .line[hidden] { display: none; }
dialog.modal.wide .modal-head { position: sticky; top: 0; background: var(--card); z-index: 2; }
dialog.modal.wide .modal-actions { position: sticky; bottom: 0; background: var(--card); padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); z-index: 2; }
@media (max-width: 640px) {
    /* iOS 사파리: vh는 주소창·툴바를 포함해 실제 보이는 영역보다 커서 시트가 잘림 → dvh(실표시 영역) 사용 */
    dialog.modal.wide[open] {
        display: flex; flex-direction: column;
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        width: 100%; max-width: 100%; margin: 0;
        height: auto; max-height: 92vh; max-height: 92dvh;
        overflow: hidden;
    }
    /* 본문은 내용 높이만큼 차지하고, 시트 높이를 넘칠 때만 줄어들어 스크롤 (flex:1 + overflow는 0으로 접힘) */
    dialog.modal.wide .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; max-height: none; }
    dialog.modal.wide .modal-head { position: static; flex: none; }
    /* 반영 버튼은 본문 스크롤 안에서 바닥에 고정 */
    dialog.modal.wide .modal-actions { position: sticky; bottom: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

tr.total-row td { border-top: 2px solid var(--line); border-bottom: none; font-weight: 700; }

/* 시트가 열려 있는 동안 뒤 페이지 스크롤 잠금 (iOS 사파리) */
html.modal-open, html.modal-open body { overflow: hidden; }

/* 폰에서는 하단 고정 영역을 반영 버튼 하나로 간결하게 (안내 문구·중복 닫기 숨김) */
@media (max-width: 640px) {
    dialog.modal.wide .modal-actions > .muted, dialog.modal.wide .modal-actions .right .ghost { display: none; }
}
.sync-card input.name-input { width: 100%; font-size: 13px; padding: 6px 8px; }
.sync-card .line .k { width: 62px; }

/* 자산 소유자 탭 */
.owner-tabs { display: flex; justify-content: center; gap: 6px; margin: 0 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.owner-tabs::-webkit-scrollbar { display: none; }
/* 탭이 가로를 고르게 나눠 갖도록 (오른쪽에 어정쩡한 여백이 남지 않게) */
.owner-tabs a { flex: 1 1 0; min-width: 54px; max-width: 120px; text-align: center; padding: 8px 10px;
    border-radius: 999px; background: var(--card); border: 1px solid var(--line);
    color: var(--text-sub); font-weight: 700; font-size: 13.5px; text-decoration: none; white-space: nowrap; }
.owner-tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.ghost-link { font-size: 12.5px; color: var(--primary); text-decoration: none; font-weight: 600; }

/* 자산 목록 인라인 수정: 이름 + 금액 */
.asset-row .name-edit { min-width: 160px; font-size: 14px; padding: 8px 10px; }
.asset-card .edit-form { display: flex; flex-wrap: wrap; gap: 6px; }
.asset-card .edit-form .name-edit { flex: 1 1 100%; }
.asset-table .asset-row .name-edit { width: 100%; max-width: 240px; }

/* 상세 페이지 카드: 보기/수정 전환 */
.toggle-card .edit { display: none; }
.toggle-card.editing .edit { display: flex; }
.toggle-card.editing form.stack.edit { display: flex; flex-direction: column; }
.toggle-card.editing .view { display: none; }

/* 보유 종목 행: 수정 클릭 시에만 입력·삭제 */
.holding-row .edit { display: none; }
.holding-row.editing .edit { display: inline-flex; gap: 6px; align-items: center; }
.holding-row.editing input.edit { display: inline-block; }
.holding-row.editing .view { display: none; }
#holdingAddForm[hidden] { display: none; }

/* 라벨-값 줄 (상세·마이페이지) */
.kv-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
.kv-line:last-of-type { border-bottom: none; }
.kv-line > .muted:first-child { flex: none; width: 88px; font-size: 13px; }

/* 마이페이지 프로필 */
.profile { display: flex; align-items: center; gap: 14px; padding: 6px 0 2px; }
.avatar-lg { width: 56px; height: 56px; border-radius: 50%; background: var(--primary-soft, rgba(49, 130, 246, 0.12)); color: var(--primary);
    display: inline-flex; align-items: center; justify-content: center; font-family: 'Jua', 'Pretendard Variable', sans-serif; font-size: 24px; flex: none; }
.profile-name { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; display: flex; align-items: center; gap: 8px; }
.profile-body .muted { margin-top: 2px; font-size: 13px; }

/* ===== 입력 팝업 디자인 (거래·정기 항목) ===== */
.tx-form { gap: 14px; }
.segmented { display: flex; gap: 6px; }
.segmented .seg { flex: 1; position: relative; }
.segmented .seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented .seg span { display: block; text-align: center; padding: 11px 6px; border-radius: 12px; border: 1.5px solid var(--line-strong);
    font-weight: 700; font-size: 14px; color: var(--text-sub); background: var(--card); cursor: pointer; transition: all .15s; }
.segmented .seg input:checked + span { color: #fff; background: var(--text); border-color: var(--text); }
.segmented .seg.expense input:checked + span { background: var(--expense); border-color: var(--expense); }
.segmented .seg.income input:checked + span { background: var(--primary); border-color: var(--primary); }
.segmented .seg.invest input:checked + span { background: var(--invest); border-color: var(--invest); }
.segmented .seg.withdraw input:checked + span { background: var(--good); border-color: var(--good); }
.segmented.small .seg span { padding: 10px 6px; font-size: 13.5px; }
.seg-hint { margin: -6px 0 0; font-size: 12.5px; line-height: 1.5; }
.amount-wrap { display: flex; align-items: center; gap: 8px; }
.amount-wrap input { font-size: 24px; font-weight: 800; text-align: right; letter-spacing: -0.5px; padding: 12px 14px; font-variant-numeric: tabular-nums; }
.amount-wrap .unit { font-weight: 700; color: var(--text-sub); flex: none; }
.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field .muted { font-weight: 500; font-size: 12px; }
.form-note { margin: -4px 0 0; font-size: 12.5px; line-height: 1.55; }
.field[hidden] { display: none; }
@media (max-width: 640px) {
    .form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 자산 상세 히어로 */
.detail-hero-top { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-title { margin: 10px 0 2px; font-size: 20px; letter-spacing: -0.3px; }
.detail-meta { font-size: 12.5px; margin-top: 4px; }
.card.hero.detail-hero .hero-value { font-size: 30px; }

/* 팝업 입력: 금액은 다른 칸과 같은 크기, 유형 버튼은 작게 */
.amount-wrap input { font-size: 16px; font-weight: 700; padding: 11px 14px; }
.segmented .seg span { padding: 8px 6px; font-size: 13.5px; border-radius: 10px; }
.segmented.small .seg span { padding: 8px 6px; }

/* 자산 상세 한 카드 */
.toggle-block .edit { display: none; }
.toggle-block.editing .edit { display: flex; }
.toggle-block.editing form.stack.edit { flex-direction: column; }
.toggle-block.editing .view { display: none; }
.amount-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.amount-line .hero-value { margin: 0; }
.info-block { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.info-lines .kv-line { padding: 6px 0; border-bottom: none; }
.info-lines .kv-line .spacer { flex: 1; }
.detail-hero .inline-form { margin-top: 6px; }
.nav-user .avatar-sm { margin-right: 0; }

/* ===== 목록 카드 2줄 구조: 배지 줄 + 같은 줄 오른쪽에 동작 버튼 ===== */
.tx-card .meta, .rule-card .meta, .asset-card .meta { flex-wrap: nowrap; align-items: center; gap: 8px; }
.meta .badges { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; overflow: hidden; white-space: nowrap;
    mask-image: linear-gradient(90deg, #000 88%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); }
.meta .badges > * { flex: none; }
.meta .actions { display: flex; align-items: center; gap: 6px; flex: none; }
.meta .actions form { margin: 0; display: inline; }
.meta .actions button { padding: 5px 10px; font-size: 12px; }

/* 커스텀 파일 선택 */
.file-pick { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 8px; border: 1.5px dashed var(--line-strong); border-radius: 12px; background: var(--bg); position: relative; }
.file-pick input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; padding: 0; border: 0; }
.file-pick-btn { padding: 8px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 700; font-size: 13.5px; color: var(--text); flex: none; }
.file-count { font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-wrap[hidden] { display: none; }
@media (max-width: 640px) { .form-row.ocr-row { grid-template-columns: 1fr; } }

.hero-add { margin-top: 12px; display: inline-flex; align-items: center; gap: 4px; }
@media (max-width: 640px) { .hero-add { width: 100%; justify-content: center; } }

/* 카테고리 관리 */
.cat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cat-title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-title { margin: 0; font-size: 16px; }
.danger-text { color: var(--expense); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-item { display: inline-flex; align-items: center; gap: 4px; padding: 5px 6px 5px 11px; border-radius: 999px; background: var(--bg); font-size: 13px; font-weight: 600; }
.chip-item form { margin: 0; display: inline; }
.chip-x { padding: 0 6px; background: transparent; color: var(--muted); font-size: 15px; line-height: 1; border-radius: 50%; }
.chip-x:hover { background: var(--expense-weak); color: var(--expense); }
.tool-links a small { display: block; }

/* 유형 배지 색상: 지출 빨강 · 수입 파랑 · 투자 보라 · 회수 초록 */
.badge.income { background: var(--primary-weak); color: var(--primary); }
.badge.withdraw { background: var(--good-weak); color: var(--good); }

/* 가계부 필터 바 */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 4px 0 12px; }
.filter-bar select { width: auto; flex: 1 1 120px; min-width: 0; padding: 8px 10px; font-size: 13.5px; border-radius: 10px; }
.filter-bar .ghost-link { flex: none; }
.owner-tabs { margin-bottom: 12px; }
.filter-bar { margin: 10px 0 14px; }
.filter-bar select { flex: 1 1 28%; }
@media (max-width: 640px) { .filter-bar select { font-size: 13px; padding: 7px 8px; } .filter-bar .ghost-link { flex: 1 1 100%; text-align: right; } }

.check-line { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 1.5; }
.check-line input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }

/* 날짜 입력: iOS 사파리 기본 스타일 때문에 칸이 잘리던 문제 */
input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 46px;
    line-height: 1.2;
    text-align: left;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator { margin-left: auto; }
@media (max-width: 640px) {
    /* 날짜·상태는 좁으면 깨지므로 한 줄에 하나씩 */
    .form-row.two.date-row { grid-template-columns: 1fr; }
}

/* 보험 현황: 폰은 카드, 데스크톱은 표 */
.ins-cards { display: none; }
.ins-card { padding: 12px 0; border-bottom: 1px solid var(--line); }
.ins-card:last-of-type { border-bottom: none; }
.ins-card .top { display: flex; align-items: baseline; gap: 10px; }
.ins-card .top .title { flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; line-height: 1.4; word-break: keep-all; overflow-wrap: anywhere; }
.ins-card .top .amt { flex: none; font-weight: 800; font-variant-numeric: tabular-nums; }
.ins-card .meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.ins-total { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
    margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--line); font-size: 13.5px; }
@media (max-width: 640px) {
    .ins-cards { display: block; }
    .ins-table { display: none; }
    /* 저축성 보험 표는 이름이 길어 칸이 벌어지므로 폭을 눌러 준다 */
}

/* ===== 진행 중 표시 (저장·삭제·확정 등) ===== */
button.loading { color: transparent !important; position: relative; pointer-events: none; opacity: 1; }
button.loading::after {
    content: ""; position: absolute; top: 50%; left: 50%; width: 15px; height: 15px; margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.45); border-top-color: #fff; border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
button.ghost.loading::after, button.small.ghost.loading::after {
    border-color: rgba(107, 118, 132, 0.35); border-top-color: var(--text-sub);
}
button.danger.loading::after { border-color: rgba(201, 59, 82, 0.35); border-top-color: var(--expense); }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* 팝업 버튼: 취소 없이 삭제·저장을 나눠 갖는다 */
.modal-actions.split { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions.split > button { flex: 1; }
.modal-actions.split > button[hidden] { display: none; }
.modal-head .head-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.modal-head .head-actions .ghost-link { white-space: nowrap; }

/* 카테고리 관리: 제목 줄과 버튼 줄 정렬 */
.cat-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.cat-title-wrap { flex: 1; min-width: 0; }
.cat-title-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.cat-title-line .cat-title { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-title-line .sub { flex: none; }
.cat-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.cat-actions form { margin: 0; }
.cat-head.editing .cat-actions { display: none; }

/* 저축성 보험 카드: 제목이 링크라 색이 죽지 않게 */
.ins-card .top a.title { color: var(--text); text-decoration: none; }
.ins-card .top a.title:hover { text-decoration: underline; }
.ins-card .meta .actions .ghost-link { padding: 4px 2px; }


/* ===== 분석: 핵심 지표 그리드 ===== */
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
@media (max-width: 640px) { .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.metric { background: var(--bg); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.metric .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric .v { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; margin-top: 2px; font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .s { font-size: 11.5px; color: var(--muted); margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== 분석: 자동 점검 목록 (AI 리포트와 한 카드) ===== */
.check-list { display: grid; gap: 10px; margin: 12px 0 0; }
.check-item.warn { background: rgba(176, 118, 26, 0.09); border-color: rgba(176, 118, 26, 0.26); }
.check-item.good { background: rgba(53, 128, 102, 0.08); border-color: rgba(53, 128, 102, 0.24); }
.check-item.warn .ai-icon { background: var(--planned); }
.check-item.good .ai-icon { background: var(--good); }
.check-item.info .ai-icon { background: var(--primary); }

.ai-empty { margin-top: 12px; padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--line-strong); }
.ai-sections { margin-top: 14px; }
.ai-section.invest { background: rgba(184, 83, 56, 0.06); border-color: rgba(184, 83, 56, 0.22); }
.ai-section.invest .ai-icon { background: var(--primary); }
.ai-disclaimer { margin-top: 12px; font-size: 12px; line-height: 1.5; }

.bar-fill.good { background: var(--good); }
.bar-fill.pension { background: var(--invest); }

.ai-section.tax { background: rgba(62, 143, 140, 0.09); border-color: rgba(62, 143, 140, 0.24); }
.ai-section.tax .ai-icon { background: var(--teal); }
.ai-section.risk { background: rgba(110, 98, 89, 0.07); border-color: rgba(110, 98, 89, 0.20); }
.ai-section.risk .ai-icon { background: var(--slate); }

/* ===== 분석: 지난달 지출 변화 ===== */
.shift-total { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
    margin-top: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.shift-total .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.shift-total .value { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }
.shift-delta { font-size: 14px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.shift-delta.up { color: var(--expense); }
.shift-delta.down { color: var(--good); }
.shift-delta .pct { font-size: 12.5px; font-weight: 600; opacity: 0.8; }

.shift-list { margin-top: 10px; }
.shift-row { display: grid; grid-template-columns: 84px 1fr 96px 62px; align-items: center; gap: 10px; padding: 7px 0; }
.shift-cat { font-size: 13.5px; font-weight: 600; color: var(--text-sub);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shift-track { position: relative; height: 12px; background: var(--bg); border-radius: 6px; }
.shift-mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line-strong); }
.shift-bar { position: absolute; top: 0; bottom: 0; border-radius: 6px; min-width: 3px; }
.shift-bar.up { left: 50%; background: var(--expense); opacity: 0.85; }
.shift-bar.down { right: 50%; background: var(--good); opacity: 0.8; }
.shift-amt { font-size: 13.5px; font-weight: 700; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.shift-diff { font-size: 12.5px; font-weight: 700; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.shift-diff.up { color: var(--expense); }
.shift-diff.down { color: var(--good); }

@media (max-width: 640px) {
    .shift-row { grid-template-columns: 68px 1fr 78px 54px; gap: 7px; }
    .shift-cat { font-size: 12.5px; }
    .shift-amt { font-size: 12.5px; }
    .shift-diff { font-size: 11.5px; }
}

/* ===== 분석: 목표 진행률 ===== */
.goal-list { display: grid; gap: 14px; margin-top: 12px; }
@media (min-width: 761px) { .goal-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; } }
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.goal-name { font-size: 14px; font-weight: 700; }
.goal-pct { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.goal-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; margin-top: 5px;
    font-size: 12px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.goal-foot span { white-space: nowrap; }
.goal-note { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.5; }

/* ===== 금액 가리기 (홍보용 캡처 모드) ===== */
.nav-privacy {
    background: none;
    border: 0;
    padding: 6px;
    border-radius: 10px;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    flex: none;
}
.nav-privacy:hover { background: var(--bg); color: var(--text-sub); }
.nav-privacy svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7;
    stroke-linecap: round; stroke-linejoin: round; }
.nav-privacy .ico-eye-off { display: none; }
html.privacy .nav-privacy { color: var(--primary); background: var(--primary-weak); }
html.privacy .nav-privacy .ico-eye { display: none; }
html.privacy .nav-privacy .ico-eye-off { display: inline; }

.blur-money {
    filter: blur(5.5px);
    user-select: none;
    -webkit-user-select: none;
}
/* 입력칸에 적힌 금액도 함께 가린다 (고칠 때는 눌러서 잠깐 풀림) */
html.privacy input[name="amount"],
html.privacy input[name$="Amount"],
html.privacy input[inputmode="numeric"] { filter: blur(5px); }
html.privacy input:focus { filter: none; }


/* ===== 알림 설정 ===== */
.push-state { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 600; margin-top: 12px; }
.push-state .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.push-state .dot.on { background: var(--good); }
.push-state .dot.off { background: var(--muted); }
.push-state .dot.wait { background: var(--planned); }
.push-actions { display: flex; gap: 8px; margin-top: 10px; }
.push-hint { font-size: 12.5px; line-height: 1.55; margin-top: 8px; }

.device-list { display: grid; gap: 8px; margin-top: 12px; }
.device { display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 14px; border-radius: 12px; background: var(--bg); }
.device .t { font-size: 14px; font-weight: 700; }
.device .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pref-list { display: grid; gap: 8px; margin-top: 12px; }
@media (min-width: 761px) { .pref-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pref { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px;
    background: var(--bg); cursor: pointer; }
.pref input { margin-top: 2px; width: 18px; height: 18px; flex: none; accent-color: var(--primary); }
.pref .t { display: block; font-size: 14px; font-weight: 700; }
.pref .s { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.field .hint { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; margin-top: 4px; line-height: 1.5; }

/* 알림: 무엇이 막고 있는지 보여주는 안내 */
.push-guide { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--primary-weak); }
.push-guide .t { font-size: 13.5px; font-weight: 700; color: var(--primary); }
.push-guide ol { margin: 8px 0 0; padding-left: 20px; }
.push-guide li { font-size: 13px; line-height: 1.7; }
.push-env { margin-top: 10px; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
button:disabled { opacity: 0.5; cursor: default; }
.push-hint .ok { color: var(--good); font-weight: 600; }

/* 카드 알림 수집 — 발급한 열쇠는 길어서 줄바꿈이 되게 두고, 눈에 띄게 감싼다 */
.token-box { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 12px 14px;
    background: var(--primary-weak); border: 1px solid var(--line-strong); border-radius: 14px; }
.token-box code { flex: 1; font-size: 13px; line-height: 1.5; word-break: break-all; color: var(--text); }
.guide-steps { margin: 6px 0 12px; padding-left: 20px; font-size: 14px; line-height: 1.75; color: var(--text-sub); }

/* 방금 등록·수정한 거래: 어디 들어갔는지 눈에 띄게 한 번 빛나고 가라앉는다 */
.tx-card.focus, tr.focus > td { animation: tx-focus 2.4s ease-out 1; }
@keyframes tx-focus {
    0% { background: var(--primary-weak); box-shadow: 0 0 0 2px var(--primary-soft); }
    60% { background: var(--primary-weak); box-shadow: 0 0 0 2px var(--primary-soft); }
    100% { background: transparent; box-shadow: none; }
}

/* 상단 브랜드 옆 아이콘 — 홈 화면 아이콘과 같은 그림. 둥근 사각으로 잘라 작게 */
.nav-logo { width: 26px; height: 26px; border-radius: 8px; display: block; }

/* 마이페이지 분석 기준 요약 */
.profile-lines { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.8; color: var(--text-sub); }

/* 계정 삭제 카드: 눈에 띄되 평소엔 접혀 있다 */
.danger-card { border: 1px solid var(--expense-weak); }
.danger-card .t { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.danger-card hr.soft { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
button.danger { background: var(--expense); color: #fff; }

/* 카카오 로그인 버튼 — 카카오 브랜드 가이드 색(노랑 #FEE500 · 검정 글자) */
.kakao-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
    padding: 13px 16px; border-radius: 14px; background: #FEE500; color: #191919; font-weight: 700;
    font-size: 15px; text-decoration: none; }
.kakao-btn:hover { filter: brightness(0.97); }
/* 로그인 버튼과 카카오 사이의 "또는" — 양옆으로 선이 뻗는 형태 */
.auth-wrap .or { display: flex; align-items: center; gap: 12px; margin: 16px 0 14px;
    font-size: 12.5px; color: var(--muted); }
.auth-wrap .or::before, .auth-wrap .or::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }

/* 개인정보 처리방침 — 길어서 읽기 편하게 (본문 폭·줄간격을 넉넉히) */
.policy { max-width: 720px; }
.policy-head { text-align: center; padding: 24px 0 8px; }
.policy-head h1 { font-size: 22px; margin: 10px 0 4px; }
.policy h2 { font-size: 16px; margin: 0 0 12px; }
.policy h3 { font-size: 14px; margin: 18px 0 8px; color: var(--text-sub); }
.policy p { font-size: 14px; line-height: 1.8; color: var(--text-sub); margin: 0 0 10px; }
.policy ul { margin: 0 0 10px; padding-left: 20px; font-size: 14px; line-height: 1.9; color: var(--text-sub); }
.policy b { color: var(--text); }
.policy-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 4px 0 12px; }
.policy-table th, .policy-table td { text-align: left; vertical-align: top; padding: 10px 8px;
    border-bottom: 1px solid var(--line); line-height: 1.7; color: var(--text-sub); }
.policy-table th { font-weight: 700; color: var(--text); background: var(--bg); }

/* 카드 아래에 붙는 보충 설명 (대출 상환 분리 안내 등) */
.note-line { margin-top: 14px; padding: 12px 14px; background: var(--bg); border-radius: 12px; }
.note-line .t { font-size: 13.5px; font-weight: 600; color: var(--text); }
.note-line .s { font-size: 12.5px; color: var(--text-sub); line-height: 1.7; margin-top: 4px; }

/* 카테고리 관리의 "필수 지출" 토글 */
.essential-btn.on { color: var(--primary); border-color: var(--primary); background: var(--primary-weak); font-weight: 700; }

/* 앱 내려받기 목록 */
.app-list { display: grid; gap: 8px; margin-top: 12px; }
.app-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; text-decoration: none;
    border: 1px solid var(--line-strong); border-radius: 14px; background: var(--card); color: var(--text); }
.app-row:hover { border-color: var(--primary); }
.app-row .ico { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px;
    flex: none; border-radius: 11px; background: var(--primary-weak); color: var(--primary); }
.app-row .body { flex: 1; min-width: 0; }
.app-row .t { display: block; font-size: 14px; font-weight: 700; }
.app-row .s { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.app-row .size { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* 순자산 추이 그래프 — 표 위에 흐름만 먼저 보여 준다 */
.nw-chart { position: relative; margin: 4px 0 16px; }
.nw-chart svg { display: block; width: 100%; height: 150px; overflow: visible; }
.nw-chart .area { fill: var(--primary-weak); }
.nw-chart .line { fill: none; stroke: var(--primary); stroke-width: 2.5;
    stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.nw-chart .head { fill: var(--primary); stroke: var(--card); stroke-width: 2.5; }
.nw-chart .axis { position: absolute; right: 0; font-size: 11px; color: var(--muted); }
.nw-chart .axis.top { top: -2px; }
.nw-chart .axis.bottom { bottom: 20px; }
.nw-chart .months { display: flex; justify-content: space-between; font-size: 11px;
    color: var(--muted); margin-top: 4px; }

/* 계정 삭제 카드 안쪽.
   .edit 는 원래 가로 배치(인라인 수정 폼들이 그렇게 쓴다)라, 폼 두 개가 나란히 찌그러졌다.
   이 카드만 세로로 쌓는다 */
.danger-card .danger-actions { flex-direction: column; gap: 18px; align-items: stretch; }
.danger-card .danger-actions > form { margin: 0; }
.danger-card hr.soft { width: 100%; margin: 0; }

/* 분석 기준 추천 — 빈 칸을 우리집 숫자로 채워 주는 안내 */
.suggest {
    background: var(--primary-weak);
    border-radius: 14px;
    padding: 14px 16px;
}

.suggest-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.suggest-top b {
    font-size: 14.5px;
    color: var(--primary);
}

.suggest-why {
    margin: 10px 0 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.suggest-why li {
    font-size: 13px;
    color: var(--text-sub);
    line-height: 1.55;
}

.suggest-why:empty {
    display: none;
}

.suggest-next {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(184, 83, 56, 0.18);
}

.suggest-next b {
    font-size: 13px;
    color: var(--primary);
}

.suggest-next ul {
    margin: 6px 0 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.suggest-next li {
    font-size: 12.5px;
    color: var(--text-sub);
    line-height: 1.55;
}

/* 1년치가 모였을 때만 나오는 비정기 지출 안내 */
.suggest-irregular {
    margin: 10px 0 0;
    padding: 10px 12px;
    background: var(--card);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-sub);
    line-height: 1.6;
}
