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

:root {
  --bg:       #f4f5f7;
  --surface:  #ffffff;
  --surface2: #f0f1f3;
  --border:   #e2e5ea;
  --text:     #1a1d27;
  --muted:    #7a7f9a;
  --accent:   #4f7fe8;
  --accent2:  #e8632b;
}

html {
  scroll-behavior: smooth;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
}

/* ── Sticky Top Navigation Bar ────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 200;
  box-shadow: 0 1px 0 rgba(255,255,255,0.05);
}

.top-nav-left {
  display: flex;
  gap: 8px;
}

.top-nav-right {
  display: flex;
  align-items: center;
}

.top-nav-link {
  padding: 8px 16px;
  border-radius: 6px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.top-nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}

.top-nav-link.active {
  background: rgba(79,127,232,0.25);
  color: #fff;
}

.top-nav-upload {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.5);
  background: transparent;
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.top-nav-upload:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.75);
  color: #fff;
}


.top-nav-clear {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  margin-left: 8px;
  transition: background 0.15s, color 0.15s;
}
.top-nav-clear:hover {
  background: rgba(231,76,60,0.2);
  border-color: rgba(231,76,60,0.5);
  color: #ff8a80;
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  padding: 32px 32px 48px;
}

/* ── Upload Status Bar ──────────────────────────────────────── */
#upload-status-bar {
  display: none;
}
#upload-status-bar.active {
  display: flex;
}

/* ── Sections with scroll margin ──────────────────────────── */
section {
  scroll-margin-top: 72px;
}

section + section {
  margin-top: 48px;
}

/* ── Page title / section heading ─────────────────────────── */
.section-heading {
  font-size: 20px;
  font-weight: 700;
  color: #1a1d27;
  margin-bottom: 20px;
}

/* ── KPI cards (Row 1) ─────────────────────────────────────── */
.kpi-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  flex: 1;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  padding: 18px 20px;
  border: 1px solid var(--border);
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
  min-height: 14px;
}

/* ── Row separator ─────────────────────────────────────────── */
.row-separator {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Chart download button ─────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  padding: 20px 20px 12px;
  border: 1px solid var(--border);
}

.chart-title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.chart-download-btn {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.chart-download-btn:hover {
  opacity: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.08);
}

.chart-dl-wrap {
  position: relative;
  flex-shrink: 0;
}

.chart-dl-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 130px;
  z-index: 100;
  overflow: hidden;
}

.chart-dl-menu.open {
  display: block;
}

.chart-dl-menu button {
  display: block;
  width: 100%;
  padding: 9px 14px;
  text-align: left;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.chart-dl-menu button:hover {
  background: var(--surface2);
  color: var(--accent);
}

.chart-full-width {
  width: 100%;
}

/* ── Charts row (50-50 grid) ──────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1d27;
  margin-bottom: 14px;
}

.chart-placeholder {
  height: 200px;
  background: var(--surface2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}

/* ── Top 20 Products Table ────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

.top-products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.top-products-table thead {
  position: sticky;
  top: 0;
  background: #f0f1f3;
  z-index: 1;
}

.top-products-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: #1a1d27;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.top-products-table td {
  padding: 10px 12px;
  color: #3a3f52;
  border-bottom: 1px solid var(--border);
}

.top-products-table tbody tr:nth-child(even) {
  background: #f8f9fa;
}

.top-products-table tbody tr:nth-child(odd) {
  background: #ffffff;
}

.top-products-table tbody tr:hover {
  background: #eef1f8;
}

.top-products-table tbody tr.top-rank {
  background: #fff8e1;
  font-weight: 700;
}

.top-products-table tbody tr.top-rank td {
  color: #1a1d27;
}

.table-loading {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.top-nav-clear:hover {
  background: rgba(231,76,60,0.2);
  border-color: rgba(231,76,60,0.5);
  color: #ff8a80;
}

/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar-wrapper {
  margin-bottom: 20px;
}

.filter-toggle-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.filter-toggle-btn:hover {
  background: var(--surface2);
}

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-top: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}

/* Date range inputs */
.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.date-input:focus {
  outline: none;
  border-color: var(--accent);
}

.date-sep {
  color: var(--muted);
  font-size: 12px;
}

/* Price range slider */
.price-range-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.price-range-track {
  position: relative;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px 0 4px;
}

.price-range-fill {
  position: absolute;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
}

.price-slider {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 4px;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
  margin: 0;
}

.price-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  pointer-events: all;
  cursor: pointer;
}

.price-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  pointer-events: all;
  cursor: pointer;
}

.price-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

/* Filter actions row */
.filter-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-btns {
  display: flex;
  gap: 8px;
}

.btn-apply {
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-apply:hover { background: #3d6fd4; }

.btn-reset {
  padding: 8px 16px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-reset:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-download-data {
  padding: 8px 16px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-left: 4px;
}

.btn-download-data:hover {
  background: var(--accent);
  color: #fff;
}

/* Active filter tags */
.active-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 10px;
  background: #eef1f8;
  border: 1px solid #c2d4f8;
  border-radius: 20px;
  font-size: 11px;
  color: #1a1d27;
}

.filter-tag button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}

.filter-tag button:hover { color: var(--text); }

/* ── Multi-Select Dropdown ──────────────────────────────────── */
.ms-wrapper {
  position: relative;
}

.ms-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}

.ms-toggle:hover { border-color: var(--accent); }

.ms-toggle-text {
  flex: 1;
  font-weight: 500;
  color: var(--text);
}

.ms-count {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.ms-arrow {
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.15s;
}

.ms-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  max-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 500;
  overflow: hidden;
}

.ms-search {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

.ms-search:focus { outline: none; }

.ms-actions {
  display: flex;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.ms-action-link {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.ms-action-link:hover { text-decoration: underline; }

.ms-options {
  max-height: 220px;
  overflow-y: auto;
  padding: 6px 0;
}

.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background 0.1s;
}

.ms-option:hover { background: var(--surface2); }

.ms-option.checked { background: #eef1f8; }

.ms-option input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
@media (max-width: 900px) {
  .kpi-row { flex-wrap: wrap; }
  .kpi-row .kpi-card { min-width: 45%; flex: 1 1 45%; }
  .charts-row { grid-template-columns: 1fr; }
}

/* ── Hamburger button ─────────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin-right: 8px;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile menu drawer ──────────────────────────────────────────── */
.mobile-menu {
  display: none;
  flex-direction: column;
  background: #1a1a2e;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.mobile-menu.open {
  display: flex;
  max-height: 400px;
}
.mobile-nav-link {
  padding: 14px 24px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.mobile-nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .top-nav-left .top-nav-link { display: none; }
  .top-nav-left.open .top-nav-link { display: flex; flex-direction: column; width: 100%; }
}

/* ── Loading overlay on chart cards ───────────────────────────────── */
.chart-card-loading {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}
.chart-card-loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty / no-data state ────────────────────────────────────────── */
.chart-empty {
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  gap: 10px;
}
.chart-empty-icon {
  font-size: 32px;
  opacity: 0.4;
}
.data-empty-msg {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
}

/* ── Chart footnote ──────────────────────────────────────────────────────── */
.chart-note {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}

/* ── Section heading underline ────────────────────────────────────── */
.section-heading {
  font-size: 18px;
  font-weight: 700;
  color: #1a1d27;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}

/* ── Apply button loading state ───────────────────────────────────── */
.btn-apply.loading {
  opacity: 0.7;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Empty state (no data uploaded) ───────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}
.empty-state-icon {
  font-size: 48px;
  opacity: 0.35;
  margin-bottom: 16px;
}
.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.empty-state-sub {
  font-size: 13px;
  color: var(--muted);
}

/* ── B2B Nav Link ─────────────────────────────────────────────── */
.top-nav-b2b {
  color: rgba(255,255,255,0.75);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  margin-right: 8px;
  transition: color 0.15s, border-color 0.15s;
}
.top-nav-b2b:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.6);
}

/* ── B2B Dashboard ────────────────────────────────────────────── */
.b2b-customer-card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  margin-bottom: 24px;
  overflow: hidden;
}

.b2b-customer-header {
  background: #1B3A5C;
  color: #fff;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.b2b-customer-header .b2b-customer-name {
  font-size: 15px;
  font-weight: 600;
}
.b2b-customer-header .b2b-customer-meta {
  font-size: 11px;
  opacity: 0.7;
  white-space: nowrap;
}

.b2b-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 10px 20px 6px;
  border-top: 1px solid var(--border);
}

.b2b-table-wrap {
  padding: 0 20px 16px;
  overflow-x: auto;
}

.b2b-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.b2b-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.b2b-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.b2b-table tbody tr:last-child td {
  border-bottom: none;
}
.b2b-table tbody tr:hover {
  background: rgba(0,0,0,0.02);
}