:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--gray-50); color: var(--gray-900); line-height: 1.5; }

/* Header */
.header { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); color: white; padding: 1rem 2rem; display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow-lg); }
.header h1 { font-size: 1.4rem; font-weight: 700; }
.header .badge { background: rgba(255,255,255,.2); padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; }

/* Layout */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* Cards */
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--gray-700); margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }

/* Stat cards */
.stat-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; text-align: center; border-top: 3px solid var(--primary); }
.stat-card.success { border-color: var(--success); }
.stat-card.warning { border-color: var(--warning); }
.stat-card.danger { border-color: var(--danger); }
.stat-card.info { border-color: var(--info); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.info .stat-value { color: var(--info); }
.stat-label { font-size: .8rem; color: #6b7280; margin-top: .25rem; }

/* Upload zone */
.upload-zone { border: 2px dashed var(--gray-200); border-radius: var(--radius); padding: 3rem 2rem; text-align: center; cursor: pointer; transition: all .2s; background: var(--gray-50); }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: #eff6ff; }
.upload-zone .icon { font-size: 3rem; margin-bottom: 1rem; }
.upload-zone p { color: #6b7280; font-size: .9rem; }
.upload-zone strong { color: var(--primary); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .6rem 1.2rem; border: none; border-radius: var(--radius); cursor: pointer; font-size: .9rem; font-weight: 500; transition: all .15s; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: white; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: #eff6ff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-lg { padding: .8rem 1.8rem; font-size: 1rem; }

/* Form */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .85rem; font-weight: 500; color: var(--gray-700); margin-bottom: .3rem; }
.form-control { width: 100%; padding: .5rem .75rem; border: 1px solid var(--gray-200); border-radius: var(--radius); font-size: .9rem; transition: border .15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
select.form-control { background-color: white; }

/* Progress */
.progress { height: 8px; background: var(--gray-100); border-radius: 999px; overflow: hidden; margin: .5rem 0; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }

/* Badge */
.badge-pill { display: inline-flex; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-gray { background: var(--gray-100); color: var(--gray-700); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { background: var(--gray-50); padding: .6rem .75rem; text-align: left; font-weight: 600; color: var(--gray-700); border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
td { padding: .5rem .75rem; border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }

/* Steps */
.steps { display: flex; gap: 0; margin-bottom: 2rem; }
.step { flex: 1; text-align: center; padding: .75rem; background: var(--gray-100); font-size: .8rem; font-weight: 500; color: #6b7280; position: relative; }
.step.active { background: var(--primary); color: white; }
.step.done { background: var(--success); color: white; }
.step:not(:last-child)::after { content: ''; position: absolute; right: -10px; top: 50%; transform: translateY(-50%); border: 10px solid transparent; border-left-color: inherit; z-index: 1; }
.step.active::after { border-left-color: var(--primary); }
.step.done::after { border-left-color: var(--success); }

/* Alert */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.alert-info { background: #e0f2fe; color: #0369a1; border-left: 3px solid var(--info); }
.alert-warning { background: #fef3c7; color: #92400e; border-left: 3px solid var(--warning); }
.alert-success { background: #dcfce7; color: #14532d; border-left: 3px solid var(--success); }
.alert-danger { background: #fee2e2; color: #991b1b; border-left: 3px solid var(--danger); }

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); margin-bottom: 1.5rem; }
.tab { padding: .6rem 1.2rem; cursor: pointer; font-size: .9rem; font-weight: 500; color: #6b7280; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Spinner */
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mode selector */
.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; }
.mode-card { border: 2px solid var(--gray-200); border-radius: var(--radius); padding: 1rem; cursor: pointer; transition: all .15s; text-align: center; }
.mode-card:hover { border-color: var(--primary); }
.mode-card.selected { border-color: var(--primary); background: #eff6ff; }
.mode-card .mode-icon { font-size: 1.5rem; margin-bottom: .4rem; }
.mode-card .mode-name { font-weight: 600; font-size: .9rem; }
.mode-card .mode-desc { font-size: .75rem; color: #6b7280; margin-top: .2rem; }

/* Chart canvas */
.chart-container { position: relative; height: 250px; }

/* Column mapping */
.col-map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* Hidden sections */
.section { display: none; }
.section.visible { display: block; }

/* Mini upload zone */
.upload-zone.mini { padding: 1.25rem 1rem; border-radius: var(--radius); }
.upload-zone.mini:hover { border-color: var(--primary); background: #eff6ff; }

/* Responsive */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .col-map-grid { grid-template-columns: 1fr; }
}

/* v2.3.7 interactive results */
.clickable-stat { border: 0; text-align: left; width: 100%; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.clickable-stat:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(15, 23, 42, .10); }
.interactive-table th[data-sort], .interactive-table th[data-fbcr-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.interactive-table th[data-sort]:hover, .interactive-table th[data-fbcr-sort]:hover { background: #eef2ff; color: #1d4ed8; }
.interactive-table th.sorted { background: #dbeafe; color: #1e40af; }
.interactive-table td.num { text-align: right; white-space: nowrap; }
.result-row:hover { background: #f8fafc; }
.responsive-table { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }
.mini-check { padding: .45rem .65rem; border-radius: 8px; margin-top: .35rem; font-size: .84rem; border-left: 3px solid #94a3b8; background: #f8fafc; }
.mini-check.ok { border-left-color: #16a34a; background: #f0fdf4; }
.mini-check.warning { border-left-color: #d97706; background: #fffbeb; }
.mini-check.critical { border-left-color: #dc2626; background: #fef2f2; }
@media (max-width: 760px) {
  .interactive-table { font-size: .78rem; }
  .interactive-table th, .interactive-table td { padding: .45rem .5rem; }
  #detailsCount { width: 100%; margin-left: 0 !important; }
}

/* Per-campaign margin controls */
.campaign-margin-card {
  margin-top: 1.2rem;
  padding: 1rem;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
}
.campaign-margin-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: .85rem;
}
.campaign-margin-head p { font-size: .82rem; color: #6b7280; margin-top: .25rem; }
.compact-grid { gap: .75rem; }
.margin-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  font-size: .82rem;
  color: #374151;
  padding-top: .2rem;
}
.margin-options-row label { display: inline-flex; align-items: center; gap: .35rem; }
.margin-help { margin-top: .7rem; font-size: .78rem; color: #2563eb; }
.compact-switch { margin: 0; white-space: nowrap; }
@media (max-width: 760px) {
  .campaign-margin-head { flex-direction: column; }
  .margin-options-row { flex-direction: column; gap: .4rem; }
}

/* Exact SKU batch rules */
.sku-rules-card {
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid rgba(99,102,241,.16);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(99,102,241,.06), rgba(14,165,233,.04));
}
.sku-rules-textarea {
  min-height: 92px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.sku-rules-actions {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  margin-top: .75rem;
}
.sku-rules-hint {
  color: #6b7280;
  font-size: .82rem;
  line-height: 1.35;
}
.sku-rules-list {
  margin-top: .85rem;
}
.empty-sku-rules {
  border: 1px dashed rgba(107,114,128,.35);
  color: #6b7280;
  background: rgba(255,255,255,.7);
  padding: .7rem .8rem;
  border-radius: 12px;
  font-size: .86rem;
}
.sku-rules-summary {
  font-size: .9rem;
  margin-bottom: .6rem;
  color: #374151;
}
.sku-rule-chips {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  max-height: 210px;
  overflow: auto;
  padding-right: .25rem;
}
.sku-rule-chip {
  display: inline-grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: .45rem;
  border: 1px solid rgba(37,99,235,.18);
  background: #fff;
  color: #1f2937;
  border-radius: 999px;
  padding: .38rem .45rem .38rem .65rem;
  box-shadow: 0 8px 18px rgba(15,23,42,.06);
  max-width: 100%;
}
.sku-rule-chip strong { font-size: .82rem; }
.sku-rule-chip span { font-size: .78rem; color: #2563eb; }
.sku-rule-chip em { font-size: .76rem; color: #6b7280; font-style: normal; }
.sku-rule-chip button {
  border: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 700;
}
@media (max-width: 720px) {
  .sku-rule-chip { grid-template-columns: 1fr auto; border-radius: 14px; width: 100%; }
  .sku-rule-chip em { grid-column: 1 / -1; }
}

/* v2.3.10 manual missing SKU/cost additions */
.code-help{background:#f8fafc;border:1px solid #e5e7eb;border-radius:8px;padding:.65rem .75rem;font-size:.78rem;color:#334155;white-space:pre-wrap;margin:.25rem 0 .75rem}
.compact-table table{font-size:.82rem}
.mini-btn{padding:.2rem .45rem!important;font-size:.72rem!important;line-height:1!important}

/* v2.3.12 category mapping + manual result editing */
.manual-discount-control { display: inline-flex; gap: .35rem; align-items: center; justify-content: flex-end; min-width: 118px; }
.manual-discount-input { width: 70px; padding: .28rem .4rem; border: 1px solid var(--gray-200); border-radius: 6px; text-align: right; font-size: .78rem; }
.manual-discount-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.12); }

.discount-visible-control { min-width: 172px; }
.discount-badge { display: inline-block; min-width: 46px; padding: .16rem .42rem; border-radius: 999px; font-weight: 700; text-align: center; background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.discount-badge.muted { background: #f3f4f6; color: #6b7280; border-color: #e5e7eb; }
.falabella-discount-badge { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.mini-btn { padding: .28rem .55rem; font-size: .76rem; }
.soft-card { box-shadow: none; border-radius: 12px; }
@media (max-width: 768px) {
  .manual-discount-control { min-width: 100px; }
  .manual-discount-input { width: 64px; }
}

/* v2.3.25 profitability detail and contextual help */
.profit-cell {
  display: inline-block;
  min-width: 64px;
  padding: .16rem .42rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: help;
  border: 1px solid transparent;
}
.profit-success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.profit-warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.profit-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.profit-muted { background: #f3f4f6; color: #6b7280; border-color: #e5e7eb; }
.help-panel {
  margin-top: 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #f8fafc;
  padding: .9rem 1rem;
  color: #374151;
}
.help-title {
  font-weight: 800;
  margin-bottom: .65rem;
  color: #111827;
}
.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .65rem;
}
.help-grid > div {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: .65rem .75rem;
}
.help-grid strong {
  display: block;
  font-size: .84rem;
  margin-bottom: .22rem;
  color: #111827;
}
.help-grid span, .help-note {
  font-size: .78rem;
  line-height: 1.35;
  color: #6b7280;
}
.help-note { margin: .75rem 0 0; }
.interactive-table th[title], .btn[title], .form-control[title] { cursor: help; }
