:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --ink: #15171c;
  --muted: #5f6470;
  --faint: #8f949e;
  --line: #e7e5e0;
  --brand: #23314f;
  --brand-2: #31436a;
  --brand-soft: #eceff5;
  --accent: #a67c3d;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --ok: #2e6b4f;
  --ease: cubic-bezier(.2, .7, .1, 1);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; font-size: 15px; line-height: 1.5; letter-spacing: -0.01em; }
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.sample-bar { background: #1a1c21; color: #d8dbe2; font-size: 12px; text-align: center; padding: 7px 16px; }

.top { max-width: 880px; margin: 0 auto; padding: 18px 20px 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who b { display: block; font-size: 16px; }
.who small { color: var(--muted); font-size: 13px; }
.tag-sample { font-size: 11px; font-weight: 600; color: #7a5d22; background: #f4ecdb; padding: 2px 8px; border-radius: 99px; margin-left: 4px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.me { background: var(--brand); color: #fff; }
.avatar.big { width: 56px; height: 56px; font-size: 22px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 15px; text-decoration: none; transition: background .18s, border-color .18s, transform .15s var(--ease); white-space: nowrap; }
.btn:hover { border-color: #d6d3cc; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.ghost { color: var(--muted); }
.btn.full { width: 100%; }
.link { border: 0; background: none; padding: 6px 4px; color: var(--muted); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: #cfccc5; }
.link.small { font-size: 13px; }
.link.tiny { font-size: 12px; padding: 0 2px; margin-left: auto; color: var(--faint); }
.link.danger { color: var(--danger); }

.tabs { max-width: 880px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { text-decoration: none; padding: 12px 10px; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.tabs a.on { color: var(--ink); border-color: var(--ink); }
.badge:not(:empty) { background: var(--danger); color: #fff; font-size: 12px; min-width: 20px; height: 20px; border-radius: 99px; display: inline-grid; place-items: center; padding: 0 6px; }
.count { color: var(--faint); font-weight: 500; font-size: 13px; }

.main { max-width: 880px; margin: 0 auto; padding: 22px 20px 80px; }
.date-line { margin: 4px 0 2px; color: var(--muted); font-size: 14px; }
h1 { font-size: 28px; letter-spacing: -0.03em; margin: 0 0 22px; line-height: 1.25; }
h1.h-small { font-size: 22px; margin-bottom: 6px; }
.sub { color: var(--muted); margin: 0 0 18px; }

.group { margin-bottom: 26px; }
.group h2 { font-size: 15px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.group h2 span { color: var(--faint); font-weight: 500; }
.group:first-child h2 { color: var(--danger); }
.g-note { margin: 0 0 10px; font-size: 13px; color: var(--faint); }

.rows { list-style: none; margin: 8px 0 0; padding: 0; background: var(--surface); border-radius: 16px; box-shadow: 0 1px 0 var(--line); overflow: hidden; }
.rows:empty { display: none; }
.row-wrap { display: flex; align-items: stretch; border-top: 1px solid #f0eee9; }
.row-wrap:first-child { border-top: 0; }
.row { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 0; background: none; text-align: left; transition: background .15s; }
.row:hover { background: #fbfaf8; }
.row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.row-main { flex: 1; min-width: 0; }
.row-name { display: flex; align-items: center; gap: 8px; }
.row-name b { font-size: 16px; }
.row-main small { display: block; color: var(--faint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-side { text-align: right; flex: none; max-width: 42%; }
.row-side small { display: block; color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call { flex: none; display: grid; place-items: center; width: 64px; border-left: 1px solid #f0eee9; color: var(--brand); font-weight: 700; font-size: 14px; text-decoration: none; }
.call:hover { background: var(--brand-soft); }

.pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #f1efea; color: var(--muted); white-space: nowrap; }
.pill[data-s="상담 중"] { background: #e9eef7; color: #2c4a80; }
.pill[data-s="계약"] { background: #e7f1ec; color: var(--ok); }
.pill[data-s="보류"] { background: #f3f1ec; color: #8a8378; }
.pill.arch { background: #f4ecdb; color: #7a5d22; margin-left: 6px; }
.due { font-style: normal; font-weight: 600; font-size: 13px; color: var(--muted); }
.due.today { color: var(--brand); }
.due.overdue { color: var(--danger); }
.due.none { color: #b5b8bf; font-weight: 500; }

.search input { width: 100%; height: 50px; border: 1px solid var(--line); border-radius: 14px; padding: 0 16px 0 44px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%238f949e' stroke-width='2'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E") no-repeat 15px 50%; font-size: 16px; outline: none; }
.search input:focus { border-color: var(--brand); }
.filters { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; }
.filters select { height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: #fff; }
.seg { display: inline-flex; background: #eceae5; border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
.seg label { position: relative; flex: none; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; transition: background .15s, color .15s; }
.seg input:checked + span { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }
.seg.small span { padding: 6px 10px; font-size: 13px; }
.seg.wrap { flex-wrap: wrap; }
.tag-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 11px; font-size: 13px; color: var(--muted); font-weight: 500; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.mini { padding: 3px 9px; font-size: 12px; }
.result-line { font-size: 13px; color: var(--faint); margin: 14px 2px 0; }
.tg { font-size: 13px; color: var(--brand); background: var(--brand-soft); padding: 2px 8px; border-radius: 6px; margin: 0 4px 4px 0; display: inline-block; }

.empty { text-align: center; padding: 48px 20px; background: var(--surface); border-radius: 16px; box-shadow: 0 1px 0 var(--line); }
.empty-mark { width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 14px; background: var(--brand-soft); position: relative; }
.empty-mark::after { content: ''; position: absolute; inset: 17px; border: 2.5px solid var(--brand); border-radius: 50%; opacity: .5; }
.empty b { display: block; font-size: 17px; margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 340px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.empty.small { padding: 22px 16px; box-shadow: none; background: #faf9f7; }
.empty.small p { margin-bottom: 0; font-size: 14px; }

/* 가져오기·내보내기 */
.io-card { background: var(--surface); border-radius: 16px; padding: 22px 20px; box-shadow: 0 1px 0 var(--line); margin-top: 16px; }
.io-card h2 { font-size: 17px; margin: 0 0 6px; }
.io-card p { margin: 0 0 14px; color: var(--muted); }
.io-card.muted { background: #fbfaf8; }
.drop { display: block; position: relative; border: 1.5px dashed #d3d0c8; border-radius: 14px; padding: 26px 16px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop b { display: block; color: var(--brand); }
.drop small { color: var(--faint); }
.imp { margin: 14px 0 0 !important; padding: 12px 14px; border-radius: 10px; }
.imp.ok { background: #eef5f1; color: var(--ok) !important; }
.imp.bad { background: var(--danger-soft); color: var(--danger) !important; }
.skips { margin: 8px 0 0; padding: 0 0 0 18px; color: var(--muted); font-size: 14px; }
.skips li { margin: 3px 0; }
.io-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 상세 패널: 오른쪽에서 열림 */
.scrim { position: fixed; inset: 0; background: rgba(16, 19, 26, .38); opacity: 0; transition: opacity .3s var(--ease); z-index: 20; }
.scrim.on { opacity: 1; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg); z-index: 21; transform: translateX(104%); transition: transform .38s var(--ease); overflow-y: auto; overscroll-behavior: contain; padding: 0 0 40px; outline: none; box-shadow: -20px 0 50px rgba(0,0,0,.08); }
.panel.open { transform: none; }
.p-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: rgba(247,246,243,.92); backdrop-filter: blur(10px); }
.p-actions { display: flex; gap: 6px; }
.x { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #ebe9e4; font-size: 20px; color: var(--muted); display: grid; place-items: center; }
.p-id { display: flex; gap: 14px; align-items: center; padding: 6px 20px 16px; }
.p-id h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.03em; }
.p-phone { margin: 0 20px; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--surface); border-radius: 14px; text-decoration: none; box-shadow: 0 1px 0 var(--line); }
.p-phone span { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.p-phone b { color: var(--brand); font-size: 14px; }
.p-nophone { margin: 0 20px; color: var(--faint); }
.p-next { margin: 12px 20px 0; padding: 16px; border-radius: 14px; background: var(--surface); box-shadow: 0 1px 0 var(--line); }
.p-next.due-now { background: #fff7f6; box-shadow: inset 0 0 0 1px #f2d3d0; }
.p-next h3, .p-logs h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.p-next p { margin: 0; }
.p-next .reason { color: var(--muted); margin-top: 2px; }
.muted { color: var(--faint); }
.p-info { margin: 12px 20px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: 14px; overflow: hidden; }
.p-info div { background: var(--surface); padding: 14px 16px; }
.p-info .full { grid-column: 1 / -1; }
.p-info dt { font-size: 12px; color: var(--faint); margin-bottom: 4px; }
.p-info dd { margin: 0; }
.p-info dd small { color: var(--faint); }
.memo { white-space: pre-wrap; }
.p-logs { margin: 22px 20px 0; }
.p-logs h3 span { color: var(--faint); font-weight: 500; }
.log-form { background: var(--surface); border-radius: 14px; padding: 14px; box-shadow: 0 1px 0 var(--line); display: grid; gap: 10px; margin-bottom: 18px; }
.log-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.log-form input[type=date], .log-form input:not([type]), .log-form textarea { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fcfbfa; outline: none; }
.log-form textarea { resize: vertical; width: 100%; font-size: 16px; }
.log-form input:focus, .log-form textarea:focus { border-color: var(--brand); background: #fff; }
.next-pick { display: grid; gap: 8px; padding-top: 4px; }
.next-pick > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 8px; bottom: 8px; width: 1.5px; background: var(--line); }
.timeline li { display: flex; gap: 14px; padding: 0 0 16px; position: relative; }
.tl-dot { width: 13px; height: 13px; border-radius: 50%; background: #fff; border: 2.5px solid var(--brand); margin-top: 5px; flex: none; position: relative; z-index: 1; }
.tl-dot[data-ch="방문"] { border-color: var(--accent); }
.tl-dot[data-ch="문자"], .tl-dot[data-ch="카톡"] { border-color: #8f949e; }
.tl-body { flex: 1; min-width: 0; }
.tl-meta { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.tl-meta span { color: var(--muted); }
.tl-meta small { color: var(--faint); }
.tl-body p { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; }
.p-foot { margin: 20px; font-size: 12px; color: var(--faint); }

/* 창 */
.dlg { border: 0; padding: 0; border-radius: 20px; width: min(520px, calc(100% - 24px)); max-height: 90vh; background: #fff; color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.18); }
.dlg::backdrop { background: rgba(16, 19, 26, .42); }
.dlg[open] { animation: pop .3s var(--ease); }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.dlg.small { width: min(380px, calc(100% - 24px)); }
.dlg form { display: flex; flex-direction: column; max-height: 90vh; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.dlg-head h2, .dlg-body h2 { margin: 0; font-size: 19px; }
.dlg-body { padding: 12px 20px; overflow-y: auto; }
.dlg-body p { color: var(--muted); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid #f0eee9; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #3b3f48; }
.field > span small { font-weight: 400; color: var(--faint); }
.field i { font-style: normal; color: var(--accent); font-size: 12px; margin-left: 3px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fcfbfa; outline: none; font-size: 16px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); background: #fff; }
.field.bad input { border-color: var(--danger); background: #fffafa; }
.err, .warn { display: block; font-style: normal; font-size: 13px; margin-top: 5px; font-weight: 600; }
.err { color: var(--danger); }
.warn { color: #8a5a00; }
.err:empty, .warn:empty { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.guide h3 { font-size: 15px; margin: 18px 0 4px; }
.guide h3:first-child { margin-top: 4px; }
.guide h3.accent { color: var(--accent); }
.guide p { margin: 0; line-height: 1.65; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #1c1f26; color: #fff; padding: 12px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center; opacity: 0; pointer-events: none; transition: opacity .25s, transform .3s var(--ease); z-index: 40; font-size: 14px; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: #d6b77d; font-weight: 700; padding: 0; }

@media (max-width: 560px) {
  .top { padding: 14px 16px 8px; }
  .tabs, .main { padding-left: 16px; padding-right: 16px; }
  .link#open-guide { display: none; }
  h1 { font-size: 24px; }
  .two { grid-template-columns: 1fr; gap: 0; }
  .p-info { grid-template-columns: 1fr; }
  .row { padding: 13px 12px; gap: 10px; }
  .avatar { width: 36px; height: 36px; }
  .call { width: 56px; }
  .tag-filter { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  .tag-filter::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .filters { flex-wrap: nowrap; }
  .filters select { flex: none; }
  .dlg { width: 100%; max-width: none; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 94vh; }
  .dlg.small { width: calc(100% - 24px); margin: auto; border-radius: 20px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
.backup-note { margin: 0 0 14px !important; padding: 10px 12px; border-radius: 10px; background: #f8f2e5; color: #7a5d22 !important; font-size: 14px; }
.btn.danger-t { color: var(--danger); }

.nonext-link { display: flex; align-items: center; gap: 6px; width: 100%; margin-top: 4px; padding: 14px 16px; border: 1px dashed #d6d3cc; border-radius: 14px; background: none; color: var(--muted); font-size: 14px; text-align: left; }
.nonext-link b { color: var(--ink); }
.nonext-link span { margin-left: auto; }
.nonext-link:hover { border-color: var(--brand); color: var(--brand); }
.chip.warn-chip { border-style: dashed; }
.chip.warn-chip.on { border-style: solid; }
.tl-acts { margin-left: auto; display: inline-flex; gap: 8px; }
.tl-acts .link.tiny { margin-left: 0; }
.edited { color: var(--faint); font-size: 12px; }
.log-form.editing { box-shadow: inset 0 0 0 1.5px var(--brand); }
.edit-note { margin: 0; font-size: 13px; font-weight: 600; color: var(--brand); }
.two-btn { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.btn.more { margin-top: 4px; color: var(--muted); }
.dup-box { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: #f8f2e5; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dup-box p { margin: 0 !important; color: #7a5d22 !important; font-size: 14px; }
