*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:           #f0f4f8;
  --card:         #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --muted:        #64748b;
  --primary:      #2563eb;
  --primary-lt:   #eff6ff;
  --green:        #059669;
  --green-lt:     #ecfdf5;
  --red:          #dc2626;
  --red-lt:       #fef2f2;
  --amber:        #d97706;
  --amber-lt:     #fffbeb;
  --purple:       #7c3aed;
  --purple-lt:    #f5f3ff;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08);
  --radius:       12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  color: #fff;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(37,99,235,.35);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.header-brand p {
  font-size: 12px;
  opacity: .75;
  margin-top: 2px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 10px;
  padding: 8px 14px;
  flex-wrap: wrap;
}
.filter-bar label {
  font-size: 12px;
  opacity: .85;
  white-space: nowrap;
}
.filter-bar input[type="date"] {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 6px;
  color: #fff;
  padding: 5px 8px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.filter-bar input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity:.8; }
.filter-bar input[type="date"]:focus { border-color: rgba(255,255,255,.6); }

/* Date shortcut buttons */
.date-shortcuts {
  display: flex;
  gap: 3px;
  align-items: center;
  border-left: 1px solid rgba(255,255,255,.2);
  padding-left: 8px;
  margin-left: 2px;
}
.btn-shortcut {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.9);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  line-height: 1.4;
}
.btn-shortcut:hover { background: rgba(255,255,255,.26); color: #fff; }

.btn { border: none; border-radius: 7px; padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .15s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn-white { background: #fff; color: var(--primary); }
.btn-white:hover { opacity: .92; }
.btn-ghost { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.btn-ghost:hover { background: rgba(255,255,255,.26); }

/* ── Tab Navigation ─────────────────────────────────────── */
.tab-nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 0 24px;
  position: sticky;
  top: 74px;
  z-index: 90;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.tab-btn {
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Error Banner ───────────────────────────────────────── */
#error-banner {
  display: none;
  background: var(--red-lt);
  border: 1px solid #fca5a5;
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  align-items: center;
  gap: 10px;
}
#error-banner.show { display: flex; }
#error-banner button {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--red);
  font-size: 16px;
  line-height: 1;
}

/* ── Toast ──────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
  z-index: 9000;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.toast-success { background: var(--green); }
#toast.toast-error   { background: var(--red); }
#toast.toast-info    { background: var(--primary); }

/* ── Main ───────────────────────────────────────────────── */
.main { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* ── Team KPI Row ───────────────────────────────────────── */
.team-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.team-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--border);
  transition: transform .2s, box-shadow .2s;
}
.team-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.team-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.team-name {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text);
  line-height: 1.3;
  max-width: 70%;
}
.team-share-wrap { text-align: right; }
.team-share-pct {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.team-share-label { font-size: 10px; color: var(--muted); }
.team-share-bar {
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
.team-share-fill { height: 100%; border-radius: 2px; transition: width .5s; }
.team-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}
.team-stat-label { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.team-stat-value { font-size: 13px; font-weight: 700; margin-top: 1px; }

/* ── Team filter buttons ─────────────────────────────────── */
.team-filter-btn {
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.team-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.team-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── KPI Cards ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid transparent;
  transition: transform .2s, box-shadow .2s;
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: attr(data-icon);
  position: absolute;
  right: 16px;
  bottom: 10px;
  font-size: 36px;
  opacity: .08;
  pointer-events: none;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.kpi-card.c-blue   { border-top-color: var(--primary); }
.kpi-card.c-red    { border-top-color: var(--red); }
.kpi-card.c-green  { border-top-color: var(--green); }
.kpi-card.c-purple { border-top-color: var(--purple); }

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 6px;
}
.c-blue   .kpi-value { color: var(--primary); }
.c-red    .kpi-value { color: var(--red); }
.c-green  .kpi-value { color: var(--green); }
.c-purple .kpi-value { color: var(--purple); }

.kpi-sub { font-size: 12px; color: var(--muted); }

/* ── Charts ─────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .accent {
  display: inline-block;
  width: 3px;
  height: 16px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-wrap { position: relative; }

/* ── ADS% Chart (Theo ngày tab) ─────────────────────────── */
.ads-chart-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.ads-chart-section .card-title { margin-bottom: 14px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.table-header .accent { display: inline-block; width: 3px; height: 16px; background: var(--primary); border-radius: 2px; }

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
}
table { width: 100%; border-collapse: collapse; }

thead th {
  background: #f8fafc;
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  /* sticky within the table-wrap scroll container */
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 10;
}
th.r, td.r { text-align: right; }

/* Sortable column headers */
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--primary); background: #f1f5f9; }
th.sortable .sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  opacity: .4;
}
th.sort-asc  .sort-icon { opacity: 1; color: var(--primary); }
th.sort-asc  .sort-icon::after { content: '▲'; }
th.sort-desc .sort-icon { opacity: 1; color: var(--primary); }
th.sort-desc .sort-icon::after { content: '▼'; }
th.sort-none .sort-icon::after { content: '⇅'; }

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}
.rank.r1 { background: #fef3c7; color: #92400e; }
.rank.r2 { background: #f1f5f9; color: #475569; }
.rank.r3 { background: #fde8cc; color: #92400e; }
.rank.rn { background: var(--primary-lt); color: var(--primary); }

/* ADS badges & colors */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.tot        { background: #dcfce7; color: #166534; }
.badge.trung-binh { background: #fef9c3; color: #854d0e; }
.badge.kem        { background: #fee2e2; color: #991b1b; }
.badge.na         { background: #f1f5f9; color: #64748b; }

.pct.tot        { color: #16a34a; font-weight: 700; }
.pct.trung-binh { color: #d97706; font-weight: 700; }
.pct.kem        { color: #dc2626; font-weight: 700; }
.pct.na         { color: #94a3b8; }

/* product name */
.sp-name { font-weight: 600; color: var(--text); max-width: 220px; }

/* ── Expandable product-MKT table ───────────────────────── */
.sp-row { cursor: pointer; user-select: none; }
.sp-row:hover td { background: #f0f7ff !important; }
.sp-row td:first-child { padding-left: 12px; }

.expand-icon {
  display: inline-block;
  width: 18px; height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 4px;
  background: var(--primary-lt);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
  transition: transform .2s;
  flex-shrink: 0;
}
.sp-row.open .expand-icon { transform: rotate(90deg); }

.mkt-rows { display: none; }
.mkt-rows.open { display: table-row-group; }

.mkt-row td {
  background: #f8fafc;
  padding: 8px 16px 8px 52px;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
}
.mkt-row:last-child td { border-bottom: 2px solid var(--border); }
.mkt-row:hover td { background: #f1f5fb !important; }

/* Sản phẩm sub-row trong bảng MKT: indent cột đầu, các cột sau padding bình thường */
.sp-detail-row td { padding: 8px 16px; }
.sp-detail-row td:first-child { padding-left: 48px; }

.mkt-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.tot        { background: #16a34a; }
.dot.trung-binh { background: #d97706; }
.dot.kem        { background: #dc2626; }
.dot.na         { background: #94a3b8; }

.pct-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pct-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: #e2e8f0;
  overflow: hidden;
  min-width: 60px;
}
.pct-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s;
}
.pct-bar-fill.tot        { background: #16a34a; }
.pct-bar-fill.trung-binh { background: #d97706; }
.pct-bar-fill.kem        { background: #dc2626; }
.pct-bar-fill.na         { background: #94a3b8; }

/* ── Loading ─────────────────────────────────────────────── */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  display: inline-block;
  width: 140px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(90deg,#f1f5f9 25%,#e2e8f0 50%,#f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Progress bar for MKT table ─────────────────────────── */
.progress-wrap { position: relative; }
.progress-bar {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  border-radius: 3px;
  opacity: .12;
  pointer-events: none;
}

/* ── SP Analysis Panel ───────────────────────────────────── */
.sp-analysis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}
.analysis-col {
  padding: 16px 20px;
  border-right: 1px solid var(--border);
  position: relative;
}
.analysis-col:last-child { border-right: none; }
.analysis-col.c-tot { background: linear-gradient(135deg, #f0fdf4 0%, #fff 60%); }
.analysis-col.c-tb  { background: linear-gradient(135deg, #fefce8 0%, #fff 60%); }
.analysis-col.c-kem { background: linear-gradient(135deg, #fff8f8 0%, #fff 60%); }

.analysis-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.analysis-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.analysis-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.analysis-count { font-size: 26px; font-weight: 800; line-height: 1; margin-bottom: 2px; }
.analysis-meta  { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.analysis-seg-bg {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
  gap: 1px;
}
.analysis-seg {
  height: 100%;
  border-radius: 2px;
  transition: width .5s;
}

.analysis-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
}
.analysis-stat-item { display: flex; flex-direction: column; gap: 2px; }
.analysis-stat-val  { font-size: 14px; font-weight: 700; }
.analysis-stat-lbl  { color: var(--muted); font-size: 11px; }

.analysis-saving {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(220,38,38,.07);
  border-radius: 10px;
  border-left: 3px solid var(--red);
}
.analysis-saving-title { font-size: 11px; font-weight: 700; color: var(--red); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.analysis-saving-row   { font-size: 12.5px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.analysis-saving-new   { font-weight: 800; color: var(--green); }

.analysis-good-note {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(5,150,105,.07);
  border-radius: 10px;
  border-left: 3px solid var(--green);
  font-size: 12.5px;
  color: #166534;
}

/* ── MKT Contribution Panel ─────────────────────────────── */
.mkt-summary-row {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.mkt-summary-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1.5px solid #e2e8f0;
  background: #fff;
}
.mkt-summary-card.c-tot   { border-color: #bbf7d0; background: #f0fdf4; }
.mkt-summary-card.c-kem   { border-color: #fecaca; background: #fff5f5; }
.mkt-summary-card.c-waste { border-color: #fed7aa; background: #fffbeb; }
.mkt-sum-icon { font-size: 22px; line-height: 1; margin-top: 1px; }
.mkt-sum-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mkt-sum-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.mkt-sum-name  { font-size: 18px; font-weight: 800; color: var(--text); line-height: 1.2; }
.mkt-sum-detail{ display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 1px; }
.mkt-sum-sub   { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ── Heatmap Ma Trận SP × MKT ────────────────────────────── */
.mx-legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.mx-leg-item { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.mx-dot      { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.mx-dot.mx-tot          { background: rgba(22,163,74,.25);  border: 1.5px solid #16a34a; }
.mx-dot.mx-trung-binh   { background: rgba(217,119,6,.2);   border: 1.5px solid #d97706; }
.mx-dot.mx-kem          { background: rgba(220,38,38,.2);   border: 1.5px solid #dc2626; }
.mx-dot.mx-empty-dot    { background: #f1f5f9; border: 1.5px solid #e2e8f0; }

.mx-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.mx-table thead th {
  position: sticky; top: 0; z-index: 10;
  background: #f8fafc; border-bottom: 2px solid #e2e8f0;
  padding: 7px 8px; white-space: nowrap;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.mx-th-sp  { text-align: left; min-width: 190px; position: sticky; left: 0; z-index: 11; background: #f8fafc; }
.mx-th-dt  { text-align: right; min-width: 72px; }
.mx-th-ads { text-align: right; min-width: 52px; }
.mx-th-mkt { text-align: center; min-width: 72px; max-width: 88px; }

.mx-table tbody tr:hover td { background: rgba(37,99,235,.04); }
.mx-table tbody tr:hover td.mx-tot         { background: rgba(22,163,74,.2); }
.mx-table tbody tr:hover td.mx-trung-binh  { background: rgba(217,119,6,.22); }
.mx-table tbody tr:hover td.mx-kem         { background: #fcd0d0; }

.mx-sp-name {
  position: sticky; left: 0; z-index: 2;
  background: #fff; border-right: 1px solid #e2e8f0;
  padding: 6px 10px; white-space: nowrap;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.mx-table tbody tr:hover .mx-sp-name { background: #f8fafc; }
.mx-sp-label { font-weight: 700; font-size: 12.5px; color: var(--text); }
.mx-sp-share { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.mx-sp-dt  { text-align: right; padding: 6px 8px; color: var(--green); font-weight: 600; white-space: nowrap; }
.mx-sp-ads { text-align: right; padding: 6px 8px; }

.mx-cell {
  text-align: center; padding: 5px 6px;
  border: 1px solid transparent; vertical-align: middle;
}
.mx-cell.mx-empty  { color: #cbd5e1; font-size: 11px; background: #fafafa; }
.mx-cell.mx-tot         { background: rgba(22,163,74,.13);  border-color: rgba(22,163,74,.25); }
.mx-cell.mx-trung-binh  { background: rgba(217,119,6,.15);  border-color: rgba(217,119,6,.3); }
.mx-cell.mx-kem         { background: #fde8e8; border-color: #fca5a5; }
.mx-cell.mx-kem .mx-pct { color: #b91c1c; }
.mx-cell.mx-kem .mx-diff{ color: #b91c1c !important; }
.mx-pct  { font-weight: 700; font-size: 12px; }
.mx-diff { font-size: 10px; display: block; font-weight: 700; }

/* ── SP Lãng Phí Section ─────────────────────────────────── */
.lolai-section {
  padding: 18px 20px 20px;
  background: linear-gradient(135deg, #fff7ed 0%, #fef3f2 60%, #fffbf0 100%);
  border-top: 3px solid #f97316;
  border-bottom: 1px solid #fed7aa;
  position: relative;
}
.lolai-section::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(249,115,22,.12);
}
.lolai-title {
  font-size: 13px; font-weight: 800; color: #9a3412;
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
  text-transform: uppercase; letter-spacing: .4px;
}
.lolai-title .accent { background: #f97316; }
.lolai-cards {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.lolai-card {
  flex: 1; min-width: 160px;
  padding: 13px 16px; border-radius: 10px;
  border: 1.5px solid #fed7aa; background: rgba(255,255,255,.75);
  backdrop-filter: blur(4px);
}
.lolai-card.c-warn  { border-color: #fca5a5; background: rgba(254,242,242,.85); }
.lolai-card.c-waste { border-color: #f97316; background: rgba(255,247,237,.9); box-shadow: 0 0 0 3px rgba(249,115,22,.08); }
.lolai-card-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #92400e; margin-bottom: 4px; }
.lolai-card-val   { font-size: 22px; font-weight: 800; line-height: 1.2; }
.lolai-card-sub   { font-size: 11px; color: #b45309; margin-top: 3px; }

/* ── MKT Mini Analysis (inside expanded row) ─────────────── */
.mkt-mini-wrap {
  padding: 12px 16px 12px 50px;
  background: #f8fafc;
  border-bottom: 1px solid #e9f0f7;
}
.mkt-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.mkt-mini-card {
  padding: 10px 14px;
  border-radius: 10px;
}
.mkt-mini-card.c-tot { background: #f0fdf4; border-left: 3px solid #16a34a; }
.mkt-mini-card.c-tb  { background: #fefce8; border-left: 3px solid #d97706; }
.mkt-mini-card.c-kem { background: #fff8f8; border-left: 3px solid #dc2626; }
.mkt-mini-title { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px; }
.mkt-mini-count { font-size: 19px; font-weight: 800; line-height: 1; margin-bottom: 6px; }
.mkt-mini-row   { font-size: 12px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; color: var(--muted); }
.mkt-mini-row strong { color: var(--text); }
.mkt-mini-saving {
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(220,38,38,.08);
  border-radius: 7px;
  font-size: 11.5px;
}
.mkt-mini-saving-title { font-weight: 700; color: var(--red); margin-bottom: 4px; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination-wrap {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.pagination-info { font-size: 12px; color: var(--muted); }
.btn-show-more {
  background: var(--primary-lt);
  color: var(--primary);
  border: 1.5px solid #bfdbfe;
  border-radius: 8px;
  padding: 7px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-show-more:hover { background: #dbeafe; }

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: #94a3b8;
}

/* ── Filter Tabs ─────────────────────────────────────────── */
.table-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-tab {
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--muted);
  transition: all .15s;
  white-space: nowrap;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); }
.filter-tab.f-all.active    { background: var(--primary);  color: #fff;     border-color: var(--primary); }
.filter-tab.f-tot.active    { background: #dcfce7; color: #166534; border-color: #16a34a; }
.filter-tab.f-tb.active     { background: #fef9c3; color: #854d0e; border-color: #d97706; }
.filter-tab.f-kem.active    { background: #fee2e2; color: #991b1b; border-color: #dc2626; }
.filter-count { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ── KPI delta badges ────────────────────────────────────── */
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.kpi-delta.pos { background: var(--green-lt); color: var(--green); }
.kpi-delta.neg { background: var(--red-lt);   color: var(--red);   }
.kpi-delta.neu { background: var(--bg);       color: var(--muted); }

/* ── Trend arrows (product table) ────────────────────────── */
.trend { font-size: 11px; font-weight: 700; margin-left: 5px; white-space: nowrap; }
.trend.up   { color: #dc2626; }
.trend.down { color: #059669; }
.trend.flat { color: #94a3b8; }

/* ── Sync Overlay ────────────────────────────────────────── */
#sync-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.sync-card {
  background: #fff;
  border-radius: 18px;
  padding: 32px 36px;
  width: 460px;
  max-width: 90vw;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
}
.sync-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.sync-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.sync-done-icon { font-size: 22px; display: none; }
.sync-title  { font-size: 16px; font-weight: 700; }
.sync-sub    { font-size: 12.5px; color: var(--muted); margin-bottom: 20px; margin-top: 2px; }
.sync-bar-bg { height: 8px; background: #e2e8f0; border-radius: 4px; margin-bottom: 16px; overflow: hidden; }
.sync-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: 4px;
  transition: width .5s ease;
  width: 0;
}
.sync-steps {
  display: flex; flex-direction: column; gap: 5px;
  max-height: 190px; overflow-y: auto;
}
.sync-step-item {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; padding: 3px 0; transition: all .2s;
}
.s-icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 13px; }
.sync-step-item.active  { color: var(--primary); font-weight: 600; }
.sync-step-item.done    { color: #94a3b8; }
.sync-step-item.success { color: var(--green); font-weight: 700; }

/* ── Users Modal ─────────────────────────────────────────── */
#users-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.users-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 32px;
  width: 580px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
}
.users-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.users-title { font-size: 17px; font-weight: 800; color: var(--text); }
.users-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; line-height: 1; }
.users-close:hover { background: var(--bg); }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 20px; }
.users-table th { background: #f8fafc; text-align: left; padding: 9px 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); border-bottom: 2px solid var(--border); }
.users-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: #f8fafc; }
.users-form { border-top: 2px solid var(--border); padding-top: 20px; }
.users-form-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.users-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.users-form-grid label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; display: block; margin-bottom: 4px; }
.users-form-grid input,
.users-form-grid select { width: 100%; padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 13px; outline: none; }
.users-form-grid input:focus,
.users-form-grid select:focus { border-color: var(--primary); }
.users-form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-danger { background: var(--red-lt); color: var(--red); border: none; border-radius: 7px; padding: 5px 12px; font-size: 12px; font-weight: 700; cursor: pointer; }
.btn-danger:hover { background: #fecaca; }
.btn-primary { background: var(--primary); color: #fff; border: none; border-radius: 7px; padding: 6px 16px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn-primary:hover { opacity: .9; }

/* ── Help Modal ──────────────────────────────────────────── */
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.help-card {
  background: #fff;
  border-radius: 18px;
  padding: 32px 36px;
  width: 640px;
  max-width: 95vw;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  position: relative;
}
.help-close {
  position: absolute;
  top: 18px; right: 20px;
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.help-close:hover { background: var(--bg); }
.help-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--text);
}
.help-subtitle {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 24px;
}
.help-section {
  margin-bottom: 22px;
}
.help-section-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--primary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-lt);
}
.help-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 7px 0;
  border-bottom: 1px solid #f1f5f9;
}
.help-row:last-child { border-bottom: none; }
.help-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  min-width: 68px;
  text-align: center;
}
.hb-blue   { background: var(--primary-lt); color: var(--primary); }
.hb-red    { background: var(--red-lt);     color: var(--red); }
.hb-green  { background: var(--green-lt);   color: var(--green); }
.hb-purple { background: var(--purple-lt);  color: var(--purple); }
.hb-amber  { background: var(--amber-lt);   color: var(--amber); }
.hb-gray   { background: #f1f5f9;           color: #475569; }
.help-row-body { flex: 1; }
.help-row-name { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.help-row-desc { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.help-row-desc strong { color: var(--text); }
.help-tip {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12.5px;
  color: #92400e;
  line-height: 1.6;
  margin-top: 16px;
}
.help-tip strong { color: #78350f; }

/* ── Chart team filter tabs ─────────────────────────────── */
.chart-team-tab {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.chart-team-tab:hover { background: var(--primary-lt); color: var(--primary); border-color: var(--primary); }
.chart-team-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1024px) {
  .kpi-grid    { grid-template-columns: repeat(2,1fr); }
  .team-grid   { grid-template-columns: repeat(2,1fr); }
  .charts-row  { grid-template-columns: 1fr; }
  .tab-nav     { overflow-x: auto; justify-content: flex-start; }
}
@media (max-width: 640px) {
  .header      { flex-direction: column; align-items: flex-start; }
  .kpi-grid    { grid-template-columns: 1fr; }
  .team-grid   { grid-template-columns: 1fr; }
  .filter-bar  { flex-wrap: wrap; }
  .tab-nav     { justify-content: flex-start; }
}

/* ── Print / PDF ─────────────────────────────────────────── */
@media print {
  @page { size: A4 landscape; margin: 12mm 10mm; }

  .header,
  .tab-nav,
  .table-toolbar,
  .charts-row,
  .help-overlay,
  #sp-analysis,
  #mkt-analysis,
  .btn,
  .filter-bar,
  .pagination-wrap { display: none !important; }

  body { background: #fff; font-size: 11px; }
  .main { padding: 0; max-width: 100%; }
  .tab-panel { display: block !important; }
  .table-wrap { max-height: none; overflow: visible; }

  .kpi-grid  { grid-template-columns: repeat(4,1fr); gap: 8px; margin-bottom: 12px; }
  .team-grid { grid-template-columns: repeat(4,1fr); gap: 8px; margin-bottom: 12px; }
  .kpi-card, .team-card { box-shadow: none; border: 1px solid #e2e8f0; padding: 10px 12px; }
  .kpi-value { font-size: 18px; }

  .table-card { box-shadow: none; border: 1px solid #e2e8f0; margin-bottom: 16px; break-inside: avoid; }
  .table-header { padding: 10px 14px; font-size: 13px; }
  .tbl-wrap, [style*="overflow"] { overflow: visible !important; }
  table { width: 100%; font-size: 10px; }
  th, td { padding: 4px 6px !important; }

  .sp-detail-row[style*="display: none"],
  .sp-detail-row[style*="display:none"] { display: table-row !important; }
  .mkt-detail-row[style*="display: none"],
  .mkt-detail-row[style*="display:none"] { display: table-row !important; }

  .print-title { display: block !important; }
  thead { position: static; }
}

.print-title { display: none; font-size: 15px; font-weight: 700; padding: 0 0 10px; color: #1e293b; }
