/* Money Calendar - 공통 토큰·레이아웃·컴포넌트 */

:root {
  /* Theme tokens (Light) */
  --color-primary: #22c55e;
  --color-primary-hover: #16a34a;
  --color-bg: #ffffff;
  --color-bg-soft: #f6f7fb;
  --color-surface: #ffffff;
  --color-surface-2: rgba(248, 250, 252, 0.92);
  --color-text-primary: #0f172a;
  --color-text-secondary: #334155;
  --color-text-muted: #64748b;
  --color-income: #3b82f6;
  --color-expense: #ef4444;
  --color-warn: #f59e0b;
  --border-default: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-soft: 0 20px 70px rgba(15, 23, 42, 0.09);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-3xl: 28px;
  --container-max-width: 1440px;
  /* 헤더(홈·기능 공통): PC 기준 69px — html 배율(100% / 85% / 75%)에 맞춰 rem으로 비례 축소 */
  --mc-header-height: 4.3125rem;
  --mc-header-inner-gap: 0.75rem;
  /* 로고·토글·햄버거: 768px 이하 0.85, 480px 이하 0.7(요청 비율) */
  --mc-header-scale: 1;
  --shadow-card: 0 14px 46px rgba(15, 23, 42, 0.07);
  --focus-ring: 0 0 0 3px rgba(34, 197, 94, 0.22);
  /* 종이 가계부 셸 */
  --mc-paper-bg: #fbfaf7;
  --mc-paper-veil: #fbfaf7;
  /* 종이 격자·톤: 대비 ~18% 상승, 선은 슬레이트+미세 웜톤으로 피로 완화 */
  --mc-paper-texture: radial-gradient(900px 420px at 12% -10%, rgba(34, 197, 94, 0.072), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.74) 0%, transparent 38%),
    repeating-linear-gradient(
      0deg,
      rgba(71, 85, 105, 0.022) 0px,
      rgba(71, 85, 105, 0.022) 1px,
      transparent 1px,
      transparent 28px
    );
}

/* Theme tokens (Dark) */
html[data-theme="dark"] {
  --color-primary: #34d399; /* slightly brighter for dark */
  --color-primary-hover: #22c55e;
  --color-bg: #0b1220; /* deep navy */
  --color-bg-soft: #0f172a;
  --color-surface: rgba(17, 24, 39, 0.72); /* charcoal glass */
  --color-surface-2: rgba(17, 24, 39, 0.56);
  --color-text-primary: #e5e7eb; /* off-white */
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #94a3b8;
  --border-default: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.35);
  --shadow-card: 0 18px 60px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 26px 80px rgba(0, 0, 0, 0.45);
  --focus-ring: 0 0 0 3px rgba(52, 211, 153, 0.24);
  --mc-paper-bg: #0c111d;
  --mc-paper-veil: #111827;
  --mc-paper-texture: radial-gradient(800px 380px at 10% 0%, rgba(52, 211, 153, 0.084), transparent 52%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.045) 0%, transparent 40%),
    repeating-linear-gradient(
      0deg,
      rgba(203, 213, 225, 0.036) 0px,
      rgba(203, 213, 225, 0.036) 1px,
      transparent 1px,
      transparent 26px
    );
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: #ffffff;
  overflow-x: hidden;
  max-width: 100%;
  font-size: 100%;
  /* 고정 헤더·sticky 앵커 시 본문이 가리지 않도록 */
  scroll-padding-top: var(--mc-header-height);
}

@media (max-width: 1024px) {
  html {
    font-size: 85%;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 75%;
  }

  .site-header > .container.site-header__inner,
  .mc-global-header > .container.mc-global-header__inner {
    padding-left: 12px;
    padding-right: 12px;
  }
}

html,
body,
h1,
h2,
h3,
p,
ul,
ol,
figure {
  margin: 0;
  padding: 0;
}

/* List reset: 브라우저 기본 불릿/여백 제거 */
ul,
ol {
  list-style: none;
}

li {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}

body.mc-app {
  background: transparent;
}

main section,
.mc-app section,
section.card {
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

/* Logo hardening: ensure mc-logo.svg is always visible */
.brand__mark,
.mc-brand__mark {
  position: relative;
  z-index: 999;
  overflow: visible;
}

.brand__mark img,
.mc-brand__mark img {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  visibility: visible !important;
  opacity: 1 !important;
  object-fit: contain;
}

.mc-app canvas,
.tl-chart-wrap canvas {
  max-width: 100%;
  display: block;
}

/* 본문용 리스트(SEO/가이드 텍스트): 들여쓰기 + 가독성 간격, 가로 스크롤 방지 */
.mc-prose-list {
  padding-left: 1.1rem;
  display: grid;
  gap: 0.55rem;
  max-width: 100%;
}

.mc-prose-list > li {
  position: relative;
  padding-left: 0.9rem;
  min-width: 0;
}

.mc-prose-list > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.65em;
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-text-muted) 55%, transparent);
}

.mc-prose-steps {
  padding-left: 1.1rem;
  display: grid;
  gap: 0.65rem;
  max-width: 100%;
}

.mc-prose-steps > li {
  min-width: 0;
  padding-left: 0.9rem;
  position: relative;
}

.mc-prose-steps > li::before {
  counter-increment: mcStep;
  content: counter(mcStep) ".";
  position: absolute;
  left: -1.1rem;
  top: 0;
  width: 1.1rem;
  text-align: right;
  font-weight: 800;
  color: var(--color-text-muted);
}

.mc-prose-steps {
  counter-reset: mcStep;
}

/* Borderless Grid: 선 없이 여백/위계로 구분하는 텍스트 블록 */
.mc-borderless-stack {
  display: grid;
  gap: 14px;
  max-width: 100%;
  min-width: 0;
}

.mc-borderless-item {
  padding: 14px 16px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  box-shadow: none;
  border: none;
  max-width: 100%;
  min-width: 0;
}

.mc-borderless-item .text-body,
.mc-borderless-item p {
  line-height: 1.7;
}

/* 텍스트 입력: 한글 IME 우선 (브라우저가 지원하는 범위에서) */
input[type="text"],
input[type="search"],
textarea,
input:not([type]) {
  ime-mode: active;
}

/* Date/Month picker: 내장 '삭제(클리어)' UI 숨김(지원 브라우저 한정) */
input[type="date"]::-webkit-clear-button,
input[type="month"]::-webkit-clear-button,
input[type="date"]::-webkit-inner-spin-button,
input[type="month"]::-webkit-inner-spin-button {
  display: none;
}
input[type="date"]::-ms-clear,
input[type="month"]::-ms-clear {
  display: none;
}

/* Brand typography (홈/기능 공통) */
.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand__name {
  font-weight: 850;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

.brand__tag {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* Smooth theme transition (respects reduce motion) */
@media (prefers-reduced-motion: no-preference) {
  html[data-theme] body,
  html[data-theme] .card,
  html[data-theme] .btn,
  html[data-theme] .btn-secondary,
  html[data-theme] input,
  html[data-theme] select,
  html[data-theme] textarea {
    transition: background-color 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  }
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  width: 100%;
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 24px;
  min-width: 0;
  box-sizing: border-box;
}

/* App header — 홈·기능 페이지 공통: 최소 69px, 제목 2줄일 때는 높이 자동 확장 */
/* 별칭 .common-header__inner — 동일 규격 재사용 시 사용 */
.site-header__inner,
.mc-global-header__inner,
.common-header__inner {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--mc-header-inner-gap);
  min-width: 0;
  min-height: var(--mc-header-height);
  height: auto;
  max-height: none;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

/* .container와 겹친 한 요소: 좌우는 .container, 세로는 제목 2줄 대비 */
.site-header > .container.site-header__inner,
.mc-global-header > .container.mc-global-header__inner {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

/* —— Header: 겹침 방지 + 로고·테마·햄버거 유동 축소(768→85%, 480→70%) —— */
.site-header .brand,
.mc-global-header .mc-brand {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: calc(12px * var(--mc-header-scale));
  text-decoration: none;
  color: inherit;
}

.brand__text,
.mc-brand__titles {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: visible;
}

/* 헤더 제목: 잘림 방지(줄바꿈), 한글은 단어 단위 유지 */
.site-header .brand__name,
.site-header .brand__tag,
.mc-global-header .mc-brand__series {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-break: keep-all;
  overflow-wrap: break-word;
  line-height: 1.28;
}

.site-header .brand__mark,
.mc-global-header .brand__mark,
.mc-brand__mark {
  width: calc(44px * var(--mc-header-scale));
  height: calc(44px * var(--mc-header-scale));
  max-width: calc(44px * var(--mc-header-scale));
  max-height: calc(44px * var(--mc-header-scale));
  border-radius: calc(14px * var(--mc-header-scale));
  flex: 0 0 auto;
  overflow: hidden;
  background: transparent;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
  box-sizing: border-box;
}

.site-header .header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: calc(10px * var(--mc-header-scale));
}

.mc-global-header .mc-global-header__tools {
  gap: calc(10px * var(--mc-header-scale));
}

.site-header .theme-toggle,
.mc-global-header .theme-toggle {
  width: calc(54px * var(--mc-header-scale));
  height: calc(34px * var(--mc-header-scale));
  flex-shrink: 0;
}

.site-header .theme-toggle__thumb,
.mc-global-header .theme-toggle__thumb {
  top: calc(3px * var(--mc-header-scale));
  left: calc(3px * var(--mc-header-scale));
  width: calc(26px * var(--mc-header-scale));
  height: calc(26px * var(--mc-header-scale));
}

html[data-theme="dark"] .site-header .theme-toggle__thumb,
html[data-theme="dark"] .mc-global-header .theme-toggle__thumb {
  transform: translateX(calc(20px * var(--mc-header-scale)));
}

.site-header .hamburger,
.mc-global-header .hamburger,
.mc-hamburger {
  width: calc(48px * var(--mc-header-scale));
  height: calc(48px * var(--mc-header-scale));
  border-radius: calc(16px * var(--mc-header-scale));
  flex-shrink: 0;
}

.site-header .hamburger__icon,
.mc-global-header .hamburger__icon,
.mc-hamburger__icon {
  transform: scale(var(--mc-header-scale));
  transform-origin: center;
}

/* 브랜드가 가로를 우선(즐겨찾기 영역은 필요 시 수축) */
.site-header__inner .mc-fav-bar,
.site-header__inner .mc-fav-dropdown,
.mc-global-header__inner .mc-fav-bar,
.mc-global-header__inner .mc-fav-dropdown,
.page-home .site-header__inner .mc-fav-bar,
.page-home .site-header__inner .mc-fav-dropdown {
  flex: 0 1 40%;
  min-width: 0;
  max-width: min(28rem, 48%);
}

.page-foot {
  max-width: 100%;
  box-sizing: border-box;
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
}

p,
.text-body {
  color: var(--color-text-secondary);
  font-size: 0.9375rem;
}

small,
.text-sm {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-default);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  background: var(--color-primary-hover);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--block {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-weight: 700;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--color-surface-2);
}

.btn-secondary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.28);
}

input,
select,
button,
textarea {
  font: inherit;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="month"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--color-surface);
  color: var(--color-text-primary);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="month"],
input[type="date"],
input[type="datetime-local"],
select:not([multiple]) {
  min-height: 48px;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="tel"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="month"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="datetime-local"],
html[data-theme="dark"] select:not([multiple]) {
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.32);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

/* 숫자 전용: 천 단위 콤마 UI와 정렬 통일 (type=tel / inputmode=numeric / .money-input) */
input[type="tel"][inputmode="numeric"],
input[type="text"][inputmode="numeric"],
input.money-input {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input.money-input.sm {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 0.875rem;
}

.money-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.money-wrap .money-input {
  flex: 1 1 auto;
  min-width: 0;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  color-scheme: dark;
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  color-scheme: light;
}

input:focus:not(textarea),
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15), inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

html[data-theme="dark"] input:focus:not(textarea),
html[data-theme="dark"] select:focus {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15), inset 0 1px 2px rgba(0, 0, 0, 0.32);
}

.flex {
  display: flex;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-12 {
  gap: 12px;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.text-center {
  text-align: center;
}

.mt-10 {
  margin-top: 10px;
}
.mt-16 {
  margin-top: 16px;
}
.mt-20 {
  margin-top: 20px;
}
.mt-24 {
  margin-top: 24px;
}
.mb-10 {
  margin-bottom: 10px;
}
.mb-20 {
  margin-bottom: 20px;
}

.text-income {
  color: var(--color-income);
}
.text-expense {
  color: var(--color-expense);
}
.text-warn {
  color: var(--color-warn);
}

/* 기능·가이드 등 공통: 카카오 광고 상단 여백(메인 index와 동일) + 가운데 정렬 */
ins.kakao_ad_area {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 56px 0 0;
  text-align: center;
}

ins.kakao_ad_area > iframe,
ins.kakao_ad_area iframe,
ins.kakao_ad_area > div,
ins.kakao_ad_area > span {
  display: block;
  margin-left: auto !important;
  margin-right: auto !important;
  max-width: 100%;
}

/* 메인(홈)만 왼쪽 정렬 — 광고 위쪽 margin-top(56px / 600px↓ 40px)은 그대로 */
.page-home ins.kakao_ad_area {
  text-align: left;
}

.page-home ins.kakao_ad_area > iframe,
.page-home ins.kakao_ad_area iframe,
.page-home ins.kakao_ad_area > div,
.page-home ins.kakao_ad_area > span {
  margin-left: 0 !important;
  margin-right: auto !important;
}

@media (max-width: 600px) {
  ins.kakao_ad_area {
    margin-top: 40px;
  }
}

@media (max-width: 768px) {
  :root {
    --mc-header-scale: 0.85;
  }

  .container {
    padding: 16px;
  }

  .site-header > .container.site-header__inner,
  .mc-global-header > .container.mc-global-header__inner {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  h1 {
    font-size: 1.5rem;
  }
}

/* 480px는 768px보다 캐스케이드가 뒤에 와야 --mc-header-scale(0.7)이 덮어씀 */
@media (max-width: 480px) {
  :root {
    --mc-header-scale: 0.7;
    --mc-header-inner-gap: 0.5rem;
  }

  .site-header .brand__name,
  .site-header .brand__tag,
  .mc-global-header .mc-brand__series {
    font-size: 0.86rem; /* 약 14% 수준 축소(1rem 대비) */
    line-height: 1.3;
  }
}
