:root {
  --bg: #f4f6fa;
  --bg-elevated: #ffffff;
  --ink: #152033;
  --muted: #5b6475;
  --line: #e2e7ef;
  --line-strong: #cfd5e0;
  --brand-blue: #1e3a8a;
  --brand-blue-deep: #152c6b;
  --brand-red: #d21f26;
  --surface: #ffffff;
  --surface-soft: #f0f3f8;
  --danger: #b42318;
  --focus: #2563eb;
  --shadow-soft: 0 1px 2px rgba(21, 32, 51, 0.04), 0 8px 24px rgba(21, 32, 51, 0.05);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: "Segoe UI Variable Text", "Segoe UI", "SF Pro Text", "Helvetica Neue", sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", "SF Pro Display", "Helvetica Neue", sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(30, 58, 138, 0.08), transparent 60%),
    radial-gradient(700px 360px at 100% 0%, rgba(210, 31, 38, 0.05), transparent 55%),
    linear-gradient(180deg, #f8f9fc 0%, var(--bg) 40%, #eef2f7 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

button, input, select {
  font: inherit;
}

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px 36px;
}

/* ——— Header / brand ——— */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 6px rgba(21, 44, 107, 0.18));
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 5vw, 2rem);
  font-weight: 750;
  letter-spacing: 0.08em;
  line-height: 1;
  color: var(--brand-blue);
}

.brand-sub {
  color: var(--muted);
  font-size: 0.92rem;
  letter-spacing: 0.01em;
}

.view.hidden, .hidden {
  display: none !important;
}

.view h1 {
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 10px;
}

.lead {
  color: var(--muted);
  line-height: 1.5;
  max-width: 34rem;
  margin: 0 0 18px;
  font-size: 1rem;
}

.empty-state {
  max-width: 28rem;
  margin: 28px auto 0;
  text-align: left;
}

.empty-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 14px;
}

/* ——— Buttons ——— */

.btn, .icon-btn, .select, .search {
  min-height: var(--tap);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn.primary {
  background: var(--brand-blue);
  color: #fff;
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.22);
}

.btn.primary:hover {
  background: var(--brand-blue-deep);
}

.btn.secondary {
  border-color: var(--line);
  background: var(--surface);
}

.btn.sync-btn {
  width: 100%;
  max-width: 280px;
  border: 1px solid rgba(30, 58, 138, 0.22);
  background: linear-gradient(180deg, #ffffff 0%, #f3f6fb 100%);
  color: var(--brand-blue);
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-soft);
}

.btn.sync-btn:hover {
  border-color: rgba(30, 58, 138, 0.4);
  background: #fff;
}

.btn.sync-btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-soft);
}

.btn:focus-visible, .icon-btn:focus-visible, .search:focus-visible, .select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, white);
  outline-offset: 2px;
}

/* ——— Sync panel ——— */

.sync-panel {
  margin-bottom: 16px;
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
}

.server-updated {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--muted);
}

.status-text {
  min-height: 1.25em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-text.error {
  color: var(--danger);
}

.status-text.ok,
.offline-ready.ok {
  color: #1f6b3a;
  font-weight: 600;
}

/* ——— Toolbar / filters ——— */

.toolbar {
  display: grid;
  gap: 12px;
  margin-bottom: 8px;
}

.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.95rem 0.7rem 2.55rem;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.search::placeholder {
  color: #8a93a3;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 720px) {
  .filters {
    grid-template-columns: 1.3fr 1fr;
    align-items: end;
  }
}

.field {
  min-width: 0;
}

.filter-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 10px;
  height: 10px;
  pointer-events: none;
  transform: translateY(-60%) rotate(45deg);
  border-right: 2px solid var(--brand-blue);
  border-bottom: 2px solid var(--brand-blue);
  opacity: 0.85;
}

.select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 2.4rem 0.7rem 0.95rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.result-count {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 550;
}

/* ——— Product grid ——— */

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (min-width: 720px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 980px) {
  .product-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.product-card {
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.product-card .thumb-wrap {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(160deg, #eef2f8, #f7f8fb);
  margin-bottom: 10px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.product-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-card .name {
  font-family: var(--font-display);
  font-weight: 650;
  margin: 0 0 6px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  min-height: calc(1.25em * 2);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.product-card .meta {
  margin: 0;
  margin-top: auto;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ——— Product detail ——— */

.product-detail h1 {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.product-hero {
  aspect-ratio: 1 / 1;
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  background: var(--surface-soft);
  margin-bottom: 12px;
  padding: 0;
  border: 1px solid var(--line);
  width: 100%;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.product-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 14px;
}

.thumbs button {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
}

.thumbs button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, white);
  outline-offset: 2px;
}

.thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.price {
  font-size: 1.4rem;
  font-weight: 750;
  margin: 8px 0 4px;
  color: var(--brand-blue);
  font-variant-numeric: tabular-nums;
}

.sku {
  color: var(--muted);
  margin: 0 0 14px;
  font-size: 0.95rem;
}

.attr-block {
  margin: 16px 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.attr-block h2 {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.attr-block dl {
  margin: 0;
  display: grid;
  gap: 10px;
}

.attr-block dt {
  font-weight: 650;
}

.attr-block dd {
  margin: 2px 0 0;
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ——— Lightbox ——— */

.lightbox {
  position: fixed;
  inset: 0;
  background: #101522;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(12px + var(--safe-top))
    calc(12px + var(--safe-right))
    calc(12px + var(--safe-bottom))
    calc(12px + var(--safe-left));
}

.lightbox img {
  max-width: min(100%, 1200px);
  max-height: calc(100vh - 120px);
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close,
.lightbox-nav {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: transparent;
  box-shadow: none;
}

.lightbox-close {
  position: absolute;
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-nav.prev { left: calc(8px + var(--safe-left)); }
.lightbox-nav.next { right: calc(8px + var(--safe-right)); }

.lightbox-counter {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  margin: 0;
  color: #f2f4f8;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
