:root {
  --brand: #8c1914;
  --brand-dark: #6e120e;
  --brand-soft: #fbeeed;
  --ink: #17140f;
  --ink-2: #4a453e;
  --ink-3: #8a847a;
  --line: #e8e4dd;
  --line-2: #f1eee8;
  --bg: #f7f5f1;
  --card: #ffffff;
  --ok: #1f7a4d;
  --ok-soft: #e7f4ec;
  --warn: #a35a00;
  --warn-soft: #fdf1e1;
  --info: #24569e;
  --info-soft: #e9f0fa;
  --mute-soft: #efede9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 20, 15, .04), 0 4px 16px rgba(23, 20, 15, .06);
  --header-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 36px 28px 28px; }
.login-card .logo { display: block; width: 190px; max-width: 70%; margin: 0 auto 6px; }
.login-card .sub { text-align: center; color: var(--ink-3); font-size: 14px; margin: 0 0 28px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 11px 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(140, 25, 20, .12); }
.textarea { resize: vertical; min-height: 84px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 14px;
  font-weight: 600; font-size: 14px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--line-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-block { width: 100%; padding: 13px; font-size: 15px; }
.btn-danger { color: var(--brand); border-color: #ecc9c6; }
.btn-danger:hover { background: var(--brand-soft); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.form-error { color: var(--brand); font-size: 13px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- Header ---------- */
.header {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
}
.header .logo { height: 26px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; color: var(--ink-3); }
.nav button.active { color: var(--ink); background: var(--line-2); }
.header .spacer { flex: 1; }
.me { position: relative; }
.me > button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.me .badge-role { font-size: 11px; color: var(--brand); background: var(--brand-soft); padding: 1px 7px; border-radius: 999px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 170px; padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.menu button:hover { background: var(--line-2); }

/* ---------- Layout ---------- */
.main { max-width: 1240px; margin: 0 auto; padding: 20px 20px 80px; }
.page-title { font-size: 20px; font-weight: 700; margin: 4px 0 16px; letter-spacing: -.01em; }

/* ---------- Status tabs ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.tab .n { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab.active .n { color: rgba(255, 255, 255, .7); }
.tab.recall { border-color: #f0d3b0; }
.tab.recall.active { background: var(--warn); border-color: var(--warn); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search .input { padding-left: 36px; }
.toolbar .search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.toolbar .select { width: auto; min-width: 120px; }
.count-line { color: var(--ink-3); font-size: 13px; margin: -4px 0 10px; }

/* ---------- Lead table ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); font-size: 14px; vertical-align: middle; }
.table tbody tr { cursor: pointer; transition: background .1s; }
.table tbody tr:hover { background: #fcfbf9; }
.table tbody tr:last-child td { border-bottom: 0; }
.nm { font-weight: 700; }
.ph { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st-신규 { background: var(--info-soft); color: var(--info); }
.st-부재 { background: var(--warn-soft); color: var(--warn); }
.st-상담중 { background: var(--brand-soft); color: var(--brand); }
.st-미팅시식 { background: #f3e9f8; color: #6b2e8a; }
.st-계약완료 { background: var(--ok-soft); color: var(--ok); }
.st-계약실패, .st-단순문의종료, .st-조건미달, .st-불량 { background: var(--mute-soft); color: var(--ink-3); }
.src { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-right: 3px; border: 1px solid var(--line); color: var(--ink-2); background: #fff; }
.src-meta { color: #1d4ed8; border-color: #cfdcf7; }
.src-bizchange { color: var(--brand); border-color: #ecc9c6; }
.src-insta { color: #b0306a; border-color: #f0cbdc; }
.recall-due { color: var(--warn); font-weight: 700; }

/* Mobile list */
.lead-cards { display: none; }
.lead-card { padding: 14px 16px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.lead-card:last-child { border-bottom: 0; }
.lead-card .row1 { display: flex; align-items: center; gap: 8px; }
.lead-card .row1 .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-card .row2 { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 13px; color: var(--ink-3); }

.empty { padding: 48px 16px; text-align: center; color: var(--ink-3); }

/* ---------- Drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(23, 20, 15, .32); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 41;
  display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
}
.drawer-head { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 18px; display: flex; align-items: center; gap: 12px; }
.drawer-head .who { flex: 1; min-width: 0; }
.drawer-head .who .nm { font-size: 18px; }
.icon-btn { border: 0; background: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:hover { background: var(--line-2); }
.call-btn { background: var(--brand); color: #fff; border-radius: 10px; padding: 9px 14px; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }
.section { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.section h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.seg button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 11px; font-weight: 700; }
.seg button.on-absent { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.seg button.on-talk { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.t-call-absent::before { background: var(--warn); }
.timeline li.t-call-talk::before { background: var(--ok); }
.timeline li.t-status::before { background: var(--brand); }
.timeline li.t-sub::before { background: var(--info); }
.timeline .when { font-size: 12px; color: var(--ink-3); }
.memo-text { white-space: pre-wrap; font-size: 14px; }
.memo-old { white-space: pre-wrap; font-size: 13px; color: var(--ink-2); background: var(--line-2); border-radius: 8px; padding: 10px 12px; margin-top: 10px; max-height: 220px; overflow: auto; }

/* ---------- Stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .l { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--ink-3); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 112px; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 9px; }
.bar { height: 10px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.bar-row .pct { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.stack { display: flex; height: 14px; border-radius: 999px; overflow: hidden; margin: 6px 0 12px; background: var(--line-2); }
.stack > i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini-table th, .mini-table td { padding: 8px 6px; border-bottom: 1px solid var(--line-2); text-align: right; font-variant-numeric: tabular-nums; }
.mini-table th:first-child, .mini-table td:first-child { text-align: left; }
.mini-table th { font-size: 12px; color: var(--ink-3); font-weight: 600; }

/* ---------- Staff ---------- */
.staff-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.staff-row:last-child { border-bottom: 0; }
.staff-row .info { flex: 1; min-width: 160px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { width: 36px; height: 20px; appearance: none; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: left .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { left: 18px; }

/* ---------- Modal / toast ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(23, 20, 15, .4); }
.modal { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 80; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .header { padding: 0 12px; gap: 8px; }
  .header .logo { height: 22px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; background: #fff; border-top: 1px solid var(--line); z-index: 35; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .nav button { flex: 1; font-size: 13px; padding: 9px 4px; }
  .nav.single { display: none; }
  .main { padding: 14px 12px 96px; }
  .table-wrap { display: none; }
  .lead-cards { display: block; }
  .toolbar .select { flex: 1; min-width: 0; }
  .drawer { width: 100%; }
  .drawer-body { padding: 12px 12px 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 84px 1fr; }
}
