/* ============================================================
   Commercial Plan workspace styles
   Magnolia DS v1.0 — BRAND palette (Apothecary Heritage)
   Vintage pharmacy catalog · apothecary green + rust + medicine gold · kraft paper bg
   Georgia serif for headings/KPI values per design system spec.
   ============================================================ */

#workspace-commercial-plan {
  padding: 0;
  background: #f4ede0;          /* Kraft paper */

  /* DS tokens (--p-* per spec) */
  --p-page: #f4ede0;
  --p-card: #fbf6ea;
  --p-border: #dccbab;
  --p-text: #1f1a14;
  --p-muted: #5a4a3a;
  --p-primary: #1a4d3e;          /* Apothecary green */
  --p-primary-light: #2d6a55;
  --p-secondary: #7c2d12;        /* Rust red */
  --p-secondary-light: #a3522c;
  --p-warm: #c2a050;             /* Medicine gold */
  --p-warm-light: #d4b562;
  --p-neutral: #cdbb95;

  /* Legacy var aliases — so existing components inherit Brand palette automatically */
  --bg: #f4ede0;
  --bg-soft: #ebe2cc;
  --bg-card: #fbf6ea;
  --bg-hover: #ebe2cc;
  --text: #1f1a14;
  --text-muted: #5a4a3a;
  --text-soft: #8a7a5c;
  --accent: #1a4d3e;
  --accent-2: #7c2d12;
  --accent-soft: #d8e6dd;
  --border: #dccbab;
  --border-soft: #ebe2cc;
}

/* Georgia serif for Brand domain headings (KPI value dùng sans-serif tabular cho số đẹp) */
#workspace-commercial-plan .cp-title,
#workspace-commercial-plan h2,
#workspace-commercial-plan h3 {
  font-family: Georgia, 'Times New Roman', serif;
}

.cp-header {
  background: var(--bg-card, #fff);
  border-bottom: 1px solid #e5e7eb;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.cp-title {
  font-size: 20px;
  font-weight: 600;
  color: #1B2A4A;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cp-month-picker {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.cp-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-card, #fff);
  padding: 0 32px;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}

.cp-tab {
  padding: 12px 20px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all .15s ease;
}

.cp-tab:hover {
  color: #1B2A4A;
  background: #f3f4f6;
}

.cp-tab.active {
  color: #D4A843;
  border-bottom-color: #D4A843;
  font-weight: 600;
}

.cp-tab-content {
  display: none;
  padding: 24px 32px;
}

.cp-tab-content.active {
  display: block;
}

/* ============================================================
   Toolbar + filters
   ============================================================ */

.cp-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.cp-toolbar select,
.cp-toolbar input {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-card, #fff);
}

.cp-btn {
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  background: var(--bg-card, #fff);
  color: #374151;
  border-color: #d1d5db;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cp-btn:hover { background: #f9fafb; }

.cp-btn.primary {
  background: #1B2A4A;
  color: #fff;
  border-color: #1B2A4A;
}
.cp-btn.primary:hover { background: #243453; }

.cp-btn.gold {
  background: #D4A843;
  color: #fff;
  border-color: #D4A843;
}
.cp-btn.gold:hover { background: #c39a3c; }
.cp-btn.cp-btn-warn {
  background: #fef3c7; color: #92400e; border-color: #fde68a;
}
.cp-btn.cp-btn-warn:hover { background: #fde68a; color: #78350f; }

.cp-btn:disabled { opacity: .5; cursor: not-allowed; }

.cp-filter-count {
  margin-left: auto;
  font-size: 12px;
  color: #6b7280;
}

/* ============================================================
   KPI cards
   ============================================================ */

.cp-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.cp-kpi {
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
}

.cp-kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.cp-kpi-value {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #1B2A4A;
  margin-top: 4px;
  /* Digits cùng width + lining-style → "13.780" và "0" cao đều, không nhô lên thụt xuống */
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: -0.01em;
}

.cp-kpi-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}

/* ============================================================
   Table
   ============================================================ */

.cp-table-wrap {
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 320px);
}

.cp-table {
  width: 100%;
  border-collapse: separate;       /* `collapse` breaks position:sticky on table cells */
  border-spacing: 0;
  font-size: 13px;
}

.cp-table thead th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

.cp-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

.cp-table tbody tr:hover { background: #f9fafb; }

.cp-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.cp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: #6b7280;
  gap: 12px;
}

.cp-empty-icon { font-size: 48px; opacity: .5; }
.cp-empty h3 { margin: 0; font-size: 18px; color: #1B2A4A; font-weight: 600; }
.cp-empty p { margin: 0; font-size: 14px; max-width: 480px; line-height: 1.6; }
.cp-empty code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ============================================================
   Status badges
   ============================================================ */

.cp-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.cp-badge.stage-build { background: #fef3c7; color: #92400e; }
.cp-badge.stage-grow { background: #d1fae5; color: #065f46; }
.cp-badge.stage-maintain { background: #dbeafe; color: #1e40af; }
.cp-badge.stage-churned { background: #fee2e2; color: #991b1b; }
.cp-badge.stage-pipeline { background: #ede9fe; color: #5b21b6; }

.cp-badge.format-keg { background: #dbeafe; color: #1e40af; }
.cp-badge.format-bottle { background: #d1fae5; color: #065f46; }
.cp-badge.format-can { background: #fef3c7; color: #92400e; }

.cp-health-healthy { color: #059669; font-weight: 600; }
.cp-health-warning { color: #d97706; font-weight: 600; }
.cp-health-unhealthy { color: #dc2626; font-weight: 600; }

/* ============================================================
   Loading + error states
   ============================================================ */

.cp-loading {
  padding: 40px;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
}

.cp-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #fca5a5;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Override existing .cp-placeholder (from sidebar.css) so it still works as fallback */
#workspace-commercial-plan .cp-placeholder {
  background: var(--bg-card, #fff);
  border-radius: 12px;
  margin: 24px 32px;
  padding: 60px 32px;
}

/* ============================================================
   V2 Template — wide table with grouped headers (matches Excel C.S Forecast)
   ============================================================ */

.cp-template-v2 {
  max-height: calc(100vh - 220px);
  overflow: auto;
  position: relative;
}

.cp-fc-table {
  font-size: 11px;
  white-space: nowrap;
}

.cp-fc-table thead .cp-section-row th {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 8px 6px;
  color: #fff;
  border-bottom: 1px solid #1B2A4A;
}

.cp-fc-table thead .cp-col-row th {
  position: sticky;
  top: 27px;
  z-index: 4;
  background: var(--bg-card, #fff);
  padding: 6px 6px;
  font-size: 10px;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
  vertical-align: middle;
  text-align: left;
}

.cp-fc-table thead .cp-col-row th.num { text-align: right; }

.cp-fc-table thead th.cp-sku-h {
  text-align: center;
  min-width: 42px;
  max-width: 50px;
  font-size: 10px;
  padding: 4px 2px;
  line-height: 1.2;
}
.cp-fc-table thead th.cp-sku-h small {
  font-size: 9px;
  color: #9ca3af;
  font-weight: 400;
}

/* Section colors — scope dưới .cp-fc-table thead để thắng .cp-table thead th (background #f9fafb) */
.cp-fc-table thead .cp-section-row th.cp-sec-info       { background: #4b5563; }
.cp-fc-table thead .cp-section-row th.cp-sec-summary    { background: #1B2A4A; }
.cp-fc-table thead .cp-section-row th.cp-sec-baseline-v { background: #2A9D8F; }
.cp-fc-table thead .cp-section-row th.cp-sec-baseline-r { background: #5b21b6; }
.cp-fc-table thead .cp-section-row th.cp-sec-target-v   { background: #D4A843; color: #1B2A4A !important; }
.cp-fc-table thead .cp-section-row th.cp-sec-target-r   { background: #c2410c; }
.cp-fc-table thead .cp-section-row th.cp-sec-action     { background: #be185d; }   /* magenta — strategic actions */

/* Quarterly forecast — per-month tint on TARGET sections */
.cp-sec-m1 { box-shadow: inset 0 -3px 0 rgba(255,255,255,0.45); }
.cp-sec-m2 { box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18); }
.cp-sec-m3 { box-shadow: inset 0 -3px 0 rgba(255,255,255,0.7); }
.cp-fc-table td.cp-target-m1 { background: #fffbeb; }   /* lightest gold */
.cp-fc-table td.cp-target-m2 { background: #fef3c7; }   /* mid gold */
.cp-fc-table td.cp-target-m3 { background: #fde68a; }   /* deepest gold */
/* Cột tổng target (Tgt Vol Keg/Chai/Lon, Tgt DT) — nền sáng + chữ đậm để đọc rõ
   (trước đây nền navy đậm → ô trống thành khối đen đặc) */
.cp-fc-table td.cp-q-total {
  background: #eef2f7;
  color: #1B2A4A;
  font-weight: 700;
}
.cp-fc-table th.cp-q-total {
  background: #334a6b !important;   /* navy nhạt hơn header thường để phân biệt */
  color: #fff !important;
}

/* Quarter banner above the forecast table */
.cp-quarter-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 10px 0; padding: 10px 14px;
  background: linear-gradient(90deg, #fffbeb, #fef3c7);
  border: 1px solid #fde68a; border-radius: 8px;
  font-size: 13px; color: #1B2A4A;
}
/* Picker tháng forecast (đã chuyển từ header CP xuống đây) — nổi bật, gold để dễ thấy */
.cp-fc-month-label {
  font-weight: 700; font-size: 14px; color: #78350f;
  margin-right: 2px;
}
.cp-fc-month-input {
  margin-left: 0 !important;
  padding: 7px 12px !important;
  font-size: 14px !important;
  font-weight: 700;
  color: #1B2A4A;
  background: var(--bg-card, #fff);
  border: 2px solid #D4A843 !important;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(212,168,67,0.3);
  cursor: pointer;
  font-family: inherit;
}
.cp-fc-month-input:hover { background: #fffdf7; border-color: #b8902f !important; }
.cp-fc-month-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(212,168,67,0.35); }
.cp-fc-month-current {
  font-size: 14px; color: #92400e; font-weight: 700;
  background: #fef3c7; padding: 4px 10px; border-radius: 14px;
  border: 1px solid #fde68a;
}
.cp-month-chip {
  display: inline-block; padding: 4px 12px; border-radius: 14px;
  font-size: 12px; font-weight: 600; color: #1B2A4A;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s ease, box-shadow .15s ease;
}
.cp-month-chip:hover {
  box-shadow: 0 2px 6px rgba(212,168,67,0.35);
  transform: translateY(-1px);
}
.cp-month-chip:active { transform: translateY(0); }
.cp-month-chip.m1 { background: #fffbeb; border: 1px solid #fde68a; }
.cp-month-chip.m2 { background: #fef3c7; border: 1px solid #fcd34d; }
.cp-month-chip.m3 { background: #fde68a; border: 1px solid #f59e0b; }

/* Forecast logic config panel — inline (collapsible) above the forecast table */
.cp-cfg-inline {
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin: 12px 0 16px;
  overflow: hidden;
}
.cp-cfg-inline > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 18px;
  background: linear-gradient(90deg, #f8fafc, #fff);
  font-size: 13px;
  color: #1B2A4A;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.cp-cfg-inline > summary::-webkit-details-marker { display: none; }
.cp-cfg-inline > summary::before {
  content: '▶';
  font-size: 10px;
  transition: transform .15s ease;
  color: #6b7280;
}
.cp-cfg-inline[open] > summary::before { transform: rotate(90deg); }
.cp-cfg-inline > summary:hover { background: #f1f5f9; }
.cp-cfg-inline[open] > summary { border-bottom-color: #e5e7eb; }
.cp-cfg-inline > div#cp-fc-cfg-body {
  padding: 12px 14px;
  /* 2-col grid so 6 sections fit in ~half the height */
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
  gap: 14px 18px;
}
@media (max-width: 900px) {
  .cp-cfg-inline > div#cp-fc-cfg-body { grid-template-columns: 1fr; }
}

/* Effective-period banner inside config panel */
.cp-cfg-effective-banner {
  grid-column: 1 / -1;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: #0c4a6e;
  margin-bottom: 4px;
}

/* Stage Win Prob table — narrow & compact rows */
.cp-cfg-stage-table tbody td { padding: 2px 6px !important; line-height: 1.3; }
.cp-cfg-stage-table input[type="number"] { width: 60px !important; }
.cp-cfg-stage-table th, .cp-cfg-stage-table td { white-space: nowrap; }

/* Info button + collapsible description in each config section */
.cp-cfg-info-btn {
  background: transparent; border: 1px solid #cbd5e1; border-radius: 50%;
  width: 18px; height: 18px; font-size: 10px; line-height: 1;
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: #475569; margin-left: 2px;
  transition: background .15s ease, transform .12s ease;
}
.cp-cfg-info-btn:hover { background: #e0f2fe; border-color: #0ea5e9; transform: scale(1.1); }
.cp-cfg-info-btn.active { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }
.cp-cfg-info {
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 4px;
  padding: 5px 8px; margin: 3px 0 6px;
  font-size: 10px; color: #0c4a6e; line-height: 1.35;
}
.cp-cfg-info strong { color: #075985; font-weight: 600; }
.cp-cfg-info ul { margin: 2px 0 0 14px; padding: 0; }
.cp-cfg-info li { margin-bottom: 1px; }
.cp-cfg-info em { color: #0369a1; font-style: italic; }

/* Forecast Spec panel */
.cp-spec-summary {
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 8px 12px; margin-bottom: 12px; font-size: 12px; color: #1B2A4A;
}
.cp-spec-category { margin-bottom: 14px; }
.cp-spec-category h3 {
  margin: 0 0 6px; font-size: 13px; color: #0f172a;
  border-bottom: 2px solid #1B2A4A; padding-bottom: 3px;
}
.cp-spec-group { margin-left: 4px; margin-bottom: 10px; }
.cp-spec-group h4 {
  margin: 6px 0 4px; font-size: 12px; color: #475569;
  text-transform: uppercase; letter-spacing: .3px; font-weight: 700;
}
.cp-spec-items { display: flex; flex-direction: column; gap: 4px; }
.cp-spec-item {
  background: var(--bg-card, #fff); border: 1px solid #e5e7eb; border-radius: 5px;
  padding: 5px 8px; transition: background .15s ease;
}
.cp-spec-item:hover { background: #f8fafc; }
.cp-spec-item.cp-spec-skipped { opacity: .45; background: #f8fafc; }
.cp-spec-head {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
}
.cp-spec-toggle input { margin: 0; }
.cp-spec-status { font-size: 12px; }
.cp-spec-label { flex: 1; color: #1B2A4A; }
.cp-spec-source { font-size: 10px; color: #94a3b8; }
.cp-spec-info { margin-top: 4px; }
.cp-spec-info code {
  background: #f1f5f9; padding: 1px 5px; border-radius: 3px;
  font-size: 10px; color: #475569;
}
.cp-spec-info input.cp-spec-notes {
  width: 100%; padding: 3px 6px; border: 1px solid #d1d5db;
  border-radius: 3px; font-size: 11px; margin-top: 2px;
  font-family: inherit;
}

/* Source badges in spec items — show where each field lives in the app */
.cp-spec-src {
  font-size: 10px; padding: 1px 6px; border-radius: 10px;
  font-weight: 600; white-space: nowrap;
}
.cp-spec-src.src-misa     { background: #dbeafe; color: #1e40af; }
.cp-spec-src.src-manual   { background: #fef3c7; color: #92400e; }
.cp-spec-src.src-computed { background: #ede9fe; color: #5b21b6; }
.cp-spec-src.src-derived  { background: #d1fae5; color: #065f46; }

/* Data tab — collapsible sections per table */
.cp-data-view { padding: 4px 0; }
.cp-data-header { margin-bottom: 14px; }
.cp-data-header h2 { margin: 0 0 4px; font-size: 18px; color: #1B2A4A; }
.cp-data-header p.muted { margin: 0; font-size: 12px; color: #6b7280; }

#cp-data-sections { display: flex; flex-direction: column; gap: 8px; }
.cp-data-section {
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.cp-data-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  background: linear-gradient(90deg, #f8fafc, #fff);
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: #1B2A4A;
  transition: background .15s ease;
}
.cp-data-section > summary::-webkit-details-marker { display: none; }
.cp-data-section > summary::before {
  content: '▶'; font-size: 10px; color: #6b7280;
  transition: transform .15s ease;
}
.cp-data-section[open] > summary::before { transform: rotate(90deg); }
.cp-data-section > summary:hover { background: #f1f5f9; }
.cp-data-section[open] > summary { border-bottom: 1px solid #e5e7eb; }
.cp-data-icon { font-size: 18px; }
.cp-data-table-tag code {
  background: #f1f5f9; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; color: #475569;
}
.cp-data-count {
  margin-left: auto;
  background: #e0e7ff; color: #3730a3;
  padding: 2px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.cp-data-section-body { padding: 12px 16px 16px; }
.cp-data-desc { margin: 0 0 10px; font-size: 12px; color: #475569; }
.cp-data-meta { margin-bottom: 8px; }
.cp-data-table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
.cp-data-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
.cp-data-table thead th {
  background: #f9fafb; position: sticky; top: 0; z-index: 10;
  text-align: left; padding: 6px 10px; font-weight: 600;
  color: #475569; border-bottom: 1px solid #e5e7eb;
  font-size: 11px; white-space: nowrap;
  box-shadow: 0 1px 0 #e5e7eb;
}
.cp-data-table tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid #f3f4f6;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden; text-overflow: ellipsis;
}
.cp-data-table tbody tr:hover { background: #f8fafc; }

/* New SKU table — import schedule per row */
.cp-new-sku-table td.cp-import-list { max-width: 300px; white-space: normal; font-size: 11px; }
.cp-import-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 2px 0; border-bottom: 1px dashed #f1f5f9;
}
.cp-import-row:last-child { border-bottom: none; }
.cp-import-status {
  font-size: 9px; padding: 1px 6px; border-radius: 8px; font-weight: 700;
  text-transform: uppercase;
}
.cp-import-status.status-planned    { background: #fef3c7; color: #92400e; }
.cp-import-status.status-in_transit { background: #ddd6fe; color: #5b21b6; }
.cp-import-status.status-received   { background: #dcfce7; color: #166534; }
.cp-import-status.status-cancelled  { background: #fee2e2; color: #991b1b; text-decoration: line-through; }
.cp-import-edit, .cp-import-del {
  background: transparent; border: none; cursor: pointer;
  font-size: 11px; padding: 0 2px; opacity: .5;
  margin-left: 2px;
}
.cp-import-row:hover .cp-import-edit,
.cp-import-row:hover .cp-import-del { opacity: 1; }
.cp-import-edit:hover { transform: scale(1.15); }
.cp-import-del:hover { color: #b91c1c; transform: scale(1.15); }
input.cp-prod-edit {
  padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 3px;
  font-family: inherit; font-size: 11px;
  transition: background .15s ease;
}
input.cp-prod-edit:focus { outline: 2px solid #2A9D8F; outline-offset: -2px; }

.cp-new-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.cp-new-badge.new-month   { background: #dc2626; color: #fff; }
.cp-new-badge.new-2months { background: #fbbf24; color: #78350f; }

/* Group banner row inside Products Catalog table — sticks just below the column header */
.cp-group-banner td {
  background: #f1f5f9;
  font-size: 12px;
  padding: 8px 12px !important;
  border-top: 2px solid #cbd5e1;
  position: sticky; top: 28px; z-index: 5;
}
.cp-group-banner.group-new-month   td { background: #fee2e2; border-top-color: #dc2626; }
.cp-group-banner.group-new-2months td { background: #fef3c7; border-top-color: #f59e0b; }
.cp-group-banner.group-rest        td { background: #f1f5f9; border-top-color: #94a3b8; }
.cp-group-banner.group-imported    td { background: #e0e7ff; border-top-color: #6366f1; }

/* Sub-group banner inside "Các SKU còn lại" — grouped by format */
.cp-subgroup-banner td {
  background: #fafafa;
  font-size: 11px;
  padding: 5px 12px !important;
  color: #64748b;
  border-top: 1px dashed #cbd5e1;
  position: sticky; top: 60px; z-index: 4;
}

/* Historical Trend table — year comparison pivot */
.cp-trend-wrap { max-height: 75vh; }
.cp-trend-table { font-size: 11px; }
.cp-trend-table th.cp-trend-month { text-align: center; min-width: 50px; font-size: 10px; }
.cp-trend-table .cp-trend-total-cell { background: #f9fafb; font-weight: 600; }
.cp-trend-cat-row td {
  background: #eef2ff; padding: 8px 12px !important;
  border-top: 2px solid #6366f1; font-size: 12px;
  position: sticky; top: 28px; z-index: 5;
}
.cp-trend-sku-row td {
  background: #f8fafc; padding: 6px 10px !important;
  border-top: 1px dashed #cbd5e1;
  font-size: 11px;
}
.cp-trend-product-row td {
  background: #fafafa; padding: 6px 10px !important;
  border-top: 1px solid #d1d5db; font-size: 12px;
}
.cp-trend-channel-row td {
  background: var(--bg-card, #ffffff); padding: 4px 10px 4px 24px !important;
  font-size: 10px; color: #64748b;
  border-top: 1px dashed #e5e7eb;
}
.cp-trend-sub-cell {
  background: #fcfcfc; padding-left: 32px !important;
  font-size: 10px; color: #475569;
  border-right: 1px solid #f3f4f6;
}
.cp-subhead {
  margin: 18px 0 8px; font-size: 13px; color: #1B2A4A;
  border-left: 3px solid #D4A843; padding-left: 8px;
}
.cp-bar-wrap {
  position: relative; background: #f3f4f6; border-radius: 4px;
  height: 18px; min-width: 80px; overflow: hidden;
}
.cp-bar-wrap span {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-size: 10px; font-weight: 600; color: #1B2A4A;
}
.cp-bar { height: 100%; border-radius: 4px; }
.cp-bar.bar-green { background: #86efac; }
.cp-bar.bar-amber { background: #fcd34d; }
.cp-bar.bar-red   { background: #fca5a5; }
.cp-bar.bar-blue  { background: #93c5fd; }
.cp-ta-edit {
  border: 1px solid transparent; background: transparent;
  font-size: 11px; text-align: right; padding: 2px 4px;
  border-radius: 3px; font-family: inherit;
}
.cp-ta-edit:hover { border-color: #e5e7eb; background: var(--bg-card, #fff); }
.cp-ta-edit:focus { border-color: #D4A843; background: #fffbeb; outline: none; }
.cp-trend-channel-cell {
  background: #f8fafc; font-weight: 500;
  vertical-align: middle; text-align: left;
  border-right: 1px solid #e5e7eb;
}
.cp-trend-year-cell { font-weight: 600; color: #475569; text-align: center; }
.cp-trend-data-row.current-year .cp-trend-year-cell { background: #fef3c7; color: #92400e; }
.cp-trend-data-row.current-year td.num { background: #fffbeb; }
.cp-trend-table tbody td { padding: 5px 8px; }
.cp-trend-table td.trend-up   { color: #059669; background: #ecfdf5; }
.cp-trend-table td.trend-down { color: #dc2626; background: #fef2f2; }
.cp-trend-arrow {
  font-size: 8px; margin-left: 3px; vertical-align: middle; opacity: .8;
}
/* Historical Trend — line chart layout (mỗi product = 1 chart) */
.cp-trend-cat-banner {
  display: flex; align-items: baseline; gap: 8px;
  padding: 10px 14px; margin: 18px 0 8px;
  background: linear-gradient(90deg, #1e40af 0%, #3b82f6 100%);
  color: #fff; border-radius: 8px; font-size: 14px;
}
.cp-trend-cat-banner .cp-trend-cat-total {
  margin-left: auto; font-weight: 700; font-size: 13px;
}
.cp-trend-product-block {
  margin: 12px 0; padding: 12px 14px;
  border: 1px solid #e5e7eb; border-radius: 8px; background: #fff;
}
.cp-trend-product-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid #f3f4f6;
}
.cp-trend-product-head strong { font-size: 13px; color: #1e293b; }
.cp-trend-product-head .cp-trend-product-total {
  margin-left: auto; font-weight: 700; color: #475569; font-size: 12px;
}
.cp-trend-chart-wrap {
  position: relative; height: 240px; width: 100%;
}
/* Competitor column headers — TM (xanh dương) vs TC (tím) để dễ phân biệt 2 nhóm */
.cp-md-table thead th.cp-md-comp-tm {
  background: linear-gradient(180deg, #1e40af 0%, #2563eb 100%) !important;
  color: #fff !important;
  border-right: 1px solid #1e3a8a;
}
.cp-md-table thead th.cp-md-comp-tc {
  background: linear-gradient(180deg, #6b21a8 0%, #9333ea 100%) !important;
  color: #fff !important;
  border-right: 1px solid #581c87;
}
.cp-md-table thead th.cp-md-comp-tm .cp-md-col-label,
.cp-md-table thead th.cp-md-comp-tc .cp-md-col-label { color: #fff; }
/* Filter button (▾) trên header competitor cũng đổi màu cho readable */
.cp-md-table thead th.cp-md-comp-tm .cp-md-filter-btn,
.cp-md-table thead th.cp-md-comp-tc .cp-md-filter-btn { color: #fff; opacity: 0.85; }

/* Top SKU table — clickable row + expanded chart */
.cp-modal-top-sku-table tr.cp-modal-sku-row:hover { background: #f1f5f9; }
.cp-modal-top-sku-table tr.cp-modal-sku-chart-row td { border-bottom: 2px solid #e5e7eb; }

/* Nút "Xem all products" — pinned bên phải header, gradient cam vàng nổi bật */
.cp-fc-view-all-products {
  margin-left: auto;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
  letter-spacing: 0.2px;
  transition: transform .12s, box-shadow .12s, filter .12s;
  animation: cpViewAllPulse 2.4s ease-in-out infinite;
}
.cp-fc-view-all-products:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.5);
  animation: none;
}
.cp-fc-view-all-products:active { transform: translateY(0); }
@keyframes cpViewAllPulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35); }
  50%      { box-shadow: 0 2px 18px rgba(234, 88, 12, 0.7); }
}

/* Overlay "Xem all products" — full-screen TRÊN forecast modal (z-index 9000) */
.cp-fc-trend-all-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 10000;
  align-items: center; justify-content: center;
  padding: 20px;
}
.cp-fc-trend-all-modal {
  background: #fff; border-radius: 10px;
  width: 95vw; max-width: 1400px;
  height: 92vh; max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.cp-fc-trend-all-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: linear-gradient(90deg, #1e40af 0%, #3b82f6 100%);
  color: #fff;
}
.cp-fc-trend-all-header h3 {
  margin: 0; font-size: 15px; flex: 1;
}
.cp-fc-trend-all-close {
  background: rgba(255, 255, 255, 0.15);
  border: none; color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 6px;
  font-size: 16px; line-height: 1;
  transition: background .15s;
}
.cp-fc-trend-all-close:hover { background: rgba(255, 255, 255, 0.3); }
.cp-fc-trend-all-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
}
/* Grid 1 hàng N chart theo năm — auto-fit, min 280px mỗi chart */
.cp-trend-year-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.cp-trend-year-chart {
  border: 1px solid #f1f5f9; border-radius: 6px; padding: 8px 10px; background: #fafbfc;
}
.cp-trend-year-head {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px;
  padding-bottom: 4px; border-bottom: 1px dashed #e5e7eb;
}
.cp-trend-year-head strong { font-size: 12px; color: #1e293b; font-weight: 700; }
.cp-trend-year-head .cp-trend-year-vol { margin-left: auto; font-size: 11px; color: #6b7280; font-weight: 600; }
/* Current-year highlight should win over trend bg for year-cell only */
.cp-trend-data-row.current-year .cp-trend-year-cell { background: #fef3c7 !important; }

/* Stock cell — read-only, synced from MISA */
.cp-stock-cell {
  background: #eff6ff;
  color: #1e40af;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.cp-stock-case-cell {
  background: #f0f9ff;
  color: #0c4a6e;
  font-variant-numeric: tabular-nums;
}

/* Coverage badge — show how many outlets have data for this spec item */
.cp-spec-cov {
  font-size: 10px; padding: 1px 7px; border-radius: 10px;
  font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cp-spec-cov.cov-ok   { background: #dcfce7; color: #166534; }
.cp-spec-cov.cov-mid  { background: #fef3c7; color: #92400e; }
.cp-spec-cov.cov-low  { background: #fee2e2; color: #991b1b; }
.cp-spec-cov.cov-warn { background: #f1f5f9; color: #475569; font-style: italic; }

.cp-cfg-section { margin: 0; }
.cp-cfg-section h3 {
  margin: 0 0 3px; font-size: 12px; color: #1B2A4A; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid #e5e7eb; padding-bottom: 3px;
}
.cp-cfg-section p.muted {
  margin: 0 0 6px; font-size: 10px; color: #94a3b8; line-height: 1.35;
}
.cp-cfg-table { width: 100%; font-size: 11px; }
.cp-cfg-table th { padding: 3px 6px; font-size: 10px; }
.cp-cfg-table td { padding: 3px 6px; }
.cp-cfg-table input[type="number"] {
  padding: 2px 6px; border: 1px solid #d1d5db; border-radius: 3px;
  font-family: inherit; font-size: 11px; text-align: right;
}
.cp-cfg-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.cp-cfg-grid > div {
  display: flex; flex-direction: column; gap: 2px;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 4px;
  padding: 5px 7px;
}
.cp-cfg-grid label {
  font-size: 10px; font-weight: 600; color: #475569;
  text-transform: uppercase; letter-spacing: .2px;
  display: flex; align-items: center; gap: 4px;
}
.cp-cfg-grid input[type="number"] {
  padding: 2px 6px; border: 1px solid #d1d5db; border-radius: 3px;
  font-family: inherit; font-size: 11px;
}
.cp-cfg-grid input[type="checkbox"] { margin-right: 4px; }
.cp-cfg-grid small.muted { font-size: 9px; }
.cp-cfg-footer {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding-top: 10px; border-top: 1px solid #e5e7eb;
  margin-top: 0;
  flex-wrap: wrap;
}
.cp-cfg-footer-info { display: flex; flex-direction: column; gap: 2px; }
.cp-cfg-footer-info small { font-size: 10px; }
.cp-cfg-footer-buttons {
  display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap;
}
.cp-cfg-footer .cp-btn { padding: 6px 12px; font-size: 12px; }

/* Legend strip above forecast table */
.cp-legend {
  display: flex; gap: 18px; flex-wrap: wrap;
  margin: 0 0 10px; font-size: 12px; color: #475569;
}
.cp-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.cp-legend-box {
  display: inline-block; width: 16px; height: 14px; border-radius: 3px;
}

/* Cells pulled from Master Data — read-only, distinct light-blue tint */
.cp-fc-table td.cp-from-md {
  background: #eff6ff;       /* soft blue — "from Master Data" */
  color: #1e3a5f;
  cursor: default;
  user-select: text;
  border-right: 1px solid #dbeafe;
}
.cp-fc-table td.cp-from-md:hover {
  background: #dbeafe;
}
.cp-fc-table td.cp-from-md.sticky-1,
.cp-fc-table td.cp-from-md.sticky-2 {
  /* keep sticky tint consistent */
  background: #eff6ff;
}

/* Outlet name cell — click để mở detail modal (giống Master Data) */
.cp-fc-table td.cp-fc-outlet-name {
  cursor: pointer;
  color: #1B2A4A;
  font-weight: 600;
  text-decoration: underline;
}
.cp-fc-table td.cp-fc-outlet-name:hover {
  background: #bfdbfe !important;
  color: #0c1626;
}

/* Action category cells — manual entry, white bg, click to edit */
.cp-fc-table td.cp-action-cell {
  background: var(--bg-card, #fff);
  min-width: 130px;
  max-width: 220px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
  line-height: 1.35;
  vertical-align: top;
  outline-offset: -2px;
}
.cp-fc-table td.cp-action-cell:focus {
  outline: 2px solid #be185d;
  background: #fdf2f8;
}
.cp-fc-table td.cp-action-cell:empty::before {
  content: '—';
  color: #cbd5e1;
}

/* Ô nhập tay (TARGET Volume + Tier forecast) — viền cyan khi focus, nền nhạt gợi ý nhập được */
.cp-fc-table td.cp-fc-target-edit,
.cp-fc-table td.cp-fc-tier-edit {
  cursor: text;
  outline-offset: -2px;
}
.cp-fc-table td.cp-fc-tier-edit { background: #ecfeff; }
.cp-fc-table td.cp-fc-target-edit:hover,
.cp-fc-table td.cp-fc-tier-edit:hover { box-shadow: inset 0 0 0 1px #67e8f9; }
.cp-fc-table td.cp-fc-target-edit:focus,
.cp-fc-table td.cp-fc-tier-edit:focus {
  outline: 2px solid #06b6d4;
  background: #ecfeff !important;
}

/* Ô TARGET Revenue — công thức = Vol × Giá outlet (read-only, không nhập tay) */
.cp-fc-table td.cp-fc-target-rev {
  background: #f5f3ff !important;   /* lavender nhạt — phân biệt ô formula */
  color: #5b21b6;
  font-style: italic;
  cursor: default;
}
.cp-fc-table td.cp-fc-target-rev:hover { background: #ede9fe !important; }

/* ============================================================
   ĐỐI CHIẾU vs ACTUAL — cột "% Đạt DT" trong SUMMARY + badge ✓/⚠ cho Stage/Tier FC
   ============================================================ */
.cp-fc-table td.cp-fc-achievement { font-weight: 700; text-align: right; }
.cp-fc-table td.cp-fc-achievement-low  { background: #fecaca !important; color: #7f1d1d; }   /* <50% — đỏ */
.cp-fc-table td.cp-fc-achievement-mid  { background: #fed7aa !important; color: #7c2d12; }   /* 50-89% — cam */
.cp-fc-table td.cp-fc-achievement-good { background: #bbf7d0 !important; color: #14532d; }   /* 90-109% — xanh */
.cp-fc-table td.cp-fc-achievement-over { background: #93c5fd !important; color: #1e3a8a; }   /* ≥110% — xanh đậm */
.cp-fc-table td.cp-fc-achievement-na   { background: #f3f4f6 !important; color: #9ca3af; font-weight: 400; }

/* Badge ✓ / ⚠ so sánh Stage/Tier FC vs MISA actual */
.cp-fc-match-ok {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #16a34a;
  border-radius: 50%;
  vertical-align: middle;
}
.cp-fc-match-warn {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #ea580c;
  border-radius: 50%;
  vertical-align: middle;
  animation: cp-fc-pulse 1.6s ease-in-out infinite;
}
@keyframes cp-fc-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(234, 88, 12, 0.6); }
  50% { box-shadow: 0 0 0 4px rgba(234, 88, 12, 0); }
}

/* ============================================================
   FORECAST INPUT MODAL — riêng tab Forecast, không đụng Master Data outlet detail
   ============================================================ */
.cp-fc-input-modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 9000;
}
.cp-fc-input-modal.open { display: block; }
.cp-fc-input-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}
.cp-fc-input-content {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(1480px, 96vw);   /* Modal rộng hơn để bảng Historical Trend (14 cột) đủ chỗ */
  max-height: 94vh;
  background: var(--bg-card, #fff);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.cp-fc-input-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #1B2A4A, #2a4373);
  color: #fff;
  border-bottom: 3px solid #D4A843;
}
.cp-fc-input-title-group { flex: 1; min-width: 0; }
.cp-fc-input-title-group h2 { margin: 0; font-size: 18px; font-weight: 700; }
.cp-fc-input-subtitle { font-size: 12px; opacity: 0.85; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.cp-fc-input-subtitle span { white-space: nowrap; }
.cp-fc-input-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 18px; width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
}
.cp-fc-input-close:hover { background: rgba(255,255,255,0.3); }
.cp-fc-input-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  background: #f8fafc;
}
.cp-fc-input-section {
  background: var(--bg-card, #fff);
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.cp-fc-input-section h3 {
  margin: 0 0 10px;
  font-size: 14px; font-weight: 700;
  color: #1B2A4A;
  border-bottom: 2px solid #e2e8f0; padding-bottom: 6px;
}
.cp-fc-input-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
/* Divider ngăn cách phần INFO (trên) vs phần PLAN (dưới) */
.cp-fc-plan-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 24px 0 12px;
}
.cp-fc-plan-divider-line {
  flex: 1; height: 3px;
  background: linear-gradient(90deg, transparent, #06b6d4 30%, #06b6d4 70%, transparent);
  border-radius: 2px;
}
.cp-fc-plan-divider-label {
  padding: 6px 16px;
  background: linear-gradient(135deg, #06b6d4, #0891b2);
  color: white; font-size: 13px; font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(6, 182, 212, 0.3);
  white-space: nowrap;
}
/* Highlight section đầu của phần plan để rõ ràng đây là input zone */
.cp-fc-input-section-plan {
  background: #f0fdfa;
  border: 1px solid #5eead4;
  border-radius: 8px;
  padding: 12px 16px;
}
.cp-fc-input-section-plan > h3 {
  color: #0f766e;
  border-bottom-color: #5eead4;
}

/* 4-col variant for Stage/Tier section — current + forecast side by side */
.cp-fc-input-grid-4 {
  grid-template-columns: 1fr 1.2fr 1fr 1.2fr;
  gap: 10px;
}
.cp-fc-input-readonly {
  padding: 6px 10px; min-height: 32px; line-height: 20px;
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 4px;
  font-size: 13px; color: #475569; font-weight: 500;
}
.cp-fc-input-arrow { color: #06b6d4; font-weight: 700; margin-left: 2px; }
.cp-fc-input-grid label, .cp-fc-input-action-row label {
  display: block; font-size: 11px; font-weight: 600; color: #475569; margin-bottom: 4px;
}
.cp-fc-input-grid input, .cp-fc-input-grid select,
.cp-fc-input-action-row textarea, .cp-fc-input-sku-row input {
  width: 100%; padding: 6px 10px;
  border: 1px solid #cbd5e1; border-radius: 4px;
  font-size: 13px; font-family: inherit;
  background: var(--bg-card, #fff);
}
.cp-fc-input-grid input:focus, .cp-fc-input-grid select:focus,
.cp-fc-input-action-row textarea:focus, .cp-fc-input-sku-row input:focus {
  outline: 2px solid #06b6d4; border-color: #06b6d4;
}
.cp-fc-input-sku-table {
  width: 100%; font-size: 12px;
  border-collapse: collapse;
}
.cp-fc-input-sku-table th, .cp-fc-input-sku-table td {
  padding: 4px 8px; border-bottom: 1px solid #f1f5f9; text-align: left;
}
.cp-fc-input-sku-table th { font-size: 11px; font-weight: 700; color: #475569; background: #f8fafc; }
.cp-fc-input-sku-table td.num,
.cp-fc-input-sku-table th.num,
.cp-fc-input-sku-table th:nth-child(2),
.cp-fc-input-sku-table th:nth-child(3),
.cp-fc-input-sku-table th:nth-child(5) { text-align: right; }
.cp-fc-input-sku-table .cp-fc-input-group-row td {
  background: #fef3c7; color: #78350f; font-weight: 700; padding: 6px 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px;
}
.cp-fc-input-sku-row input { max-width: 80px; text-align: right; }
.cp-fc-input-vol-wrap { display: inline-flex; align-items: center; gap: 4px; }
.cp-fc-input-vol-unit { font-size: 11px; min-width: 28px; text-align: left; }
.cp-fc-input-rev-cell { color: #5b21b6; font-weight: 600; font-style: italic; }
.cp-fc-baseline-rev { color: #047857; font-weight: 600; }

/* Summary section — tổng hợp theo Team / Stage */
#cp-fc-summary:not(:empty) { margin: 12px 0; }
.cp-fc-summary-wrap {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.cp-fc-summary-card {
  background: var(--bg-card, #fff); border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 12px 16px;
}
.cp-fc-summary-title {
  font-size: 13px; font-weight: 700; color: #1B2A4A; margin: 0 0 8px;
  padding-bottom: 6px; border-bottom: 2px solid #e2e8f0;
}
.cp-fc-summary-table {
  width: 100%; font-size: 12px; border-collapse: collapse;
}
.cp-fc-summary-table th, .cp-fc-summary-table td {
  padding: 5px 8px; border-bottom: 1px solid #f1f5f9; text-align: left;
}
.cp-fc-summary-table th {
  font-size: 11px; font-weight: 700; color: #475569; background: #f8fafc;
  position: sticky; top: 0;
}
.cp-fc-summary-table td.num, .cp-fc-summary-table th.num { text-align: right; }
.cp-fc-summary-table tfoot tr.cp-fc-summary-total td {
  border-top: 2px solid #1B2A4A; background: #f0fdf4;
  color: #14532d; font-weight: 700; padding-top: 6px; padding-bottom: 6px;
}
.cp-fc-summary-funnel {
  display: inline-block; padding: 1px 5px; margin-left: 4px;
  border-radius: 3px; font-size: 10px; font-weight: 700;
}
@media (max-width: 1024px) { .cp-fc-summary-wrap { grid-template-columns: 1fr; } }
/* Format badge ô đầu SKU row */
.cp-fc-sku-fmt {
  display: inline-block; width: 18px; height: 18px; line-height: 18px;
  text-align: center; font-size: 10px; font-weight: 700;
  border-radius: 4px; margin-right: 4px; vertical-align: middle;
}
.cp-fc-sku-fmt-keg    { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.cp-fc-sku-fmt-bottle { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }
.cp-fc-sku-fmt-can    { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
/* Discount badge */
.cp-fc-disc-badge {
  display: inline-block; padding: 1px 5px;
  background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5;
  border-radius: 3px; font-size: 10px; font-weight: 700; margin-left: 4px;
  vertical-align: middle;
}
/* MISA list price (giá niêm yết) badge — fallback khi outlet chưa có giá riêng */
.cp-fc-niemyet-badge {
  display: inline-block; padding: 1px 5px;
  background: #f3e8ff; color: #6b21a8; border: 1px solid #d8b4fe;
  border-radius: 3px; font-size: 9px; font-weight: 700; margin-left: 4px;
  vertical-align: middle; text-transform: uppercase; letter-spacing: 0.3px;
  cursor: help;
}
/* Sales-derived price badge — derive từ revenue đơn gần nhất */
.cp-fc-thucte-badge {
  display: inline-block; padding: 1px 5px;
  background: #ecfdf5; color: #047857; border: 1px solid #6ee7b7;
  border-radius: 3px; font-size: 9px; font-weight: 700; margin-left: 4px;
  vertical-align: middle; text-transform: uppercase; letter-spacing: 0.3px;
  cursor: help;
}
/* Last order date / vol */
.cp-fc-last-date { font-size: 11px; font-weight: 600; color: #1B2A4A; }
.cp-fc-last-vol  { font-size: 10px; font-weight: 500; }
/* Remove button */
.cp-fc-sku-remove {
  background: transparent; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 4px; cursor: pointer; padding: 2px 6px; font-size: 11px; font-weight: 700;
}
.cp-fc-sku-remove:hover { background: #fef2f2; border-color: #b91c1c; }
.cp-fc-sku-remove-cell { text-align: center; width: 32px; }
/* SKU picker */
.cp-fc-sku-picker {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 8px 10px;
  background: #f0fdfa; border: 1px dashed #5eead4; border-radius: 6px;
}
.cp-fc-sku-picker label { font-size: 12px; font-weight: 600; color: #0f766e; margin: 0; }
.cp-fc-sku-picker select {
  flex: 1; padding: 6px 10px;
  border: 1px solid #cbd5e1; border-radius: 4px; font-size: 12px;
}
.cp-fc-sku-picker button {
  padding: 6px 14px; background: #06b6d4; color: white;
  border: none; border-radius: 4px; font-weight: 600; font-size: 12px; cursor: pointer;
}
.cp-fc-sku-picker button:hover { background: #0891b2; }
.cp-fc-sku-picker button:disabled { background: #cbd5e1; cursor: not-allowed; }
/* Searchable SKU picker — autocomplete */
.cp-fc-sku-search-wrap { flex: 1; position: relative; }
.cp-fc-sku-search-wrap input {
  width: 100%; padding: 6px 10px;
  border: 1px solid #cbd5e1; border-radius: 4px; font-size: 12px;
}
.cp-fc-sku-search-wrap input:focus {
  outline: 2px solid #06b6d4; border-color: #06b6d4;
}
.cp-fc-sku-suggest {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 50;
  max-height: 280px; overflow-y: auto;
  background: var(--bg-card, #fff); border: 1px solid #cbd5e1; border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.cp-fc-sku-suggest-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; cursor: pointer; font-size: 12px;
  border-bottom: 1px solid #f1f5f9;
}
.cp-fc-sku-suggest-item:last-child { border-bottom: none; }
.cp-fc-sku-suggest-item:hover, .cp-fc-sku-suggest-item.active { background: #ecfeff; }
.cp-fc-sku-suggest-text { flex: 1; min-width: 0; line-height: 1.25; }
.cp-fc-sku-suggest-text strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-fc-sku-suggest-fmt { margin-left: auto; font-size: 10px; white-space: nowrap; }
.cp-fc-sku-suggest-empty {
  padding: 8px 10px; font-size: 12px; color: #94a3b8; font-style: italic;
}
.cp-fc-input-sku-table tfoot td {
  border-top: 2px solid #1B2A4A;
  padding-top: 8px; padding-bottom: 8px;
  background: #f0fdf4; color: #14532d; font-size: 13px;
}
.cp-fc-input-action-deadline {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 12px;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 6px;
}
.cp-fc-input-action-deadline label {
  font-size: 13px; font-weight: 700; color: #9a3412; margin: 0;
}
.cp-fc-input-action-deadline input[type="date"] {
  padding: 6px 10px; font-size: 13px;
  border: 1px solid #fdba74; border-radius: 4px; background: var(--bg-card, #fff);
  min-width: 160px;
}
.cp-fc-input-action-deadline input[type="date"]:focus {
  outline: 2px solid #f97316; border-color: #f97316;
}
.cp-fc-input-action-deadline small { font-size: 11px; }
.cp-fc-input-action-result {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f0fdf4; border: 1px solid #86efac; border-radius: 6px;
}
.cp-fc-input-action-result label {
  display: block; font-size: 13px; font-weight: 700; color: #14532d; margin-bottom: 6px;
}
.cp-fc-input-action-result textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid #86efac; border-radius: 4px; background: var(--bg-card, #fff);
  font-size: 13px; font-family: inherit; resize: vertical; min-height: 60px;
}
.cp-fc-input-action-result textarea:focus {
  outline: 2px solid #22c55e; border-color: #22c55e;
}
.cp-fc-input-action-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
/* Push New SKU multi-select chip picker */
.cp-fc-input-action-multi {
  background: #fefce8; border: 1px solid #fde68a; border-radius: 6px;
  padding: 8px 10px;
}
.cp-fc-new-chip-wrap {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0;
  min-height: 22px;
}
.cp-fc-new-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: var(--bg-card, #fff); border: 1px solid #d1d5db;
  border-radius: 999px; font-size: 11px; line-height: 1.2;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.cp-fc-new-chip-remove {
  background: transparent; border: none; color: #ef4444; cursor: pointer;
  padding: 0 2px; font-size: 14px; line-height: 1; font-weight: 700;
}
.cp-fc-new-chip-remove:hover { color: #b91c1c; }
.cp-fc-new-picker { position: relative; }
.cp-fc-new-search {
  width: 100%; padding: 5px 8px; font-size: 12px;
  border: 1px solid #cbd5e1; border-radius: 4px;
}
.cp-fc-new-search:focus {
  outline: 2px solid #f59e0b; border-color: #f59e0b;
}
.cp-fc-new-suggest {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 50;
  max-height: 240px; overflow-y: auto;
  background: var(--bg-card, #fff); border: 1px solid #cbd5e1; border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.cp-fc-input-action-row textarea {
  min-height: 36px; resize: vertical;
}
.cp-fc-input-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
}

/* SP mới ra mắt + tồn kho — section đầu tiên modal forecast */
.cp-fc-input-section-new {
  border: 2px solid #D4A843 !important;
  background: #fffbeb !important;
}
.cp-fc-input-section-new h3 { color: #78350f !important; }
.cp-fc-new-products-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.cp-fc-new-products-table th, .cp-fc-new-products-table td {
  padding: 4px 8px; border-bottom: 1px solid #fde68a; text-align: left;
}
.cp-fc-new-products-table th { background: #fef3c7; font-size: 11px; font-weight: 700; color: #92400e; }
.cp-fc-new-products-table th.num, .cp-fc-new-products-table td.num { text-align: right; }
.cp-fc-new-products-table .cp-fc-new-products-group td {
  background: #fde68a; font-weight: 700; color: #78350f;
  font-size: 11px; padding: 6px 8px; text-transform: uppercase; letter-spacing: 0.3px;
}

/* Forecast modal — info grid gọn hơn (ẩn address + contact, dồn 3 cột) */
.cp-fc-data-compact #cp-modal-info-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 8px !important;
}
.cp-fc-data-compact .cp-info-section {
  padding: 8px 10px !important;
  font-size: 11px;
}
.cp-fc-data-compact .cp-info-section h4 {
  font-size: 11px !important; margin-bottom: 4px !important;
}
.cp-fc-data-compact .cp-info-section dl {
  display: grid !important;
  grid-template-columns: minmax(0, max-content) 1fr;
  column-gap: 6px;
  row-gap: 2px;
}
.cp-fc-data-compact .cp-info-section dt {
  font-weight: 600; color: #475569; font-size: 10px; padding: 1px 0;
}
.cp-fc-data-compact .cp-info-section dd {
  margin: 0; padding: 1px 0; font-size: 11px; color: #1B2A4A;
}

/* Recommend SKU push cards — peers buy but this outlet doesn't */
.cp-fc-rec-section { margin: 6px 0 12px; padding: 10px 12px; background: #fef9c3; border: 1px solid #fde68a; border-radius: 6px; }
.cp-fc-rec-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px;
}
.cp-fc-rec-card {
  padding: 8px 10px; border-radius: 6px;
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  font-size: 12px;
  transition: transform .15s, box-shadow .15s;
}
.cp-fc-rec-card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.cp-fc-rec-cat { font-size: 9px; font-weight: 700; color: #78350f; letter-spacing: 0.5px; text-transform: uppercase; }
.cp-fc-rec-product { font-size: 13px; font-weight: 700; color: #1B2A4A; margin: 2px 0 4px; }
.cp-fc-rec-stat { font-size: 11px; color: #475569; }
.cp-fc-rec-vol { font-size: 11px; color: #6b7280; margin-top: 2px; }
/* Heat coloring — overlap (both Channel & TA) = hot; Channel-only = warm; TA-only = cool */
.cp-fc-rec-hot   { border-left: 4px solid #dc2626; background: linear-gradient(90deg, #fee2e2 0%, #fff 70%); box-shadow: 0 2px 6px rgba(220,38,38,0.25); }
.cp-fc-rec-warm  { border-left: 4px solid #ea580c; background: linear-gradient(90deg, #fed7aa 0%, #fff 70%); }
.cp-fc-rec-cool  { border-left: 4px solid #16a34a; background: linear-gradient(90deg, #bbf7d0 0%, #fff 70%); }

/* Legend at top of recommendation section */
.cp-fc-rec-legend { display: flex; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.cp-fc-rec-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
}
.cp-fc-rec-badge-both { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.cp-fc-rec-badge-ch   { background: #fed7aa; color: #9a3412; border: 1px solid #fdba74; }
.cp-fc-rec-badge-ta   { background: #bbf7d0; color: #166534; border: 1px solid #86efac; }

/* Format badges in Trend rows (KEG=bom / BOTTLE=chai / CAN=lon) */
.cp-trend-fmt-badge {
  display: inline-block; padding: 1px 6px; border-radius: 8px;
  font-size: 9px; font-weight: 700; margin-right: 4px; letter-spacing: 0.3px;
}
.cp-trend-fmt-keg    { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.cp-trend-fmt-bottle { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }
.cp-trend-fmt-can    { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.cp-trend-fmt-cont   { opacity: 0.65; font-weight: 500; }

/* Trend section header — phân biệt Channel trend vs TA trend */
.cp-fc-trend-section { margin: 12px 0 4px; }
.cp-fc-trend-section-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 8px; padding: 8px 12px; font-size: 13px; border-radius: 6px;
}
.cp-fc-trend-section-ch { background: #eff6ff; border-left: 4px solid #3b82f6; color: #1e3a8a; }
.cp-fc-trend-section-ta { background: #fdf4ff; border-left: 4px solid #a855f7; color: #581c87; }
.cp-fc-trend-section-meta { margin-left: auto; font-size: 11px; font-weight: 500; opacity: 0.75; }
/* Highlight TA row matching outlet's own TA trong Demand Pool table */
.cp-fc-dp-my-ta > td { background: #fef3c7 !important; font-weight: 600; }
.cp-fc-dp-my-ta > td:first-child { color: #92400e; }
/* Demand Pool stats grid — alcohol propensity + spend/occasion */
.cp-fc-dp-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px; margin-top: 10px;
}
.cp-fc-dp-stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px; background: #fefce8; border: 1px solid #fde68a; border-radius: 6px;
}
.cp-fc-dp-stat-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #92400e; font-weight: 600; }
.cp-fc-dp-stat strong { font-size: 14px; color: #1B2A4A; }
.cp-fc-dp-stat small { font-size: 10px; font-weight: 500; color: #64748b; }
.cp-fc-dp-warn {
  padding: 6px 10px; margin-bottom: 6px;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 6px;
  font-size: 11px; color: #9a3412;
}

/* Per-product trend block — mỗi sản phẩm 1 bảng riêng */
.cp-fc-trend-products {
  display: flex; flex-direction: column; gap: 16px;
}
.cp-fc-trend-product-block {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-card, #fff);
}
.cp-fc-trend-product-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px;
  background: linear-gradient(90deg, #1B2A4A, #2a4373);
  color: #fff;
  font-size: 13px;
}
.cp-fc-trend-product-cat {
  font-size: 10px; font-weight: 700; padding: 2px 8px;
  background: rgba(255,255,255,0.18); border-radius: 10px; letter-spacing: 0.4px;
}
.cp-fc-trend-product-name { font-size: 14px; }
.cp-fc-trend-product-fmts { font-size: 11px; opacity: 0.85; }
.cp-fc-trend-product-total {
  margin-left: auto; font-size: 12px;
  background: rgba(212,168,67,0.25); padding: 3px 10px; border-radius: 4px;
  border: 1px solid #D4A843;
}
.cp-fc-trend-product-block .cp-trend-table { width: 100%; font-size: 11px; border-collapse: collapse; }
.cp-fc-trend-product-block .cp-trend-table thead th {
  background: #1B2A4A; color: #fff; padding: 6px 8px; text-align: right;
}
.cp-fc-trend-product-block .cp-trend-table thead th:first-child { text-align: left; }
.cp-fc-trend-product-block .cp-trend-table td { padding: 4px 8px; border-bottom: 1px solid #f1f5f9; }
.cp-fc-trend-product-block .cp-trend-cur-month {
  background: #D4A843 !important; color: #1B2A4A !important;
  box-shadow: inset 0 -3px 0 #92400e;
}
.cp-fc-trend-product-block .cp-trend-cur-month-col {
  background: #fef3c7 !important;
  border-left: 2px solid #D4A843; border-right: 2px solid #D4A843;
  font-weight: 700;
}
/* Tint nền nhẹ + line trên mỗi nhóm format (bom/chai/lon) → dễ tách nhóm */
.cp-fc-trend-product-block tr.cp-trend-row-keg    > td { background: #fffaeb; }
.cp-fc-trend-product-block tr.cp-trend-row-bottle > td { background: #eff6ff; }
.cp-fc-trend-product-block tr.cp-trend-row-can    > td { background: #f0fdf4; }
.cp-fc-trend-product-block tr.cp-trend-row-fmt-first > td {
  border-top: 2px solid #94a3b8;
}
/* current-year nổi bật trong tint */
.cp-fc-trend-product-block tr.current-year.cp-trend-row-keg    > td { background: #fef3c7; }
.cp-fc-trend-product-block tr.current-year.cp-trend-row-bottle > td { background: #dbeafe; }
.cp-fc-trend-product-block tr.current-year.cp-trend-row-can    > td { background: #dcfce7; }
/* Highlight tháng đang plan vẫn ưu tiên — override tint format */
.cp-fc-trend-product-block tr .cp-trend-cur-month-col { background: #fef3c7 !important; }

/* Historical Trend pivot wrap (forecast modal version — channel+sub filtered) */
.cp-fc-trend-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.cp-fc-trend-wrap .cp-trend-table {
  font-size: 11px;
  width: 100%;
  border-collapse: collapse;
}
.cp-fc-trend-wrap .cp-trend-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: #1B2A4A; color: #fff;
  padding: 6px 8px;
  text-align: right;
}
.cp-fc-trend-wrap .cp-trend-table thead th:first-child { text-align: left; }
.cp-fc-trend-wrap .cp-trend-table td { padding: 4px 8px; border-bottom: 1px solid #f1f5f9; }
/* Highlight tháng đang plan (M1) — header + cả cột data */
.cp-fc-trend-wrap .cp-trend-cur-month {
  background: #D4A843 !important;
  color: #1B2A4A !important;
  box-shadow: inset 0 -3px 0 #92400e;
}
.cp-fc-trend-wrap .cp-trend-cur-month-col {
  background: #fef3c7 !important;
  border-left: 2px solid #D4A843;
  border-right: 2px solid #D4A843;
  font-weight: 700;
}

/* Peer benchmark — trendline chart wrap */
.cp-fc-peer-chart-wrap {
  position: relative;
  height: 240px;
  margin: 4px 0 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px;
}

/* Peer benchmark table */
.cp-fc-peer-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.cp-fc-peer-table th, .cp-fc-peer-table td {
  padding: 6px 8px; border-bottom: 1px solid #f1f5f9; text-align: right;
}
.cp-fc-peer-table th:first-child, .cp-fc-peer-table td:first-child { text-align: left; }
.cp-fc-peer-table thead th { background: #f8fafc; font-weight: 700; color: #475569; }
.cp-fc-peer-table .cp-fc-peer-row-label { background: #f0f9ff; font-weight: 600; }

/* Product catalog */
.cp-fc-catalog-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.cp-fc-catalog-group h4 {
  margin: 0 0 6px; font-size: 12px; font-weight: 700; color: #1B2A4A;
  padding: 4px 8px; background: #fef3c7; border-radius: 4px;
}
.cp-fc-catalog-table { width: 100%; font-size: 11px; border-collapse: collapse; }
.cp-fc-catalog-table td { padding: 3px 6px; border-bottom: 1px solid #f1f5f9; }
.cp-fc-catalog-table td:first-child { white-space: nowrap; color: #1B2A4A; }

/* Tier FC cell: inner editable input + non-editable badge phía sau */
.cp-fc-table td.cp-fc-tier-edit { background: #ecfeff; cursor: default; padding: 4px 6px; }
.cp-fc-table td.cp-fc-tier-edit .cp-fc-tier-input {
  display: inline-block;
  min-width: 40px;
  padding: 2px 4px;
  outline: none;
  cursor: text;
  border-radius: 2px;
}
.cp-fc-table td.cp-fc-tier-edit .cp-fc-tier-input:hover { box-shadow: inset 0 0 0 1px #67e8f9; }
.cp-fc-table td.cp-fc-tier-edit .cp-fc-tier-input:focus { box-shadow: inset 0 0 0 2px #06b6d4; background: var(--bg-card, #fff); }

/* GLOBAL — Header cột có công thức: nhỏ ƒx chấm bên dưới label + hover cursor help.
   Áp dụng trên mọi bảng (cp-fc-table + cp-md-table + bất kỳ bảng khác dùng .cp-formula-h)
   Tooltip công thức nằm ở attribute title của <th>. */
th.cp-fc-formula-h,
th.cp-formula-h {
  position: relative;
  cursor: help;
}
th.cp-fc-formula-h::after,
th.cp-formula-h::after {
  content: 'ƒx';
  display: inline-block;
  margin-left: 3px;
  padding: 0 3px;
  font-size: 8px;
  font-weight: 700;
  font-style: italic;
  color: #fff;
  background: #d4a843;
  border-radius: 2px;
  vertical-align: super;
  line-height: 1.4;
  letter-spacing: 0.3px;
}
/* Section row formula tooltip — không hiện chữ ƒx (vì label đã in hoa to), chỉ đổi cursor */
.cp-section-row th[title]:not(.cp-sec-info):not(.cp-sec-action) { cursor: help; }

/* ============================================================
   2-WAY SYNC MISA — cảnh báo cột "sửa ở đây sẽ push ngược lên MISA"
   Header: viền cam đậm + badge ↔ ; cell hover: shadow cam
   Áp dụng cho 8 cột: Stage / Đường / Quận / Tỉnh / Channel / Channel Seg /
   Tiềm năng outlet / Contact SĐT.
   ============================================================ */
.cp-md-table thead .cp-col-row th.cp-md-misa-2way {
  background: #fff7ed !important;          /* cam nhạt warning */
  color: #9a3412 !important;
  border-bottom: 3px solid #ea580c !important;
  border-top: 1px solid #fdba74 !important;
}
.cp-md-table thead .cp-col-row th.cp-md-misa-2way::before {
  content: '↔';
  display: inline-block;
  margin-right: 4px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 900;
  color: #fff;
  background: #ea580c;
  border-radius: 3px;
  vertical-align: middle;
}
.cp-md-table thead .cp-col-row th.cp-md-misa-2way .cp-md-col-label {
  font-weight: 700;
}
/* Cell editable đã có style riêng (cp-md-misa-edit) — bổ sung hover shadow cam để gợi nhắc 2-way */
.cp-md-table td.cp-md-misa-edit:hover,
.cp-md-table td.cp-md-stage-edit:hover {
  box-shadow: inset 0 0 0 2px #ea580c;
}

/* Outlet MỚI chưa forecast → highlight vàng + đẩy lên đầu để nhắc */
.cp-fc-table tbody tr.cp-fc-new-row td { background: #fef9c3 !important; }
.cp-fc-table tbody tr.cp-fc-new-row td.sticky-1,
.cp-fc-table tbody tr.cp-fc-new-row td.sticky-2 { background: #fef08a !important; }
.cp-fc-table tbody tr.cp-fc-new-row:hover td { background: #fde68a !important; }
.cp-fc-table tbody tr.cp-fc-new-row td.sticky-1 { border-left: 3px solid #d97706; font-weight: 700; }

/* Stage forecast cell (cột Stage T+1) — select gọn dạng pill, màu theo stage */
.cp-fc-table td.cp-fc-stageplan-cell {
  background: #fffbeb;          /* vàng nhạt — manual/forecast */
  padding: 4px 6px;
  vertical-align: middle;
}
.cp-fc-table select.cp-fc-stageplan {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-left-width: 3px;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-card, #fff);
  color: #1B2A4A;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='3' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 18px;
}
.cp-fc-table select.cp-fc-stageplan:hover { background-color: #f9fafb; }
.cp-fc-table select.cp-fc-stageplan:focus { outline: 2px solid #1B2A4A; outline-offset: -2px; }

.cp-fc-table tbody td {
  padding: 6px 6px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 11px;
}

.cp-fc-table tbody td.cp-sku {
  text-align: right;
  padding: 5px 4px;
  background: #fcfcfc;
  min-width: 42px;
  max-width: 50px;
}

.cp-fc-table tbody td.cp-target {
  background: #fef9e7;
}

.cp-fc-table tbody td.cp-sku.cp-target {
  background: #fef9e7;
}

.cp-fc-table tbody tr:hover td { background: #f0f9ff; }
.cp-fc-table tbody tr:hover td.cp-target { background: #fef3c7; }

/* Sticky columns: Sales Sup + Outlet */
.cp-fc-table .sticky-1,
.cp-fc-table .sticky-2 {
  position: sticky;
  background: var(--bg-card, #fff);
  z-index: 3;
}
.cp-fc-table .sticky-1 { left: 0; min-width: 100px; max-width: 130px; }
.cp-fc-table .sticky-2 { left: 100px; min-width: 200px; max-width: 280px; white-space: normal; }
.cp-fc-table thead .cp-col-row .sticky-1,
.cp-fc-table thead .cp-col-row .sticky-2 { z-index: 6; background: #f9fafb; }
.cp-fc-table tbody tr:hover .sticky-1,
.cp-fc-table tbody tr:hover .sticky-2 { background: #f0f9ff; }

/* ============================================================
   Master Data table — 76 cols
   ============================================================ */
.cp-md-table {
  font-size: 11px;
  white-space: nowrap;
}
.cp-md-table thead .cp-md-section-row th {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 9px 0;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.2);
}
.cp-md-table thead .cp-md-section-row .cp-md-sec-label {
  padding: 0 12px;
  display: inline-block;
  white-space: nowrap;
}
.cp-md-table thead .cp-md-section-row .cp-md-sec-info   { background: #4b5563; }
.cp-md-table thead .cp-md-section-row .cp-md-sec-price  { background: #D4A843; color: #1B2A4A; }
.cp-md-table thead .cp-md-section-row .cp-md-sec-other  { background: #1B2A4A; }

.cp-md-table thead .cp-col-row th {
  position: sticky;
  top: 32px;
  z-index: 4;
  background: #1B2A4A;
  color: #fff;
  padding: 8px 8px;
  font-size: 10px;
  font-weight: 600;
  border-bottom: 1px solid #1B2A4A;
  vertical-align: middle;
  text-align: left;
}
.cp-md-table thead .cp-col-row th.num { text-align: right; }
.cp-md-table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #f3f4f6;
  border-right: 1px solid #e5e7eb;
  font-size: 11px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cp-md-table thead .cp-col-row th {
  border-right: 1px solid rgba(255,255,255,0.15);
}
.cp-md-table tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cp-md-table tbody tr:hover td { background: #f0f9ff; }

/* Sticky left columns — 6 cột identification luôn nhìn thấy khi scroll ngang */
.cp-md-table .md-sticky {
  position: sticky;
  background: var(--bg-card, #fff);
  z-index: 3;
  border-right: 1px solid #d1d5db;
}
/* Thead sticky cells: higher z-index so they overlap scrolling body */
.cp-md-table thead .cp-col-row th.md-sticky    { z-index: 7 !important; background: #1B2A4A !important; }
.cp-md-table thead .cp-md-section-row th.md-sticky { z-index: 8 !important; }
.cp-md-table tbody tr:hover td.md-sticky { background: #f0f9ff; }
/* Last sticky col has thicker right border to mark the freeze boundary */
.cp-md-table .md-sticky-1 { border-right: 2px solid #1B2A4A; }

/* Discount badge next to price (after CK + VAT) */
.cp-md-disc-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.2;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  vertical-align: middle;
}

/* ───── MISA vs Manual column tint ─────
   col-misa  = data kéo trực tiếp từ MISA → nền xanh nhạt
   col-manual = phải nhập tay / import từ Excel → nền vàng nhạt */
.cp-md-table thead .cp-col-row th.col-misa {
  background: #1e3a5f;
}
.cp-md-table thead .cp-col-row th.col-manual {
  background: #5b4513;
}
.cp-md-table thead .cp-col-row th.col-computed {
  background: #5b21b6;
}

.cp-md-table tbody td.col-misa {
  background: #e0f2fe;        /* sky-100 — MISA columns */
}
.cp-md-table tbody td.col-manual {
  background: #fef3c7;        /* amber-100 — manual fill columns */
}
.cp-md-table tbody td.col-computed {
  background: #ede9fe;        /* purple-100 — auto-computed columns */
  font-style: italic;
  color: #5b21b6;
}
.cp-md-table tbody tr:hover td.col-misa { background: #bae6fd; }
.cp-md-table tbody tr:hover td.col-manual { background: #fde68a; }

/* MISA cell có data → khoá, hover hiển thị cursor not-allowed */
.cp-md-table tbody td.cp-md-misa-locked {
  cursor: not-allowed;
}
.cp-md-table tbody td.cp-md-misa-locked:hover {
  outline: 1px dashed #94a3b8;
  outline-offset: -2px;
}
/* MISA cell rỗng → cho nhập tay, giữ màu nền cột MISA bình thường */
.cp-md-table tbody td.cp-md-misa-fillable {
  cursor: text;
}
.cp-md-table tbody td.cp-md-misa-fillable:focus {
  outline: 2px solid #1B2A4A;
  outline-offset: -2px;
  background: #fff !important;
}

/* Per-column filter button on thead (Excel-like autofilter) */
.cp-md-col-label {
  display: inline-block;
  vertical-align: middle;
  max-width: calc(100% - 18px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.cp-md-col-filter {
  display: inline-block;
  vertical-align: middle;
  margin-left: 4px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity .15s, background .15s;
}
.cp-md-col-filter:hover { opacity: 1; background: rgba(255,255,255,0.25); }
/* Có filter đang bật — nổi bật bằng badge vàng + viền + nhô ra để dễ nhìn nhiều cột cùng lúc */
.cp-md-col-filter.active {
  background: #D4A843;
  color: #1B2A4A;
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(212, 168, 67, 0.45);
  transform: scale(1.1);
}
/* Tô vàng cả header column khi cột đó đang lọc — quét mắt là biết cột nào đang filter */
.cp-md-table thead .cp-col-row th:has(.cp-md-col-filter.active) {
  background: #fef3c7 !important;
  color: #78350f !important;
  border-bottom: 2px solid #D4A843 !important;
}

/* Filter popover (floating, position:fixed) */
.cp-md-colfilter-pop {
  position: fixed;
  z-index: 1500;
  min-width: 240px;
  max-width: 320px;
  max-height: 480px;
  background: var(--bg-card, #fff);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  font-size: 13px;
}
.cp-md-colfilter-pop[hidden] { display: none !important; }
.cp-md-colfilter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 8px 8px 0 0;
}
.cp-md-colfilter-close {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: #6b7280;
}
.cp-md-colfilter-search {
  margin: 8px 10px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
}
.cp-md-colfilter-actions {
  display: flex;
  gap: 4px;
  padding: 0 10px 8px;
}
.cp-md-colfilter-actions button {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  background: var(--bg-card, #fff);
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  color: #374151;
}
.cp-md-colfilter-actions button:hover { background: #f3f4f6; }
.cp-md-colfilter-clear { color: #b91c1c !important; border-color: #fca5a5 !important; }
.cp-md-colfilter-list {
  overflow-y: auto;
  flex: 1;
  padding: 4px 10px 10px;
  max-height: 320px;
}
.cp-md-colfilter-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
}
.cp-md-colfilter-list label:hover { background: #f3f4f6; }
.cp-md-colfilter-val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-md-colfilter-count {
  background: #f1f5f9;
  color: #6b7280;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

/* Forecast mode — outlet MỚI chưa forecast: highlight vàng nhắc nhập */
.cp-md-table tbody tr.cp-fc-new-row td { background: #fef9c3 !important; }
.cp-md-table tbody tr.cp-fc-new-row td.md-sticky { background: #fef08a !important; }
.cp-md-table tbody tr.cp-fc-new-row:hover td { background: #fde68a !important; }
.cp-md-table tbody tr.cp-fc-new-row td.md-sticky-1 {
  border-left: 3px solid #d97706;
  font-weight: 700;
}

/* Overdue orders highlight box (đầu Master Data — outlets >6 tháng không order) */
.cp-md-overdue-box:empty { display: none; }
.cp-md-overdue-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid #dc2626;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.cp-md-overdue-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #7f1d1d;
  margin-bottom: 10px;
}
.cp-md-overdue-header strong { color: #b91c1c; font-size: 15px; }
.cp-md-overdue-icon { font-size: 18px; }
.cp-md-overdue-toggle {
  margin-left: auto;
  background: var(--bg-card, #fff);
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.cp-md-overdue-toggle:hover { background: #fee2e2; }
.cp-md-overdue-groups {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 1100px) {
  .cp-md-overdue-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.cp-md-overdue-group {
  background: var(--bg-card, #fff);
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 8px 10px;
}
.cp-md-overdue-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 8px;
  border-bottom: 1px solid #fee2e2;
  margin-bottom: 6px;
  font-size: 12px;
  color: #1B2A4A;
}
.cp-md-overdue-group-title strong { font-size: 13px; }
.cp-md-overdue-group-count {
  background: #fee2e2;
  color: #b91c1c;
  padding: 1px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 11px;
}
.cp-md-overdue-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.cp-md-overdue-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-card, #fff);
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}
.cp-md-overdue-item:hover {
  background: #fef2f2;
  border-color: #f87171;
}
.cp-md-overdue-days {
  background: #dc2626;
  color: #fff;
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
  min-width: 58px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1.4;
}
.cp-md-overdue-name {
  flex: 1;
  font-weight: 600;
  color: #1B2A4A;
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 0;
}
.cp-md-overdue-date { color: #6b7280; font-variant-numeric: tabular-nums; font-size: 11px; flex-shrink: 0; }
.cp-md-overdue-stage {
  flex-shrink: 0; padding: 2px 8px; font-size: 10px; font-weight: 600;
  border-radius: 10px; white-space: nowrap;
}
.cp-md-overdue-empty {
  grid-column: 1 / -1; padding: 12px;
  text-align: center; font-size: 12px; color: #16a34a;
  font-style: italic; background: #f0fdf4; border-radius: 6px;
}
.cp-md-overdue-more {
  grid-column: 1 / -1;
  text-align: center;
  padding: 6px;
  color: #6b7280;
  font-size: 11px;
  font-style: italic;
}

/* Group separator rows (bán bia tươi / chưa bán) — sticky cả ngang lẫn dọc khi cuộn */
.cp-md-table tbody tr.cp-md-group-row td {
  position: sticky;
  left: 0;
  top: 60px;   /* dưới thead 2 rows */
  padding: 10px 16px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-top: 2px solid #1B2A4A;
  border-bottom: 2px solid #1B2A4A;
  z-index: 6;
}
.cp-md-table tbody tr.cp-md-group-row td.cp-md-group-draft {
  background: #1B2A4A;
  color: #D4A843;
}
.cp-md-table tbody tr.cp-md-group-row td.cp-md-group-nodraft {
  background: #475569;
  color: #fff;
}
.cp-md-table tbody tr.cp-md-group-row:hover td { background: inherit; }

/* Sub-group separator (level 2) — bia chai/lon vs chỉ bia tươi */
.cp-md-table tbody tr.cp-md-subgroup-row td {
  position: sticky;
  left: 0;
  top: 96px;   /* dưới group row */
  padding: 7px 28px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid #cbd5e1;
  z-index: 5;
}
.cp-md-table tbody tr.cp-md-subgroup-row td.cp-md-sub-bottle {
  background: #fef3c7;
  color: #92400e;
}
.cp-md-table tbody tr.cp-md-subgroup-row td.cp-md-sub-onlydraft {
  background: #dbeafe;
  color: #1e40af;
}
.cp-md-table tbody tr.cp-md-subgroup-row:hover td { background: inherit; }

/* Forecast — same 2-level group separator (Bán bia tươi / Bán cả bia chai/lon / Chưa bán) */
.cp-fc-table tbody tr.cp-fc-group-row td {
  position: sticky;
  left: 0;
  top: 60px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-top: 2px solid #1B2A4A;
  border-bottom: 2px solid #1B2A4A;
  z-index: 6;
}
.cp-fc-table tbody tr.cp-fc-group-row td.cp-fc-group-draft   { background: #1B2A4A; color: #D4A843; }
.cp-fc-table tbody tr.cp-fc-group-row td.cp-fc-group-nodraft { background: #475569; color: #fff; }
.cp-fc-table tbody tr.cp-fc-group-row:hover td { background: inherit; }
.cp-fc-table tbody tr.cp-fc-subgroup-row td {
  position: sticky;
  left: 0;
  top: 96px;
  padding: 7px 28px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid #cbd5e1;
  z-index: 5;
}
.cp-fc-table tbody tr.cp-fc-subgroup-row td.cp-fc-sub-bottle    { background: #fef3c7; color: #92400e; }
.cp-fc-table tbody tr.cp-fc-subgroup-row td.cp-fc-sub-onlydraft { background: #dbeafe; color: #1e40af; }
.cp-fc-table tbody tr.cp-fc-subgroup-row td.cp-fc-sub-placeholder,
.cp-md-table tbody tr.cp-md-subgroup-row td.cp-md-sub-placeholder { background: #e2e8f0; color: #475569; }
.cp-fc-table tbody tr.cp-fc-subgroup-row:hover td { background: inherit; }
/* L0 planning status row — CẦN PLAN / ĐÃ PLAN (NOT sticky, chỉ là divider) */
.cp-fc-table tbody tr.cp-fc-planning-row td {
  position: sticky; left: 0;
  padding: 14px 16px;
  font-weight: 800; font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.5px;
  border-top: 3px solid #1B2A4A;
  border-bottom: 3px solid #1B2A4A;
  z-index: 5;
}
.cp-fc-table tbody tr.cp-fc-planning-row td.cp-fc-planning-todo {
  background: linear-gradient(90deg, #dc2626, #f97316);
  color: white;
}
.cp-fc-table tbody tr.cp-fc-planning-row td.cp-fc-planning-done {
  background: #166534; color: white;
}
.cp-fc-table tbody tr.cp-fc-planning-row td.cp-fc-planning-delete {
  background: linear-gradient(90deg, #475569, #64748b);
  color: #e2e8f0;
}
.cp-fc-table tbody tr.cp-fc-planning-row:hover td { background: inherit; }

/* Miền group row (L3 grouping) — shared style for forecast + master data */
.cp-fc-table tbody tr.cp-fc-mien-row td,
.cp-md-table tbody tr.cp-md-mien-row td {
  position: sticky; left: 0;
  top: 126px;   /* dưới subgroup row */
  padding: 5px 44px;
  font-weight: 600; font-size: 11px;
  letter-spacing: 0.3px;
  border-bottom: 1px solid #e2e8f0;
  z-index: 4;
}
.cp-fc-table tbody tr.cp-fc-mien-row td.cp-fc-mien-Miền-Nam,
.cp-md-table tbody tr.cp-md-mien-row td.cp-md-mien-Miền-Nam   { background: #ecfccb; color: #3f6212; }
.cp-fc-table tbody tr.cp-fc-mien-row td.cp-fc-mien-Miền-Trung,
.cp-md-table tbody tr.cp-md-mien-row td.cp-md-mien-Miền-Trung { background: #ffedd5; color: #9a3412; }
.cp-fc-table tbody tr.cp-fc-mien-row td.cp-fc-mien-Miền-Bắc,
.cp-md-table tbody tr.cp-md-mien-row td.cp-md-mien-Miền-Bắc   { background: #e0f2fe; color: #075985; }
.cp-fc-table tbody tr.cp-fc-mien-row td.cp-fc-mien-Khác,
.cp-md-table tbody tr.cp-md-mien-row td.cp-md-mien-Khác       { background: #f1f5f9; color: #475569; }
.cp-fc-table tbody tr.cp-fc-mien-row:hover td,
.cp-md-table tbody tr.cp-md-mien-row:hover td { background: inherit; }

/* MISA 2-way edit cells (Stage / Region / Channel / Name / Tier / Phone / ...) */
.cp-md-table tbody td.cp-md-stage-edit,
.cp-md-table tbody td.cp-md-misa-edit {
  cursor: pointer;
}
.cp-md-table tbody td.cp-md-stage-edit:hover,
.cp-md-table tbody td.cp-md-misa-edit:hover {
  outline: 2px solid #D4A843;
  outline-offset: -2px;
}
.cp-md-table tbody td.cp-md-stage-empty {
  background: #fef9c3 !important;
  text-align: center;
}

/* Stage picker popover */
.cp-md-stage-pop {
  position: fixed;
  z-index: 1600;
  min-width: 260px;
  background: var(--bg-card, #fff);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 13px;
}
.cp-md-stage-pop[hidden] { display: none !important; }
.cp-md-stage-pop-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  background: #1B2A4A;
  color: #fff;
  border-radius: 8px 8px 0 0;
}
.cp-md-stage-pop-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.cp-md-stage-pop-list {
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
  max-height: 420px;
  overflow-y: auto;
}
.cp-md-stage-pop-section {
  font-size: 10px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 8px 4px;
  border-top: 1px solid #f3f4f6;
}
.cp-md-stage-pop-section:first-child { border-top: none; }
.cp-md-stage-opt {
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: var(--bg-card, #fff);
  cursor: pointer;
  font-size: 12px;
  border-radius: 4px;
  transition: background .12s;
}
.cp-md-stage-opt:hover { background: #f3f4f6; }
.cp-md-stage-opt.selected {
  background: #1B2A4A;
  color: #D4A843;
  font-weight: 700;
}
.cp-md-stage-pop-foot {
  padding: 7px 12px;
  font-size: 11px;
  color: #6b7280;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 0 0 8px 8px;
}

/* Native <select> in cell — show full list khi click, có "+ Thêm option mới" ở cuối */
.cp-md-table tbody td.cp-md-select-cell {
  padding: 0;
}
.cp-md-table tbody td.cp-md-select-cell select.cp-md-select {
  width: 100%;
  height: 100%;
  padding: 9px 18px 9px 12px;
  border: none;
  background: transparent;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}
.cp-md-table tbody td.cp-md-select-cell select.cp-md-select:focus {
  outline: 2px solid #1B2A4A;
  outline-offset: -2px;
  background-color: var(--bg-card, #fff);
}
.cp-md-table tbody td.cp-md-select-cell select.cp-md-select:hover {
  background-color: rgba(27, 42, 74, 0.04);
}
/* "+ Thêm option mới" option styling */
.cp-md-table tbody td.cp-md-select-cell select.cp-md-select option.cp-md-opt-add {
  color: #D4A843;
  font-weight: 700;
  font-style: italic;
  border-top: 1px solid #cbd5e1;
}

/* Sticky cells keep source-based bg color so user sees MISA/manual tint even when frozen */
.cp-md-table tbody td.md-sticky.col-misa   { background: #e0f2fe; }
.cp-md-table tbody td.md-sticky.col-manual { background: #fef3c7; }

/* Legend */
.cp-md-legend {
  display: flex;
  gap: 16px;
  margin: 8px 0 12px;
  font-size: 12px;
  color: #4b5563;
}
.cp-md-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cp-md-legend .legend-swatch {
  display: inline-block;
  width: 16px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid #d1d5db;
}
.cp-md-legend .legend-misa { background: #e0f2fe; }
.cp-md-legend .legend-manual { background: #fef3c7; }
.cp-md-legend .legend-computed { background: #ede9fe; }

/* ============================================================
   Outlet Detail Modal
   ============================================================ */
.cp-outlet-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.cp-outlet-modal.open { display: flex; }

.cp-outlet-modal .cp-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
}

.cp-outlet-modal .cp-modal-content {
  position: relative;
  background: var(--bg-card, #fff);
  border-radius: 12px;
  width: 92vw;
  max-width: 1280px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.cp-outlet-modal .cp-modal-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid #e5e7eb;
}
.cp-outlet-modal .cp-modal-title-group { flex: 1; min-width: 0; }
.cp-outlet-modal #cp-modal-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: #1B2A4A;
}
.cp-outlet-modal .cp-modal-subtitle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  color: #4b5563;
  align-items: center;
}
.cp-outlet-modal .cp-modal-close {
  flex-shrink: 0;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  width: 36px;
  height: 36px;
  font-size: 18px;
  border-radius: 50%;
  cursor: pointer;
  color: #6b7280;
}
.cp-outlet-modal .cp-modal-close:hover {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

.cp-outlet-modal .cp-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.cp-outlet-modal .cp-modal-loading,
.cp-outlet-modal .cp-modal-error,
.cp-outlet-modal .cp-modal-empty {
  padding: 40px;
  text-align: center;
  color: #6b7280;
  font-style: italic;
}
.cp-outlet-modal .cp-modal-error { color: #991b1b; }

/* KPIs */
.cp-modal-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.cp-modal-kpis .kpi {
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
}
.cp-modal-kpis .kpi .lbl {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .4px;
  font-weight: 500;
}
.cp-modal-kpis .kpi .val {
  font-size: 22px;
  font-weight: 700;
  color: #1B2A4A;
  margin: 4px 0;
}
.cp-modal-kpis .kpi .sub {
  font-size: 11px;
  color: #6b7280;
}

/* Sections */
.cp-modal-section {
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}
.cp-modal-section h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #1B2A4A;
  font-weight: 600;
}

.cp-modal-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.cp-modal-grid-2 .cp-modal-section { margin-bottom: 0; }
@media (max-width: 900px) {
  .cp-modal-grid-2 { grid-template-columns: 1fr; }
}

/* Product table */
.cp-modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  max-height: 240px;
}
.cp-modal-table thead th {
  background: #f9fafb;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600;
  color: #374151;
}
.cp-modal-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #f3f4f6;
}
.cp-modal-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cp-modal-table .cp-badge.format-keg    { background: #dbeafe; color: #1e40af; padding: 2px 7px; border-radius: 10px; font-size: 11px; }
.cp-modal-table .cp-badge.format-bottle { background: #d1fae5; color: #065f46; padding: 2px 7px; border-radius: 10px; font-size: 11px; }
.cp-modal-table .cp-badge.format-can    { background: #fef3c7; color: #92400e; padding: 2px 7px; border-radius: 10px; font-size: 11px; }

/* Recent volume table in outlet modal */
.cp-modal-vol-period {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #f9fafb;
  border-radius: 5px;
}
.cp-modal-vol-period strong { color: #1B2A4A; }
.cp-modal-vol-table .cp-vol-total {
  background: #fef3c7;
}
.cp-modal-vol-table .cp-vol-total td {
  border-bottom: 2px solid #D4A843;
  padding-top: 9px;
  padding-bottom: 9px;
}
/* Mini detail columns (T-3, T-2, T-1) — nhỏ + xám hơn để distinguish với 2 cột chính */
.cp-modal-vol-table .cp-vol-mini {
  font-size: 11px;
  color: #6b7280;
  background: #f9fafb;
  padding-left: 8px;
  padding-right: 8px;
  border-left: 1px dashed #e5e7eb;
}
.cp-modal-vol-table .cp-vol-pname {
  font-weight: 500;
  color: #1B2A4A;
  font-size: 12px;
  line-height: 1.3;
}
.cp-modal-vol-table .cp-vol-psku {
  font-size: 10px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}
.cp-modal-vol-table thead th.cp-vol-mini {
  color: #6b7280;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

/* SKU price grid in outlet modal — 3 columns side-by-side for KEG / BOTTLE / CAN */
#cp-modal-price-grid {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 14px;
  width: 100%;
}
.cp-modal-price-group {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 0;     /* allow shrink trong grid cell */
  width: 100%;      /* explicit — auto không stretch trong context này (default justify-self không fire) */
  box-sizing: border-box;
}
.cp-modal-price-group .cp-modal-table { width: 100%; }
.cp-modal-price-group h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}
.cp-modal-price-group .cp-modal-table { font-size: 12px; }
.cp-modal-price-group .cp-modal-table tbody td { padding: 4px 8px; }

/* Info grid sections */
#cp-modal-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
/* Competitor widget — span full width của info grid (không bị bóp vào 1 cột) */
.cp-cmp-section { grid-column: 1 / -1; }
/* Info grid editable inputs — inline cho từng field */
.cp-info-edit {
  width: 100%; padding: 3px 6px;
  border: 1px solid #e5e7eb; border-radius: 4px;
  font-size: 12px; box-sizing: border-box; background: #fff;
  transition: background .2s, border-color .15s;
}
.cp-info-edit:hover { border-color: #94a3b8; }
.cp-info-edit:focus { border-color: #2563eb; outline: none; box-shadow: 0 0 0 2px #2563eb22; }
.cp-info-empty { color: #cbd5e1; font-style: italic; font-size: 11px; }
.cp-info-readonly-empty dd, dd.cp-info-readonly-empty { color: #cbd5e1; }
/* Inner 2-col chỉ áp dụng khi parent đủ rộng, nếu không stack vertical */
.cp-cmp-section .cp-cmp-groups {
  display: grid; gap: 12px; margin-top: 6px;
  grid-template-columns: repeat(auto-fit, minmax(560px, 1fr));
}
.cp-info-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #D4A843;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 2px solid #D4A843;
  padding-bottom: 4px;
}
.cp-info-section dl {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  font-size: 12px;
}
.cp-info-section dt {
  color: #6b7280;
  font-weight: 500;
}
.cp-info-section dd {
  margin: 0;
  color: #1B2A4A;
  font-weight: 500;
}

/* ============================================================
   Menu Gallery Modal
   ============================================================ */
.cp-menu-gallery {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1100;
  align-items: center;
  justify-content: center;
}
.cp-menu-gallery.open { display: flex; }
.cp-menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
}
.cp-menu-content {
  position: relative;
  background: var(--bg-card, #fff);
  border-radius: 12px;
  width: 92vw;
  max-width: 1100px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.cp-menu-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}
.cp-menu-header h3 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  color: #1B2A4A;
}
.cp-menu-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.cp-menu-close {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  color: #6b7280;
}
.cp-menu-close:hover { background: #fee2e2; color: #991b1b; }
#cp-menu-del-all {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
  font-weight: 600;
}
#cp-menu-del-all:hover { background: #fecaca; }
.cp-menu-body {
  padding: 16px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.cp-menu-body a {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  transition: transform .2s ease, box-shadow .2s ease;
}
.cp-menu-body a:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.cp-menu-body img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}

/* Image wrapper with delete button overlay */
.cp-menu-img-wrap {
  position: relative;
}
.cp-menu-img-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(220, 38, 38, 0.9);   /* red, always visible */
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform .15s, background .15s;
  z-index: 2;
}
.cp-menu-img-del:hover {
  background: #dc2626;
  transform: scale(1.15);
}

/* Outlet detail modal menu gallery (inline) */
.cp-modal-menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.cp-modal-menu-grid a {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  transition: transform .2s ease;
}
.cp-modal-menu-grid a:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.cp-modal-menu-grid img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

/* Editable cells (manual cols) */
.cp-md-table td[contenteditable] {
  cursor: text;
  outline: none;
}
.cp-md-table td[contenteditable]:hover {
  background: #fde68a !important;
  box-shadow: inset 0 0 0 1px #f59e0b;
}
.cp-md-table td[contenteditable]:focus {
  background: #fff !important;
  box-shadow: inset 0 0 0 2px #2A9D8F;
}
.cp-md-table td.cp-md-saving {
  background: #ddd6fe !important;
}
.cp-md-table td.cp-md-saved {
  background: #d1fae5 !important;
  box-shadow: inset 0 0 0 2px #10b981;
  transition: background .5s ease;
}
.cp-md-table td.cp-md-save-error {
  background: #fee2e2 !important;
  box-shadow: inset 0 0 0 2px #ef4444;
}


/* ============================================================
   Summary view — tổng hợp per sales (CA pipeline + CS forecast)
   ============================================================ */
.cp-sum-wrap {
  padding: 12px 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 1200px) { .cp-sum-wrap { grid-template-columns: 1fr; } }
.cp-sum-team {
  background: var(--bg-card, #fff); border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 12px 16px;
}
.cp-sum-team-title {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  margin: 0 0 12px; font-size: 14px; font-weight: 700; color: #1B2A4A;
  padding-bottom: 6px; border-bottom: 2px solid #1B2A4A;
}
.cp-sum-sales-list { display: flex; flex-direction: column; gap: 12px; }
.cp-sum-sales {
  background: #fafafa; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 10px 12px;
}
.cp-sum-sales-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid #e2e8f0;
  font-size: 13px; color: #1B2A4A;
}
.cp-sum-role {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.cp-sum-role-leader { background: #1B2A4A; color: #D4A843; }
.cp-sum-role-member { background: #e0f2fe; color: #0369a1; }
.cp-sum-role-team { background: #fef3c7; color: #92400e; }

/* Team-level board: target tổng + CS aggregated */
.cp-sum-team-board {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 2px solid #f59e0b; border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px;
}
.cp-sum-team-board-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px dashed #f59e0b;
  font-size: 13px; color: #78350f;
}
.cp-sum-section-sub {
  margin: 12px 0 8px; font-size: 13px; font-weight: 600; color: #475569;
  padding-bottom: 4px; border-bottom: 1px solid #e2e8f0;
}
.cp-sum-tables {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
/* Team nửa screen → khi viewport < 1600px, CA + CS bên trong stack vertical (đỡ cramp) */
@media (max-width: 1600px) and (min-width: 1201px) {
  .cp-sum-team .cp-sum-tables { grid-template-columns: 1fr; }
}
@media (max-width: 900px) { .cp-sum-tables { grid-template-columns: 1fr; } }
.cp-sum-table-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px 10px; }
.cp-sum-table-title {
  margin: 0 0 6px; font-size: 12px; font-weight: 600; color: #475569;
  padding-bottom: 4px; border-bottom: 1px solid #f1f5f9;
}
.cp-sum-table { width: 100%; font-size: 11px; border-collapse: collapse; }
.cp-sum-table th, .cp-sum-table td {
  padding: 4px 6px; border-bottom: 1px solid #f1f5f9; text-align: left;
}
.cp-sum-table th { font-size: 10px; font-weight: 700; color: #6b7280; background: #f8fafc; }
.cp-sum-table th.num, .cp-sum-table td.num { text-align: right; }
.cp-sum-table tfoot tr.cp-sum-total-row { height: 34px; }
.cp-sum-table tfoot tr.cp-sum-total-row td {
  border-top: 2px solid #1B2A4A; background: #f0fdf4;
  color: #14532d; font-weight: 700; padding-top: 6px; padding-bottom: 6px;
  vertical-align: middle;
}
.cp-sum-pct-ok   { color: #15803d; font-weight: 700; }
.cp-sum-pct-warn { color: #ca8a04; font-weight: 700; }
.cp-sum-pct-low  { color: #dc2626; font-weight: 700; }
/* Đảm bảo mọi row trong summary table có cùng height → TỔNG ở 2 bảng ngang nhau */
.cp-sum-table tbody tr { height: 28px; }
.cp-sum-table tbody tr td { vertical-align: middle; }
.cp-sum-row-pad td { background: transparent !important; border-bottom: 1px solid #f8fafc; opacity: 0.3; height: 28px; }
.cp-sum-row-empty td { color: #cbd5e1; }
.cp-sum-lead-own {
  display: inline-block; padding: 1px 8px;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  border-radius: 4px; font-size: 11px; font-weight: 600;
}
.cp-sum-actual {
  font-size: 10px; color: #047857; font-style: italic; margin-top: 2px;
}
