:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2430;
  --text-dim: #6b7280;
  --primary: #2563eb;
  --primary-dim: #93c5fd;
  --border: #e5e7eb;
  --danger: #dc2626;
  --warn: #f59e0b;
  --ok: #16a34a;
  --tab-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  height: 100%;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

header.topbar {
  padding: 16px 20px 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

main {
  flex: 1;
  padding: 12px 16px calc(var(--tab-h) + 24px);
  overflow-y: auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.hidden { display: none !important; }

/* ── 등록 화면 ─────────────────────────────────────── */
#screen-register .card { margin-top: 40px; }
#screen-register h2 { margin: 0 0 6px; font-size: 18px; }
#screen-register p { color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }

label { display: block; font-size: 13px; color: var(--text-dim); margin: 10px 0 4px; }

input[type="text"], input[type="tel"], textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 15px;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.input-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

button.primary {
  width: 100%;
  padding: 13px;
  margin-top: 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:disabled { opacity: .5; cursor: default; }
button.primary:active { opacity: .85; }

button.secondary {
  width: 100%;
  padding: 11px;
  margin-top: 8px;
  border: 1px solid var(--primary);
  border-radius: 10px;
  background: #fff;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.ok-msg { color: var(--ok); font-size: 13px; margin-top: 8px; }

/* ── 문서종류 선택 ─────────────────────────────────── */
.doctype-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.doctype-item {
  display: flex; flex-direction: column;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; user-select: none;
}
.doctype-item.checked { border-color: var(--primary); background: #eff6ff; }
.doctype-row-top { display: flex; align-items: center; justify-content: space-between; }
.doctype-item .label { font-size: 14px; font-weight: 600; }
.doctype-item .price { font-size: 13px; color: var(--text-dim); }
.doctype-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.doctype-row { display: flex; align-items: center; gap: 10px; }
.doctype-note { font-size: 11px; color: var(--text-dim); margin-top: 4px; margin-left: 28px; }

.select-all-row { display: flex; justify-content: flex-end; margin-top: 4px; }
.select-all-row button {
  border: none; background: none; color: var(--primary); font-size: 13px; cursor: pointer; padding: 4px;
}

/* ── 진행 상태 ─────────────────────────────────────── */
.status-pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.status-대기 { background: #fef3c7; color: #92400e; }
.status-처리중 { background: #dbeafe; color: #1e40af; }
.status-완료 { background: #dcfce7; color: #166534; }
.status-실패 { background: #fee2e2; color: #991b1b; }

.result-images { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.result-images img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; background: #eee;
}

.balance-line { margin-top: 10px; font-size: 13px; color: var(--text-dim); }

/* ── 히스토리 ──────────────────────────────────────── */
#history-search {
  margin-bottom: 10px;
}

.date-filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.date-filter-row input[type="date"] {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 14px;
}
.date-filter-row button {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--primary);
  background: #fff; color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}

.sort-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.sort-toggle button {
  flex: 1; padding: 9px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--text-dim); font-size: 13px; cursor: pointer;
}
.sort-toggle button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.history-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-delete {
  border: none; background: none; font-size: 15px; padding: 4px 6px; cursor: pointer;
  border-radius: 8px; line-height: 1; flex-shrink: 0;
}
.history-delete:active { background: var(--bg); }
.history-item .addr { font-weight: 700; font-size: 14px; }
.history-item .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.history-item .badges { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: var(--primary);
}
.empty-hint { text-align: center; color: var(--text-dim); font-size: 13px; padding: 40px 0; }

/* ── 캐시 탭 ───────────────────────────────────────── */
.balance-label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.balance-big { font-size: 30px; font-weight: 800; color: var(--primary); margin-top: 2px; }
.balance-sub { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.low-balance-banner {
  background: #fff7ed; border: 1px solid var(--warn); color: #9a3412;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 12px;
}

.section-title { font-size: 14px; font-weight: 700; margin-bottom: 10px; }

.ledger-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.ledger-row:last-child { border-bottom: none; }
.ledger-main { display: flex; justify-content: space-between; align-items: baseline; }
.ledger-note { font-size: 14px; font-weight: 600; }
.ledger-amount { font-size: 14px; font-weight: 700; }
.ledger-amount.plus { color: var(--ok); }
.ledger-amount.minus { color: var(--danger); }
.ledger-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ── 하단 탭바 (인스타그램 스타일) ─────────────────── */
nav.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: 480px; height: var(--tab-h);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom, 0);
}
nav.tabbar button {
  flex: 1; border: none; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; color: var(--text-dim);
  font-size: 11px; cursor: pointer;
}
nav.tabbar button .icon { font-size: 22px; line-height: 1; }
nav.tabbar button.active { color: var(--primary); font-weight: 700; }

/* ── 이미지 전체보기 모달 ──────────────────────────── */
.img-modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 20, .94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
}
.img-modal.hidden { display: none; }
.img-modal img { max-width: 100%; max-height: 68vh; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.img-modal-close {
  position: absolute; top: max(16px, env(safe-area-inset-top, 0)); right: 16px;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.15); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.img-modal-save {
  padding: 13px 28px; border-radius: 999px; border: none; background: var(--primary); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.img-modal-hint { color: rgba(255,255,255,.55); font-size: 12px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px); transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 12px 20px; border-radius: 18px;
  font-size: 13px; line-height: 1.6; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 82%; text-align: center; z-index: 50; word-break: keep-all; overflow-wrap: break-word;
}
.toast.show { opacity: 1; }
