/* ============================================================
   CS Customer Management — styles
   ============================================================ */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #0ea5e9;
  --danger: #ef4444;
  --success: #10b981;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --radius: 10px;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; background: var(--surface-2);
  color: var(--text); transition: background .12s, border-color .12s, transform .04s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.btn-secondary:hover:not(:disabled) { background: #bae6fd; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }

/* ---------- login ---------- */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e0e7ff 0%, var(--bg) 55%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 32px; display: flex; flex-direction: column; gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 6px; }
.login-logo {
  width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; font-weight: 800; font-size: 20px;
  display: flex; align-items: center; justify-content: center; letter-spacing: 1px;
}
.login-brand h1 { font-size: 20px; margin: 0 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.login-card input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.login-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.login-hint { text-align: center; font-size: 12px; margin: 4px 0 0; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 18px; }
.brand { font-weight: 800; font-size: 16px; color: var(--primary); letter-spacing: -.2px; }
.env-badge { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 6px; letter-spacing: .5px; }
.env-badge.env-dev { background: #fef3c7; color: #92400e; }
.env-badge.env-local { background: #e2e8f0; color: #475569; }
.page-nav { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.page-nav-btn {
  border: none; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit;
}
.page-nav-btn.is-active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 13px; color: var(--muted); font-weight: 600; }
.ai-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); }
.ai-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }

/* ---------- page ---------- */
.page { padding: 16px 18px 40px; max-width: 1600px; margin: 0 auto; }

/* ---------- month tabs ---------- */
.month-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.month-tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.month-tab:hover { border-color: var(--border-strong); }
.month-tab.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.month-add { border-style: dashed; color: var(--primary); }

/* ---------- toolbar (actions row + filter bar) ---------- */
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.filter-bar { display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.filter-bar .fbl { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.filter-bar select, .filter-bar .filter-date { padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 7px; font-size: 12px; font-family: inherit; background: var(--surface); }
.filter-bar .filter-search { padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 13px; font-family: inherit; min-width: 200px; }

/* ---------- typed cells ---------- */
.cell-num .cell-inner { text-align: right; font-variant-numeric: tabular-nums; }
.cell-long .cell-more { display: block; color: var(--primary); font-size: 11px; margin-top: 2px; }
.name-cell { min-width: 150px; }
.name-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 10px; }
.name-link { border: none; background: transparent; cursor: pointer; text-align: left; padding: 0; font-family: inherit; }
.name-orig { font-weight: 700; color: var(--primary); font-size: 13px; }
.name-ko { color: var(--muted); font-size: 12px; }
.name-copy { border: none; background: #eef2ff; color: var(--primary); cursor: pointer; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 5px; font-family: inherit; }
.name-copy:hover { background: #e0e7ff; }
.cell-sel { padding: 4px 6px; }
.cell-select { width: 100%; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-family: inherit; background: var(--surface); }
.status-sel { font-weight: 700; }
.status-최초 { background: #f1f5f9; color: #475569; }
.status-상담 { background: #dbeafe; color: #1d4ed8; }
.status-연결 { background: #e0e7ff; color: #4338ca; }
.status-예약 { background: #fef3c7; color: #92400e; }
.status-완료 { background: #dcfce7; color: #15803d; }
.settle-cell { cursor: pointer; text-align: center; padding: 8px; }
.settle-x { color: var(--danger); font-weight: 800; }
.settle-date { color: #15803d; font-weight: 700; font-size: 12px; }
.hist-btn { border: 1px solid #bae6fd; background: #e0f2fe; color: #0369a1; cursor: pointer; font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 6px; font-family: inherit; margin: 6px; }
.hist-btn:hover { background: #bae6fd; }

/* history modal */
.hist-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.hist-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; align-items: center; padding: 7px 10px; background: var(--surface-2); border-radius: 8px; }
.hist-date { font-weight: 700; color: var(--primary); font-size: 12px; }
.hist-text { font-size: 13px; }
.hist-del { border: none; background: transparent; color: var(--danger); cursor: pointer; font-size: 11px; }
.hist-add { display: grid; grid-template-columns: 150px 1fr auto; gap: 8px; }
.hist-add .hist-in { width: auto; }

/* column manager */
.col-manage-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.col-manage-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--surface-2); border-radius: 7px; font-size: 13px; }
.col-add-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; margin-top: 10px; }
.col-add-row .col-type { width: auto; }

/* user management */
.um-list { max-height: 320px; overflow: auto; margin: 8px 0 4px; }
.um-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.um-table th, .um-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: middle; }
.um-table thead th { background: var(--surface-2); position: sticky; top: 0; font-weight: 700; }
.um-sel { width: auto; padding: 4px 6px; font-size: 12px; }
.um-del { color: var(--danger); }
.um-create { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr 0.8fr auto; gap: 6px; align-items: center; }
.um-create .form-input { font-size: 12px; padding: 6px 8px; }

/* photos */
.name-link.has-photo .name-orig::before { content: "📷 "; font-size: 10px; }
.detail-photo { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.detail-photo-img { max-width: 160px; max-height: 200px; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; }
.detail-photo-empty { width: 120px; height: 120px; border: 1px dashed var(--border-strong); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.detail-photo-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.photo-preview { position: fixed; z-index: 300; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px; pointer-events: none; }
.photo-preview img { display: block; max-width: 180px; max-height: 220px; border-radius: 7px; }

/* PDF condition modal */
.pdf-cond { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; align-items: center; }
.pdf-range { display: flex; align-items: center; gap: 6px; }
.pdf-range .form-input { width: auto; }
.pdf-cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.pdf-col { display: flex; align-items: center; gap: 5px; font-size: 12px; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px;
}
.toolbar-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-search, .filter-value {
  padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 13px; font-family: inherit;
}
.filter-search { width: 180px; }
.filter-value { width: 130px; }
.filter-field { padding: 7px 8px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 13px; font-family: inherit; background: var(--surface); }
.date-range { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.filter-date { padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 12px; font-family: inherit; }
.table-meta { margin: 2px 2px 8px; font-size: 12px; }

/* ---------- table ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 250px); position: relative;
}
.data-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: left; }
.data-table thead th {
  position: sticky; top: 0; z-index: 5; background: var(--surface-2);
  padding: 8px 10px; font-size: 12px; font-weight: 700; color: #334155; vertical-align: bottom;
}
.th-inner { display: flex; align-items: center; gap: 6px; }
.th-label { white-space: nowrap; }
.th-badges { display: inline-flex; gap: 4px; }
.badge { font-size: 9px; padding: 1px 5px; border-radius: 6px; font-weight: 700; }
.badge-t { background: #ede9fe; color: #6d28d9; }
.th-actions { display: inline-flex; gap: 2px; margin-left: auto; }
.th-edit, .th-del { border: none; background: transparent; color: var(--border-strong); cursor: pointer; font-size: 11px; padding: 2px 4px; border-radius: 4px; }
.th-edit:hover { color: var(--primary); background: #eef2ff; }
.th-del:hover { color: var(--danger); background: #fef2f2; }
.col-idx { width: 40px; text-align: center; }
.col-idx-click { cursor: pointer; }
.col-idx-click:hover { color: var(--primary); text-decoration: underline; }
.col-actions { width: 72px; }
.col-data { min-width: 130px; max-width: 240px; }
.data-table tbody td { padding: 0; }
.cell { cursor: pointer; vertical-align: top; }
.cell:hover { background: #eef2ff; }
.cell-inner {
  padding: 8px 10px; max-height: 84px; overflow: hidden; font-size: 13px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.cell-empty .cell-inner { color: #cbd5e1; }
.data-table tbody tr:hover { background: #f8fafc; }
.col-idx.muted { padding: 8px; font-size: 12px; }
.row-del, .row-detail { border: none; background: transparent; cursor: pointer; font-size: 13px; opacity: .55; padding: 8px 5px; }
.row-del:hover, .row-detail:hover { opacity: 1; }

/* customer detail view */
.detail-sub { margin-bottom: 12px; }
.detail-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.detail-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: start; background: var(--surface); padding: 9px 12px; }
.detail-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.detail-value { font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.detail-copy { border: none; background: transparent; cursor: pointer; opacity: .5; font-size: 12px; }
.detail-copy:hover { opacity: 1; }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state p { margin: 4px 0; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow: auto;
}
.modal-card {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; animation: pop .14s ease-out;
}
.modal-wide { max-width: 720px; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { border: none; background: transparent; font-size: 15px; color: var(--muted); cursor: pointer; }
.modal-body { padding: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-msg { margin: 0 0 4px; line-height: 1.5; }

.field-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 10px 0 5px; }
.form-input, .cell-edit, .bulk-input, .lang-select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px;
  font-size: 13px; font-family: inherit; resize: vertical;
}
.form-input:focus, .cell-edit:focus, .bulk-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-top: 4px; }
.form-cell textarea { min-height: 34px; }
.check-row { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 10px; cursor: pointer; }

.bulk-input { min-height: 200px; }
.bulk-status { margin-top: 8px; min-height: 16px; }

/* import mapping */
.imp-file-row { margin: 8px 0 4px; display: flex; align-items: center; gap: 6px; }
.imp-summary { margin: 4px 0 8px; }
.imp-map-wrap { max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; }
.imp-map { border-collapse: collapse; width: 100%; font-size: 13px; }
.imp-map th, .imp-map td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: middle; }
.imp-map thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; }
.imp-h { font-weight: 600; white-space: nowrap; }
.imp-sample { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-sel { padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 7px; font-size: 12px; font-family: inherit; background: var(--surface); max-width: 200px; }
.imp-month-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.imp-month { width: auto; }

/* cell popover tools */
.cell-tools { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.lang-select { width: auto; padding: 6px 8px; }
.summary-out { margin-top: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.summary-text { white-space: pre-wrap; line-height: 1.5; font-size: 13px; }

/* ---------- dashboard ---------- */
.dash-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.dash-header h2 { margin: 0; font-size: 18px; }
.dash-controls { display: flex; align-items: center; gap: 10px; }
.dash-scope { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dash-scope select { padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 8px; font-family: inherit; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-value { font-size: 30px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.kpi-label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.kpi-sub { font-size: 11px; margin-top: 2px; }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.dash-card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.dash-card-head h4 { margin: 0; font-size: 14px; }
.dash-card-body { overflow-x: auto; }
.chart-svg { width: 100%; height: auto; display: block; max-width: 100%; }
.chart-val { font-size: 11px; fill: var(--muted); font-weight: 700; }
.chart-lbl { font-size: 11px; fill: #475569; }
.chart-empty { text-align: center; color: var(--border-strong); padding: 40px 0; font-size: 13px; }
.chart-donut { width: 160px; height: 160px; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut-center { font-size: 22px; font-weight: 800; fill: var(--text); }
.legend { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- toast ---------- */
.toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }

@media (max-width: 720px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .page-nav-btn { padding: 7px 10px; }
  .brand { display: none; }
}
