/* 가계부 (/mydesk/ledger · 다이어리 가계부 칸) - 접두사 lg-.  색은 토큰만.
   수입 · 지출 색은 차트 기본 팔레트(파랑 · 주황, 색약 검사 통과한 인접 쌍)에서 가져왔다.
   막대 · 점은 --lg-income / --lg-expense, 글자는 대비를 맞춘 -ink 를 쓴다. */

:root, html[data-theme="light"] {
  --lg-income: #2a78d6;
  --lg-expense: #eb6834;
  --lg-income-ink: #1c5cab;
  --lg-expense-ink: #b4461a;
}
html[data-theme="dark"] {
  --lg-income: #3987e5;
  --lg-expense: #d95926;
  --lg-income-ink: #86b6ef;
  --lg-expense-ink: #f29a6b;
}

.lg-page { padding-bottom: 56px; }

/* ---- 머리 · 탭 ---- */
.lg-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lg-header .mydesk-pill svg { width: 16px; height: 16px; }
.lg-tabs { display: inline-flex; gap: 4px; margin: 0 0 18px; padding: 4px; border: 1px solid var(--brand-border); border-radius: 999px; background: var(--brand-surface); }
.lg-tabs a { padding: 6px 16px; border-radius: 999px; color: var(--brand-text-secondary); font-size: 14px; font-weight: 500; text-decoration: none; transition: background-color var(--transition-fast), color var(--transition-fast); }
.lg-tabs a:hover { color: var(--brand-text-primary); text-decoration: none; }
.lg-tabs a.is-active { background: var(--mydesk-accent); color: var(--text-accent, var(--brand-accent)); font-weight: 600; }
html[data-theme="dark"] .lg-tabs a.is-active { background: color-mix(in srgb, var(--brand-accent) 18%, var(--brand-surface)); }

.lg-help { margin: 0 0 14px; color: var(--brand-text-muted); font-size: 13px; line-height: 1.6; }
.lg-help svg { vertical-align: -2px; }
.lg-empty-line { margin: 8px 0; color: var(--brand-text-muted); font-size: 13px; }

/* ---- 달 넘기기 ---- */
.lg-monthbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.lg-month-title { min-width: 8.5em; margin: 0; font-size: 20px; font-weight: 700; text-align: center; letter-spacing: -0.01em; }
.lg-today-link, .lg-stats-link { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--brand-border); border-radius: 999px; background: var(--brand-surface); color: var(--brand-text-secondary); font-size: 13px; font-weight: 500; text-decoration: none; }
.lg-today-link:hover, .lg-stats-link:hover { border-color: var(--brand-border-strong); color: var(--brand-text-primary); text-decoration: none; }
.lg-stats-link { margin-left: auto; }

.lg-icon-btn { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--brand-text-muted); cursor: pointer; list-style: none; text-decoration: none; transition: background-color var(--transition-fast), color var(--transition-fast); }
.lg-icon-btn::-webkit-details-marker { display: none; }
.lg-icon-btn:hover { background: var(--brand-surface-muted); color: var(--brand-text-primary); text-decoration: none; }
.lg-icon-btn.is-danger:hover { background: color-mix(in srgb, var(--brand-danger) 10%, var(--brand-surface)); color: var(--brand-danger); }
.lg-icon-btn:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 1px; }

/* ---- 요약 카드 ---- */
.lg-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 18px; }
.lg-summary.is-five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.lg-kpi { display: grid; gap: 4px; align-content: start; padding: 16px 18px; border: 1px solid var(--brand-border); border-radius: 14px; background: var(--brand-surface); }
.lg-kpi-label { display: inline-flex; align-items: center; gap: 4px; color: var(--brand-text-secondary); font-size: 13px; font-weight: 600; }
.lg-kpi.is-income .lg-kpi-label svg { color: var(--lg-income); }
.lg-kpi.is-expense .lg-kpi-label svg { color: var(--lg-expense); }
/* 수입 · 지출 카드는 이름 앞 작은 점으로만 가른다(카드 모양은 cards.css 의 공통 모양). */
.lg-kpi.is-income .lg-kpi-label::before, .lg-kpi.is-expense .lg-kpi-label::before { content: ""; width: 8px; height: 8px; margin-right: 2px; border-radius: 50%; background: var(--lg-expense); }
.lg-kpi.is-income .lg-kpi-label::before { background: var(--lg-income); }
.lg-kpi.is-income .lg-kpi-label svg, .lg-kpi.is-expense .lg-kpi-label svg { display: none; }
.lg-kpi-value { color: var(--brand-text-primary); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.lg-kpi-value.is-minus { color: var(--brand-danger); }
.lg-kpi-value.is-muted { color: var(--brand-text-muted); font-size: 16px; }
.lg-kpi small { color: var(--brand-text-muted); font-size: 12px; }

/* ---- 화면 짜임 ---- */
.lg-layout { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
.lg-add { position: sticky; top: 88px; padding: 18px; }
.lg-add h2, .lg-edit h2 { margin: 0 0 12px; font-size: 16px; }
.lg-edit { max-width: 560px; padding: 20px; }

/* ---- 폼 ---- */
.lg-form { display: grid; gap: 12px; }
.lg-field { display: grid; gap: 6px; margin: 0; }
.lg-field > span { color: var(--brand-text-secondary); font-size: 13px; font-weight: 600; }
.lg-field > span small { color: var(--brand-text-muted); font-weight: 400; }
.lg-field input, .lg-field select, .lg-select, .lg-diary-row input { width: 100%; min-width: 0; box-sizing: border-box; }
.lg-field input[data-lg-amount], .lg-diary-row input[data-lg-amount] { font-variant-numeric: tabular-nums; text-align: right; }
.lg-iconrow { position: relative; display: flex; align-items: stretch; gap: 8px; }
.lg-iconrow > input { flex: 1; min-width: 0; }
.lg-submit { justify-content: center; width: 100%; }
.lg-form-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.lg-delete-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--brand-border); }
.lg-icon-pick .desk-icon-panel { min-width: min(320px, 80vw); }

.lg-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border: 1px solid var(--brand-border); border-radius: 999px; background: var(--brand-bg); }
.lg-seg label { position: relative; cursor: pointer; }
.lg-seg input { position: absolute; opacity: 0; pointer-events: none; }
.lg-seg span { display: flex; justify-content: center; padding: 6px 10px; border-radius: 999px; color: var(--brand-text-secondary); font-size: 14px; font-weight: 600; transition: background-color var(--transition-fast), color var(--transition-fast); }
.lg-seg input:checked + span { background: var(--brand-surface); color: var(--brand-text-primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.lg-seg .is-expense input:checked + span { box-shadow: inset 0 -2px 0 var(--lg-expense), 0 1px 3px rgba(15, 23, 42, .12); }
.lg-seg .is-income input:checked + span { box-shadow: inset 0 -2px 0 var(--lg-income), 0 1px 3px rgba(15, 23, 42, .12); }
.lg-seg input:focus-visible + span { outline: 2px solid var(--brand-accent); outline-offset: 1px; }

.lg-settings { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--brand-border); }
.lg-settings > summary { display: inline-flex; align-items: center; gap: 6px; color: var(--brand-text-secondary); font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; }
.lg-settings > summary::-webkit-details-marker { display: none; }
.lg-settings > summary:hover { color: var(--brand-text-primary); }
.lg-settings[open] > summary { margin-bottom: 12px; }

.lg-form-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.lg-check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13.5px; }
.lg-check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--brand-accent); }
.lg-check span { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--brand-text-primary); font-weight: 600; }
.lg-check small { color: var(--brand-text-muted); font-weight: 400; }
.lg-import { display: grid; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--brand-border); }
.lg-import .lg-help { margin: 0; }
.lg-summary.is-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lg-upcoming { border-style: dashed; background: color-mix(in srgb, var(--brand-surface) 70%, var(--brand-bg)); }
.lg-upcoming .lg-day-head h3 { display: inline-flex; align-items: center; gap: 6px; }
.lg-row.is-upcoming .lg-ico, .lg-row.is-upcoming .lg-amount { opacity: .7; }
.lg-row.is-paused { opacity: .55; }
.lg-tag { display: inline-flex; margin-left: 4px; padding: 0 7px; border: 1px solid var(--brand-border); border-radius: 999px; color: var(--brand-text-muted); font-size: 11px; font-weight: 600; vertical-align: 2px; }

/* ---- 날짜별 내역 ---- */
.lg-days { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }   /* 긴 메모가 목록 전체를 넓히던 것 */
.lg-day { padding: 12px 16px 6px; scroll-margin-top: 96px; }
.lg-day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--brand-border); }
.lg-day-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.lg-day-head h3 span { margin-left: 4px; color: var(--brand-text-muted); font-weight: 500; }
.lg-day-head p { display: flex; gap: 10px; margin: 0; font-size: 13px; }

.lg-rows { margin: 0; padding: 0; list-style: none; }
.lg-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid color-mix(in srgb, var(--brand-border) 70%, transparent); }
.lg-row:last-child { border-bottom: 0; }
.lg-row-main { flex: 1; min-width: 0; }
.lg-row-title { margin: 0; overflow: hidden; color: var(--brand-text-primary); font-size: 14.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.lg-row-meta { margin: 2px 0 0; color: var(--brand-text-muted); font-size: 12.5px; }
.lg-row-meta a { display: inline-flex; align-items: center; gap: 3px; color: var(--brand-text-secondary); }
.lg-row-actions { display: inline-flex; align-items: center; gap: 2px; }
.lg-row-actions form { display: contents; margin: 0; }

.lg-ico { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 11px; }
.lg-ico.is-expense { background: color-mix(in srgb, var(--lg-expense) 13%, var(--brand-surface)); color: var(--lg-expense-ink); }
.lg-ico.is-income { background: color-mix(in srgb, var(--lg-income) 13%, var(--brand-surface)); color: var(--lg-income-ink); }
.lg-amount { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.lg-amount.is-expense { color: var(--lg-expense-ink); }
.lg-amount.is-income { color: var(--lg-income-ink); }
.lg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.lg-dot.is-expense { background: var(--lg-expense); }
.lg-dot.is-income { background: var(--lg-income); }

.lg-empty { display: grid; justify-items: center; gap: 6px; padding: 40px 20px; text-align: center; }
.lg-empty h3 { margin: 6px 0 0; font-size: 16px; }
.lg-empty p { margin: 0; color: var(--brand-text-muted); font-size: 13.5px; }
.lg-empty-ico { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand-surface-muted); color: var(--brand-text-muted); }

/* ---- 카테고리 관리 ---- */
.lg-cat-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.lg-cat-kind { display: grid; gap: 10px; scroll-margin-top: 96px; }
.lg-cat-kind-title { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 16px; }
.lg-cat { position: relative; padding: 12px 14px; }
/* 고치기 창을 연 카드를 위로 - 안 그러면 아래 카드가 창과 아이콘 판을 덮는다. */
.lg-cat:has(details[open]), .lg-cat-new:has(details[open]), .lg-cat-new[open], .lg-add:has(.lg-icon-pick[open]) { z-index: 20; }
.lg-cat-head { position: relative; display: flex; align-items: center; gap: 10px; }
.lg-cat-head h3 { flex: 1; margin: 0; font-size: 15px; }
.lg-cat-edit { position: static; }
.lg-cat-edit > summary { list-style: none; }
.lg-cat-edit > summary::-webkit-details-marker { display: none; }
.lg-cat-edit[open] > .lg-cat-form { position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 5; padding: 12px; border: 1px solid var(--brand-border); border-radius: 12px; background: var(--brand-surface); box-shadow: 0 10px 30px rgba(15, 23, 42, .12); }
.lg-cat-form { display: grid; gap: 10px; }
.lg-subcats { position: relative; display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.lg-subcat { display: inline-flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; border: 1px solid var(--brand-border); border-radius: 999px; background: var(--brand-bg); font-size: 13px; }
.lg-subcat .lg-icon-btn { width: 24px; height: 24px; border-radius: 999px; }
.lg-subcat-ico { display: inline-flex; color: var(--brand-text-muted); }
.lg-subcat-name { color: var(--brand-text-primary); font-weight: 500; }
.lg-subcat.is-add { padding: 0; border-style: dashed; background: transparent; }
.lg-subcat-add { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; color: var(--brand-text-secondary); cursor: pointer; font-size: 13px; font-weight: 500; }
.lg-subcat-add:hover { color: var(--text-accent, var(--brand-accent)); }
.lg-cat-new { position: relative; padding: 12px 14px; border-style: dashed; }
.lg-cat-new > summary { display: inline-flex; align-items: center; gap: 6px; color: var(--brand-text-secondary); cursor: pointer; font-size: 14px; font-weight: 600; list-style: none; }
.lg-cat-new > summary::-webkit-details-marker { display: none; }
.lg-cat-new[open] > summary { margin-bottom: 10px; }

/* ---- 다이어리 가계부 칸 ---- */
.lg-diary { border: 1px solid var(--brand-border); border-radius: 12px; background: var(--brand-surface); }
.lg-diary-summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; list-style: none; }
.lg-diary-summary::-webkit-details-marker { display: none; }
.lg-diary-summary .lg-ico { width: 30px; height: 30px; border-radius: 9px; }
.lg-diary-summary strong { font-size: 14px; }
.lg-diary-summary small { flex: 1; color: var(--brand-text-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.lg-diary-chevron { display: inline-flex; color: var(--brand-text-muted); transition: transform var(--transition-fast); }
.lg-diary[open] .lg-diary-chevron { transform: rotate(180deg); }
.lg-diary-body { display: grid; gap: 10px; padding: 0 12px 12px; }
.lg-diary-rows { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.lg-diary-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr) minmax(0, 1.4fr) 32px; gap: 8px; align-items: center; }
.lg-diary-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lg-diary-link { color: var(--brand-text-secondary); font-size: 13px; }

.lg-entry-block { margin: 18px 0; padding: 14px 16px; border: 1px solid var(--brand-border); border-radius: 12px; background: var(--brand-bg); }
.lg-entry-block header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.lg-entry-block h2 { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 15px; }
.lg-entry-block header p { display: flex; gap: 10px; margin: 0; font-size: 13px; }
.lg-entry-block .lg-ico { width: 32px; height: 32px; }

/* ---- 통계 ---- */
.lg-chart { margin: 0 0 18px; padding: 16px 18px; }
.lg-chart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.lg-chart-head h2 { margin: 0; font-size: 15px; }
.lg-chart-total { color: var(--brand-text-secondary); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lg-stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.lg-stats-grid > .lg-chart { margin: 0 0 18px; }

.lg-legend { display: flex; gap: 14px; margin: 0; padding: 0; color: var(--brand-text-secondary); font-size: 13px; list-style: none; }
.lg-legend li { display: inline-flex; align-items: center; gap: 6px; }
.lg-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.lg-legend i.is-income { background: var(--lg-income); }
.lg-legend i.is-expense { background: var(--lg-expense); }

/* 세로 막대: 바닥선에 붙고 위쪽만 4px 둥글게.  막대 사이 2px. */
.lg-columns { display: flex; align-items: flex-end; gap: 6px; height: 176px; padding: 0 2px; border-bottom: 1px solid var(--brand-border-strong); background: repeating-linear-gradient(to top, transparent 0 34px, color-mix(in srgb, var(--brand-border) 60%, transparent) 34px 35px); }
.lg-col { position: relative; display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; height: 100%; cursor: default; }
.lg-col::before { content: ""; position: absolute; inset: 0 -3px; border-radius: 6px; }
.lg-col:hover::before { background: color-mix(in srgb, var(--brand-text-primary) 5%, transparent); }
.lg-col-bars { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 100%; }
.lg-bar { display: block; width: min(16px, 42%); height: max(var(--h), 0px); border-radius: 4px 4px 0 0; background: var(--lg-expense); }
.lg-bar.is-income { background: var(--lg-income); }
.lg-columns.is-daily { gap: 2px; height: 150px; }
.lg-columns.is-daily .lg-bar { width: min(14px, 80%); }
.lg-col.is-future .lg-bar { opacity: .35; }
.lg-col-label { position: absolute; bottom: -22px; color: var(--brand-text-muted); font-size: 11.5px; white-space: nowrap; }
.lg-col.is-current .lg-col-label { color: var(--brand-text-primary); font-weight: 700; }
.lg-col.is-weekend .lg-col-label { color: var(--brand-text-secondary); }
.lg-chart .lg-columns { margin-bottom: 30px; }

/* 가로 막대(카테고리 · 요일) */
.lg-break, .lg-hbars, .lg-break-sub { margin: 0; padding: 0; list-style: none; }
.lg-break-item details > summary { list-style: none; cursor: pointer; }
.lg-break-item details > summary::-webkit-details-marker { display: none; }
.lg-break-item details.is-flat > summary { cursor: default; }
.lg-break-row { display: grid; grid-template-columns: 30px minmax(4.5em, 8em) minmax(0, 1fr) 3.6em minmax(6.5em, auto); gap: 10px; align-items: center; padding: 6px 4px; border-radius: 8px; }
.lg-break-row:hover { background: var(--brand-surface-muted); }
.lg-break-row .lg-ico { width: 30px; height: 30px; border-radius: 9px; }
.lg-break-name { overflow: hidden; color: var(--brand-text-primary); font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.lg-break-track { display: block; height: 10px; border-radius: 0 999px 999px 0; background: var(--brand-surface-muted); }
.lg-break-bar { display: block; width: max(var(--w), 2px); height: 100%; border-radius: 0 999px 999px 0; background: var(--lg-expense); }
.lg-break-bar.is-income { background: var(--lg-income); }
.lg-break-bar.is-light { opacity: .6; }
.lg-break-share { color: var(--brand-text-secondary); font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; }
.lg-break-amount { color: var(--brand-text-primary); font-size: 13.5px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.lg-break-sub { margin: 2px 0 6px; padding-left: 18px; border-left: 2px solid var(--brand-border); margin-left: 18px; }
.lg-break-row.is-sub { grid-template-columns: 20px minmax(4em, 7em) minmax(0, 1fr) 3.6em minmax(6em, auto); }
.lg-break-row.is-sub .lg-break-name { font-weight: 500; font-size: 13px; }
.lg-break-row.is-sub .lg-break-track { height: 8px; }
.lg-hbars .lg-break-row { grid-template-columns: 2em minmax(0, 1fr) minmax(6.5em, auto); }
.lg-hbar-label { color: var(--brand-text-secondary); font-size: 13px; font-weight: 600; text-align: center; }

.lg-table-view { margin-top: 4px; }
.lg-table-view > summary { color: var(--brand-text-secondary); cursor: pointer; font-size: 13px; }
.lg-table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.lg-table th, .lg-table td { padding: 6px 8px; border-bottom: 1px solid var(--brand-border); text-align: right; }
.lg-table th[scope="row"], .lg-table thead th:first-child { text-align: left; }
.lg-table thead th { color: var(--brand-text-secondary); font-weight: 600; }

.lg-tip { position: fixed; z-index: 50; max-width: 240px; padding: 8px 10px; border: 1px solid var(--brand-border); border-radius: 10px; background: var(--brand-surface-elevated, var(--brand-surface)); box-shadow: 0 8px 24px rgba(15, 23, 42, .16); color: var(--brand-text-primary); font-size: 12.5px; font-variant-numeric: tabular-nums; line-height: 1.55; pointer-events: none; white-space: pre-line; }

/* ---- 좁은 화면 ---- */
@media (max-width: 1080px) {
  .lg-summary.is-five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .lg-layout, .lg-cat-columns, .lg-stats-grid { grid-template-columns: minmax(0, 1fr); }
  .lg-add { position: static; }
  .lg-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .lg-summary, .lg-summary.is-five { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .lg-kpi { padding: 12px; }
  .lg-kpi-value { font-size: 18px; }
  .lg-stats-link { margin-left: 0; }
  .lg-diary-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px; padding-bottom: 8px; border-bottom: 1px solid var(--brand-border); }
  .lg-diary-row select { grid-column: 1 / 3; grid-row: 1; }
  .lg-diary-row [data-lg-remove-row] { grid-column: 3; grid-row: 1; }
  .lg-diary-row input[data-lg-amount] { grid-column: 1; grid-row: 2; }
  .lg-diary-row input[name="ledger_memo"] { grid-column: 2 / 4; grid-row: 2; }
  .lg-break-row { grid-template-columns: 30px minmax(0, 1fr) minmax(5.5em, auto); }
  .lg-break-row .lg-break-track, .lg-break-row .lg-break-share { display: none; }
  .lg-break-row.is-sub { grid-template-columns: 20px minmax(0, 1fr) minmax(5em, auto); }
  .lg-columns { gap: 3px; }
  .lg-columns.is-pair .lg-col-label { font-size: 10px; }
  .lg-row-actions .lg-icon-btn { width: 28px; height: 28px; }
}

/* ---- 통계 카드: Market Snapshot(21st.dev) 모양 ----
   작은 이름 · 큰 숫자 + 변화량 · 점선 격자 위 선 · 마우스 십자선과 날짜 말풍선 ·
   아래 기간 칸(고른 칸 밑에 짧은 막대).  선은 초록(오르면) · 주황(내리면). */
.lg-viz { --ms-hair: color-mix(in srgb, var(--brand-text-primary) 6%, transparent); --ms-up: #1baf7a; --ms-down: var(--lg-expense); --ms-up-ink: #13845b; }
html[data-theme="dark"] .lg-viz { --ms-up: #199e70; --ms-up-ink: #4dbe95; }
.ms-grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 18px; margin: 0 0 18px; align-items: stretch; }
.ms-card { display: flex; flex-direction: column; overflow: hidden; min-width: 0; border: 1px solid var(--brand-border); border-radius: var(--card-radius, 16px); background: var(--brand-surface); }
.ms-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 8px; }
.ms-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--brand-text-muted); font-size: 12px; font-weight: 500; }
.ms-label i { width: 8px; height: 8px; border-radius: 50%; background: var(--lg-expense); }
.ms-label i.is-income { background: var(--lg-income); }
.ms-figure { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.ms-value { color: var(--brand-text-primary); font-size: 22px; font-weight: 600; letter-spacing: -0.035em; }
.ms-value.is-minus { color: var(--brand-danger); }
.ms-value.is-pop { animation: ms-pop .18s ease-out; }
@keyframes ms-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ms-delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ms-delta.is-good { color: var(--ms-up-ink); }
.ms-delta.is-bad { color: var(--lg-expense-ink); }
.ms-delta.is-flat { color: var(--brand-text-muted); font-weight: 500; }
.ms-tag { color: var(--brand-text-primary); font-size: 12px; font-weight: 600; }
.ms-chart { position: relative; flex: 1; padding: 0 12px; }
.ms-svg { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.ms-grid-line { stroke: var(--ms-hair); stroke-dasharray: 2 5; }
.ms-line { fill: none; stroke: var(--ms-up); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ms-line.is-down { stroke: var(--ms-down); }
.ms-cross { stroke: color-mix(in srgb, var(--brand-text-primary) 16%, transparent); }
.ms-dot { fill: var(--ms-up); stroke: var(--brand-surface); stroke-width: 1.5; }
.ms-line.is-down ~ .ms-dot { fill: var(--ms-down); }
.ms-tip { position: absolute; top: 0; z-index: 2; padding: 2px 6px; border: 1px solid var(--ms-hair); border-radius: 6px; background: var(--brand-surface); box-shadow: 0 6px 18px rgba(0, 0, 0, .18); color: var(--brand-text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; pointer-events: none; transform: translateX(-50%); white-space: nowrap; }
.ms-empty { margin: 24px 8px; color: var(--brand-text-muted); font-size: 13px; text-align: center; }
.ms-foot { padding: 12px 16px 16px; border-top: 1px solid var(--ms-hair); }
.ms-periods { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.ms-period { position: relative; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--brand-text-muted); cursor: pointer; font: inherit; font-size: 11.5px; font-weight: 600; transition: color var(--transition-fast), background-color var(--transition-fast); }
.ms-period:hover { color: var(--brand-text-primary); }
.ms-period.is-active { background: var(--ms-hair); color: var(--brand-text-primary); }
.ms-period.is-active::after { content: ""; position: absolute; right: 6px; bottom: -5px; left: 6px; height: 3px; border-radius: 3px 3px 0 0; background: var(--ms-up); }
.ms-period:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 1px; }
.ms-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; color: var(--brand-text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ms-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-content: start; }
.ms-kpi { display: grid; gap: 2px; align-content: start; padding: 18px 20px; border: 1px solid var(--brand-border); border-radius: var(--card-radius, 16px); background: var(--brand-surface); }
.ms-kpi .ms-delta { margin-top: 2px; }
.ms-kpis-note { grid-column: 1 / -1; margin: 0; color: var(--brand-text-muted); font-size: 12px; }
@media (max-width: 900px) {
  .ms-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .ms-kpis { grid-template-columns: minmax(0, 1fr); }
  .ms-period { padding: 6px 5px; font-size: 11px; }
}
