* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", "Malgun Gothic", sans-serif; background: #f5f5f7; color: #1c1c1e; }
body { min-height: 100vh; min-height: 100dvh; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; font-size: 16px; }

.hidden { display: none !important; }

/* ===== PIN 잠금 화면 ===== */
.pin-wrap {
  max-width: 360px; margin: 0 auto; padding: 60px 24px 40px;
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pin-wrap h1 { font-size: 26px; margin: 0 0 8px; }
.pin-wrap .sub { color: #8e8e93; margin: 0 0 32px; font-size: 14px; }
.pin-display { display: flex; gap: 16px; margin-bottom: 8px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 7px; background: transparent;
  border: 2px solid #c7c7cc; transition: all 0.15s;
}
.pin-dot.filled { background: #007aff; border-color: #007aff; }
.pin-error {
  height: 20px; color: #ff3b30; font-size: 13px; margin: 16px 0 24px;
  animation: shake-fix 0.4s;
}
.pin-error.shake { animation: shake 0.4s; }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }
@keyframes shake-fix { from{opacity:0;} to{opacity:1;} }
.pin-keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  width: 100%; max-width: 280px;
}
.pin-key {
  height: 68px; border-radius: 34px; background: #fff; font-size: 26px; font-weight: 400;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  transition: all 0.1s;
}
.pin-key:active { background: #e5e5ea; transform: scale(0.95); }
.pin-key.empty { background: transparent; box-shadow: none; pointer-events: none; }
.pin-key.back { font-size: 22px; color: #8e8e93; background: transparent; box-shadow: none; }

/* ===== 앱 설치 안내 모달 ===== */
.install-box {
  position: relative; background: #fff; border-radius: 20px;
  padding: 32px 28px 24px; margin: auto; max-width: 320px; width: calc(100% - 40px);
  text-align: center; animation: fadeIn 0.2s;
}
.install-icon { font-size: 48px; margin-bottom: 12px; }
.install-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.install-desc { color: #555; font-size: 14px; line-height: 1.5; margin-bottom: 24px; }
.install-actions { display: flex; gap: 10px; }
.install-actions button { flex: 1; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600; }
.btn-primary { background: #007aff; color: #fff; }
.btn-primary:active { background: #0066d4; }
.btn-secondary { background: #f0f0f3; color: #1c1c1e; }
.modal#modal-install { align-items: center; }

/* ===== 멤버 선택 화면 ===== */
.member-wrap {
  max-width: 480px; margin: 0 auto; padding: 60px 24px 40px;
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
}
.member-wrap h1 { text-align: center; font-size: 28px; margin: 0 0 8px; }
.member-wrap .sub { text-align: center; color: #8e8e93; margin: 0 0 32px; }
#member-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.member-btn {
  width: 100%; padding: 18px; border-radius: 14px; background: #fff;
  font-size: 18px; font-weight: 600; border: 2px solid transparent;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06); transition: all 0.15s;
  display: flex; align-items: center; justify-content: space-between;
}
.member-btn:active { transform: scale(0.98); border-color: #007aff; }
.member-btn .del-x {
  width: 28px; height: 28px; border-radius: 14px; background: #ff3b30; color: #fff;
  font-size: 16px; line-height: 1; display: none;
}
.member-btn.edit-mode .del-x { display: inline-flex; align-items: center; justify-content: center; }
.add-member { display: flex; gap: 8px; }
.add-member input {
  flex: 1; padding: 14px; border-radius: 12px; border: 1px solid #d1d1d6; background: #fff;
}
.add-member button {
  padding: 14px 20px; border-radius: 12px; background: #007aff; color: #fff; font-weight: 600;
}

/* ===== 메인 화면 ===== */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: #fff; border-bottom: 1px solid #e5e5ea; position: sticky; top: 0; z-index: 10;
}
.member-chip {
  padding: 6px 14px; border-radius: 14px; background: #007aff; color: #fff;
  font-size: 14px; font-weight: 600;
}
.export-btn {
  width: 32px; height: 32px; font-size: 16px; color: #007aff;
  border-radius: 8px;
}
.export-btn:active { background: #f0f0f3; }
.month-picker { display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 16px; }
.month-picker button {
  width: 32px; height: 32px; font-size: 20px; color: #007aff;
}
#cur-month-label { min-width: 110px; text-align: center; }

.summary { padding: 24px 20px 16px; background: #fff; }
.summary-label { font-size: 13px; color: #8e8e93; }
.summary-amount { font-size: 32px; font-weight: 700; margin-top: 4px; }

.list { padding: 8px 0 120px; }
.empty { text-align: center; padding: 80px 20px; color: #8e8e93; font-size: 14px; }

.day-group { margin-top: 16px; }
.day-header {
  padding: 8px 20px 6px; font-size: 13px; font-weight: 600; color: #8e8e93;
  display: flex; justify-content: space-between;
}
.day-header .day-sum { color: #1c1c1e; }
.tx-row {
  padding: 14px 20px; background: #fff; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #f0f0f3;
}
.tx-row:active { background: #f5f5f7; }
.tx-main { flex: 1; min-width: 0; }
.tx-merchant { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: #8e8e93; margin-top: 2px; }
.tx-amount { font-size: 17px; font-weight: 600; margin-left: 12px; white-space: nowrap; }
.tx-amount.income { color: #34c759; }

.cat-tag {
  display: inline-block; padding: 1px 8px; border-radius: 8px; font-size: 11px;
  background: #f0f0f3; color: #555;
}
.cat-식비 { background: #ffe8e0; color: #c2410c; }
.cat-교통 { background: #dbeafe; color: #1d4ed8; }
.cat-의료 { background: #fce7f3; color: #be185d; }
.cat-생활 { background: #dcfce7; color: #15803d; }
.cat-쇼핑 { background: #f3e8ff; color: #7c3aed; }
.cat-기타 { background: #f0f0f3; color: #555; }

.fab {
  position: fixed; right: 20px; bottom: max(24px, env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 30px; background: #007aff; color: #fff;
  font-size: 32px; font-weight: 300; line-height: 1;
  box-shadow: 0 4px 16px rgba(0,122,255,0.4); z-index: 20;
}
.fab:active { transform: scale(0.95); }

/* ===== 모달 공통 ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet {
  position: relative; width: 100%; max-width: 480px;
  background: #fff; border-radius: 16px 16px 0 0; padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  animation: slideUp 0.25s;
}
.sheet-item {
  width: 100%; padding: 18px; font-size: 17px; border-radius: 12px;
  text-align: center; color: #007aff;
}
.sheet-item:active { background: #f0f0f3; }
.sheet-item.cancel { color: #ff3b30; font-weight: 600; margin-top: 4px; border-top: 1px solid #f0f0f3; border-radius: 0; }

.dialog {
  position: relative; width: 100%; max-width: 480px;
  background: #fff; border-radius: 16px 16px 0 0; max-height: 90dvh; overflow-y: auto;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  animation: slideUp 0.25s;
}
.dialog-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid #f0f0f3; font-weight: 600; font-size: 17px;
  position: sticky; top: 0; background: #fff; z-index: 1;
}
.dialog-head .x { font-size: 28px; color: #8e8e93; width: 32px; }

.form { padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; }
.form label span { font-size: 13px; color: #555; font-weight: 500; }
.form input, .form select {
  padding: 12px 14px; border-radius: 10px; border: 1px solid #d1d1d6; background: #fff;
}
.form input:focus, .form select:focus { outline: 2px solid #007aff; outline-offset: -2px; border-color: transparent; }

.items-preview {
  background: #fafafa; border-radius: 10px; padding: 10px 14px; font-size: 13px;
}
.items-preview h4 { margin: 0 0 6px; font-size: 12px; color: #8e8e93; font-weight: 600; }
.items-preview .item { display: flex; justify-content: space-between; padding: 2px 0; }

.dialog-actions { display: flex; gap: 10px; margin-top: 8px; }
.dialog-actions button {
  flex: 1; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600;
}
.dialog-actions .primary { background: #007aff; color: #fff; }
.dialog-actions .primary:active { background: #0066d4; }
.dialog-actions .danger { background: #fff; color: #ff3b30; border: 1px solid #ff3b30; }

/* 분석 중 */
.parsing-box {
  position: relative; background: #fff; border-radius: 16px; padding: 32px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px; margin: auto;
  animation: fadeIn 0.2s;
}
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid #e5e5ea; border-top-color: #007aff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.modal#modal-parsing { align-items: center; }
