/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg:          #f7f8fa;
  --surface:     #ffffff;
  --border:      #e4e7ec;
  --border-2:    #f2f4f7;
  --text:        #101828;
  --text-muted:  #667085;
  --text-light:  #98a2b3;
  --ink:         #101828;      /* header / primary button */
  --ink-2:       #1d2939;
  --green:       #027a48;
  --green-bg:    #ecfdf3;
  --red:         #b42318;
  --red-bg:      #fef3f2;
  --radius:      8px;
  --radius-sm:   6px;
  --shadow-xs:   0 1px 2px rgba(16,24,40,.05);
  --shadow-sm:   0 1px 3px rgba(16,24,40,.10), 0 1px 2px rgba(16,24,40,.06);
  --shadow-md:   0 4px 8px -2px rgba(16,24,40,.10), 0 2px 4px -2px rgba(16,24,40,.06);
}

html, body {
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--ink);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 28px; height: 28px;
  background: rgba(255,255,255,.15);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  letter-spacing: -.3px;
}
.logo-text { font-size: 14px; font-weight: 600; color: #fff; letter-spacing: -.1px; }
.data-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: rgba(255,255,255,.6);
}
.data-dot {
  width: 6px; height: 6px;
  border-radius: 50%; background: #12b76a;
  box-shadow: 0 0 0 2px rgba(18,183,106,.25);
}
#headerDateRange { color: rgba(255,255,255,.85); font-weight: 500; }

/* ── Main ── */
.app-main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── KPI Cards ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
}
@media (max-width: 1200px) { .kpi-row { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 700px)  { .kpi-row { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow-xs);
}
.kpi-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 5px;
}
.kpi-sub { font-size: 10px; font-weight: 400; color: var(--text-light); text-transform: none; letter-spacing: 0; }
.kpi-value {
  font-size: 20px; font-weight: 700;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.3px;
}

/* ── Filter Panel ── */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-xs);
}
.filter-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.filter-panel-title {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .8px;
}
.btn-ghost {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 12px; padding: 0;
  font-family: inherit;
  transition: color .15s;
}
.btn-ghost:hover { color: var(--text); }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px 12px;
  margin-bottom: 14px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
}

.filter-input,
.filter-select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px; font-family: inherit;
  color: var(--text); background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  appearance: none;
}
.filter-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23667085' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.filter-input:focus,
.filter-select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(16,24,40,.06); }

/* ── Multi-Select ── */
.ms-wrapper { position: relative; }
.ms-trigger {
  display: flex; align-items: center; justify-content: space-between;
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
  user-select: none;
  transition: border-color .15s;
}
.ms-trigger:hover { border-color: var(--text-muted); }
.ms-trigger:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(16,24,40,.06); }
.ms-trigger.open { border-color: var(--ink); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

.ms-label { font-size: 12.5px; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
.ms-label.has-selection { font-weight: 600; }
.ms-arrow { font-size: 10px; color: var(--text-light); margin-left: 6px; transition: transform .15s; flex-shrink: 0; }
.ms-trigger.open .ms-arrow { transform: rotate(180deg); }

.ms-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--ink); border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  z-index: 300; box-shadow: var(--shadow-md);
  max-height: 240px; display: flex; flex-direction: column;
}
.ms-dropdown.hidden { display: none; }
.ms-search-wrap { padding: 7px 7px 4px; }
.ms-search {
  width: 100%; height: 28px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; font-family: inherit; outline: none;
  color: var(--text);
}
.ms-search:focus { border-color: var(--text-muted); }
.ms-actions { display: flex; gap: 4px; padding: 2px 7px 5px; }
.ms-actions button {
  font-size: 11px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); padding: 2px 8px;
  cursor: pointer; color: var(--text-muted);
  transition: all .1s;
}
.ms-actions button:hover { background: var(--bg); border-color: var(--text-muted); color: var(--text); }
.ms-list { overflow-y: auto; flex: 1; padding: 3px 4px 5px; }
.ms-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 7px; border-radius: 4px;
  cursor: pointer; font-size: 12.5px; user-select: none;
}
.ms-item:hover { background: var(--bg); }
.ms-item input[type="checkbox"] { cursor: pointer; flex-shrink: 0; accent-color: var(--ink); }

/* ── Options Row ── */
.options-row {
  display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border-2);
}
.option-group { display: flex; flex-direction: column; gap: 5px; }
.option-group--grow { flex: 1; min-width: 0; }
.action-group { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.checkbox-group {
  display: flex; flex-wrap: wrap;
  gap: 4px 12px; padding-top: 2px;
}
.cb-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; cursor: pointer;
  color: var(--text); white-space: nowrap;
  user-select: none;
}
.cb-label input { cursor: pointer; accent-color: var(--ink); }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer; border: none;
  background: var(--ink); color: #fff;
  transition: background .15s, opacity .15s;
  white-space: nowrap; letter-spacing: -.1px;
}
.btn-primary:hover  { background: var(--ink-2); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); background: var(--bg); }
.btn-secondary:disabled { opacity: .45; cursor: not-allowed; }

/* ── Status Bar ── */
.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted);
  box-shadow: var(--shadow-xs);
}
.row-count { font-weight: 600; color: var(--text); font-size: 12px; }
.status-loading { color: var(--text-muted); }
.status-error   { color: var(--red); }

/* ── Table Section ── */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }

.table-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 64px 20px; gap: 10px;
  color: var(--text-muted); font-size: 13.5px;
}
.table-empty-icon { font-size: 32px; opacity: .6; }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table.hidden { display: none; }

.data-table thead { background: var(--bg); position: sticky; top: 0; z-index: 10; }
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.data-table th:hover { color: var(--text); }
.data-table th.sort-asc::after  { content: " ↑"; color: var(--ink); }
.data-table th.sort-desc::after { content: " ↓"; color: var(--ink); }

.data-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-2);
  color: var(--text); white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg); }
.data-table tbody tr.zero-sales td { color: var(--text-light); }

.data-table td.num-cell  { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.net-pos   { color: var(--green); font-weight: 600; }
.data-table td.net-neg   { color: var(--red);   font-weight: 600; }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.pagination.hidden { display: none; }
.page-btn {
  height: 30px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface); font-size: 12px; font-family: inherit;
  cursor: pointer; color: var(--text-muted); font-weight: 500;
  transition: all .12s;
}
.page-btn:hover:not(:disabled) { border-color: var(--text-muted); color: var(--text); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-info { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.page-size-wrap { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.page-size-label { font-size: 11px; color: var(--text-muted); }
.page-size-select {
  height: 28px; padding: 0 6px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; font-family: inherit;
  background: var(--surface); cursor: pointer; color: var(--text);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #98a2b3; }

/* ── Spinner ── */
.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════
   NAV TABS
══════════════════════════════════════════════════ */
.header-right { display: flex; align-items: center; gap: 12px; }

.app-nav {
  display: flex; align-items: center; gap: 2px;
  margin-left: 10px;
}
.nav-item {
  display: flex; align-items: center;
  height: 32px; padding: 0 13px;
  font-size: 12.5px; font-weight: 500;
  color: rgba(255,255,255,.55);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.nav-item:hover  { color: rgba(255,255,255,.85); background: rgba(255,255,255,.08); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.13); }

/* ══════════════════════════════════════════════════
   SELLER KPI ROW
══════════════════════════════════════════════════ */
.kpi-row--seller { grid-template-columns: repeat(7, 1fr); }
@media (max-width: 1100px) { .kpi-row--seller { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 680px)  { .kpi-row--seller { grid-template-columns: repeat(2, 1fr); } }

.kpi-pct {
  font-size: 11px; font-weight: 500;
  color: var(--text-muted); margin-top: 3px;
}

/* coloured left-border accents on seller KPI cards */
.kpi-card--fast { border-left: 3px solid #12b76a; }
.kpi-card--avg  { border-left: 3px solid #f79009; }
.kpi-card--slow { border-left: 3px solid #f04438; }
.kpi-card--dead { border-left: 3px solid #98a2b3; }

/* ══════════════════════════════════════════════════
   MODE TOGGLE  (Global / Local)
══════════════════════════════════════════════════ */
.mode-toggle {
  display: flex; align-items: center;
  background: rgba(255,255,255,.10);
  border-radius: var(--radius-sm);
  padding: 2px;
  flex-shrink: 0;
}
.mode-btn {
  display: flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 12px;
  border: none; border-radius: 4px;
  font-size: 12px; font-weight: 500; font-family: inherit;
  cursor: pointer;
  background: transparent; color: rgba(255,255,255,.6);
  transition: all .15s;
}
.mode-btn:hover  { color: rgba(255,255,255,.9); }
.mode-btn.active { background: rgba(255,255,255,.18); color: #fff; }

/* ══════════════════════════════════════════════════
   SELLER CONFIG ROW  (dates + thresholds)
══════════════════════════════════════════════════ */
.seller-config-row {
  display: flex; flex-wrap: wrap; gap: 10px 12px;
  margin-bottom: 14px;
}
.seller-config-row .filter-group { flex: 1; min-width: 120px; }
.thresh-group { max-width: 160px; }

/* ── Ageing date filter row ── */
.age-filter-row {
  background: #f8faff;
  border: 1px solid #e0e8ff;
  border-radius: 8px;
  padding: 10px 14px;
  gap: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.age-filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}
.age-filter-label {
  font-size: 12px;
  font-weight: 600;
  color: #4361ee;
  white-space: nowrap;
  min-width: 130px;
}
.age-filter-dates {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.age-filter-dates .filter-group {
  flex: 0 0 auto;
  min-width: 0;
}
.age-filter-dates .filter-input {
  width: 130px;
}
.age-arrow {
  color: #94a3b8;
  font-size: 14px;
  line-height: 1;
}
.age-filter-divider {
  width: 1px;
  height: 40px;
  background: #d1d5db;
  margin: 0 16px;
}
.age-clear-btn {
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 50%;
  width: 22px; height: 22px;
  cursor: pointer;
  font-size: 10px;
  color: #9ca3af;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: all .15s;
}
.age-clear-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #ef4444;
}

/* ── Local-mode badge ── */
.badge-local {
  display: inline-flex; align-items: center;
  padding: 1px 6px; border-radius: 10px;
  font-size: 10px; font-weight: 600;
  background: #fffaeb; color: #b54708;
  border: 1px solid #fedf89;
  text-transform: uppercase; letter-spacing: .4px;
  margin-left: 4px; vertical-align: middle;
}

/* ── Local store filter row ── */
.filter-grid--local {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-2);
  margin-bottom: 4px;
}

/* ══════════════════════════════════════════════════
   CLASSIFICATION BADGES
══════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge--fast { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.badge--avg  { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; }
.badge--slow { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }
.badge--dead { background: #f2f4f7; color: #667085; border: 1px solid #d0d5dd; }
.badge--na   { background: #f2f4f7; color: #98a2b3; border: 1px solid #e4e7ec; }

/* ══════════════════════════════════════════════════
   STR VALUE COLORING
══════════════════════════════════════════════════ */
.str-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 12px;
}
.str-fast    { color: #027a48; }
.str-average { color: #b54708; }
.str-slow    { color: #b42318; }
.str-dead    { color: #98a2b3; }

/* ══════════════════════════════════════════════════
   ROW TINTS  (seller table)
══════════════════════════════════════════════════ */
.data-table tbody tr.row-fast td { background: rgba(18,183,106,.04); }
.data-table tbody tr.row-slow td { background: rgba(240,68,56,.04); }
.data-table tbody tr.row-dead td { background: rgba(152,162,179,.07); }
.data-table tbody tr.row-fast:hover td { background: rgba(18,183,106,.09); }
.data-table tbody tr.row-slow:hover td { background: rgba(240,68,56,.09); }
.data-table tbody tr.row-dead:hover td { background: rgba(152,162,179,.13); }

/* ══════════════════════════════════════════════════
   TABLE SECTION HEADER  (legend row)
══════════════════════════════════════════════════ */
.table-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap; gap: 8px;
}
.table-section-title { font-size: 12px; font-weight: 600; color: var(--text); }
.class-legend {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-muted);
}

/* ══════════════════════════════════════════════════
   SUBSECTION BREAKDOWN
══════════════════════════════════════════════════ */
.breakdown-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.breakdown-section.hidden { display: none; }
.breakdown-header {
  display: flex; align-items: baseline; gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.breakdown-title { font-size: 12px; font-weight: 600; color: var(--text); }
.breakdown-sub   { font-size: 11px; color: var(--text-muted); }
.breakdown-table-wrap { overflow-x: auto; }
.breakdown-table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}
.breakdown-table th {
  padding: 8px 14px;
  text-align: left;
  font-size: 10px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.badge-head--fast { color: #027a48; }
.badge-head--avg  { color: #b54708; }
.badge-head--slow { color: #b42318; }
.badge-head--dead { color: #667085; }
.breakdown-table td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border-2);
}
.breakdown-table tbody tr:last-child td { border-bottom: none; }
.breakdown-table tbody tr:hover td { background: var(--bg); }
.breakdown-subsec { font-weight: 500; }
.breakdown-num    { font-variant-numeric: tabular-nums; }

.mini-bar {
  height: 3px; background: var(--border);
  border-radius: 2px; margin-top: 3px;
  min-width: 50px; width: 100%;
}
.mini-bar-fill {
  height: 100%; border-radius: 2px;
  transition: width .3s ease;
}
.bar--fast { background: #12b76a; }
.bar--avg  { background: #f79009; }
.bar--slow { background: #f04438; }
.bar--dead { background: #98a2b3; }

/* ══════════════════════════════════════════════════
   RESHUFFLE PANEL
══════════════════════════════════════════════════ */
.reshuffle-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.reshuffle-section.hidden { display: none; }
.reshuffle-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.reshuffle-title {
  font-size: 13px; font-weight: 600; color: var(--text);
}
.reshuffle-sub {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.reshuffle-count {
  font-size: 12px; font-weight: 600;
  background: var(--ink); color: #fff;
  padding: 3px 10px; border-radius: 10px;
  flex-shrink: 0;
}
.reshuffle-table th { background: var(--bg); }
.from-store { color: var(--red);   font-weight: 500; }
.to-store   { color: var(--green); font-weight: 500; }
.recommend-qty {
  font-weight: 700; color: var(--ink);
  background: rgba(16,24,40,.05);
}
