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

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --link: #0066c0;
  --link-hover: #c45500;
  --row-alt: #f8f9fa;
  --row-hover: #e9ecef;
  --accent: #198754;
  --prime-blue: #00698f;
}

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

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

header .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 2px;
}

header .updated {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}

/* Layout */
.container {
  display: flex;
  gap: 0;
  max-width: 100%;
}

/* Sidebar */
aside#filters {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.filter-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#reset-filters {
  font-size: 12px;
  color: var(--link);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
}

#reset-filters:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

fieldset {
  border: none;
  margin-bottom: 16px;
}

fieldset legend {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
}

.filter-checkboxes {
  max-height: 200px;
  overflow-y: auto;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 2px 0;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  cursor: pointer;
}

.range-inputs {
  display: flex;
  gap: 8px;
}

.range-inputs label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

.range-inputs input {
  margin-top: 2px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 13px;
  width: 100%;
}

.result-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Main */
main {
  flex: 1;
  overflow-x: auto;
  min-width: 0;
}

#loading,
#error {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

#error {
  color: #dc3545;
}

/* Table */
#table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  background: #e9ecef;
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  user-select: none;
}

th.num-col {
  text-align: right;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  background: #dee2e6;
}

th.sortable::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

th.sorted-asc::after {
  border-bottom: 5px solid var(--text);
  border-top: none;
}

th.sorted-desc::after {
  border-top: 5px solid var(--text);
  border-bottom: none;
}

td {
  padding: 6px 10px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

td.num-col {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

tr:nth-child(even) {
  background: var(--row-alt);
}

tr:hover {
  background: var(--row-hover);
}

/* Price per ball highlight */
td.ppb {
  font-weight: 600;
  color: var(--accent);
}

/* Product cell */
.product-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.product-cell img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 3px;
  flex-shrink: 0;
}

.product-cell .placeholder-img {
  width: 40px;
  height: 40px;
  background: #eee;
  border-radius: 3px;
  flex-shrink: 0;
}

.product-cell a {
  color: var(--link);
  text-decoration: none;
  line-height: 1.3;
}

.product-cell a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* Prime badge */
.prime-badge {
  color: var(--prime-blue);
  font-weight: 600;
  font-size: 12px;
}

/* Rating */
.rating-cell {
  white-space: nowrap;
}

.rating-stars {
  color: #ffa41c;
  font-size: 12px;
}

.rating-count {
  color: var(--text-muted);
  font-size: 11px;
}

/* Footer */
footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Mobile toggle button */
#filter-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }

  aside#filters {
    width: 100%;
    min-width: unset;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: none;
  }

  aside#filters.open {
    display: block;
  }

  #filter-toggle {
    display: block;
  }

  table {
    font-size: 12px;
  }

  th, td {
    padding: 5px 6px;
  }

  .product-cell img,
  .product-cell .placeholder-img {
    width: 32px;
    height: 32px;
  }
}
