:root {
  --bg: #f5f3ef;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --border: #e5e0d8;
  --primary: #9e2a2b;
  --primary-light: #fdf2f2;
  --keep: #1b7f4b;
  --keep-bg: #eaf7f0;
  --del: #cf222e;
  --del-bg: #ffebe9;
  --warn: #9a6700;
  --warn-bg: #fff8c5;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 84px;
}

.hidden { display: none !important; }

/* Auth */
.auth-overlay, .modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.auth-card, .modal-card {
  background: #fff;
  width: 100%;
  max-width: 380px;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.auth-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.auth-card h2 { margin: 0 0 6px; font-size: 20px; }
.auth-desc { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 12px;
}
.auth-error { color: var(--del); font-size: 13px; margin: 10px 0 0; min-height: 18px; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 960px;
  margin: 0 auto;
}
.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}
.brand-title .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sync-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
}
.sync-badge.ok { background: var(--keep-bg); color: var(--keep); }
.sync-badge.err { background: var(--warn-bg); color: var(--warn); }

.progress-wrap {
  max-width: 960px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: #eae6df;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.25s ease;
}
.progress-text {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.filters-row {
  max-width: 960px;
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr) 1.3fr;
  gap: 6px;
}
.filters-row select, .filters-row input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: var(--text);
}
@media (max-width: 640px) {
  .filters-row { grid-template-columns: 1fr 1fr; }
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
}
.btn-ghost {
  background: #f3f1ed;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}
.btn-secondary {
  background: #f3f1ed;
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}
.btn-link {
  background: none;
  color: var(--primary);
  font-size: 12px;
  padding: 2px 4px;
}
.full-width { width: 100%; margin-top: 8px; }

/* Main Card */
.main-container {
  max-width: 760px;
  margin: 14px auto;
  padding: 0 12px;
}
.product-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
}
.card-media {
  position: relative;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: 320px;
  padding: 10px;
}
.card-media img {
  max-width: 100%;
  max-height: 290px;
  object-fit: contain;
  border-radius: 8px;
}
.media-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge-dark { background: rgba(31,35,40,0.78); color: #fff; }
.badge-pending { background: #eef2f6; color: #475569; }
.badge-kept { background: var(--keep-bg); color: var(--keep); }
.badge-deleted { background: var(--del-bg); color: var(--del); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

.card-body { padding: 14px 16px 18px; }
.prod-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.meta-chip {
  font-size: 11px;
  background: #f3f1ed;
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 6px;
}
.prod-name {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.35;
}

.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: 8px;
  margin-bottom: 10px;
}
.price-box {
  background: #faf9f6;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.price-box.highlight {
  background: var(--primary-light);
  border-color: #f2c6c6;
}
.price-label { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.price-val { font-size: 15px; font-weight: 700; }
.price-val.muted { color: var(--muted); text-decoration: line-through; font-weight: 500; }
.price-val.cost { color: #b45309; }
.price-input-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
  color: var(--primary);
}
.price-input-wrap input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  outline: none;
}

.orig-ref {
  font-size: 12px;
  color: var(--muted);
  background: #f8f7f4;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.orig-label { font-weight: 600; color: var(--text); }

.spec-details {
  margin-bottom: 14px;
  font-size: 13px;
}
.spec-details summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
}
.prod-spec {
  margin: 8px 0 0;
  line-height: 1.55;
  color: #374151;
  background: #faf9f6;
  padding: 10px;
  border-radius: 8px;
}

/* Tags */
.tags-section { margin-bottom: 12px; }
.tags-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}
.tag-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tag-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fcfbf9;
}
.tag-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}
.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-pill {
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  transition: all 0.12s ease;
}
.tag-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.note-row input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

/* Action Bar */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 0.9fr 1fr 1.6fr;
  gap: 8px;
  z-index: 60;
}
.btn-nav {
  background: #f3f1ed;
  color: var(--text);
  padding: 12px 8px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}
.btn-delete {
  background: var(--del-bg);
  color: var(--del);
  padding: 12px 10px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
}
.btn-keep {
  background: var(--keep);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
}

/* List Mode */
.list-container {
  max-width: 960px;
  margin: 14px auto;
  padding: 0 12px;
}
.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.list-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  gap: 10px;
  cursor: pointer;
}
.list-item img {
  width: 68px;
  height: 68px;
  object-fit: contain;
  border-radius: 8px;
  background: #fafafa;
  flex-shrink: 0;
}
.list-item-info { flex: 1; min-width: 0; }
.list-item-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.list-item-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Empty & Modal */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.empty-icon { font-size: 40px; margin-bottom: 8px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h3 { margin: 0; }
.export-summary { font-size: 13px; color: var(--text); margin-bottom: 12px; }
.export-hint { font-size: 12px; color: var(--muted); margin: 6px 0 14px; }
