/* Design tokens */
:root {
  --bg: #ffffff;
  --bg2: #f6f8fa;
  --bg3: #f4f4f4;
  --text: #111111;
  --text2: #555555;
  --text3: #888888;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --border: #d0d7de;
  --border2: #eaeef2;
  --green: #1a7f37;
  --green-bg: #dafbe1;
  --red: #cf222e;
  --red-bg: #ffebe9;
  --orange: #9a6700;
  --orange-bg: #fff8c5;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --border: #30363d;
    --border2: #21262d;
    --green: #3fb950;
    --green-bg: #0d2d1a;
    --red: #f85149;
    --red-bg: #2d1216;
    --orange: #d29922;
    --orange-bg: #272115;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --border: #30363d;
  --border2: #21262d;
  --green: #3fb950;
  --green-bg: #0d2d1a;
  --red: #f85149;
  --red-bg: #2d1216;
  --orange: #d29922;
  --orange-bg: #272115;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

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

/* Nav */
.nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 48px;
}
.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.nav-brand:hover { text-decoration: none; color: var(--text); }
.nav-links { display: flex; gap: 0.25rem; margin-left: auto; }
.nav-links a {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text2);
  font-size: 0.875rem;
}
.nav-links a:hover {
  background: var(--bg3);
  color: var(--text);
  text-decoration: none;
}
.nav-links a.active {
  background: var(--bg3);
  color: var(--text);
}

/* Page layout */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Hero (homepage) */
.hero {
  text-align: center;
  padding: 4rem 1rem 3rem;
}
.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}
.hero p {
  color: var(--text2);
  margin: 0 0 2rem;
}

/* Search bar */
.search-wrap {
  display: flex;
  gap: 0.5rem;
  max-width: 600px;
  margin: 0 auto;
}
.search-input {
  flex: 1;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(9,105,218,.15); }

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin: 1.25rem 0;
  padding: 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-group { display: flex; flex-direction: column; gap: 0.3rem; }
.filter-label { font-size: 0.75rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }
.filter-checks { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.check-pill {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text2);
  user-select: none;
}
.check-pill input { accent-color: var(--accent); }
.check-pill:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.price-filter-group { flex: 1; min-width: 220px; max-width: 420px; }
.price-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 0.5rem;
}
#price-slider {
  margin: 0 4px;
}
/* noUiSlider theme overrides */
.noUi-target { background: var(--border); border: none; box-shadow: none; height: 5px; border-radius: 3px; }
.noUi-connect { background: var(--accent); }
.noUi-handle {
  width: 16px !important;
  height: 16px !important;
  right: -8px !important;
  top: -6px !important;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  cursor: pointer;
}
.noUi-handle::before, .noUi-handle::after { display: none; }
.noUi-handle:focus { outline: none; box-shadow: 0 0 0 3px rgba(9,105,218,.25); }
.filter-stock { display: flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; color: var(--text2); cursor: pointer; }
.filter-stock input { accent-color: var(--accent); }

/* Results area */
.results-meta {
  font-size: 0.85rem;
  color: var(--text3);
  margin: 0 0 0.75rem;
}
.results-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text3);
}
.results-empty .empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.results-empty p { margin: 0.25rem 0 0; font-size: 0.9rem; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border2);
}
.page-info { font-size: 0.85rem; color: var(--text3); min-width: 60px; text-align: center; }

/* Loading indicator */
#results.htmx-request { opacity: 0.5; transition: opacity 0.15s 0.1s; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
}
td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border2); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg2); }

.product-name { font-weight: 500; color: var(--text); }
.product-name a { color: var(--text); }
.product-name a:hover { color: var(--accent); text-decoration: underline; }
.store-label { font-size: 0.78rem; color: var(--text3); margin-top: 1px; }
.price-cell { font-weight: 600; white-space: nowrap; color: var(--text); }
.ext-link { font-size: 0.8rem; white-space: nowrap; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }

/* Product detail page */
.product-header { margin-bottom: 1.5rem; }
.product-header h1 { font-size: 1.4rem; margin: 0 0 0.25rem; }
.product-meta { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }
.product-meta .store-label { font-size: 0.85rem; }

.price-display {
  font-size: 2rem;
  font-weight: 700;
  margin: 1rem 0 0.25rem;
}
.price-updated { font-size: 0.8rem; color: var(--text3); }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-title { font-size: 0.85rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.75rem; }

.chart-wrap { height: 240px; }

/* Watchlist page */
.wl-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.wl-header h1 { font-size: 1.4rem; margin: 0; flex: 1; }
.add-form { display: flex; gap: 0.5rem; }
.add-input {
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  width: 220px;
}
.add-input:focus { outline: none; border-color: var(--accent); }
.btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.875rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--bg3); color: var(--text2); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.775rem; }

.wl-list { list-style: none; padding: 0; margin: 0; }
.wl-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.wl-item-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.wl-query { font-weight: 600; flex: 1; }
.wl-remove-form { margin: 0; }
.wl-results { padding: 0.5rem 0; }
.wl-results table { font-size: 0.85rem; }

/* Status page */
.status-grid { display: grid; gap: 1rem; }
.status-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 1rem;
  align-items: start;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
}
.status-name { font-weight: 600; }
.status-method { font-size: 0.75rem; color: var(--text3); font-family: monospace; }
.status-info { font-size: 0.82rem; color: var(--text2); }
.status-info strong { color: var(--text); }
.status-error { font-size: 0.78rem; color: var(--red); margin-top: 0.25rem; font-family: monospace; word-break: break-all; }

/* Page title row */
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0 0 1.5rem; }

/* Misc */
.muted { color: var(--text3); }
hr { border: none; border-top: 1px solid var(--border2); margin: 1.5rem 0; }

@media (max-width: 600px) {
  .hero { padding: 2.5rem 0 2rem; }
  .hero h1 { font-size: 1.5rem; }
  .filters { gap: 0.75rem; }
  .search-wrap { flex-direction: column; }
  th, td { padding: 0.4rem 0.5rem; }
  .price-display { font-size: 1.5rem; }
}
