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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a1a;
  min-height: 100vh;
}

header {
  background: #1a1a2e url('/banner2.png') center/contain repeat;
  color: #fff;
  padding: 2px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-logo {
  height: 200px;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#store-greeting {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.store-greeting-logo {
  height: 32px;
  width: 32px;
  object-fit: contain;
  border-radius: 4px;
}

.auth-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
}

.auth-badge.connected {
  background: #22c55e;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.auth-badge-logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 3px;
}

.auth-badge.disconnected {
  background: #ef4444;
  color: #fff;
}

button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#btn-refresh {
  background: #3b82f6;
  color: #fff;
}

#btn-refresh:hover:not(:disabled) {
  background: #2563eb;
}

#btn-auth {
  background: #f59e0b;
  color: #1a1a1a;
}

#btn-auth:hover {
  background: #d97706;
}

#btn-trophies {
  background: #fbbf24;
  color: #1a1a1a;
}

#btn-trophies:hover {
  background: #f59e0b;
}

#btn-instructions {
  background: #e0e7ff;
  color: #3730a3;
}

#btn-instructions:hover {
  background: #c7d2fe;
}

/* Instructions modal */
.instructions-content {
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 0; /* the sticky header supplies the top spacing */
}

/* Keep the header (and its Close button) pinned while the long guide scrolls,
   so it's always reachable on mobile. */
.instructions-content .trophies-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  margin: 0 -24px 12px;   /* bleed over the modal padding to form a full-width bar */
  padding: 18px 24px 12px;
  border-bottom: 1px solid #e5e7eb;
}

/* Bigger, easier tap target for the guide's Close button on mobile */
.instructions-content .trophies-header .btn-save {
  padding: 10px 18px;
  font-size: 15px;
}

.instructions-body h4 {
  margin: 16px 0 6px;
  font-size: 15px;
  color: #1a1a1a;
}

.instructions-body ol,
.instructions-body ul {
  margin: 6px 0 8px;
  padding-left: 22px;
}

.instructions-body li {
  font-size: 14px;
  color: #374151;
  line-height: 1.5;
  margin-bottom: 6px;
}

.instructions-callout {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 14px;
  line-height: 1.5;
}

.instructions-callout.warn {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
}

.instructions-callout.info {
  background: #e0f2fe;
  border: 1px solid #38bdf8;
  color: #075985;
}

.instructions-callout strong {
  color: inherit;
}

.instructions-body .field-name {
  font-family: monospace;
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

/* Trophies modal */
.trophies-content {
  max-width: 720px;
  width: 92%;
}

.trophies-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.trophies-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#trophies-season {
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.trophies-progress {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.tp-card {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.tp-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.tp-value {
  font-size: 20px;
  font-weight: 700;
  color: #059669;
  margin-top: 4px;
}

.tp-next {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

.tp-count {
  font-size: 12px;
  font-weight: 600;
  color: #f59e0b;
  margin-top: 6px;
}

.trophies-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-height: 60vh;
  overflow-y: auto;
}

.trophy-column {
  display: flex;
  flex-direction: column;
}

.trophy-col-header {
  font-size: 12px;
  font-weight: 700;
  color: #1a1a2e;
  text-align: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid #f59e0b;
}

.trophy-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.trophy-tile {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: transform 0.1s;
}

.trophy-tile:hover {
  transform: scale(1.08);
}

.trophy-tile.earned {
  background: #fffbeb;
  border: 1px solid #fbbf24;
}

.trophy-tile.earned img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.trophy-tile.earned.img-missing::after {
  content: '🏆';
  font-size: 22px;
}

.trophy-tile.locked {
  background: #f3f4f6;
  border: 1px dashed #d1d5db;
  color: #9ca3af;
  font-size: 20px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .trophies-progress { grid-template-columns: 1fr; }
  .trophies-grid { grid-template-columns: 1fr; gap: 18px; }
}

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 20px 24px;
  max-width: 900px;
  margin: 0 auto;
}

.panel {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.panel h2 {
  font-size: 18px;
  margin-bottom: 4px;
  color: #1a1a2e;
}

.panel-subtitle {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 16px;
}

.listing-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.placeholder {
  color: #9ca3af;
  font-style: italic;
  text-align: center;
  padding: 40px 0;
}

.listing-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  transition: border-color 0.15s;
}

.listing-card {
  display: flex;
  gap: 12px;
  align-items: center;
}

.listing-card:hover {
  border-color: #3b82f6;
}

.listing-card.listing-dropped {
  opacity: 0.45;
  filter: grayscale(60%);
}

.listing-thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
  background: #f9fafb;
}

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

.listing-card .title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  line-height: 1.3;
}

.listing-card .title a {
  color: #1a1a2e;
  text-decoration: none;
}

.listing-card .title a:hover {
  color: #3b82f6;
}

/* Editable relist title: compact read-only view by default, expands to an editor
   on "Edit" (keeps listing cards small — and non-scrolling — on mobile). */
.title-edit {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 6px;
}

.title-edit .card-number {
  margin-top: 1px;
}

/* --- Compact read-only view --- */
.title-view {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

.title-text {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.35;
  color: #1a1a2e;
  word-break: break-word;
}

.title-text.title-short {
  color: #b45309;
}

.title-edit-btn {
  flex-shrink: 0;
  padding: 3px 9px;
  font-size: 12px;
  background: #e5e7eb;
  color: #374151;
}

.title-edit-btn:hover {
  background: #d1d5db;
}

/* --- Full editor (shown while editing) --- */
.title-editor {
  display: none;
  flex: 1;
  min-width: 0;
}

.title-edit.editing .title-view {
  display: none;
}

.title-edit.editing .title-editor {
  display: block;
}

.title-input {
  width: 100%;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  color: #1a1a2e;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
}

.title-input:focus {
  outline: none;
  border-color: #3b82f6;
}

.title-editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.title-done-btn {
  padding: 3px 12px;
  font-size: 12px;
  background: #2563eb;
  color: #fff;
}

.title-done-btn:hover {
  background: #1d4ed8;
}

.title-count {
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
}

/* Soft heads-up when the relist title drops under 60 chars */
.title-count.title-short {
  color: #d97706;
  font-weight: 600;
}

/* Watchers + drop-price (keep watchers) */
.watch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.watch-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 12px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.btn-drop-price {
  background: #16a34a;
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
}

.seo-flags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.seo-flag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 12px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.btn-drop-price:hover {
  background: #15803d;
}

.btn-drop-price:disabled {
  background: #86efac;
  cursor: default;
}

.watched-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  margin-bottom: 6px;
}

.watched-title a {
  color: #1a1a2e;
  text-decoration: none;
}

.watched-title a:hover {
  color: #3b82f6;
}

#watched-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.listing-card .meta {
  font-size: 13px;
  color: #6b7280;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.listing-card .meta span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.listing-card .meta .price {
  color: #059669;
  font-weight: 600;
}

.price-arrow {
  color: #9ca3af;
  font-weight: 600;
}

.new-price-input {
  width: 70px;
  padding: 3px 6px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #059669;
}

.new-price-input:focus {
  outline: none;
  border-color: #3b82f6;
}

/* Flags a new price that looks like a fat-finger (see priceWarning() in app.js) */
.new-price-input.price-warn {
  border-color: #dc2626;
  color: #dc2626;
  background: #fef2f2;
}

.btn-ban {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: #f3f4f6;
  color: #9ca3af;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.btn-ban:hover:not(:disabled) {
  background: #fee2e2;
  color: #ef4444;
}


.btn-apply {
  background: #3b82f6;
  color: #fff;
}

.btn-apply:hover {
  background: #2563eb;
}

.btn-save {
  background: #e5e7eb;
  color: #374151;
}

.btn-save:hover {
  background: #d1d5db;
}

.loading {
  text-align: center;
  padding: 40px 0;
  color: #6b7280;
}

.loading::before {
  content: '';
  display: block;
  width: 80px;
  height: 80px;
  margin: 0 auto 10px;
  background: url('/loading.webp') center/contain no-repeat;
  animation: spin-bounce 1.2s ease-in-out infinite;
}

@keyframes spin-bounce {
  0%   { transform: rotate(0deg)   scale(1);   }
  25%  { transform: rotate(90deg)  scale(1.3);  }
  50%  { transform: rotate(180deg) scale(1);   }
  75%  { transform: rotate(270deg) scale(1.3);  }
  100% { transform: rotate(360deg) scale(1);   }
}

.error {
  text-align: center;
  padding: 20px;
  color: #ef4444;
  background: #fef2f2;
  border-radius: 8px;
}

.card-number {
  color: #9ca3af;
  font-size: 12px;
  font-weight: 600;
  margin-right: 4px;
}

/* Auth modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
}

.modal-content h3 {
  margin-bottom: 12px;
}

.modal-content p {
  font-size: 14px;
  color: #374151;
  margin-bottom: 8px;
  line-height: 1.4;
}

.modal-content code {
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

#btn-open-ebay {
  background: #f59e0b;
  color: #1a1a1a;
  width: 100%;
}

#btn-open-ebay:hover {
  background: #d97706;
}

#auth-code-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

/* Sell Similar button */
.btn-sell-similar {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 16px 24px;
  background: #dc2626;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-sell-similar:hover:not(:disabled) {
  background: #b91c1c;
  transform: scale(1.01);
}

.btn-sell-similar:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sell-similar.running {
  background: #9ca3af;
  cursor: wait;
}

#sell-similar-progress {
  margin-top: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

#progress-log {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px 14px;
  background: #1a1a2e;
  color: #a5f3fc;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
}

#progress-log .log-error {
  color: #fca5a5;
}

#progress-log .log-success {
  color: #86efac;
}

#progress-log .log-status {
  color: #fde68a;
}

#progress-results {
  padding: 14px;
  background: #f9fafb;
}

#progress-results a {
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
}

#progress-results a:hover {
  text-decoration: underline;
}

.results-summary {
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 600;
}

.new-listing-link {
  display: block;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #e5e7eb;
}

.new-listing-link:last-child {
  border-bottom: none;
}

/* Relist History Section */
.history-section {
  max-width: 900px;
  margin: 0 auto 20px;
  padding: 0 24px;
}

.history-section h2 {
  font-size: 14px;
  margin-bottom: 2px;
  color: #1a1a2e;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 10px 10px 0 0;
  padding: 10px 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn-check-sold {
  background: #6366f1;
  color: #fff;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.btn-check-sold:hover:not(:disabled) {
  background: #4f46e5;
}

#history-list {
  background: #fff;
  border-radius: 0 0 10px 10px;
  padding: 4px 14px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.history-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 11px;
  line-height: 1.3;
}

.history-row:last-child {
  border-bottom: none;
}

.history-row.history-sold {
  background: #f0fdf4;
}

.sold-tag, .unsold-tag {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.sold-tag {
  background: #22c55e;
  color: #fff;
}

.unsold-tag {
  background: #e5e7eb;
  color: #6b7280;
}

.history-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #374151;
  text-decoration: none;
}

.history-name:hover {
  color: #3b82f6;
}

.history-price {
  flex-shrink: 0;
  color: #059669;
  font-weight: 600;
}

/* Disputes summary */
.disputes-grid {
  display: flex;
  gap: 16px;
  padding: 10px 14px;
  background: #fff;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  flex-wrap: wrap;
}

.dispute-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}

.dispute-count {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
}

.dispute-total {
  color: #6366f1;
}

.dispute-good {
  color: #059669;
}

.dispute-warn {
  color: #dc2626;
}

.dispute-label {
  font-size: 11px;
  color: #6b7280;
  text-align: center;
}


@media (max-width: 768px) {
  header {
    flex-direction: column;
    padding: 12px 16px;
    gap: 12px;
  }
  .header-logo {
    height: 120px;
  }
  .header-actions {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
  }
  main {
    padding: 16px;
  }
  .history-section {
    padding: 0 16px;
  }
  .history-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  .history-titles {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .history-arrow {
    margin: 0;
  }
  .history-card {
    flex-direction: column;
    align-items: flex-start;
  }
}
