/* ── Dark tokens (default) ─────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #0F0F13;
  --surface: #17171D;
  --text: #EAE8E3;
  --sub: #78766E;
  --border: #232330;
  --border-hi: #333340;
  --accent: #7BA4F0;
  --accent-dim: #12192E;
  --accent-ink: #FFFFFF;
  --green: #4AD980;
  --red: #E05555;
  --thumb-bg: #1C1C24;
  --r: 8px;
  --rs: 5px;
  --arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2378766E' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ── Light override ─────────────────────────────────────────── */
[data-theme="light"] {
  color-scheme: light;
  --bg: #F5F4F0;
  --surface: #FFFFFF;
  --text: #1C1B18;
  --sub: #706E66;
  --border: #E0DED8;
  --border-hi: #C5C2BA;
  --accent: #2B5EA7;
  --accent-dim: #EBF0FA;
  --accent-ink: #FFFFFF;
  --green: #1D7A45;
  --red: #B33030;
  --thumb-bg: #EDEAE3;
  --arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23706E66' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.brand-mark {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-meta {
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
}

/* ── Theme toggle ──────────────────────────────────────────── */
.theme-toggle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  color: var(--sub);
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.theme-toggle:hover {
  border-color: var(--border-hi);
  color: var(--text);
  background: var(--border);
}

/* dark → show sun (click = go to light) */
.theme-toggle::after { content: "☀"; }
/* light → show moon (click = go to dark) */
[data-theme="light"] .theme-toggle::after { content: "☽"; }

/* ── Shell ─────────────────────────────────────────────────── */
.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 20px 48px;
}

/* ── Filter bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 16px 0 12px;
}

.filter-search {
  flex: 1 1 260px;
  min-width: 0;
}

.filter-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
.filter-search input:focus { border-color: var(--accent); }
.filter-search input::placeholder { color: var(--sub); }

.filter-select {
  flex: 0 1 auto;
  height: 38px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  background: var(--surface);
  background-image: var(--arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  white-space: nowrap;
  max-width: 200px;
}
.filter-select:focus { border-color: var(--accent); }

.clear-btn {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  background: transparent;
  cursor: pointer;
  color: var(--sub);
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.clear-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Toolbar row ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  font-size: 13px;
}

.result-count { color: var(--sub); }
.result-count strong { color: var(--text); }

/* ── Product grid ──────────────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.product-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  transition: box-shadow 0.18s, border-color 0.18s;
}
.product-card:hover {
  border-color: var(--border-hi);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .product-card:hover {
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.08);
}

.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--thumb-bg);
}

.card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta-line {
  font-size: 12px;
  color: var(--sub);
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.price { color: var(--green); font-weight: 700; font-size: 13px; }
.old-price { color: var(--sub); text-decoration: line-through; font-size: 12px; margin-left: 3px; }

/* ── Pills & Tags ──────────────────────────────────────────── */
.format-row, .tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-dim);
  color: var(--accent);
  border: none;
}

.tag-link {
  background: var(--border);
  color: var(--sub);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.tag-link:hover { background: var(--accent-dim); color: var(--accent); }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 32px;
}

.page-btn {
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--rs);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s, color 0.15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: 0.32; cursor: default; }

.page-label { font-size: 13px; color: var(--sub); }

/* ── Product detail ────────────────────────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  align-items: start;
  padding-top: 20px;
}

.product-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(220px, 400px) minmax(0, 1fr);
  gap: 22px;
  padding: 20px;
}

.detail-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--rs);
  background: var(--thumb-bg);
}

.detail-hero .format-row { margin-top: 10px; }

.back-link {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  color: var(--sub);
  margin-bottom: 14px;
  transition: color 0.12s;
}
.back-link:hover { color: var(--accent); }

.detail-title {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.3px;
  margin-bottom: 10px;
}

.detail-copy {
  font-size: 13px;
  color: var(--sub);
  line-height: 1.7;
  margin-top: 8px;
}

[data-theme="light"] .detail-copy { color: #3C3B36; }

/* ── Sections ──────────────────────────────────────────────── */
.section {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
}

.section h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--sub);
  margin-bottom: 12px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-heading-row h2 { margin: 0; }

/* ── Sizes table ───────────────────────────────────────────── */
.sizes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.sizes-table th,
.sizes-table td {
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.sizes-table th {
  color: var(--sub);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Detail sidebar ────────────────────────────────────────── */
.detail-side {
  position: sticky;
  top: 68px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.detail-side h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--sub);
}

.side-row { display: grid; gap: 2px; }

.side-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--sub);
}

.accent-link { color: var(--accent); }
.accent-link:hover { text-decoration: underline; }

/* ── Tag page ──────────────────────────────────────────────── */
.tag-page { display: grid; gap: 16px; padding-top: 20px; }

.tag-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px 24px;
}

/* ── States ────────────────────────────────────────────────── */
.loading, .error {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--sub);
  font-size: 13px;
}
.error { border-color: #5A2020; color: var(--red); }
[data-theme="light"] .error { border-color: #F5C5C5; }

/* ── Related products (outside layout grid) ────────────────── */
.detail-related {
  margin-top: 20px;
  padding: 16px 20px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.detail-related h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--sub);
  margin-bottom: 14px;
}

.related-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 960px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-side { position: static; }
  .detail-hero { grid-template-columns: 1fr; }
  .detail-image { max-width: 440px; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 14px; height: 48px; }
  .app-shell { padding: 0 12px 40px; }
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .related-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-search { flex: 1 1 100%; }
  .filter-select { flex: 1 1 calc(50% - 4px); max-width: none; }
  .clear-btn { width: 100%; }
  .detail-title { font-size: 18px; }
  .detail-hero { padding: 14px; gap: 14px; }
  .section { padding: 14px; }
  .tag-header { padding: 16px; }
}
