:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #d1242f;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2c3038;
    --accent: #4c8dff;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }

.view { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: 120px; }

/* 상단 막대 */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar h2 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar input[type="search"] {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
}
.back { border: 0; background: none; color: var(--accent); padding: 6px 4px; cursor: pointer; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 7px 12px; font-size: 14px; white-space: nowrap; cursor: pointer;
}
.chip.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* 로그인 */
.login { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login-logo { font-size: 48px; }
.login h1 { margin: 0 0 8px; }
.login input { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.login-note { margin: 0; font-size: 13px; color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* 목록 */
.count { color: var(--muted); font-size: 13px; margin: 10px 16px 4px; }
.card-list { list-style: none; margin: 0; padding: 0 12px; }
.card-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 6px;
  background: var(--surface); border-radius: var(--radius);
  cursor: pointer;
}
.card-list li:active { opacity: .7; }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent);
  font-weight: 700; font-size: 18px;
}
.who { flex: 1; min-width: 0; }
.who .name { font-weight: 600; }
.who .name small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.who .org, .who .tel { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; text-decoration: none;
  background: color-mix(in srgb, #2da44e 15%, transparent);
}
.empty { text-align: center; color: var(--muted); margin-top: 18vh; }

.fab-wrap { position: fixed; right: max(16px, calc(50vw - 304px)); bottom: calc(20px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; }
.fab {
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text);
  font-size: 30px; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer;
}
.fab.small { width: 46px; height: 46px; font-size: 20px; background: var(--surface); color: var(--text); }

/* 새 명함 */
.preview-wrap { padding: 16px; display: flex; justify-content: center; }
#preview { max-width: 100%; max-height: 60dvh; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.hint, .status { text-align: center; color: var(--muted); margin: 4px 16px; }
.actions { display: flex; gap: 10px; padding: 16px; }
.actions.wrap { flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
.btn {
  display: inline-flex; justify-content: center; align-items: center;
  padding: 13px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }

/* 상세 */
.card-image {
  display: block; width: calc(100% - 32px); margin: 16px auto 0;
  border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.15);
  background: var(--surface); cursor: zoom-in;
}
.card-image.small { max-height: 30dvh; object-fit: contain; }
.note { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, orange 18%, transparent); font-size: 14px; }
.fields { margin: 16px; background: var(--surface); border-radius: var(--radius); padding: 4px 0; }
.fields div { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); align-items: baseline; }
.fields div:last-child { border-bottom: 0; }
.fields dt { flex: none; width: 64px; color: var(--muted); font-size: 14px; }
.fields dd { margin: 0; flex: 1; min-width: 0; word-break: break-all; white-space: pre-wrap; }
.fields dd a { color: var(--accent); text-decoration: none; }
.fields dd .sms { margin-left: 10px; font-size: 14px; }

/* 수정 */
.edit-form { margin: 16px; display: flex; flex-direction: column; gap: 12px; }
.edit-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.edit-form input, .edit-form textarea {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 16px; color: var(--text);
}

/* 크게 보기 */
.zoom {
  position: fixed; inset: 0; z-index: 20; background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: auto; touch-action: pinch-zoom pan-x pan-y;
}
.zoom img { max-width: 100%; max-height: 100%; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30;
  max-width: calc(100vw - 32px);
}
