/*
  SKU Health Dashboard — brand tokens from AFGWork/WebDesign/brand-guidelines.md
  (Sections 3 and 6.2)
*/

:root {
  /* Brand red */
  --brand-500: #ef4444;
  --brand-600: #dc2626;

  /* Ink neutrals */
  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;

  /* Status */
  --success-500: #10b981;
  --success-50: #ecfdf5;
  --warning-500: #f59e0b;
  --warning-50: #fffbeb;
  --error-500: #ef4444;
  --error-50: #fef2f2;

  /* Shadows */
  --shadow-soft: 0 20px 60px -40px rgba(15, 23, 42, 0.45);
  --shadow-lift: 0 16px 35px -22px rgba(15, 23, 42, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  color: var(--ink-900);
  background: var(--ink-100);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--brand-500);
  text-decoration: none;
}
a:hover { color: var(--brand-600); text-decoration: underline; }

/* ---------- Layout ---------- */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: white;
  border-bottom: 1px solid var(--ink-200);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-logo {
  height: 44px;
  width: auto;
  flex-shrink: 0;
}

.header-title-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--brand-500);
  font-weight: 500;
}

.title-h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-900);
  margin: 0;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  color: var(--ink-500);
  font-size: 12px;
  margin-right: 12px;
}

.header-meta strong {
  color: var(--ink-900);
  font-weight: 600;
}

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  padding: 12px 32px 24px;
  min-height: 0;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 128px);
  overflow-y: auto;
}

.main-pane {
  min-width: 0; /* so flex/grid children can shrink */
}

/* ---------- Live stats panel ---------- */

.stats-panel {
  padding: 16px 32px 0;
}

.stats-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 4px 0 10px;
  cursor: pointer;
  color: var(--ink-500);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.stats-toggle:hover { color: var(--brand-500); }

.stats-toggle .chevron {
  width: 14px;
  height: 14px;
  transition: transform 200ms ease;
}
.stats-panel.collapsed .stats-toggle .chevron {
  transform: rotate(-90deg);
}

.stats-toggle-label { color: var(--ink-700); }
.stats-toggle:hover .stats-toggle-label { color: var(--brand-500); }
.stats-toggle-hint { color: var(--ink-500); font-weight: 400; text-transform: none; letter-spacing: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 1.3fr 1.6fr;
  gap: 16px;
  transition: max-height 200ms ease, opacity 150ms ease, padding-top 200ms ease, margin-bottom 200ms ease;
  overflow: hidden;
  max-height: 280px;
  margin-bottom: 0;
}

.stats-panel.collapsed .stats-grid {
  max-height: 0;
  opacity: 0;
  margin-bottom: -12px;
}

.stat-card {
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: 20px;
  padding: 16px 20px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 104px;
}

.stat-card-hero {
  background: linear-gradient(135deg, #fff 0%, #fef2f2 100%);
  border-color: rgba(239, 68, 68, 0.2);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--brand-500);
  font-weight: 600;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 11px;
  color: var(--ink-500);
  font-weight: 500;
}

.stat-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--ink-700);
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--ink-100);
  border: 1px solid var(--ink-200);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.stat-chip .stat-chip-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink-900);
}

.stat-chip-problem {
  background: var(--error-50);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--error-500);
}
.stat-chip-healthy {
  background: var(--success-50);
  border-color: rgba(16, 185, 129, 0.2);
  color: var(--success-500);
}
.stat-chip-skipped {
  background: var(--warning-50);
  border-color: rgba(245, 158, 11, 0.25);
  color: var(--warning-500);
}
.stat-chip-untested {
  background: var(--ink-100);
  border-color: var(--ink-200);
  color: var(--ink-500);
}

/* ---------- Cards (from brand-guidelines Section 4.2) ---------- */

.soft-card {
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
}

.glass-card {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
}

/* ---------- Buttons (from brand-guidelines Section 4.3) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand-500);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: white;
  color: var(--ink-700);
  border-color: var(--ink-200);
}
.btn-secondary:hover {
  background: var(--ink-100);
  border-color: var(--ink-500);
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* ---------- Inline link buttons (All / None) ---------- */

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 11px;
  color: var(--ink-500);
  cursor: pointer;
  text-decoration: none;
  transition: color 120ms ease;
}
.link-btn:hover {
  color: var(--brand-500);
}

.link-sep {
  color: var(--ink-200);
  font-size: 11px;
  padding: 0 2px;
}

/* ---------- Filter sidebar ---------- */

.filter-group {
  margin-bottom: 22px;
}
.filter-group:last-child { margin-bottom: 0; }

.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.filter-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--brand-500);
  font-weight: 500;
}

.filter-group-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.filter-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-checklist-scroll {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  padding: 6px;
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: 12px;
}
.filter-checklist-scroll::-webkit-scrollbar { width: 8px; }
.filter-checklist-scroll::-webkit-scrollbar-thumb { background: var(--ink-200); border-radius: 4px; }
.filter-checklist-scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-500); }

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-700);
  user-select: none;
  transition: background-color 100ms ease;
}

.filter-row:hover { background: var(--ink-100); }

.filter-row input[type="checkbox"] {
  accent-color: var(--brand-500);
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.filter-row-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-row-count {
  font-size: 10.5px;
  color: var(--ink-500);
  font-variant-numeric: tabular-nums;
  background: var(--ink-100);
  padding: 1px 7px;
  border-radius: 9999px;
  font-weight: 600;
  flex-shrink: 0;
  display: none; /* hidden globally; re-enabled only in the marketplace filter */
}

#filter-marketplace .filter-row-count {
  display: inline-block;
}

.filter-search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--ink-200);
  border-radius: 12px;
  font: inherit;
  font-size: 13px;
  background: white;
}
.filter-search:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.filter-hint {
  font-size: 11px;
  color: var(--ink-500);
  margin-top: 6px;
  margin-bottom: 0;
}

/* ---------- Health pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.pill-healthy  { background: var(--success-50); color: var(--success-500); border: 1px solid rgba(16, 185, 129, 0.2); }
.pill-problem  { background: var(--error-50);   color: var(--error-500);   border: 1px solid rgba(239, 68, 68, 0.25); }
.pill-skipped  { background: var(--warning-50); color: var(--warning-500); border: 1px solid rgba(245, 158, 11, 0.25); }
.pill-untested { background: var(--ink-100);    color: var(--ink-500);     border: 1px solid var(--ink-200); }

.pill-marketplace {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--ink-100);
  color: var(--ink-700);
  border: 1px solid var(--ink-200);
  letter-spacing: 0.04em;
}

/* ---------- Table ---------- */

.table-wrapper {
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--ink-200);
  background: white;
}

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

table.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--ink-100);
  color: var(--ink-700);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ink-200);
  white-space: nowrap;
  user-select: none;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  z-index: 1;
}

table.data-table thead th.sortable {
  cursor: pointer;
}
table.data-table thead th.sortable:hover { color: var(--brand-500); }

table.data-table thead th .sort-arrow {
  opacity: 0.3;
  margin-left: 4px;
  font-size: 10px;
}
table.data-table thead th.sorted-asc .sort-arrow,
table.data-table thead th.sorted-desc .sort-arrow {
  opacity: 1;
  color: var(--brand-500);
}

table.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--ink-100);
  vertical-align: middle;
  color: var(--ink-900);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.data-table tbody tr:hover {
  background: var(--ink-100);
}

table.data-table tbody tr:nth-child(even) {
  background: rgba(241, 245, 249, 0.4);
}
table.data-table tbody tr:nth-child(even):hover {
  background: var(--ink-100);
}

table.data-table .col-reason {
  max-width: 360px;
  white-space: normal;
  color: var(--ink-700);
  font-size: 11.5px;
  line-height: 1.4;
}

table.data-table .col-sku {
  font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
  font-size: 12px;
  color: var(--ink-900);
  font-weight: 600;
}

table.data-table .col-asin a,
table.data-table .col-channel {
  font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
  font-size: 11.5px;
}

/* ---------- Tab bar ---------- */

.tab-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 12px;
}

.tab-btn {
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: 9999px;
  padding: 7px 18px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-500);
  cursor: pointer;
  transition: all 150ms ease;
}
.tab-btn:hover { color: var(--ink-900); border-color: var(--ink-500); }
.tab-btn.tab-active {
  background: var(--brand-500);
  color: white;
  border-color: var(--brand-500);
}

.counts-bar-inline {
  color: var(--ink-500);
  font-size: 12px;
}
.counts-bar-inline strong {
  color: var(--ink-900);
  font-weight: 600;
}

/* ---------- Counts / footer ---------- */

.counts-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 12px;
  color: var(--ink-500);
  font-size: 12px;
}

.counts-bar strong {
  color: var(--ink-900);
  font-weight: 600;
}

.pagination {
  display: flex;
  justify-content: center;
  padding: 16px;
}

/* ---------- Empty state ---------- */

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-500);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.empty-state img {
  max-width: 160px;
  height: auto;
  opacity: 0.9;
}
.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-700);
}

/* ---------- Loading state ---------- */

.loading-banner {
  padding: 32px;
  text-align: center;
  color: var(--ink-500);
  font-size: 13px;
}

.shimmer {
  background: linear-gradient(90deg, var(--ink-100) 25%, #e8edf3 50%, var(--ink-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
  border-radius: 12px;
  height: 20px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Fade in on load (guidelines Section 3.6) ---------- */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fadeUp 600ms ease-out; }

/* ---------- Responsive-ish ---------- */

@media (max-width: 1400px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    max-height: 420px;
  }
}

@media (max-width: 1100px) {
  .app-body {
    grid-template-columns: 260px 1fr;
  }
}

@media (max-width: 900px) {
  .app-body {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
  }
  .stats-grid {
    grid-template-columns: 1fr;
    max-height: 800px;
  }
}
