/* 영업콜 조회·MBO 웹 — 반응형(폰·PC), 라이트/다크 자동. 빌드 없는 바닐라 CSS. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1a2233;
  --text-dim: #5b6879;
  --text-faint: #8a97a8;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8f0fe;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --hot: #dc2626;
  --warm: #d97706;
  --cold: #2563eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1420;
    --surface: #161d2b;
    --surface-2: #1c2436;
    --border: #2a3446;
    --text: #e6ecf5;
    --text-dim: #a3b0c2;
    --text-faint: #6d7b90;
    --primary: #4f8bff;
    --primary-ink: #0b1120;
    --primary-soft: #1b2942;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); }

/* ── 버튼 ── */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.05); background: var(--primary); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); border-color: var(--border); }

/* ── 로그인 ── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 24px; box-shadow: var(--shadow);
}
.brand { font-size: 24px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.02em; }
.brand-dim { color: var(--text-faint); font-weight: 700; }
.login-sub { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .filters input, .filters select {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
}
.field input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.login-note { font-size: 12px; color: var(--text-faint); margin: 18px 0 0; line-height: 1.5; }

/* ── 상단바 ── */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in {
  max-width: 1720px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 12px; height: 56px;
}
.topbar-brand { font-weight: 800; font-size: 17px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; margin-left: 8px; flex: 1; overflow-x: auto; }
.tab {
  border: none; background: transparent; color: var(--text-dim);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tab.active { background: var(--primary-soft); color: var(--primary); }
.topbar-user { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.who { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.badge-admin { background: var(--warn); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; margin-left: 6px; font-weight: 700; }

/* 넓은 PC 화면 활용 — 데이터 목록/표가 좌우 여백 낭비 없이 펼쳐지도록(1080→1720). 로그인 폼·상세 패널은 별도 폭 유지. */
.main { max-width: 1720px; margin: 0 auto; padding: 18px 24px 60px; }
@media (max-width: 640px) { .main { padding: 14px 12px 48px; } .topbar-in { padding: 0 12px; } }

/* ── 필터바 ── */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
}
.filters .grow { flex: 1 1 180px; min-width: 140px; }
.filters select, .filters input { width: auto; flex: 0 0 auto; }
.filters input[type="search"] { flex: 1 1 200px; }
.filters input[type="date"] { flex: 0 0 auto; }

/* ── 리스트 카드 ── */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
}
.card:hover { border-color: var(--primary); }
.card:active { transform: scale(0.997); }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-date { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.card-headline { color: var(--text-dim); font-size: 14px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); font-weight: 600;
}
.chip.sol { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip.hot { color: var(--hot); }
.chip.warm { color: var(--warm); }
.chip.cold { color: var(--cold); }
.chip.type-sales { background: rgba(37,99,235,0.12); color: var(--primary); border-color: transparent; }

/* 회사 연락처(전화·이메일) 칩 */
.contact-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.contact-chip {
  font-size: 13px; padding: 5px 10px; border-radius: 8px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 4px;
}
.contact-x {
  border: none; background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px; margin-left: 2px;
}
.contact-x:hover { color: var(--hot); }

/* 회사 콤보박스(자동완성) */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 240px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
.combo-list.hidden { display: none; }
.combo-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 14px;
}
.combo-item:hover { background: var(--surface-2); }
.combo-badge { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

/* ── 페이지네이션 ── */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 20px; }
.pager span { color: var(--text-dim); font-size: 13px; }

/* ── 상세 오버레이 ── */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 20, 0.5); z-index: 40; display: flex; justify-content: flex-end; }
.panel {
  width: 100%; max-width: 560px; height: 100dvh; overflow-y: auto;
  background: var(--surface); box-shadow: var(--shadow); padding: 20px 22px 60px;
  animation: slidein 0.18s ease-out;
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.panel-head h2 { margin: 0; font-size: 19px; }
.panel-close { border: none; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 16px; color: var(--text-dim); }
.panel-sub { color: var(--text-faint); font-size: 13px; margin: 0 0 16px; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; margin: 12px 0; }
.kv dt { color: var(--text-faint); font-size: 13px; }
.kv dd { margin: 0; font-size: 14px; word-break: break-word; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin: 22px 0 8px; }
.notes { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; white-space: pre-wrap; line-height: 1.6; }

.phone-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.phone-val { font-variant-numeric: tabular-nums; font-weight: 700; }
.unmasked { color: var(--danger); }
.audit-note { font-size: 12px; color: var(--warn); margin-top: 6px; }

/* ── 고객 상세 · 이슈 모아보기 ── */
.issue-block { margin: 8px 0 16px; }
.issue-list { display: flex; flex-direction: column; gap: 6px; }
.issue-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 14px; }
.issue-item .meta { color: var(--text-faint); font-size: 12px; }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-item { border-left: 2px solid var(--border); padding: 2px 0 8px 14px; position: relative; }
.tl-item::before { content: ""; position: absolute; left: -5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.tl-date { font-size: 12px; color: var(--text-faint); }
.tl-head { font-weight: 600; font-size: 14px; }

/* ── MBO ── */
.mbo-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.mbo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.mbo-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.mbo-name { font-weight: 700; font-size: 15px; }
.mbo-meta { display: flex; gap: 6px; align-items: center; margin: 4px 0 10px; flex-wrap: wrap; }
.src { font-size: 11px; padding: 2px 7px; border-radius: 6px; font-weight: 700; }
.src-call { background: rgba(21,128,61,0.14); color: var(--ok); }
.src-sheet { background: rgba(37,99,235,0.14); color: var(--primary); }
.src-manual { background: rgba(180,83,9,0.16); color: var(--warn); }
.mbo-val { font-size: 22px; font-weight: 800; }
.mbo-val small { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.mbo-target { color: var(--text-faint); font-size: 13px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; border: 1px solid var(--border); }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.bar > i.done { background: var(--ok); }
.mbo-note { font-size: 12px; color: var(--warn); margin-top: 6px; }
.mbo-actions { display: flex; gap: 6px; margin-top: 10px; }
.deferred { opacity: 0.72; }

/* ── 카탈로그 선택(모달 내) ── */
.cat-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; margin: 8px 0; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }
.cat-item.sel { border-color: var(--primary); background: var(--primary-soft); }

.muted { color: var(--text-faint); }
.empty { text-align: center; color: var(--text-faint); padding: 48px 16px; }
.spin { text-align: center; color: var(--text-dim); padding: 40px; }

/* ── 토스트 ── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: 90vw;
}

@media (max-width: 560px) {
  .topbar-brand { display: none; }
  .kv { grid-template-columns: 84px 1fr; }
  .panel { max-width: 100%; }
}

/* ─── 콜 인라인 수정 · 수정뱃지 · admin owner 칩 (웹뷰 수정 트랙) ─── */
.panel-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.badge-edited {
  display: inline-block; background: var(--surface-2); color: var(--text-dim);
  border: 1px solid var(--border); font-size: 11px; padding: 2px 7px;
  border-radius: 999px; margin-left: 6px; font-weight: 600; white-space: nowrap;
}
.chip.chip-owner { background: rgba(37,99,235,0.10); color: var(--primary); border-color: transparent; font-weight: 600; }

.edit-form .field { margin-bottom: 12px; }
.edit-form .field textarea, .edit-form .field select {
  width: 100%; padding: 10px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); line-height: 1.5; resize: vertical;
}
.edit-form .field textarea:focus, .edit-form .field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.edit-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
@media (max-width: 560px) {
  .field-row { flex-direction: column; gap: 0; }
}

/* ─── 사용자 관리 ─── */
.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.user-row.inactive { opacity: 0.55; }
.user-main { min-width: 0; }
.user-id { font-weight: 700; font-size: 15px; }
.user-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-ctl .mini { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.user-ctl select { padding: 6px 8px; font-size: 14px; font-family: inherit; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); }
@media (max-width: 560px) {
  .user-row { flex-direction: column; align-items: stretch; }
  .user-ctl { justify-content: flex-start; }
}

/* ─────────────────────────── 실적현황(영업관리 CRM 미러) ─────────────────────────── */
.sales-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.sales-spacer { flex: 1; }
.subtab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600;
}
.subtab.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.sales-body { min-height: 120px; }

/* 칸반 */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kb-col {
  flex: 0 0 240px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; display: flex; flex-direction: column;
}
.kb-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; }
.kb-count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.kb-amount { color: var(--text-dim); font-size: 12px; margin: 3px 0 8px; }
.kb-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.kb-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 10px; cursor: pointer; box-shadow: var(--shadow); }
.kb-card:hover { border-color: var(--primary); }
.kb-company { font-weight: 600; font-size: 14px; }
.kb-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.kb-money { color: var(--ok); font-size: 12px; font-weight: 600; margin-top: 4px; }
.kb-empty { color: var(--text-faint); text-align: center; font-size: 13px; padding: 10px 0; }

/* 계약목록 테이블(반응형 grid row) */
.sr-table { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.sr-row { display: grid; grid-template-columns: 1.6fr 0.8fr 1fr 0.9fr 1.1fr 0.9fr; gap: 8px; padding: 10px 12px; align-items: center; border-top: 1px solid var(--border); font-size: 13px; cursor: pointer; }
.sr-row:first-child { border-top: none; }
.sr-row:not(.sr-th):hover { background: var(--surface-2); }
.sr-th { background: var(--surface-2); font-weight: 700; color: var(--text-dim); cursor: default; font-size: 12px; }
.sr-company { font-weight: 600; }
.sr-money { color: var(--ok); font-weight: 600; }
.sr-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 엑셀식 계약목록 표 — 영업관리 시트 컬럼 순서. 넓은 화면 활용 + 컬럼 많으면 가로 스크롤. */
.grid-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); -webkit-overflow-scrolling: touch; }
.grid { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
.grid thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-dim); font-weight: 700; font-size: 12px;
  text-align: left; padding: 9px 12px; border-bottom: 2px solid var(--border); user-select: none;
}
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { color: var(--text); background: var(--primary-soft); }
.grid th.sorted { color: var(--primary); }
.grid th.sr-num, .grid td.sr-num { text-align: right; font-variant-numeric: tabular-nums; }
.grid tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid td.sr-company { font-weight: 600; }
.grid td.sr-num { color: var(--text); }

/* 집계 대시보드 */
.db-ctrl { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-dim); font-size: 13px; }
.kpi-label small { color: var(--text-faint); }
.kpi-val { font-size: 30px; font-weight: 800; margin-top: 6px; }
.kpi-val small { font-size: 15px; font-weight: 600; color: var(--text-dim); }
.kpi-sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }

/* 진행단계 배지 색 */
.chip.st-done { background: #dcfce7; color: #166534; }
.chip.st-lost { background: #fee2e2; color: #991b1b; }
.chip.st-hot { background: #fef3c7; color: #92400e; }
.chip.st-warm { background: var(--surface-2); color: var(--text-dim); }
.chip.st-lead { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) {
  .chip.st-done { background: #14331f; color: #6ee7a0; }
  .chip.st-lost { background: #3a1a1a; color: #f6a6a6; }
  .chip.st-hot { background: #3a2c12; color: #f4c672; }
}

/* 월별분석 표(가로 스크롤) */
.an-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.an-table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
.an-table th, .an-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); }
.an-table thead th { background: var(--surface-2); color: var(--text-dim); font-weight: 700; position: sticky; top: 0; }
.an-label { text-align: left !important; font-weight: 600; position: sticky; left: 0; background: var(--surface); }
.an-total { font-weight: 700; }
.an-table tr.an-key td { background: var(--surface-2); font-weight: 600; }
.an-table tr.an-key .an-label { background: var(--surface-2); }
