/* 앱 틀(sh-)과 화면(hm- 홈·기본 값, it- 항목, rc- 월간 기록, hs- 변동 이력, rl- 업데이트 내역)
 * 기준: docs/design-system.md §3·§5. 색·크기는 tokens.css 만 쓴다. */

/* ══ 앱 틀 ══════════════════════════════════════════════ */
.sh-app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sh-icon {
  width: 2rem;
  height: 2rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sh-side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  height: 100vh;
  padding: var(--sp-6) var(--sp-4);
  border-right: 1px solid var(--side-line);
  background: var(--side-bg);
  overflow-y: auto;
}

.sh-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3) var(--sp-6);
}

.sh-brand__logo { display: block; width: 3.2rem; height: 3.2rem; }
.sh-brand__name { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }

.sh-nav { display: flex; flex-direction: column; gap: var(--sp-1); }

.sh-nav__link,
.sh-side__btn {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 4.6rem;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--fs-base);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
}

.sh-nav__link:hover,
.sh-side__btn:hover {
  background: var(--side-active);
  color: var(--c-text);
  text-decoration: none;
}

.sh-nav__link[aria-current="page"] {
  background: var(--side-active);
  color: var(--c-brand-text);
  font-weight: 700;
}

.sh-side__foot {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: auto;
  padding-top: var(--sp-6);
}

.sh-side__btn { color: var(--c-text-3); font-size: var(--fs-sm); min-height: 4.4rem; }

.sh-mbar { display: none; }

.sh-main {
  min-width: 0;
  padding: var(--sp-8) var(--sp-10) 6rem;
}

.sh-head,
.sh-view {
  max-width: 120rem;
}

.sh-head { margin-bottom: var(--sp-6); }
.sh-head__date { color: var(--c-text-3); font-size: var(--fs-sm); }
.sh-head__title { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -0.03em; }

.sh-tabbar { display: none; }

@media (max-width: 760px) {
  .sh-app { display: block; }
  .sh-side { display: none; }

  .sh-mbar {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-2) 0 var(--sp-4);
    padding-top: max(var(--sp-2), env(safe-area-inset-top));
  }

  .sh-mbar .sh-brand__logo { width: 2.8rem; height: 2.8rem; }
  .sh-mbar .sh-brand__name { flex: 1; font-size: 1.7rem; }

  .sh-main { padding: var(--sp-3) var(--sp-4) calc(var(--tabbar-h) + var(--sp-8) + env(safe-area-inset-bottom)); }
  .sh-head { margin-bottom: var(--sp-4); }

  .sh-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 0 var(--sp-1) env(safe-area-inset-bottom);
    border-top: 1px solid var(--side-line);
    background: var(--side-bg);
  }

  .sh-tabbar__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    color: var(--c-text-3);
    font-size: var(--fs-xs);
    font-weight: 500;
    text-decoration: none;
  }

  .sh-tabbar__link:hover { text-decoration: none; }
  .sh-tabbar__link .sh-icon { width: 2.2rem; height: 2.2rem; }
  .sh-tabbar__link[aria-current="page"] { color: var(--c-brand-text); font-weight: 700; }
}

/* ══ 홈 ═════════════════════════════════════════════════ */
/* 카드 배치 — 데스크톱은 칸 이름(grid-area)으로 놓고, 모바일은 ui-deck 이 옆으로 넘기는 네 장이 된다 */
@media (min-width: 761px) {
  .hm-deck {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "main main"
      "flow next"
      "flow recent"
      "flow .";
    gap: var(--sp-5);
    align-items: start;
  }

  .hm-main { grid-area: main; }
  .hm-flow { grid-area: flow; }
  .hm-next { grid-area: next; }
  .hm-recent { grid-area: recent; }
}

.hm-top {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: var(--sp-5);
}

.hm-hero {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-8);
  border-radius: var(--r-xl);
  background: linear-gradient(135deg, var(--c-hero-from) 0%, var(--c-hero-to) 100%);
  color: var(--c-on-brand);
  box-shadow: var(--shadow-hero);
}

.hm-hero__label { font-size: var(--fs-base); opacity: 0.92; }

.hm-hero__amount {
  font-size: var(--fs-hero);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hm-hero__note { font-size: var(--fs-sm); opacity: 0.9; }

.hm-hero__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-2);
}

.hm-hero__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 3.8rem;
  padding: 0 var(--sp-4);
  border: 0;
  border-radius: var(--r-pill);
  background: var(--c-on-brand-soft);
  color: var(--c-on-brand);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
}

.hm-hero__chip:hover { text-decoration: none; background: rgba(0, 0, 0, 0.32); }

.hm-hero__box {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
}

.hm-hero__box .sh-icon { width: 1.3rem; height: 1.3rem; stroke-width: 3; visibility: hidden; }
.hm-hero__chip[aria-pressed="true"] { background: var(--c-on-brand); color: var(--c-hero-to); }
.hm-hero__chip[aria-pressed="true"] .hm-hero__box .sh-icon { visibility: visible; }

/* 기본 값 — 홈 맨 위. 고치면 바로 저장되고 아래 결과가 다시 계산된다 */
.hm-values { margin-bottom: var(--sp-5); }

.hm-values__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: var(--sp-4);
}

.hm-values__actions { display: flex; gap: var(--sp-2); }
.hm-values__sub { margin-left: var(--sp-1); color: var(--c-text-3); font-size: var(--fs-xs); font-weight: 500; }
.hm-values__hint { margin-top: var(--sp-3); }

/* 빠른 실행 — 항목 추가·가계부 저장. 데스크톱은 초록 카드 옆에 위아래로 */
.hm-quick {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
}

.hm-quick__btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 10rem;
  padding: var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-base);
  font-weight: 700;
  text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.hm-quick__btn:hover { background: var(--c-raised); border-color: var(--c-brand-strong); }

.hm-quick__icon {
  display: grid;
  place-items: center;
  width: 3.8rem;
  height: 3.8rem;
  border-radius: 50%;
}

.hm-quick__icon--add { background: var(--c-in-soft); color: var(--c-in); }
.hm-quick__icon--save { background: var(--c-raised); color: var(--c-text-2); }


.hm-totals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-8);
  margin-bottom: var(--sp-4);
}

.hm-total { display: flex; flex-direction: column; gap: 0.2rem; }
.hm-total__label { color: var(--c-text-3); font-size: var(--fs-sm); }
.hm-total__label small { margin-left: var(--sp-1); font-size: var(--fs-xs); }
.hm-total__value { font-size: var(--fs-lg); font-weight: 800; }

.hm-legend { margin-top: var(--sp-3); }
.hm-lines { margin-top: var(--sp-4); }

.hm-outside {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px dashed var(--c-border);
}

.hm-outside__label { color: var(--c-text-3); font-size: var(--fs-sm); margin-right: var(--sp-1); }

.hm-next__amount {
  margin-bottom: var(--sp-3);
  font-size: var(--fs-xl);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hm-recent__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 5.6rem;
  border-bottom: 1px solid var(--c-line);
}

.hm-recent__item:last-child { border-bottom: 0; }

.hm-recent__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 50%;
}

.hm-recent__icon .sh-icon { width: 1.7rem; height: 1.7rem; }
.hm-recent__icon--card { background: var(--c-out-soft); color: var(--c-out); }
.hm-recent__icon--bank { background: var(--c-left-soft); color: var(--c-left); }
.hm-recent__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hm-recent__name { font-weight: 700; }
.hm-recent__time { color: var(--c-text-3); font-size: var(--fs-xs); }
.hm-recent__value { display: flex; flex-direction: column; align-items: flex-end; }
.hm-recent__delta { font-size: var(--fs-xs); color: var(--c-text-3); }
.hm-recent__delta--good { color: var(--c-left); }
.hm-recent__delta--bad { color: var(--c-out); }

@media (max-width: 1080px) {
  .hm-top { grid-template-columns: minmax(0, 1fr); }
  .hm-quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 761px) and (max-width: 1080px) {
  .hm-deck {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "main" "flow" "next" "recent";
  }
}

@media (max-width: 760px) {
  .hm-top { gap: var(--sp-4); }
  .hm-hero { padding: var(--sp-6); }

  .hm-values { margin-bottom: var(--sp-4); padding: var(--sp-4); }
  .hm-values__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }

  /* 모바일 빠른 실행 — 아이콘 왼쪽·글자 오른쪽 두 칸 */
  .hm-quick { gap: var(--sp-2); }

  .hm-quick__btn {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    min-height: 6rem;
    padding: var(--sp-3);
    font-size: var(--fs-sm);
  }

  .hm-quick__icon { width: 3.6rem; height: 3.6rem; flex: none; }

  .hm-totals { gap: var(--sp-3) var(--sp-6); }
}

/* ══ 항목 ═══════════════════════════════════════════════ */
.it-tabs { max-width: 56rem; margin-bottom: var(--sp-4); }
.it-desc { margin-bottom: var(--sp-2); color: var(--c-text-3); font-size: var(--fs-sm); }

.it-row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--sp-2);
  min-height: 5.4rem;
  border-bottom: 1px solid var(--c-line);
}

.it-row__grip {
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 4.4rem;
  color: var(--c-faint);
  cursor: grab;
  touch-action: none;
}

.it-row__grip .sh-icon { fill: currentColor; stroke: none; width: 1.6rem; height: 1.6rem; }
.it-row__name { min-width: 0; }
.it-row__tag { margin-left: var(--sp-2); color: var(--c-text-3); font-size: var(--fs-xs); white-space: nowrap; }
.it-row__actions { display: flex; gap: 0.2rem; }
.it-row__actions .sh-icon { width: 1.7rem; height: 1.7rem; }

.it-row--dragging { background: var(--c-raised); opacity: 0.75; }

.it-row--editing {
  grid-template-columns: minmax(0, 1fr) minmax(0, 16rem) auto;
  padding: var(--sp-2) 0;
}

.it-row__btns { display: flex; gap: var(--sp-1); }

.it-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) 0 0 4rem;
  font-weight: 700;
}

.it-add {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) auto auto;
  align-items: end;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  padding: var(--sp-4);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-input);
}

.it-add__quick { display: flex; gap: var(--sp-1); }
.it-add__quick .ui-btn { min-height: 4.6rem; }
.it-add__submit { min-height: 4.6rem; }

@media (max-width: 760px) {
  .it-tabs { max-width: none; }
  .it-add { grid-template-columns: minmax(0, 1fr); }
  .it-add__quick .ui-btn { flex: 1; }
  .it-row__tag { display: block; margin-left: 0; }
  .it-row--editing { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .it-row--editing .it-row__btns { grid-column: 1 / -1; justify-content: flex-end; }
  .it-total { padding-left: 0; }
}

/* ══ 월간 기록 ═══════════════════════════════════════════ */
.rc-layout {
  display: grid;
  grid-template-columns: 26rem minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

/* 달 고르기 — 연도·월 휠 두 개. 가운데 띠가 고른 값, 위아래로 갈수록 기울고 흐려진다(app.js paintWheel) */
.rc-picker { position: sticky; top: var(--sp-6); padding: var(--sp-4); }

.rc-picker__wheels {
  --wheel-item: 4.4rem;
  --wheel-rows: 5;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: var(--sp-1);
  height: calc(var(--wheel-item) * var(--wheel-rows));
}

.rc-picker__band {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: var(--wheel-item);
  transform: translateY(-50%);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-raised);
  pointer-events: none;
}

.rc-wheel {
  position: relative;
  height: 100%;
  padding-block: calc((var(--wheel-rows) - 1) / 2 * var(--wheel-item));
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  border-radius: var(--r-md);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 32%, black 68%, transparent);
  mask-image: linear-gradient(to bottom, transparent, black 32%, black 68%, transparent);
}

.rc-wheel::-webkit-scrollbar { display: none; }
.rc-wheel:focus-visible { outline-offset: -2px; }

.rc-wheel__item {
  display: grid;
  place-items: center;
  height: var(--wheel-item);
  color: var(--c-text-2);
  font-size: var(--fs-md);
  font-weight: 600;
  scroll-snap-align: center;
  cursor: pointer;
  user-select: none;
  backface-visibility: hidden;
}

.rc-wheel__item[aria-selected="true"] { color: var(--c-text); font-weight: 800; }

.rc-picker__nav {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.rc-picker__nav .sh-icon { width: 1.6rem; height: 1.6rem; }

.rc-detail__title { margin-bottom: var(--sp-3); font-size: var(--fs-lg); font-weight: 800; }

.rc-fold { margin-top: var(--sp-4); border-top: 1px solid var(--c-line); padding-top: var(--sp-2); }

.rc-fold__summary {
  display: flex;
  align-items: center;
  min-height: 4.4rem;
  color: var(--c-brand-text);
  font-weight: 700;
  cursor: pointer;
}

.rc-delta { margin-left: var(--sp-2); color: var(--c-text-3); font-size: var(--fs-xs); font-weight: 500; }

@media (max-width: 760px) {
  .rc-layout { grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
  .rc-picker { position: static; }
  .rc-picker__wheels { --wheel-rows: 3; }
}

/* ══ 변동 이력 ═══════════════════════════════════════════ */
.hs-hint { max-width: 88rem; margin-bottom: var(--sp-4); color: var(--c-text-3); font-size: var(--fs-sm); }
.hs-hint b { color: var(--c-text-2); }

/* 세 열 — 데스크톱은 나란히, 모바일은 ui-deck 이 옆으로 넘기는 세 장 */
@media (min-width: 761px) {
  .hs-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(32rem, 1fr));
    gap: var(--sp-4);
    align-items: start;
  }
}

.hs-col { padding: var(--sp-5); }
.hs-col__title { font-size: var(--fs-md); font-weight: 800; }
.hs-col__note { margin-left: var(--sp-2); color: var(--c-text-3); font-size: var(--fs-xs); font-weight: 500; }

.hs-period { margin-top: var(--sp-4); }

.hs-period__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--c-border);
}

.hs-period__title { font-weight: 800; white-space: nowrap; }
.hs-period__range { color: var(--c-text-3); font-size: var(--fs-xs); white-space: nowrap; }
.hs-spark { flex: 1; min-width: 0; height: 2.4rem; }

/* 한 줄 두 단 — 위: 시각·꼬리표 | 옮기기·삭제, 아래: 금액 | 증감. 세 열이 나란히 있어도 시각이 꺾이지 않게 */
.hs-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "time acts"
    "amt  delta";
  align-items: center;
  column-gap: var(--sp-2);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-line);
}

.hs-row__time {
  grid-area: time;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--c-text-3);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.hs-row__tag {
  align-self: flex-start;
  padding: 0 0.6rem;
  border-radius: 0.4rem;
  background: var(--c-raised);
  color: var(--c-text-2);
  font-size: 1.1rem;
  font-style: normal;
  font-weight: 600;
}

.hs-row__amount { grid-area: amt; }
.hs-row__delta { grid-area: delta; color: var(--c-text-3); font-size: var(--fs-sm); text-align: right; white-space: nowrap; }
.hs-row__delta--good { color: var(--c-left); }
.hs-row__delta--bad { color: var(--c-out); }
.hs-row__acts { grid-area: acts; display: flex; }
.hs-row__acts .ui-icon-btn { width: 3.2rem; color: var(--c-faint); }
.hs-row__acts .ui-icon-btn:hover { color: var(--c-text); }
.hs-row__acts .ui-icon-btn--danger:hover { color: var(--c-danger); }
.hs-row__acts .sh-icon { width: 1.6rem; height: 1.6rem; }

@media (max-width: 760px) {
  .hs-col { padding: var(--sp-4); }
  .hs-row__acts .ui-icon-btn { width: 4rem; height: 4rem; }
}

/* ══ 업데이트 내역 (releases.js) ═════════════════════════ */
.rl-index { display: flex; flex-direction: column; gap: var(--sp-1); }

.rl-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 5.6rem;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  text-align: left;
}

.rl-entry:hover { background: var(--c-raised); }

.rl-ver {
  padding: 0.2rem 0.8rem;
  border-radius: var(--r-sm);
  background: var(--c-brand-soft);
  color: var(--c-brand-text);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.rl-entry__body { display: flex; flex-direction: column; min-width: 0; }
.rl-name { font-weight: 700; }
.rl-date, .rl-count { color: var(--c-text-3); font-size: var(--fs-xs); }
.rl-go { color: var(--c-faint); }

.rl-back {
  min-height: 3.6rem;
  padding: 0 var(--sp-2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--fs-sm);
}

.rl-back:hover { background: var(--c-raised); }

.rl-hero { display: flex; align-items: baseline; gap: var(--sp-3); margin: var(--sp-3) 0 var(--sp-4); }
.rl-hero__ver { color: var(--c-brand-text); font-size: var(--fs-xl); font-weight: 800; }
.rl-hero__date { color: var(--c-text-3); font-size: var(--fs-sm); }

.rl-lines { display: flex; flex-direction: column; gap: var(--sp-3); }
.rl-lines li { display: flex; align-items: flex-start; gap: var(--sp-3); }

.rl-kind {
  flex: none;
  padding: 0.1rem 0.8rem;
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.rl-kind--feature { background: var(--c-in-soft); color: var(--c-in); }
.rl-kind--improve { background: var(--c-left-soft); color: var(--c-left); }
.rl-kind--fix { background: var(--c-out-soft); color: var(--c-out); }
