/* eBay-flavored admin UI. Uses eBay's brand palette (red/blue/yellow/green)
   and Market Sans-ish system font stack. */

:root {
  --ebay-red:    #e53238;
  --ebay-blue:   #0064d2;
  --ebay-yellow: #f5af02;
  --ebay-green:  #86b817;
  --ink:         #111820;
  --ink-2:       #3b4044;
  --muted:       #707578;
  --line:        #e5e5e5;
  --bg:          #f7f7f7;
  --card:        #ffffff;
  --link:        #0654ba;
  --danger:      #c7252a;
  --shadow:      0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
  --radius:      8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Market Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-style: italic;
  font-weight: 900;
  font-size: 26px;
  letter-spacing: -0.5px;
  display: flex;
  align-items: baseline;
  gap: 0;
}
.brand .e { color: var(--ebay-red); }
.brand .b { color: var(--ebay-blue); }
.brand .a { color: var(--ebay-yellow); }
.brand .y { color: var(--ebay-green); }
.brand-suffix {
  margin-left: 10px;
  color: var(--muted);
  font-style: normal;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.topbar nav {
  display: flex;
  gap: 18px;
  margin-left: auto;
  font-weight: 600;
}
.topbar nav a {
  color: var(--ink-2);
  cursor: pointer;
}
.topbar nav a.active { color: var(--ebay-blue); }
.topbar .logout {
  margin-left: 8px;
  font-weight: 600;
  color: var(--ebay-red);
  cursor: pointer;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
h1 {
  font-size: 22px;
  margin: 0 0 4px 0;
  font-weight: 700;
}
h2 {
  font-size: 17px;
  margin: 0 0 12px 0;
  font-weight: 700;
}
p.muted { color: var(--muted); margin: 4px 0 16px 0; }

/* ---------- Login ---------- */
.login-wrap {
  max-width: 380px;
  margin: 80px auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-wrap .brand { justify-content: center; font-size: 38px; margin-bottom: 8px; }
.login-wrap h1 { text-align: center; font-size: 18px; margin-bottom: 22px; }

/* ---------- Forms ---------- */
label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-2);
  margin: 14px 0 6px;
}
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #c0c4c8;
  border-radius: 6px;
  font: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ebay-blue);
  box-shadow: 0 0 0 3px rgba(0,100,210,0.15);
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 16px;
  margin-top: 4px;
}
.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin: 0;
  cursor: pointer;
  color: var(--ink);
}
.row { display: flex; gap: 14px; }
.row > * { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 24px;
  border: 1px solid var(--ebay-blue);
  background: var(--ebay-blue);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: #004a9a; border-color: #004a9a; }
.btn.secondary {
  background: #fff;
  color: var(--ebay-blue);
}
.btn.secondary:hover { background: #f0f6ff; }
.btn.danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
}
.btn.danger:hover { background: #fdecec; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover { background: #eee; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-weight: 700;
  color: var(--ink-2);
  background: #fafafa;
  position: sticky;
  top: 0;
}
tr:hover td { background: #fbfdff; }

/* ---------- Product cell (Products table, first column) ---------- */
/* Three stacked elements with breathing room: name (bold), keywords
   (mono), status row (Paused pill + listings-seen count + new-since-
   last-scan count). The fixed gaps give a clean visual hierarchy and
   keep the Paused badge from colliding with the stat text. */
.product-cell { min-width: 220px; }
.product-name {
  font-weight: 600;
  color: var(--ink);
  font-size: 14px;
  margin-bottom: 3px;
}
.product-keywords {
  color: var(--muted);
  font-size: 12.5px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  margin-bottom: 6px;
  word-break: break-word;
}
.product-status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.product-stat {
  color: var(--muted);
  font-size: 12px;
}
/* Highlight variant for fresh new-listing counts — applied when
   `new_since_last_scan > 0` so a recent scan that found something
   draws the eye. Color matches the green pill palette. */
.product-stat.highlight {
  color: #4d7000;
  font-weight: 600;
}

/* ---------- Actions cell (Products table, last column) ---------- */
/* Buttons stacked vertically so the column stays narrow. Each button
   stretches to the column width so the click targets line up cleanly
   regardless of label length ("Scan" vs "Scanning…"). */
.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
  min-width: 80px;
}
.actions-stack .btn {
  width: 100%;
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef3f7;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  margin: 0 4px 4px 0;
  /* Keep multi-word pill labels ("Buy It Now", "Best Offer") on one line.
     Without this, narrow table cells let the cell shrink to the pill's
     intrinsic width and the text wraps mid-pill. */
  white-space: nowrap;
}
.pill.green  { background: #ecf5d9; color: #4d7000; }
.pill.red    { background: #fde2e3; color: #a01a1f; }
.pill.blue   { background: #d9e7fa; color: #003a82; }
.pill.yellow { background: #fdf0cc; color: #8c6300; }
.pill.gray   { background: #eef0f2; color: #4a4f54; }

/* Status badges shown next to "last scanned" timestamps. */
.status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  margin-right: 4px;
  vertical-align: 1px;
}
.status-badge.ok       { background: #ecf5d9; color: #4d7000; }
.status-badge.err      { background: #fde2e3; color: #a01a1f; }
.status-badge.init     { background: #d9e7fa; color: #003a82; }
.status-badge.unknown  { background: #eef0f2; color: #4a4f54; }
.status-badge.scanning {
  background: #d9e7fa;
  color: #003a82;
  /* Subtle pulse so the user can see it's actively running (a single
     instant-render of "SCANNING" is easy to mistake for a stale state). */
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Source-tag pill — single letter, sits to the LEFT of the status badge.
   "A" = automatic / scheduler-driven scan, "M" = manual (a user clicked).
   Sized as a fixed square so A and M align identically in the table. */
.source-tag {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
  vertical-align: 1px;
  letter-spacing: 0;
}
.source-tag.auto   { background: #eef0f2; color: #4a4f54; }
.source-tag.manual { background: #d9e7fa; color: #003a82; }

/* Hint that the scan-status cell carries a full-detail tooltip on hover.
   white-space: nowrap keeps source-tag + badge on a single line. */
.scan-status {
  cursor: help;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center;
}
.modal header h2 { margin: 0; }
.modal header .close {
  margin-left: auto; cursor: pointer; color: var(--muted);
  font-size: 20px; background: transparent; border: 0;
}
.modal .body { padding: 16px 20px; }
.modal footer {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
  background: #fafafa;
}

/* ---------- Toast ---------- */
/* Width-capped so long server error strings (multi-sentence Bright
   Data detail) wrap into a readable block instead of running off the
   right edge. `pre-wrap` preserves embedded newlines so multi-line
   `HTTPException(detail=…)` messages stay legible. `overflow-wrap`
   covers the long-unbroken-token case (snapshot ids, URLs). */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  max-width: min(480px, calc(100vw - 48px));
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  z-index: 200;
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: #1f7a1f; }

/* ---------- Misc ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid #c0c4c8;
  border-top-color: var(--ebay-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

/* Right-side button cluster in section headers — keeps action buttons on
   one row, never wraps under the description text on the left. */
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;        /* don't get squashed by long description text */
  white-space: nowrap;   /* belt-and-braces against any individual button wrapping */
}
.muted-small { color: var(--muted); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.kbd {
  display: inline-block;
  background: #eef0f2; border: 1px solid #d0d4d8;
  border-radius: 4px; padding: 1px 6px; font-family: ui-monospace, monospace;
  font-size: 12px;
}

/* ---------- "Last scan" block on the Settings tab ---------- */
/* Shown under the Save Settings button. Timestamp on its own line; the
   per-metric chips wrap freely so the long Cloud-Scheduler summary string
   doesn't fight the Save button for horizontal space. */
.last-scan {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.last-scan-time {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 8px;
}
.last-scan-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.last-scan-metrics .chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef0f2;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Non-zero counters get a brighter tone so the eye lands on them. Errors and
   new-listings get their own colors so they stand out from neutral counters. */
.last-scan-metrics .chip.nonzero {
  background: #d9e7fa;
  color: #003a82;
  font-weight: 600;
}
.last-scan-metrics .chip.chip-errors.nonzero {
  background: #fde2e3;
  color: #a01a1f;
}
.last-scan-metrics .chip.chip-new-listings.nonzero {
  background: #ecf5d9;
  color: #4d7000;
}

/* ---------- Keyword-tips block (inside the product modal) ---------- */
/* Appears directly under the Keywords field, where the user is actually
   composing a search. Visually distinct from a regular hint (the box ties
   the four bullets together) but quiet enough not to compete with the
   form fields below it. */
.keyword-tips {
  margin: 8px 0 4px;
  padding: 10px 12px;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.keyword-tips ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.7;
  color: var(--ink-2);
  font-size: 12.5px;
}
.keyword-tips li { margin: 0; }
