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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242833;
  --border: #2e3340;
  --text: #e4e6ed;
  --text2: #8b8fa3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
body.locked header, body.locked .toolbar, body.locked main,
body.locked .toast, body.locked .modal-overlay { display: none; }

/* Login */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-icon { color: var(--text2); margin-bottom: 16px; }
.login-box h2 { font-size: 18px; margin-bottom: 24px; }
.login-box input[type="password"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color .15s;
}
.login-box input[type="password"]:focus { border-color: var(--accent); }
.login-box input[type="password"]::placeholder { color: var(--text2); }
.login-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
h1 { font-size: 20px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.upload-btn {
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.upload-btn:hover { background: var(--accent-hover); }
.product-count { font-size: 13px; color: var(--text2); }

/* Cart button */
.cart-btn {
  position: relative;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: border-color .15s;
}
.cart-btn:hover { border-color: var(--accent); }
.cart-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.cart-badge.hidden { display: none; }

/* Add to cart overlay on image */
.product-card__img-wrap {
  position: relative;
}
.product-card__cart-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  transform: scale(.9);
  z-index: 2;
}
.product-card:hover .product-card__cart-btn,
.product-card__cart-btn.mobile-show {
  opacity: 1;
  transform: scale(1);
}

/* Qty modal */
.qty-modal { max-width: 320px; }
.qty-modal__name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.qty-modal__code { font-size: 13px; color: var(--accent); font-family: 'SF Mono', Monaco, monospace; margin-bottom: 16px; }
.qty-modal__row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.qty-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-btn:hover { border-color: var(--accent); }
.qty-modal__row input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  padding: 8px;
  border-radius: 8px;
  outline: none;
  -moz-appearance: textfield;
}
.qty-modal__row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.qty-add-btn {
  width: 100%;
  background: var(--green);
  border: none;
  color: #000;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.qty-add-btn:hover { background: #16a34a; }

/* Cart modal */
.cart-modal { max-width: 440px; }
.cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.cart-item:last-child { border-bottom: none; }
.cart-item__img {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
  flex-shrink: 0;
}
.cart-item__img--empty {
  background: var(--surface2);
}
.cart-item__info { flex: 1; min-width: 0; }
.cart-item__code { font-size: 13px; color: var(--accent); font-family: 'SF Mono', Monaco, monospace; font-weight: 600; }
.cart-item__name { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item__qty { font-size: 14px; font-weight: 700; color: var(--text); white-space: nowrap; }
.cart-item__remove {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
}
.cart-item__remove:hover { color: var(--red); }
.cart-actions { margin-top: 16px; display: flex; gap: 8px; }
.cart-copy-btn {
  flex: 1;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.cart-copy-btn:hover { background: var(--accent-hover); }
.cart-clear-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.cart-clear-btn:hover { border-color: var(--red); color: var(--red); }
.cart-empty { text-align: center; color: var(--text2); font-size: 14px; padding: 24px 0; }

/* Toolbar */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 57px;
  z-index: 99;
}
.toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  color: var(--text2);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px 10px 40px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap input::placeholder { color: var(--text2); }
.toolbar select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* Model bar */
.model-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.model-bar__inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.model-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 16px;
  border-right: 1px solid var(--border);
}
.model-group:last-of-type { border-right: none; padding-right: 0; }
.model-group__label {
  font-size: 11px;
  color: var(--text2);
  margin-right: 4px;
  white-space: nowrap;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.model-btn {
  background: transparent;
  border: 2px solid var(--btn-color, var(--border));
  color: var(--btn-color, var(--text2));
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.model-btn:hover {
  background: color-mix(in srgb, var(--btn-color, var(--accent)) 15%, transparent);
  color: var(--text);
}
.model-btn.active {
  background: var(--btn-color, var(--accent));
  border-color: var(--btn-color, var(--accent));
  color: #fff;
}
.model-btn--all { margin-left: auto; --btn-color: #8b8fa3; }

/* Model colors */
.model-group .model-btn { --btn-color: #3b82f6; }

/* Main */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text2);
}
.empty-icon { margin-bottom: 16px; opacity: .4; }
.empty-state h2 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; }
.empty-state.hidden { display: none; }

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

/* Product card */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, transform .15s;
  cursor: pointer;
}
.product-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.product-card__img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  background: #fff;
  padding: 8px;
}
.product-card__img-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 13px;
}
.product-card__body { padding: 14px; }
.product-card__name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card__code {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: 'SF Mono', Monaco, monospace;
  color: var(--accent);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .15s;
}
.product-card__code:hover { background: var(--border); }
.product-card__code svg { flex-shrink: 0; }
.product-card__code--oem { color: var(--orange); font-size: 11px; padding: 3px 8px; }
.product-card__oem { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.product-card__price {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 6px;
}
.product-card__price-old {
  font-size: 13px;
  color: var(--text2);
  text-decoration: line-through;
  margin-left: 8px;
  font-weight: 400;
}
.product-card__models {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.model-badge {
  background: var(--surface2);
  color: var(--text2);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.product-card__meta {
  font-size: 12px;
  color: var(--text2);
  margin-top: 8px;
  display: flex;
  gap: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--green);
  color: #000;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: all .3s;
  z-index: 200;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 28px;
  cursor: pointer;
  z-index: 1;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-img {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 20px;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-detail { margin-bottom: 12px; }
.modal-detail__label { font-size: 12px; color: var(--text2); margin-bottom: 2px; }
.modal-detail__value {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-detail__value .copy-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.modal-detail__value .copy-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.modal-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.modal-codes .code-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: 'SF Mono', Monaco, monospace;
  color: var(--accent);
  cursor: pointer;
  transition: all .15s;
}
.modal-codes .code-chip:hover {
  background: var(--accent);
  color: #fff;
}
.modal-models { margin-top: 16px; }
.modal-models .model-badge { font-size: 12px; padding: 4px 10px; }

/* Responsive */
@media (max-width: 768px) {
  header { padding: 12px 16px; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  h1 { font-size: 17px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .upload-btn { font-size: 12px; padding: 7px 12px; }

  header { position: relative; }
  .upload-btn { display: none; }
  .product-card__cart-btn { opacity: 1; transform: scale(1); }

  .toolbar { padding: 10px 16px; position: relative; top: auto; }
  .toolbar-inner { flex-direction: column; gap: 8px; }
  .toolbar select { width: 100%; font-size: 13px; padding: 9px 8px; }
  .search-wrap { min-width: 100%; }
  .search-wrap input { padding: 9px 12px 9px 36px; font-size: 16px; }

  .model-bar { padding: 10px 12px; }
  .model-bar__inner {
    gap: 8px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .model-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
  }
  .model-group:last-of-type { border-bottom: none; padding-bottom: 0; }
  .model-group__label {
    display: block;
    font-size: 10px;
    min-width: 28px;
    text-align: right;
    margin-right: 2px;
  }
  .model-btn {
    padding: 7px 12px;
    font-size: 12px;
    text-align: center;
    border-radius: 8px;
    flex: 1;
  }
  .model-btn--all {
    margin-left: 0;
    max-width: 120px;
    align-self: center;
    flex: none;
  }

  main { padding: 10px; }
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .product-card { display: block; border-radius: 10px; }
  .product-card__img {
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: 10px 10px 0 0;
    padding: 6px;
  }
  .product-card__img-placeholder {
    width: 100%;
    aspect-ratio: 4/3;
    font-size: 11px;
  }
  .product-card__body { padding: 8px 10px 10px; }
  .product-card__name {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 6px;
    -webkit-line-clamp: 2;
    line-height: 1.3;
  }
  .product-card__code {
    font-size: 11px;
    padding: 3px 6px;
    margin-bottom: 4px;
    gap: 4px;
    width: 100%;
  }
  .product-card__code svg { width: 11px; height: 11px; }
  .product-card__oem { display: none; }
  .product-card__price {
    font-size: 17px;
    margin-bottom: 0;
    margin-top: 4px;
  }
  .product-card__price-old { font-size: 11px; margin-left: 4px; }
  .product-card__models { display: none; }
  .product-card__meta { display: none; }

  .modal { border-radius: 12px; margin: 8px; max-height: 90vh; }
  .modal-body { padding: 16px; }
  .modal-img { max-height: 250px; }
  .modal-title { font-size: 16px; }
  .modal-codes { gap: 4px; }
  .modal-codes .code-chip { font-size: 12px; padding: 4px 8px; }

  .empty-state { padding: 40px 16px; }
}

@media (max-width: 380px) {
  .product-grid { gap: 6px; }
  .product-card__name { font-size: 10px; }
  .product-card__price { font-size: 15px; }
  .product-card__code { font-size: 10px; }
}
