/* ── Reset & Tokens ───────────────────────────────────────────────────────── */

:root {
  --white: #ffffff;
  --black: #111111;
  --grey-50: #fafafa;
  --grey-100: #f5f5f5;
  --grey-200: #eeeeee;
  --grey-300: #e0e0e0;
  --grey-400: #bdbdbd;
  --grey-500: #9e9e9e;
  --grey-600: #757575;
  --grey-700: #555555;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --basket-width: 288px;
  --header-height: 58px;
}

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

body {
  background: var(--white);
  color: var(--black);
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Loading ─────────────────────────────────────────────────────────────── */

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  color: var(--grey-500);
  font-size: 14px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--grey-200);
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Header ──────────────────────────────────────────────────────────────── */

.shop-header {
  border-bottom: 1px solid var(--grey-300);
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 40;
}

.shop-header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.shop-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.condition-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.condition-switcher label {
  font-size: 11px;
  color: var(--grey-500);
  white-space: nowrap;
}

.condition-switcher select {
  font-size: 11px;
  padding: 4px 6px;
  border: 1px solid var(--grey-300);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
  color: var(--grey-700);
  max-width: 220px;
}

/* ── Category Tabs ───────────────────────────────────────────────────────── */

.category-tabs {
  border-bottom: 1px solid var(--grey-300);
  background: var(--white);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 24px;
  position: sticky;
  top: var(--header-height);
  z-index: 39;
}

.category-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--grey-500);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.03em;
}

.tab-btn:hover { color: var(--black); }

.tab-btn.active {
  color: var(--black);
  border-bottom-color: var(--black);
  font-weight: 600;
}

/* ── Shop Body Layout ────────────────────────────────────────────────────── */

.shop-body {
  flex: 1;
  display: flex;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 60px;
  align-items: flex-start;
}

.shop-main {
  flex: 1;
  min-width: 0;
  padding-top: 28px;
  padding-right: 32px;
}

/* ── Product Grid ────────────────────────────────────────────────────────── */

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px 20px;
}

@media (max-width: 1100px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 860px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); }
}

.grid-empty {
  color: var(--grey-500);
  padding: 60px 0;
  text-align: center;
  font-size: 14px;
  grid-column: 1 / -1;
}

/* ── Product Card ────────────────────────────────────────────────────────── */

.product-card {
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
}

.product-card-img-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--grey-100);
  overflow: hidden;
  flex-shrink: 0;
}

.product-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.product-card:hover .product-card-img {
  transform: scale(1.03);
}

.product-card-img.img-broken {
  visibility: hidden;
}

.in-basket-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(17, 17, 17, 0.85);
  color: var(--white);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.product-card-info {
  padding: 10px 2px 0;
}

.product-card-brand {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--grey-500);
  margin-bottom: 3px;
}

.product-card-name {
  font-size: 13px;
  line-height: 1.35;
  margin-bottom: 5px;
  color: var(--black);
}

.product-card-price {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* ── AE Label — Catalogue (small badge) ─────────────────────────────────── */

.ae-catalogue-badge {
  margin-top: 6px;
}

.ae-catalogue-badge .ae-label-img {
  height: 32px;
  width: auto;
  display: block;
}

.ae-label-fallback-small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--grey-100);
  border: 1px solid var(--grey-300);
  border-radius: 3px;
  padding: 3px 8px;
}

.ae-label-fallback-small .ae-score-num {
  font-size: 13px;
  font-weight: 700;
}

.ae-label-fallback-small .ae-score-unit {
  font-size: 9px;
  text-transform: uppercase;
  color: var(--grey-500);
  letter-spacing: 0.04em;
}

/* ── Basket Sidebar ──────────────────────────────────────────────────────── */

.basket-sidebar {
  width: var(--basket-width);
  flex-shrink: 0;
  margin-top: 28px;
  position: sticky;
  top: calc(var(--header-height) + 48px);
  height: fit-content;
  max-height: calc(100vh - var(--header-height) - 80px);
  border: 1px solid var(--grey-300);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.basket-header {
  padding: 14px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--grey-300);
  background: var(--white);
  flex-shrink: 0;
}

.basket-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  min-height: 60px;
}

.basket-empty-msg {
  color: var(--grey-400);
  font-size: 12px;
  text-align: center;
  padding: 20px 0;
}

.basket-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--grey-200);
  gap: 8px;
}

.basket-item:last-child { border-bottom: none; }

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

.basket-item-name {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 2px;
}

.basket-item-brand {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey-500);
}

.basket-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.basket-item-price {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.basket-remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--grey-400);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}

.basket-remove-btn:hover { color: var(--red); }

.basket-footer {
  border-top: 1px solid var(--grey-300);
  padding: 12px 16px;
  flex-shrink: 0;
  background: var(--white);
}

.basket-totals { margin-bottom: 12px; }

.basket-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  color: var(--grey-600);
}

.basket-row-total {
  font-weight: 700;
  color: var(--black);
  font-size: 13px;
  border-top: 1px solid var(--grey-200);
  padding-top: 7px;
  margin-top: 4px;
}

.basket-row-remaining {
  font-weight: 600;
  color: var(--green);
}

.basket-row-remaining.over-budget { color: var(--red); }

.basket-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--black);
  color: var(--white);
  border: none;
  padding: 13px 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { opacity: 0.75; }

.btn-primary:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--white);
  color: var(--black);
  border: 1px solid var(--grey-300);
  padding: 11px 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: background 0.15s;
}

.btn-secondary:hover:not(:disabled) { background: var(--grey-50); }

.btn-secondary:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Product Modal ───────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-panel {
  background: var(--white);
  max-width: 880px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--white);
  border: 1px solid var(--grey-300);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  color: var(--grey-500);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: color 0.15s, border-color 0.15s;
}

.modal-close-btn:hover { color: var(--black); border-color: var(--black); }

.modal-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

/* Modal — image side */
.modal-images {
  background: var(--grey-50);
  display: flex;
  flex-direction: column;
}

.modal-main-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.modal-thumbnails {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--grey-50);
  border-top: 1px solid var(--grey-200);
}

.thumb-btn {
  background: none;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.thumb-btn:hover { border-color: var(--grey-400); }
.thumb-btn.active { border-color: var(--black); }

.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Modal — details side */
.modal-details {
  padding: 36px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.modal-brand {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--grey-500);
}

.modal-name {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
}

.modal-price {
  font-size: 20px;
  font-weight: 700;
}

.modal-description {
  font-size: 13px;
  color: var(--grey-600);
  line-height: 1.65;
  border-top: 1px solid var(--grey-200);
  padding-top: 14px;
}

.modal-add-wrap {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--grey-200);
}

.modal-message {
  font-size: 13px;
  margin-top: 10px;
  padding: 10px 14px;
  line-height: 1.5;
}

.modal-message.error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.modal-message.info {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

/* ── AE Label — Product page ─────────────────────────────────────────────── */

.ae-product-section {
  border-top: 1px solid var(--grey-200);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ae-label-img {
  height: 72px;
  width: auto;
  display: block;
}

.ae-label-fallback {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ae-label-title {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--grey-500);
}

.ae-label-score {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.ae-label-unit {
  font-size: 11px;
  color: var(--grey-500);
}

/* Gauge placeholder */
.ae-gauge-wrap {
  background: var(--grey-50);
  border: 1px solid var(--grey-200);
  border-radius: 3px;
  padding: 10px 14px;
}

.ae-gauge-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--grey-500);
  margin-bottom: 8px;
}

.ae-gauge-track {
  position: relative;
  height: 8px;
  background: linear-gradient(to right, #4ade80, #fbbf24, #ef4444);
  border-radius: 4px;
  margin: 10px 0 6px;
}

.ae-gauge-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: var(--black);
  border: 2px solid var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.ae-gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--grey-500);
}

/* Info text */
.ae-info-section {
  font-size: 13px;
}

.ae-info-short {
  color: var(--grey-600);
  line-height: 1.6;
  margin-bottom: 6px;
}

.ae-info-more-btn {
  background: none;
  border: none;
  color: var(--black);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ae-info-long {
  font-size: 12px;
  color: var(--grey-600);
  line-height: 1.65;
  border-top: 1px solid var(--grey-200);
  padding-top: 10px;
  margin-top: 10px;
}

.ae-info-long ul {
  margin: 8px 0 8px 18px;
}

.ae-info-long em {
  color: var(--grey-500);
  font-style: italic;
}

/* ── Confirmation overlay ────────────────────────────────────────────────── */

.confirm-panel {
  max-width: 560px;
  padding: 48px 40px;
  text-align: center;
}

.confirm-panel h2 {
  font-size: 22px;
  margin-bottom: 12px;
}

.confirm-panel p {
  color: var(--grey-600);
  margin-bottom: 24px;
  line-height: 1.6;
}

.payload-preview {
  background: var(--grey-50);
  border: 1px solid var(--grey-200);
  border-radius: 3px;
  padding: 16px;
  text-align: left;
  margin-bottom: 24px;
}

.payload-preview strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--grey-500);
  margin-bottom: 8px;
}

.payload-preview pre {
  font-size: 11px;
  overflow-x: auto;
  max-height: 180px;
  line-height: 1.5;
  color: var(--grey-700);
}

/* ── Debug overlay ───────────────────────────────────────────────────────── */

.debug-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(10, 10, 10, 0.93);
  color: #4ade80;
  border-radius: 6px;
  z-index: 200;
  max-width: 380px;
  width: calc(100% - 40px);
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.debug-toggle {
  background: none;
  border: none;
  color: #4ade80;
  cursor: pointer;
  padding: 10px 14px;
  font-size: 11px;
  font-family: inherit;
  width: 100%;
  text-align: left;
  letter-spacing: 0.05em;
}

.debug-content {
  padding: 0 14px 14px;
  max-height: 380px;
  overflow-y: auto;
}

.debug-content h3 {
  font-size: 10px;
  color: #86efac;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.debug-content pre {
  font-size: 10px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

/* ── Mobile basket bar ───────────────────────────────────────────────────── */

.mobile-basket-bar { display: none; }

.mobile-basket-toggle {
  width: 100%;
  background: var(--black);
  color: var(--white);
  border: none;
  padding: 15px 24px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-align: center;
}

.mobile-basket-panel {
  background: var(--white);
  border-top: 1px solid var(--grey-300);
  overflow-y: auto;
  max-height: 60vh;
}

.mobile-basket-panel .basket-sidebar {
  width: 100%;
  position: static;
  max-height: none;
  border: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .shop-body {
    padding: 0 16px 90px;
  }

  .shop-main {
    padding-right: 0;
    padding-top: 20px;
  }

  .basket-sidebar { display: none; }

  .mobile-basket-bar {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
  }

  .modal-layout { grid-template-columns: 1fr; }

  .modal-main-img { aspect-ratio: 1; }

  .modal-details { padding: 20px; }

  .modal-panel { max-height: 96vh; }

  .category-tabs { padding: 0 16px; }

  .shop-header-inner { padding: 0 16px; }

  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 12px;
  }

  .confirm-panel {
    padding: 28px 20px;
  }
}

@media (max-width: 380px) {
  .product-grid { grid-template-columns: 1fr; }
}
