/* 명함지갑 — refined UI (2026-10) */
:root {
  --primary: #1d4ed8;
  --primary-strong: #1e40af;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-2: 0 4px 14px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .05);
  --shadow-3: 0 12px 32px rgba(15, 23, 42, .16);
  --ease: cubic-bezier(.22, .8, .36, 1);
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Pretendard', 'Noto Sans KR', -apple-system, 'Apple SD Gothic Neo', 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  line-height: 1.5; letter-spacing: -0.01em;
}
button { font-family: inherit; }
input, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- 헤더 ---------- */
header {
  background: rgba(255, 255, 255, .86);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .35);
}
.brand-mark svg { width: 20px; height: 20px; }
header h1 { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
nav { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: none; background: none; padding: 8px 14px; border-radius: 10px;
  font-size: 14px; color: var(--muted); cursor: pointer; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.tab svg { width: 18px; height: 18px; }
.tab:hover { background: #f1f5f9; color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab.active svg { stroke-width: 2.2; }

main { max-width: 720px; margin: 0 auto; padding: 20px 16px 96px; }
.view { display: none; }
.view.active { display: block; animation: view-in .22s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 검색 ---------- */
.searchbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 16px 4px 12px;
  box-shadow: var(--shadow-1);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.searchbar:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12); }
.search-icon { display: grid; place-items: center; color: var(--muted); }
.search-icon svg { width: 18px; height: 18px; }
#search {
  flex: 1; padding: 10px 0; border: none; background: none;
  font-size: 15px; color: var(--text); min-width: 0;
}
#search:focus { outline: none; }
#search::placeholder { color: #94a3b8; }
.count { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- 카테고리 칩 ---------- */
.group-chips {
  display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 14px;
  padding-bottom: 2px; scrollbar-width: none;
}
.group-chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all .18s var(--ease);
}
.chip:hover { border-color: #c7d2fe; color: var(--primary); }
.chip.active {
  background: linear-gradient(135deg, #2563eb, #4f46e5); color: #fff;
  border-color: transparent; box-shadow: 0 2px 8px rgba(37, 99, 235, .3);
}

/* ---------- 명함 목록 ---------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.grp-section {
  font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .05em;
  margin: 14px 4px 2px; text-transform: uppercase;
}
.card-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; gap: 14px; align-items: center; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.card-item:hover { box-shadow: var(--shadow-2); border-color: #d3ddf5; transform: translateY(-1px); }
.card-item:active { transform: scale(.985); }
.card-thumb {
  width: 84px; height: 54px; object-fit: cover; border-radius: 10px;
  background: #eef1f5; flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .06);
}
.card-info { min-width: 0; flex: 1; }
.card-name { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.card-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-badge {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); border: 1px solid #dce4fb; border-radius: 6px;
  padding: 1px 7px; margin-bottom: 4px; letter-spacing: 0;
}

/* ---------- 빈 상태 ---------- */
.empty { text-align: center; color: var(--muted); padding: 64px 0; line-height: 1.8; font-weight: 600; }
.empty-mark { display: flex; justify-content: center; margin-bottom: 12px; color: #cbd5e1; }
.empty-mark svg { width: 48px; height: 48px; }
.empty-sub { font-weight: 400; font-size: 14px; }
.hidden { display: none !important; }

/* ---------- 촬영 ---------- */
.capture-box { text-align: center; padding: 24px 8px; }
.hint { color: var(--muted); font-size: 14px; line-height: 1.7; margin-bottom: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 12px; padding: 12px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
  color: var(--text); box-shadow: var(--shadow-1);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.btn svg { width: 19px; height: 19px; }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, #2563eb, #4f46e5); color: #fff;
  border-color: transparent; box-shadow: 0 4px 12px rgba(37, 99, 235, .32);
}
.btn.primary:hover { box-shadow: 0 6px 18px rgba(37, 99, 235, .4); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); box-shadow: none; }
.btn.big { display: flex; width: 100%; max-width: 340px; margin: 0 auto 12px; padding: 16px; font-size: 16px; }
.dropzone {
  max-width: 340px; margin: 8px auto 0; padding: 26px 20px; border: 2px dashed #cbd5e1;
  border-radius: var(--radius); color: var(--muted); font-size: 13px;
  transition: border-color .18s var(--ease), color .18s var(--ease), background .18s var(--ease);
}
.dropzone.drag { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.ocr-progress {
  margin: 24px auto 0; display: flex; align-items: center; gap: 10px; justify-content: center;
  color: var(--primary); font-weight: 600;
}
.spinner {
  width: 20px; height: 20px; border: 3px solid #d7e3fb; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.preview { max-width: 100%; max-height: 240px; margin-top: 16px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow-2); }

/* ---------- 설정 ---------- */
.settings-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-1);
}
.settings-box h2 { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.settings-box label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
.settings-box input, .settings-box textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; background: #fbfcfe;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.settings-box input:focus, .settings-box textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
.msg { font-size: 13px; margin-top: 8px; min-height: 18px; }
.msg.ok { color: var(--ok); } .msg.err { color: var(--danger); }

/* ---------- 모달 (모바일: 바텀시트) ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; overflow-y: auto;
}
.modal-panel {
  background: var(--panel); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  position: relative; margin-top: 0;
  box-shadow: var(--shadow-3);
  animation: sheet-up .26s var(--ease);
  max-height: 92dvh; overflow-y: auto;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.icon-btn {
  position: absolute; top: 14px; right: 14px; border: none; background: #f1f5f9;
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: var(--muted);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: #e2e8f0; color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.detail-img {
  width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px;
  background: #f0f2f5; margin-bottom: 8px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .05);
  transition: transform .25s var(--ease);
  will-change: transform;
  touch-action: none; user-select: none; -webkit-user-drag: none;
}
.detail-img.dragging { transition: none; }
.flip-scene.tiltable .detail-img { background: repeating-conic-gradient(#f8fafc 0 25%, #eef2f7 0 50%) 0 0/16px 16px; }
.detail-img.is-cutout { filter: drop-shadow(0 6px 14px rgba(15, 23, 42, .18)); }
.fx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.btn.fx { padding: 9px 14px; font-size: 13.5px; background: var(--primary-soft); border-color: #dce4fb; color: var(--primary); box-shadow: none; }
.btn.fx:disabled { opacity: .6; cursor: wait; }
.tilt-hint { font-size: 11.5px; color: var(--muted); }
.detail-form label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.detail-form input, .detail-form textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; margin-top: 4px; color: var(--text); background: #fbfcfe;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.detail-form input:focus, .detail-form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
.row { display: flex; gap: 10px; }
.row > label { flex: 1; min-width: 0; }
.detail-form .row { margin-bottom: 8px; }
.detail-form .actions { margin-top: 6px; }
.detail-form .actions .btn { flex: 1; }

.email-section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.email-section h3 { font-size: 15px; font-weight: 800; margin-bottom: 10px; }
.tpl-row { display: flex; gap: 8px; margin-bottom: 10px; }
.btn.tpl { padding: 7px 14px; font-size: 13px; flex: 1; }
#mail-to, #mail-subject, #mail-body {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; margin-bottom: 8px; background: #fbfcfe;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
#mail-to:focus, #mail-subject:focus, #mail-body:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
#send-mail { width: 100%; padding: 13px; }
.email-history { margin-top: 12px; font-size: 12px; color: var(--muted); }
.email-history .log-item { padding: 7px 2px; border-bottom: 1px solid #f1f5f9; font-variant-numeric: tabular-nums; }

/* ---------- 모바일: 하단 탭바 ---------- */
@media (max-width: 640px) {
  header { justify-content: center; padding: 12px 16px; }
  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin-left: 0;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .tab {
    flex: 1; flex-direction: column; gap: 3px; padding: 6px 4px;
    font-size: 11px; border-radius: 12px;
  }
  .tab svg { width: 22px; height: 22px; }
  main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .modal-panel { border-radius: 20px 20px 0 0; }
}
@media (min-width: 641px) {
  .modal { align-items: flex-start; padding: 40px 20px; }
  .modal-panel { border-radius: var(--radius); margin-top: 0; animation: sheet-up .22s var(--ease); }
}
