/* 카드 실적 — 모바일 우선(360px), PC는 가운데 480px. 라이트/다크는 시스템 설정을 따른다. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #17191d;
  --muted: #646b76;
  --line: #dfe2e7;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --ok: #138a4a;
  --ok-bg: #dcf3e5;
  --no: #d23b3b;
  --no-bg: #fbe1e1;
  --warn: #9a6200;
  --warn-bg: #fff1d1;
  --ev: #0b7a8f;
  --ev-bg: #d9f2f6;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  --radius: 14px;
  --tabbar-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --surface: #1f2228;
    --surface-2: #2a2e36;
    --text: #eceef2;
    --muted: #9aa2ae;
    --line: #343944;
    --primary: #6d9bff;
    --primary-text: #0d1220;
    --ok: #4cc983;
    --ok-bg: #173826;
    --no: #ff7a7a;
    --no-bg: #432222;
    --warn: #f0b84d;
    --warn-bg: #3d3018;
    --ev: #5fd0e2;
    --ev-bg: #173840;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 16px; margin-bottom: 10px; }
p { margin: 0; }
pre { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.app { max-width: 480px; margin: 0 auto; min-height: 100vh; }
.view { padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.neg { color: var(--no); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 상단 */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; margin-bottom: 8px; }
.page-actions { display: flex; gap: 8px; }
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 42px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600;
}
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--no); border-color: var(--no); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.icon-btn {
  min-width: 36px; min-height: 36px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text); cursor: pointer; font-size: 15px;
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 4px 6px; font-size: 13px; }
.link-btn.danger { color: var(--no); }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.toggle {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer;
}
.toggle.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* 배지·태그 */
.badge { flex: none; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.no { background: var(--no-bg); color: var(--no); }
.badge.ref { opacity: .75; border: 1px dashed currentColor; }
.badge.small { font-size: 11px; padding: 1px 8px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; background: var(--surface-2); color: var(--muted); }
.tag.ev { background: var(--ev-bg); color: var(--ev); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.off { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }

/* 기간 선택 */
.period-bar { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 4px 0 10px; }
.retention-note { text-align: center; font-size: 12px; color: var(--muted); margin: -6px 0 10px; }
.period-label { border: 0; background: none; font-size: 18px; font-weight: 700; padding: 4px 8px; cursor: pointer; }

/* 요약·알림 */
.summary-line { text-align: center; margin-bottom: 12px; }
.alert-band { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.alert-band p + p { margin-top: 4px; }

/* 카드 실적 */
.card-list { display: grid; gap: 12px; }
.card-item {
  display: block; background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); color: inherit; border: 1px solid var(--line);
}
.card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.thumb { width: 56px; height: 35px; border-radius: 5px; object-fit: cover; background: var(--surface-2); flex: none; }
.card-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.card-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount-line { display: flex; align-items: baseline; gap: 2px; margin-bottom: 6px; }
.spent { font-size: 20px; font-weight: 800; }
.rate { margin-left: auto; font-weight: 700; color: var(--muted); }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress.small { height: 6px; flex: 1; min-width: 60px; }
.progress-fill { height: 100%; background: var(--no); border-radius: inherit; transition: width .3s; }
.progress.met .progress-fill { background: var(--ok); }
.progress.small .progress-fill { background: var(--ev); }
.progress.small.over .progress-fill { background: var(--no); }
.remain { margin-top: 6px; font-weight: 600; }
.sub-line { font-size: 13px; margin-top: 2px; }
.ev-line {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--line); font-size: 14px;
}
.ev-label { color: var(--ev); }
.ev-label strong { color: var(--text); }
.ev-over { color: var(--no); font-size: 13px; font-weight: 600; }

.card-hero { display: flex; justify-content: center; margin: 4px 0 12px; }
.hero-img { width: 100%; max-width: 320px; aspect-ratio: 1.586; object-fit: cover; border-radius: 12px; background: var(--surface-2); }

/* 섹션 */
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.section.center { background: none; border: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; }

/* 혜택 */
.benefit-list, .benefit-edit-list, .tx-list, .manage-list, .raw-list, .kw-list, .pick-list { list-style: none; margin: 0; padding: 0; }
.benefit { padding: 8px 0; border-top: 1px solid var(--line); }
.benefit:first-child { border-top: 0; padding-top: 0; }
.benefit-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.benefit-edit { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.benefit-edit:first-child { border-top: 0; }
.benefit-info { flex: 1; min-width: 0; }
.benefit-buttons { display: flex; align-items: center; flex: none; }

/* 거래 */
.tx { padding: 10px 0; border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx.excluded .tx-main { opacity: .55; }
.tx-main { display: flex; align-items: baseline; gap: 8px; }
.tx-date { color: var(--muted); font-size: 13px; flex: none; font-variant-numeric: tabular-nums; }
.tx-merchant { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-weight: 700; flex: none; font-variant-numeric: tabular-nums; }
.tx-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tx-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 6px; margin: 8px 0; font-size: 14px; }
.check input { width: 18px; height: 18px; }

/* 원거래 후보 */
.pick { display: flex; width: 100%; gap: 8px; align-items: baseline; text-align: left; padding: 12px 4px; border: 0; border-top: 1px solid var(--line); background: none; cursor: pointer; }
.pick-merchant { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 카드 관리 */
.manage-list { display: grid; gap: 8px; }
.manage-item { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; color: inherit; }
.manage-item.inactive { opacity: .6; }

/* 폼 */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* 미분류 */
.raw-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; display: grid; gap: 6px; }
.raw-text { white-space: pre-wrap; word-break: break-all; font-family: ui-monospace, "D2Coding", monospace; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 8px; }
.assign-form { margin-top: 6px; }

/* 설정 */
.token { display: block; word-break: break-all; background: var(--surface-2); border-radius: 8px; padding: 8px; font-size: 13px; }
.guide summary { cursor: pointer; color: var(--primary); margin-top: 8px; }
.guide ol { padding-left: 20px; font-size: 14px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.kw { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.kw:first-child { border-top: 0; }
.kw-list { max-height: 360px; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }
.kw.off .kw-word { text-decoration: line-through; color: var(--muted); }
.kw.new { background: var(--warn-bg); border-radius: 8px; padding: 8px; }
.kw-word { font-weight: 600; word-break: break-all; }
.kw .link-btn { margin-left: auto; }
.choice-list { display: grid; gap: 8px; margin: 12px 0; }
.kw .switch { margin-left: auto; }
.kw-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-top: 10px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .2s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 빈 상태·오류 */
.empty { color: var(--muted); text-align: center; padding: 20px 0; }
.empty-box { display: grid; justify-items: center; gap: 8px; padding: 24px 0; }
.error-box { display: grid; justify-items: center; gap: 12px; padding: 40px 0; text-align: center; }

/* 하단 탭 바 */
.tabbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); z-index: 10;
}
.tabbar[hidden] { display: none; }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; }
.tabbar a.active { color: var(--primary); font-weight: 700; }
.tab-icon { font-size: 18px; line-height: 1; }

/* 시트 */
.sheet {
  width: 100%; max-width: 480px; max-height: 88vh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / 45%); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; position: sticky; top: 0; background: var(--surface); }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 6px 16px calc(20px + env(safe-area-inset-bottom)); }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.toast.error { background: var(--no); color: #fff; }

/* PIN */
.pin-screen { display: grid; justify-items: center; gap: 18px; padding-top: 8vh; }
.pin-logo { font-size: 40px; color: var(--primary); }
.pin-title { font-size: 18px; text-align: center; }
.pin-message { min-height: 44px; text-align: center; color: var(--no); font-size: 14px; max-width: 300px; }
.pin-dots { display: flex; gap: 18px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s; }
.pin-dot.filled { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
.pin-keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 22px; }
.pin-keypad.disabled { opacity: .4; pointer-events: none; }
.pin-key {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--surface); box-shadow: var(--shadow);
  font-size: 26px; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.pin-key:active { background: var(--surface-2); }
.pin-key-small { font-size: 15px; background: transparent; box-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 360px) {
  .grid3 { grid-template-columns: 1fr; }
  .kw-add { grid-template-columns: 1fr; }
  .pin-keypad { grid-template-columns: repeat(3, 68px); gap: 12px 18px; }
  .pin-key { width: 68px; height: 68px; }
}
