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

:root {
  --bg:        #f4f6f8;
  --surface:   #ffffff;
  --surface2:  #f0f2f5;
  --border:    #dde1e7;
  --text:      #1a1f2e;
  --muted:     #6b7280;
  --accent:    #1a7a4a;
  --green:     #1a7a4a;
  --red:       #dc2626;
  --yellow:    #d97706;
  --radius:    8px;
  --gap:       16px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.site-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  white-space: nowrap;
  margin-right: 8px;
}

nav { display: flex; gap: 4px; }

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  position: relative;
}
.nav-btn:hover  { color: var(--text); border-color: var(--border); }
.nav-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(26,122,74,.08); }

/* Urgent badge on Flagged nav button */
.urgent-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  line-height: 14px;
  pointer-events: none;
}

.market-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.market-selector label { color: var(--muted); font-size: 12px; }
.market-selector select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 13px;
}

/* ── Layout ─────────────────────────────────────────────────── */
#app { padding: 24px; }

.view { display: none; }
.view.active { display: block; }

.view-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.view-toolbar h2 { font-size: 16px; font-weight: 600; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn-primary:hover    { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-secondary:hover    { background: rgba(26,122,74,.08); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

.status-label { font-size: 12px; color: var(--muted); }

/* ── Listings grid ──────────────────────────────────────────── */
.listings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--gap);
}

.listing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.listing-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card-image {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: var(--surface2);
}
.card-image-placeholder {
  width: 100%;
  height: 160px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}

.card-body { padding: 12px; }
.card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}
.badge-price    { background: rgba(26,122,74,.10); color: var(--accent); }
.badge-sold-avg { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.badge-margin   { background: rgba(26,122,74,.10); color: var(--green); }
.badge-margin.low { background: rgba(220,38,38,.08); color: var(--red); }
.badge-mislabel { background: rgba(217,119,6,.10); color: var(--yellow); }
.badge-bids     { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

.card-canonical { font-size: 11px; color: var(--muted); margin-top: 3px; margin-bottom: 2px; font-style: italic; }
.card-end-time  { font-size: 11px; color: var(--muted); margin-top: 6px; }

.badge-confidence-high   { background: rgba(26,122,74,.12);  color: var(--green); }
.badge-confidence-medium { background: rgba(217,119,6,.12);  color: var(--yellow); }
.badge-confidence-low    { background: rgba(220,38,38,.10);  color: var(--red); }

.badge-scarce    { background: rgba(26,122,74,.12);  color: var(--green); }
.badge-low-stock { background: rgba(217,119,6,.12);  color: var(--yellow); }
.badge-common    { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

/* Flag It / Watching button on listing cards */
.card-footer {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}
.btn-flag-card {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 4px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-flag-card:hover { background: rgba(26,122,74,.08); }
.btn-flag-card.watching {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-flag-card.watching:hover { opacity: 0.85; }

/* ── Flagged table ───────────────────────────────────────────── */
#flagged-container {
  overflow-x: auto;
}

.flagged-table {
  min-width: 900px;
}

.flagged-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}
.flagged-thumb-placeholder {
  width: 48px;
  height: 48px;
  background: var(--surface2);
  border-radius: 4px;
}

.flagged-name {
  max-width: 200px;
  font-weight: 500;
}

.flagged-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

/* Countdown cell */
.countdown {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.countdown.urgent-30 { color: var(--yellow); }
.countdown.urgent-10 {
  color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}
.countdown.ended { color: var(--muted); font-weight: 400; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Bid status dropdown */
.bid-status-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.bid-status-select.status-none   { color: var(--muted); }
.bid-status-select.status-queued { color: var(--yellow); border-color: var(--yellow); }
.bid-status-select.status-placed { color: var(--accent); border-color: var(--accent); }
.bid-status-select.status-won    { color: var(--green);  border-color: var(--green); font-weight: 700; }
.bid-status-select.status-lost   { color: var(--red);    border-color: var(--red); }

/* Small button variant for table rows */
.btn-sm {
  font-size: 11px !important;
  padding: 3px 8px !important;
}

/* ── Data table ─────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--surface2); }

.profit-positive { color: var(--green); font-weight: 600; }
.profit-negative { color: var(--red);   font-weight: 600; }

/* ── P&L summary ────────────────────────────────────────────── */
.pl-summary {
  display: flex;
  gap: var(--gap);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.pl-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 140px;
}
.pl-stat .label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.pl-stat .value { font-size: 22px; font-weight: 700; }

/* ── Modal base ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal h2 { font-size: 15px; margin-bottom: 12px; }
.modal-section { margin-top: 16px; }
.modal-section h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.detail-item .key { font-size: 11px; color: var(--muted); }
.detail-item .val { font-size: 14px; font-weight: 500; }

.modal-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

.btn-flag {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: opacity 0.15s;
}
.btn-flag:hover { opacity: 0.85; }
.btn-flag.watching-btn {
  background: var(--green);
}

.btn-unflag {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.btn-unflag:hover { background: var(--border); }

.btn-ebay {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s;
}
.btn-ebay:hover { background: rgba(26,122,74,.06); }

/* ── Flag form modal ─────────────────────────────────────────── */
.flag-modal {
  max-width: 480px;
}

.flag-modal-readonly {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 18px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.readonly-label { color: var(--muted); font-size: 12px; }
.readonly-value { font-weight: 600; color: var(--accent); }

.flag-form .form-group {
  margin-bottom: 14px;
}
.flag-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 500;
}
.flag-form input,
.flag-form textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.flag-form input:focus,
.flag-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.flag-form textarea { resize: vertical; }

.flag-profit-display {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.profit-label  { font-size: 12px; color: var(--muted); }
.profit-formula {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  flex: 1;
}
.profit-number { font-size: 16px; font-weight: 700; }

/* ── P&L entry modal (won → P&L) ─────────────────────────────── */
.pl-entry-modal  { max-width: 440px; }
.sold-modal      { max-width: 460px; }

.pl-entry-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.label-hint {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
}

/* ── P&L view sections ───────────────────────────────────────── */
.pl-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.pl-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.pl-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pl-section-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.table-scroll {
  overflow-x: auto;
}

.pl-active-table { min-width: 860px; }
.pl-sold-table   { min-width: 680px; }

/* Total cost cell emphasis */
.total-cost-cell {
  font-weight: 600;
  color: var(--text);
}

/* Date cell */
.date-cell {
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}

/* Inline table link (↗ icon next to item name) */
.table-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 400;
}
.table-link:hover { text-decoration: underline; }

/* ── Empty states ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* ── Markets list ───────────────────────────────────────────── */
.market-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}
.market-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.market-card p  { color: var(--muted); font-size: 13px; }
.market-card .meta { display: flex; gap: 20px; margin-top: 10px; font-size: 12px; }
.market-card .meta span { color: var(--muted); }
.market-card .meta strong { color: var(--text); }
.market-active   { border-left: 3px solid var(--green); }
.market-inactive { border-left: 3px solid var(--border); opacity: 0.6; }

/* ── Filter panel ───────────────────────────────────────────── */
.filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: flex-end;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-group label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.filter-group input[type="number"],
.filter-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.filter-group input[type="number"] { width: 90px; }
.filter-group select                { min-width: 130px; }
.filter-group input[type="number"]:focus,
.filter-group select:focus { outline: none; border-color: var(--accent); }

.filter-group-check {
  flex-direction: row;
  align-items: center;
  padding-bottom: 1px;
}
.filter-group-check label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}
.filter-group-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-reset-filters {
  align-self: flex-end;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-reset-filters:hover { color: var(--text); border-color: var(--text); }

/* ── Listings meta (count row) ──────────────────────────────── */
.listings-meta {
  margin-bottom: 10px;
  min-height: 18px;
}
.listings-count {
  font-size: 12px;
  color: var(--muted);
}

/* ── Pagination bar ─────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 24px;
  padding: 16px 0 4px;
}
.pagination-bar.hidden { display: none; }

.btn-page {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  height: 34px;
  transition: border-color 0.15s, color 0.15s;
}
.btn-page:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-page:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-page-edge {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}
.btn-page-edge:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }

.page-info {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-page-num {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-page-num:hover { border-color: var(--accent); color: var(--accent); }
.btn-page-num.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.page-ellipsis {
  font-size: 13px;
  color: var(--muted);
  padding: 0 2px;
  user-select: none;
}

.page-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  margin-left: 8px;
}

.page-goto {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}

.goto-input {
  width: 72px;
  height: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0 8px;
  font-size: 12px;
  font-family: inherit;
  text-align: center;
  transition: border-color 0.15s;
}
.goto-input:focus { outline: none; border-color: var(--accent); }
.goto-input::-webkit-inner-spin-button,
.goto-input::-webkit-outer-spin-button { opacity: 0.4; }

.btn-goto {
  height: 34px;
  padding: 0 12px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s;
}
.btn-goto:hover { border-color: var(--accent); color: var(--accent); }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b8c4; }
