/* Product Optimizer — styles */
:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e7e5e4;
  --text: #1c1917;
  --text-muted: #78716c;
  --primary: #6d28d9;
  --primary-hover: #5b21b6;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #ea580c;
  --high: #dc2626;
  --medium: #ea580c;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
header.topbar .nav {
  display: flex;
  gap: 12px;
  align-items: center;
}
header.topbar .nav a {
  color: var(--text-muted);
  font-weight: 500;
}
header.topbar .nav a.active { color: var(--text); }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f5f5f4; }
.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}
.btn.danger:hover { background: #fef2f2; border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

input[type="text"], input[type="file"], textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.1);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-muted);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  margin-bottom: 4px;
}
.stat-value { font-size: 22px; font-weight: 600; }
.stat.highlight .stat-value { color: var(--primary); }

/* Table */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: #f5f5f4;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  /* Sticky so column headers stay visible while scrolling.
     Offset matches the topbar height so it docks below it. */
  position: sticky;
  top: 49px;
  z-index: 5;
  /* Subtle shadow on scroll to separate from content */
  box-shadow: inset 0 -1px 0 var(--border);
}
th:first-child { border-top-left-radius: var(--radius); }
th:last-child { border-top-right-radius: var(--radius); }
tbody tr:hover { background: #fafaf9; cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td img.thumb, .thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: #eee;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.high { background: #fee2e2; color: var(--high); }
.badge.medium { background: #fed7aa; color: var(--medium); }
.badge.ok { background: #dcfce7; color: var(--success); }
.badge.success { background: #dcfce7; color: var(--success); }
.badge.new { background: #ede9fe; color: var(--primary); }
.badge.muted { background: #f5f5f4; color: var(--text-muted); }
/* "Already optimized" — someone has worked on this product (any time). */
.badge.optimized {
  background: #ffffff;
  color: #15803d;
  border: 1px solid #86efac;
}

.delta-up { color: var(--success); font-weight: 500; }
.delta-down { color: var(--danger); font-weight: 500; }
.delta-neutral { color: var(--text-muted); }

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters .search { flex: 1; min-width: 220px; max-width: 340px; }
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
}
.pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.pill:hover:not(.active) { background: #f5f5f4; color: var(--text); }

/* Store list */
.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.store-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.store-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.store-card h3 { margin: 0 0 4px; font-size: 18px; }
.store-card .muted { color: var(--text-muted); font-size: 13px; }
.store-card .stats-row { display: flex; gap: 16px; margin-top: 12px; }
.store-card .stats-row > div { flex: 1; }
.store-card .stats-row strong {
  display: block;
  font-size: 18px;
  color: var(--text);
}
.store-card .stats-row span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: #faf5ff;
}
.dropzone p { margin: 4px 0; color: var(--text-muted); }
.dropzone .label { font-weight: 600; color: var(--text); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin-top: 0; }
.modal .actions {
  margin-top: 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Timeline (notes + screenshots) */
.timeline-item {
  border-left: 2px solid var(--border);
  padding: 0 0 20px 20px;
  margin-left: 8px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}
.timeline-item .ts {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.timeline-item .note {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  white-space: pre-wrap;
}
.screenshot-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.screenshot-tile {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: 150px;
  background: #f5f5f4;
}
.screenshot-tile img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}
.screenshot-tile .label {
  display: block;
  font-size: 11px;
  padding: 4px 6px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
  font-weight: 500;
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 95vh; }

/* Layout helpers */
.row { display: flex; gap: 16px; }
.row > * { flex: 1; }
.hide { display: none !important; }
.right { text-align: right; }
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 400px;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty h3 { color: var(--text); margin: 0 0 8px; }

.spinner {
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 300;
  animation: slidein 0.2s;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slidein { from { transform: translateY(20px); opacity: 0; } }

/* Chart wrapper */
.chart-wrap {
  position: relative;
  height: 300px;
  margin: 16px 0;
}

/* Product header */
.product-hero {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.product-hero img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius);
  background: #eee;
}
.product-hero h2 { margin: 0 0 4px; }
