/* =========================================================
   Amazon ASIN Monitor — Dark Theme
   ========================================================= */

:root {
  color-scheme: dark;
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2e3349;
  --accent:     #4f8ef7;
  --accent-dim: #2d5cbd;
  --text:       #e4e8f4;
  --text-dim:   #8890a8;
  --green:      #22c55e;
  --red:        #ef4444;
  --yellow:     #f59e0b;
  --radius:     10px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;
  --chart-grid: #2e3349;
  --chart-text: #8890a8;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg:         #f6f9ff;
  --surface:    rgba(255, 255, 255, 0.88);
  --surface2:   #eef4fb;
  --border:     #d8e2ef;
  --accent:     #2563eb;
  --accent-dim: #1d4ed8;
  --text:       #0f172a;
  --text-dim:   #64748b;
  --green:      #16a34a;
  --red:        #dc2626;
  --yellow:     #d97706;
  --shadow:     0 18px 48px rgba(15, 23, 42, 0.12);
  --chart-grid: rgba(100, 116, 139, 0.22);
  --chart-text: #64748b;
}

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

html { font-size: 15px; }

body {
  background:
    radial-gradient(circle at top left, rgba(79, 142, 247, 0.16), transparent 34%),
    radial-gradient(circle at top right, rgba(20, 184, 166, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.header-brand svg { opacity: 0.8; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  padding: 0.42rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--surface2), rgba(79, 142, 247, 0.12));
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.theme-toggle:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}
.theme-toggle:active { transform: translateY(0); }
.theme-toggle-icon { line-height: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
}

.btn:active { transform: scale(0.97); }
.btn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dim); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: #3b1a1a;
  color: var(--red);
  border: 1px solid #5a2020;
}
.btn-danger:hover { background: #5a2020; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Container ── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 0.5rem 0.75rem 0.5rem 2.2rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.sort-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
}

.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
}

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.stats-bar span { display: flex; align-items: center; gap: 0.3rem; }

/* ── ASIN Grid ── */
.asin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.asin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}

.asin-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--surface2);
  padding: 0.75rem;
}

.card-image-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 2rem;
}

.card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.card-name {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.card-asin {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: monospace;
}

.card-price {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.1rem;
}

.card-price.no-price { color: var(--text-dim); font-size: 0.82rem; font-weight: 400; }

.card-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.card-metric {
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
}

.card-metric-label {
  display: block;
  color: var(--text-dim);
  font-size: 0.64rem;
  line-height: 1.2;
}

.card-metric-value {
  display: block;
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 0.12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deal-tag-value { color: var(--accent); }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.in-stock  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.status-dot.out-stock { background: var(--red);   box-shadow: 0 0 5px var(--red); }
.status-dot.redirected-oos { background: var(--red); box-shadow: 0 0 5px var(--red); }
.status-dot.unavailable { background: var(--yellow); box-shadow: 0 0 5px var(--yellow); }
.status-dot.unknown   { background: var(--yellow); }

.status-label {
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.card-time { font-size: 0.68rem; color: var(--text-dim); }

/* ── Empty state ── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
}
.empty-state p { margin-top: 0.5rem; }

/* ── Loading spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
html[data-theme="light"] .modal-overlay { background: rgba(15, 23, 42, 0.24); }
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-title { font-size: 1rem; font-weight: 700; }

.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 1.25rem; line-height: 1; padding: 0.1rem;
}
.modal-close:hover { color: var(--text); }

.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.82rem; color: var(--text-dim); margin-bottom: 0.4rem; }

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
  font-family: monospace;
}
.form-input:focus { border-color: var(--accent); }

.form-error { font-size: 0.8rem; color: var(--red); margin-top: 0.35rem; min-height: 1.2em; }
.form-hint  { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.35rem; }

/* ── Detail page ── */
.detail-header {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.detail-image-wrap {
  width: min(25vw, 360px);
  min-width: 240px;
  aspect-ratio: 1 / 1;
  flex: 0 0 min(25vw, 360px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.detail-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.detail-info {
  flex: 1 1 0;
  min-width: 220px;
}

.detail-name {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

.detail-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.detail-meta dt { color: var(--text-dim); }
.detail-meta dd { color: var(--text); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

.detail-price {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin: 0.5rem 0;
}

/* ── Chart sections ── */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.chart-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chart-section-title { font-size: 0.95rem; font-weight: 700; }

.chart-range {
  display: flex;
  gap: 0.4rem;
}

.range-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 5px;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition);
}
.range-btn:hover, .range-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chart-canvas-wrap { position: relative; height: 220px; }

.status-map {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.status-map-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
}

.status-map-item strong { color: var(--text); }

/* ── Seller history table ── */
.seller-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

.seller-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.seller-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.seller-table tr:last-child td { border-bottom: none; }

.seller-table tr:hover td { background: var(--surface2); }

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}
.tag-green { background: rgba(34,197,94,0.15); color: var(--green); }
.tag-red   { background: rgba(239,68,68,0.15); color: var(--red); }
.tag-blue  { background: rgba(79,142,247,0.15); color: var(--accent); }
.tag-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }

/* ── History table column widths ── */
#bsr-history-table td:first-child,
#bsr-history-table th:first-child {
  width: 40%;
}
#seller-offer-table td:first-child,
#seller-offer-table th:first-child {
  width: 50%;
}

/* ── Disabled card ── */
.asin-card-disabled {
  opacity: 0.45;
  filter: grayscale(0.7);
}
.asin-card-disabled:hover {
  opacity: 0.65;
}

/* ── Back link ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
  transition: color var(--transition);
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* ── Date range inputs ── */
.date-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.date-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  outline: none;
}
.date-input:focus { border-color: var(--accent); }
.date-input::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 500;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .container { padding: 1rem; }
  .asin-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .detail-header { flex-direction: column; }
  .detail-image-wrap {
    width: 100%;
    max-width: 240px;
    min-width: 0;
    flex: 0 0 auto;
  }
  .header { padding: 0 1rem; }
  .header-brand span { display: none; }
}

@media (max-width: 480px) {
  .asin-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: unset; }
}
