/* ===== 씨그로 공헌이익 대시보드 ===== */

.cg-app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

/* ===== Sidebar ===== */
.cg-sidebar {
  background: #fff;
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.cg-side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.cg-back {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #f4f4f8;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  transition: background .12s;
}
.cg-back:hover { background: var(--primary-soft); color: var(--primary); }

.cg-side-title { line-height: 1.2; }
.cg-side-brand { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
.cg-side-sub  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.cg-side-search {
  padding: 12px 14px 8px;
}
.cg-side-search input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 12.5px;
  background: #fafafc;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.cg-side-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(92, 92, 224, 0.12);
  background: #fff;
}

.cg-client-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.cg-client-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  transition: background .12s;
}
.cg-client-row:hover { background: #f6f6fa; }
.cg-client-row.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 600;
}

.cg-client-avatar {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: #ECECFB;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.cg-client-row.active .cg-client-avatar {
  background: var(--primary);
  color: white;
}

.cg-client-meta {
  flex: 1;
  min-width: 0;
}
.cg-client-name { font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-client-cm  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.cg-client-row.active .cg-client-cm { color: var(--primary-strong); }

/* ===== Main ===== */
.cg-main {
  padding: 24px 28px 40px;
  min-width: 0;
}

.cg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.cg-header-left { min-width: 0; }
.cg-page-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.cg-period-tabs {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.cg-period-tab {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
  font-weight: 500;
}
.cg-period-tab:hover { color: var(--text); }
.cg-period-tab.active {
  background: var(--primary);
  color: #fff;
}

.cg-btn-secondary, .cg-btn-ghost {
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.cg-btn-secondary:hover, .cg-btn-ghost:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}
.cg-btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); padding: 6px 10px; }
.cg-btn-ghost:hover { background: var(--primary-soft); color: var(--primary-strong); border-color: transparent; }

/* ===== KPI ===== */
.cg-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.cg-kpi-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.cg-kpi-card.cg-kpi-highlight {
  background: linear-gradient(135deg, var(--primary) 0%, #7676E8 100%);
  color: #fff;
  border-color: transparent;
}
.cg-kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.cg-kpi-card.cg-kpi-highlight .cg-kpi-label { color: rgba(255,255,255,0.85); }
.cg-kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.cg-kpi-meta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  min-height: 14px;
}
.cg-kpi-card.cg-kpi-highlight .cg-kpi-meta { color: rgba(255,255,255,0.9); }
.cg-kpi-meta.up   { color: #2ecc71; }
.cg-kpi-meta.down { color: #e94c3c; }

/* ===== Cards ===== */
.cg-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 16px;
}
.cg-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.cg-card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.cg-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px 10px;
  flex-wrap: wrap;
}
.leg-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.cg-card-tag {
  font-size: 10.5px;
  color: #2ecc71;
  background: #E8F8EE;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 500;
}

/* ===== Charts ===== */
.cg-chart-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.cg-chart-wrap {
  position: relative;
  height: 320px;
}
.cg-donut-wrap { height: 220px; }
.cg-donut-legend {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  font-size: 11.5px;
  color: var(--text);
}
.cg-donut-legend .leg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.cg-donut-legend .leg-name { display: flex; align-items: center; gap: 6px; }
.cg-donut-legend .leg-val { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ===== Detail row ===== */
.cg-detail-row {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
}

/* ===== Cost panel ===== */
.cg-cost-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.cg-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cg-input span {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
}
.cg-input input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  background: #fafafc;
  font-variant-numeric: tabular-nums;
}
.cg-input input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(92,92,224,0.12);
  background: #fff;
}
.cg-input small {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}
.cg-input-full { grid-column: 1 / -1; }

/* ===== Daily table ===== */
.cg-table-wrap {
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.cg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.cg-table th, .cg-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.cg-table th {
  background: #fafafc;
  position: sticky;
  top: 0;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  z-index: 1;
}
.cg-table td.num, .cg-table th.num { text-align: right; }
.cg-table tr:hover td { background: #fafafc; }
.cg-table .cm-pos { color: #1f9d55; font-weight: 600; }
.cg-table .cm-neg { color: #e94c3c; font-weight: 600; }

.src-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: -0.1px;
}
.src-badge.ok     { background: #E0F8F1; color: #1F9D7A; }
.src-badge.cafe24 { background: #EAF1FA; color: #1F4F8B; }
.src-badge.manual { background: #FFF3E0; color: #C77700; }
.src-badge.muted  { background: #f4f4f8; color: #8a8a93; }

.cg-table td.editable {
  cursor: pointer;
  position: relative;
}
.cg-table td.editable:hover {
  background: #FFF3E0;
  outline: 1px dashed #C77700;
}
.cg-table td.editable::after {
  content: '✎';
  position: absolute;
  right: 2px;
  top: 2px;
  font-size: 9px;
  color: #C77700;
  opacity: 0;
  transition: opacity .12s;
}
.cg-table td.editable:hover::after { opacity: 1; }

/* ===== Toast ===== */
.cg-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}
.cg-toast.show { opacity: 1; transform: translateY(0); }

/* ===== Empty / loading ===== */
.cg-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .cg-chart-row { grid-template-columns: 1fr; }
  .cg-detail-row { grid-template-columns: 1fr; }
  .cg-kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .cg-app { grid-template-columns: 1fr; }
  .cg-sidebar { position: static; height: auto; }
  .cg-main { padding: 16px; }
  .cg-cost-grid { grid-template-columns: 1fr; }
}

/* 자사브랜드 공헌이익 링크 섹션 */
.bl-section { margin-bottom: 16px; }
.bl-lock {
  font-size: 11px; font-weight: 600; color: #B5781D;
  background: #FBF1DD; padding: 3px 9px; border-radius: 999px;
  margin-left: 8px; vertical-align: 2px;
}
.bl-sub { font-size: 12px; color: var(--text-muted, #8a8a93); }
.bl-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-top: 12px;
}
.bl-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border: 1px solid var(--line, #E8E8EE);
  border-radius: 12px; background: #FAFBFE;
  text-decoration: none; color: inherit;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.bl-card:hover {
  border-color: #5C5CE0; box-shadow: 0 6px 18px rgba(92,92,224,0.12);
  transform: translateY(-1px);
}
.bl-card-name { font-size: 15px; font-weight: 700; color: var(--text, #1e1e24); }
.bl-card-desc { font-size: 12px; color: var(--text-muted, #8a8a93); }
.bl-card-arrow { font-size: 12.5px; font-weight: 600; color: #5C5CE0; margin-top: 6px; }
.bl-loading { padding: 18px; color: var(--text-muted, #8a8a93); font-size: 13px; }
.bl-locked {
  grid-column: 1 / -1;
  padding: 18px; border: 1px dashed #E0C070; border-radius: 10px;
  background: #FFFCF3; color: #7A5A0F; font-size: 12.5px; line-height: 1.6;
}
@media (max-width: 800px) { .bl-grid { grid-template-columns: 1fr; } }

/* 브랜드 드롭다운 — flex 는 열려있을 때만 (인라인 display 금지: [hidden] 무력화) */
.cg-brand-panel { display: flex; flex-direction: column; }
.cg-brand-panel[hidden] { display: none; }

/* 브랜드 대시보드 임베드 */
.bl-card { cursor: pointer; text-align: left; font-family: inherit; }
.bl-card.is-active { border-color: #5C5CE0; background: #F4F4FE; }
.bl-embed { margin-top: 14px; border: 1px solid var(--line, #E8E8EE); border-radius: 12px; overflow: hidden; }
.bl-embed-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #FAFBFE; border-bottom: 1px solid var(--line, #E8E8EE);
  font-size: 13px;
}
.bl-embed-btn {
  border: 1px solid var(--line, #E8E8EE); background: #fff; border-radius: 7px;
  padding: 5px 11px; font-size: 12px; font-family: inherit; cursor: pointer;
  color: #5C5CE0; text-decoration: none; font-weight: 600;
}
.bl-embed-btn:hover { border-color: #5C5CE0; }
.bl-embed-frame { display: block; width: 100%; height: 82vh; border: 0; background: #fff; }

/* 자사브랜드 전체화면 임베드 (브랜드 셀렉터 전환 방식) */
.bl-embed-frame-full { height: calc(100vh - 190px); min-height: 640px; }
#brandEmbedFull { border: 1px solid var(--line, #E8E8EE); border-radius: 12px; overflow: hidden; background: #fff; }

/* 자사브랜드 임베드 — "창 속 창" 제거, 원본 페이지처럼 풀블리드 */
#brandEmbedFull {
  border: 0; border-radius: 0; overflow: visible; background: transparent;
  /* .main padding(28px 36px 60px) 상쇄 → 좌우/하단 끝까지 */
  margin: 0 -36px -60px;
}
.bl-embed-native {
  display: block; border: 0; width: 100%;
  background: transparent;
  /* 높이는 JS(fitBrandEmbed)가 뷰포트에 맞춰 지정 */
}
/* JS 계산 전/실패 시에도 원본처럼 보이게 하는 폴백 높이 */
.bl-embed-native { min-height: calc(100vh - 180px); }

/* 자사브랜드 잠금 화면 (비관계자) */
.brand-lock {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; min-height: 50vh; text-align: center;
  border: 1px dashed var(--line, #E8E8EE); border-radius: 14px; background: #FAFBFE;
  margin: 8px 36px 60px; /* 풀블리드 상쇄분 복원 */
}
.brand-lock-icon { font-size: 40px; }
.brand-lock-title { font-size: 17px; font-weight: 700; color: var(--text, #1e1e24); }
.brand-lock-desc { font-size: 13px; color: var(--text-muted, #8a8a93); line-height: 1.7; }
