/* ============================================================
   JNK Catalogue Updater — Styles
   Mobile-first, minimalistic, fast.
   ============================================================ */

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

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #e5e5ea;
  --accent: #0071e3;
  --accent-light: #e8f2ff;
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
  --transition: 0.2s ease;
  --tap-size: 44px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* --- Sticky Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header__title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-size);
  height: var(--tap-size);
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--transition);
}

.header__btn:active {
  background: var(--accent-light);
}

.header__btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Toolbar (Search + Sort) --- */
.toolbar {
  position: sticky;
  top: 69px; /* header height */
  z-index: 99;
  padding: 10px 16px 8px;
  background: var(--bg);
}

.search-wrap {
  position: relative;
  margin-bottom: 8px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: var(--tap-size);
  padding: 0 16px 0 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, .12);
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.sort-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.sort-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chip--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chip:active {
  transform: scale(0.96);
}

/* --- Product List --- */
.product-list {
  padding: 4px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Product Card (collapsed) --- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.card:active {
  box-shadow: var(--shadow-md);
}

.card__summary {
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: flex-start;
}

.card__thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.card__thumb--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.card__info {
  flex: 1;
  min-width: 0;
}

.card__code {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 3px;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: all;
  transition: opacity var(--transition), transform var(--transition);
}

.card__code:active {
  opacity: 0.7;
  transform: scale(0.96);
}

.card__name {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.card__sizes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.size-chip {
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-secondary);
  white-space: nowrap;
}

.size-chip--low {
  background: #fff3e0;
  color: var(--warning);
}

.size-chip--out {
  background: #fdecea;
  color: var(--danger);
}

.card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
}

.card__price {
  font-weight: 600;
  color: var(--text);
}

.card__colour {
  color: var(--text-secondary);
}

.card__dot {
  color: var(--border);
}

/* --- Card Expanded --- */
.card__detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.card--expanded .card__detail {
  max-height: 2000px;
}

.card__detail-inner {
  padding: 0 12px 12px;
}

/* --- Image Carousel --- */
.carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--bg);
}

.carousel__track {
  display: flex;
  height: 100%;
  transition: transform 0.3s ease;
  will-change: transform;
}

.carousel__slide {
  flex: 0 0 100%;
  height: 100%;
}

.carousel__slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: pointer;
  background: var(--bg);
}

.carousel__dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}

.carousel__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.5);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background var(--transition);
}

.carousel__dot--active {
  background: #fff;
  box-shadow: 0 0 4px rgba(0,0,0,.3);
}

/* --- Product Details --- */
.detail__attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.attr-tag {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-secondary);
}

.attr-tag--code {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  user-select: all;
  transition: opacity var(--transition);
}

.attr-tag--code:active {
  opacity: 0.7;
}

/* --- Size Variant Editor --- */
.variant {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.variant__label {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.variant__sku {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 4px;
  cursor: pointer;
  user-select: all;
  transition: opacity var(--transition);
}

.variant__sku:active {
  opacity: 0.7;
}

.variant__fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  width: 100%;
}

.field--qty {
  grid-column: 1 / -1;
}

.field__label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field__input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: border-color var(--transition);
  min-width: 0;
  width: 100%;
}

.field__input-wrap:focus-within {
  border-color: var(--accent);
}

.field__input-wrap--changed {
  border-color: var(--warning);
  background: #fffbf0;
}

.field__input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 8px 4px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  outline: none;
  text-align: center;
}

.field__input::-webkit-inner-spin-button,
.field__input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field__input[type="number"] {
  -moz-appearance: textfield;
}

.field__stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.field__stepper:active {
  background: var(--accent-light);
}

/* Qty field spans full width */
.field--qty {
  grid-column: 1 / -1;
}

/* --- Save Button --- */
.save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: var(--tap-size);
  margin-top: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.save-btn:active {
  transform: scale(0.98);
  background: #005bb5;
}

.save-btn:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* --- Loader --- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 16px;
}

.loader.hidden {
  display: none;
}

.loader__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loader__text {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.empty-state.hidden {
  display: none;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 20px;
  border-radius: 24px;
  background: var(--text);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.toast.hidden {
  transform: translateX(-50%) translateY(100px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast--success {
  background: var(--success);
}

.toast--error {
  background: var(--danger);
}

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, .95);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.lightbox.hidden {
  display: none;
}

.lightbox__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 510;
  width: var(--tap-size);
  height: var(--tap-size);
  border: none;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 1.25rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__close:active {
  background: rgba(255,255,255,.3);
}

.lightbox__counter {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.7);
  font-size: 0.8125rem;
  z-index: 510;
}

.lightbox__canvas {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.lightbox__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.2s ease;
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: var(--tap-size);
  height: var(--tap-size);
  border: none;
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 1.75rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 510;
}

.lightbox__nav:active {
  background: rgba(255,255,255,.25);
}

.lightbox__nav--prev {
  left: 8px;
}

.lightbox__nav--next {
  right: 8px;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  -webkit-tap-highlight-color: transparent;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  font-size: 1.0625rem;
  font-weight: 700;
}

.modal__close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__body {
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.modal__product {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.modal__thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.modal__product-info {
  flex: 1;
  min-width: 0;
}

.modal__product-code {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.modal__product-name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.modal__changes-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.modal__changes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal__change-item {
  font-size: 0.8125rem;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.change__size {
  color: var(--text);
}

.change__field {
  color: var(--text-secondary);
}

.change__from {
  color: var(--danger);
  text-decoration: line-through;
}

.change__arrow {
  color: var(--text-secondary);
}

.change__to {
  color: var(--success);
  font-weight: 700;
}

.modal__footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.btn {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--secondary:active {
  background: var(--border);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:active {
  background: #005bb5;
}

.btn--primary:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* --- Responsive: wider than phone --- */
@media (min-width: 600px) {
  .product-list {
    max-width: 480px;
    margin: 0 auto;
  }

  .header,
  .toolbar {
    max-width: 480px;
    margin: 0 auto;
  }
}
