/* UGCflow — dark, calm tones, purple accent */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1115;
  --bg-soft: #141821;
  --surface: #181d27;
  --surface-2: #1f2531;
  --border: #262d3a;
  --text: #e8eaef;
  --text-dim: #98a1b3;
  --text-faint: #6b7485;
  --accent: #7c4dff;
  --accent-soft: rgba(124, 77, 255, 0.14);
  --accent-deep: #5b2fd9;
  --brand-lav: #a78bfa;
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.14);
  --ok: #58b26a;
  --ok-soft: rgba(88, 178, 106, 0.14);
  --warn: #d8a015;
  --warn-soft: rgba(216, 160, 21, 0.14);
  --radius: 12px;
}

html { -webkit-text-size-adjust: 100%; height: 100%; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  height: 100%;
}
/* app shell: fixed header/tabs, content scrolls internally so the Publish bar
   can pin to the visible bottom even inside iframes (artifact viewer, iOS) */
#app { height: 100dvh; display: flex; flex-direction: column; min-height: 0; }
.topbar, .tabs { flex: none; width: 100%; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-sub { color: var(--text-dim); font-size: 13px; margin-top: -8px; }
.mock-note { color: var(--text-faint); font-size: 12px; text-align: center; }

/* ---------- brand / topbar ---------- */
.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 22px; }
.brand .brand-flow { color: var(--brand-lav); font-weight: 600; }
.brand-logo { width: 22px; height: 22px; border-radius: 6px; display: block; }
.brand.big .brand-logo { width: 30px; height: 30px; border-radius: 8px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; max-width: 980px; margin: 0 auto;
}
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.balance {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 7px 14px; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums;
  display: flex; flex-direction: column; gap: 2px; align-items: flex-end;
}
.bal-row b { color: var(--text); font-weight: 600; margin-left: 6px; }
.bal-row.topup { color: var(--warn); font-weight: 600; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 0 20px 14px; max-width: 980px; margin: 0 auto; }
.tab {
  background: none; border: 1px solid transparent; color: var(--text-dim);
  font: inherit; font-weight: 600; padding: 7px 16px; border-radius: 999px; cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); border-color: var(--border); }
.badge {
  background: var(--accent); color: #fff; font-size: 11px; border-radius: 999px;
  padding: 1px 7px; margin-left: 4px; vertical-align: 1px;
}

/* ---------- layout / cards ---------- */
.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view-inner { max-width: 980px; margin: 0 auto; padding: 2px 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card h2 { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-bottom: 12px; letter-spacing: 0.01em; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.sec-head-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1 1 auto; }
.sec-head-left h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chips (groups) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* ---------- dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 34px 16px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 26px; color: var(--accent); margin-bottom: 6px; }
.dz-hint { color: var(--text-faint); font-size: 13px; margin-top: 4px; }
.file-loaded { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.file-meta { display: flex; align-items: center; gap: 12px; }
.file-icon { font-size: 22px; }
.file-name { font-weight: 600; }
.file-sub { color: var(--text-dim); font-size: 13px; }
.file-sub.err { color: var(--danger); font-weight: 600; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field + .field { margin-top: 12px; }
.field > span { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font: inherit; padding: 10px 12px; width: 100%;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.count { position: absolute; right: 2px; top: 0; font-size: 12px; color: var(--text-faint); font-style: normal; }
.count.over { color: var(--danger); font-weight: 700; }
.token-btn {
  background: var(--accent-soft); color: var(--accent); border: none; border-radius: 6px;
  font: inherit; font-size: 12px; font-weight: 600; padding: 2px 8px; cursor: pointer;
}
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text-dim); }
.hint { color: var(--text-faint); font-size: 13px; margin-top: 8px; }
.hint.center { text-align: center; }

/* ---------- segmented (uniques) ---------- */
.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  background: none; border: none; color: var(--text-dim); font: inherit; font-weight: 600;
  padding: 7px 16px; border-radius: 8px; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #fff; }
.uniq-custom { max-width: 110px; margin-left: 10px; }

/* ---------- item grid ---------- */
.val-summary { font-size: 13px; color: var(--text-dim); }
.item-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px; margin-top: 12px;
}
.item-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.item-card.removed { opacity: 0.35; }
.thumb { position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 44px; }
.thumb .glyph { filter: saturate(0.9); }
.thumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: transparent; }
.remove-btn {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(15,17,21,0.7); color: var(--text-dim); border: none; cursor: pointer; font-size: 14px; line-height: 1;
}
.remove-btn:hover { color: var(--danger); }
.reupload-btn {
  position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(15,17,21,0.7); color: var(--text-dim); border: none; cursor: pointer; font-size: 14px; line-height: 1;
}
.reupload-btn:hover { color: var(--ok, #6fcf8f); }
.type-tag {
  position: absolute; left: 8px; bottom: 8px; background: rgba(15,17,21,0.75);
  border-radius: 6px; font-size: 11px; padding: 3px 7px; color: var(--text-dim);
}
.item-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.item-name { position: relative; }
.item-name input { padding: 7px 9px; font-size: 14px; }
.item-name .count { top: -16px; }
.item-row { display: flex; gap: 6px; }
.item-row select { font-size: 13px; padding: 6px 8px; color: var(--text-dim); background-position: right 8px center; }
.val {
  display: flex; align-items: center; gap: 6px; font-size: 12.5px; border-radius: 7px; padding: 5px 9px;
}
.val.pending { background: var(--bg-soft); color: var(--text-dim); }
.val.ok { background: var(--ok-soft); color: var(--ok); }
.val.warn { background: var(--warn-soft); color: var(--warn); }
.val.err { background: var(--danger-soft); color: var(--danger); }
.spinner {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--text-dim);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; border-radius: 10px; padding: 11px 20px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { transform: scale(0.98); }
.btn.ghost { background: none; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
a.btn { text-decoration: none; display: inline-block; }
.verify-link { padding: 6px 12px; font-size: 13px; white-space: nowrap; }

/* ---------- publish button (in topbar) ---------- */
.topbar .btn.primary { padding: 9px 22px; font-size: 15px; box-shadow: 0 2px 12px rgba(124, 77, 255, 0.35); }

/* ---------- status view ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--text-dim); }
#batches-list { display: flex; flex-direction: column; gap: 14px; }
.stage-chip {
  background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600;
  border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}
.stage-chip.done { background: var(--ok-soft); color: var(--ok); }
.stage-chip.sim { background: var(--warn-soft); color: var(--warn); }

/* ---------- dry-run banner ---------- */
.dryrun-banner {
  flex: none; text-align: center; font-size: 13px; font-weight: 600;
  background: var(--warn-soft); color: var(--warn);
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.progress { height: 6px; background: var(--bg-soft); border-radius: 999px; margin: 14px 0 10px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .5s ease; }
.progress-fill.done { background: var(--ok); }
.ab-counts { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.ab-counts b { color: var(--text); font-variant-numeric: tabular-nums; }
.status-list { display: flex; flex-direction: column; }
.status-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 2px;
  border-top: 1px solid var(--border); font-size: 14px;
}
.status-row .mini-thumb {
  width: 34px; height: 34px; border-radius: 8px; flex: none; position: relative;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.status-row .s-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-row .s-err { color: var(--danger); font-size: 12.5px; }
.pill { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.dim { background: var(--bg-soft); color: var(--text-dim); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- history ---------- */
.history { display: flex; flex-direction: column; }
.hist-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-top: 1px solid var(--border);
}
.hist-row:first-child { border-top: none; }
.hist-name { font-weight: 600; font-size: 14px; }
.hist-sub { color: var(--text-faint); font-size: 12.5px; }

/* ---------- mobile ---------- */
@media (max-width: 480px) {
  .view-inner { padding: 0 12px 20px; }
  .topbar { padding: 12px 14px; }
  .tabs { padding: 0 14px 12px; }
  .item-grid { grid-template-columns: repeat(2, 1fr); }
  .thumb { font-size: 36px; }
  .card { padding: 14px; }
}

/* ---- texture-combo strip ---- */
.tex-strip { margin-bottom: 12px; }
.tex-chip { display: inline-flex; align-items: center; gap: 7px; cursor: default; }
.tex-chip .sw { width: 12px; height: 12px; border-radius: 4px; display: inline-block;
  border: 1px solid #ffffff22; }
.tex-row { flex-wrap: wrap; row-gap: 6px; margin-bottom: 8px; }
.ref-row { display: flex; gap: 8px; margin-bottom: 4px; }
.ref-row input { flex: 1; }
.ref-row input.required { border-color: var(--accent); }
#ref-status.err { color: var(--danger); font-weight: 600; }
#ref-status.ok { color: var(--ok, #4e9e5f); font-weight: 600; }

/* ================= My Catalog (analytics) ================= */
.cat-hero { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 2px 0 14px; }
.cat-hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.cat-hero-deltas { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-groups { display: flex; flex-direction: column; }
.cg-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  border-top: 1px solid var(--border); font-size: 14px;
}
.cg-row b { font-variant-numeric: tabular-nums; margin-left: auto; }
.cg-row .cg-pills { display: flex; gap: 6px; flex: none; }
.cg-row.cg-zero { opacity: 0.45; }
.cg-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; margin-right: 2px; vertical-align: 1px; }

.cat-controls-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg-small button { padding: 6px 12px; font-size: 13px; }
.seg button[disabled] { opacity: 0.4; cursor: not-allowed; }
.cat-group-chips { margin-top: 12px; }
.cat-group-chips .chip { font-size: 13px; padding: 6px 12px; }

.chart-card .uplot-host { min-height: 300px; margin-top: 4px; }
.chart-empty { padding: 60px 0; }
.chips.drill { margin-top: 10px; }
.chip-drill { font-size: 12.5px; padding: 5px 11px; }
.chip-x { color: var(--text-faint); margin-left: 3px; }
.crumb-back {
  background: none; border: none; color: var(--accent); font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; padding: 0;
}

.item-picker { position: relative; margin-bottom: 10px; }
.suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.suggest-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px; width: 100%;
  background: none; border: none; color: var(--text); font: inherit; font-size: 13.5px;
  padding: 9px 12px; cursor: pointer; text-align: left;
}
.suggest-row:hover { background: var(--surface); }
.suggest-row .s-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-row .s-sub { color: var(--text-faint); font-size: 12px; flex: none; }
#cat-item-chips { margin-bottom: 6px; }

.toplist { display: flex; flex-direction: column; }
.top-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 2px;
  border-top: 1px solid var(--border); font-size: 14px;
}
.top-rank { color: var(--text-faint); font-size: 12.5px; width: 18px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.top-thumb {
  width: 40px; height: 40px; border-radius: 8px; flex: none; object-fit: cover;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.top-thumb.noimg { visibility: hidden; }
.top-main { flex: 1; min-width: 0; }
.top-main a { color: var(--text); text-decoration: none; font-weight: 600; display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-main a:hover { color: var(--accent); }
.top-sub { color: var(--text-faint); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spark { flex: none; opacity: 0.9; }
.top-metric { flex: none; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.top-metric b { font-variant-numeric: tabular-nums; }
.tm-sub { color: var(--text-faint); font-size: 12px; }

/* uPlot dark-theme overrides */
.uplot { font-family: inherit; }
.u-legend { color: var(--text-dim); font-size: 12px !important; margin-top: 6px; }
.u-legend .u-label { color: var(--text-dim); }
.u-legend .u-value { color: var(--text); font-variant-numeric: tabular-nums; }
.u-legend th, .u-legend td { padding: 2px 4px; }
.u-select { background: rgba(124, 77, 255, 0.12); }
.u-cursor-x { border-right: 1px dashed var(--text-faint); }

@media (max-width: 560px) {
  .cat-hero-value { font-size: 30px; }
  .cg-row .cg-pills { display: none; }
  .spark { display: none; }
  .cat-group-chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .cat-group-chips .chip { white-space: nowrap; flex: none; }
}

/* ---- My Catalog v2 (feedback round) ---- */
/* breathing room between analytics sections + brighter section titles */
#cat-body { display: flex; flex-direction: column; gap: 28px; }
#cat-body .card { padding: 20px; }
#cat-body .card > .sec-head > h2,
#cat-body .card .sec-head-left h2 { color: var(--text); font-size: 15px; }
/* the Revenue title is short — never ellipsize it; the as-of text wraps instead */
#cat-summary .sec-head-left h2 { flex: none; }
#cat-summary .sec-head-left { flex-wrap: wrap; }
#cat-body .sec-head { margin-bottom: 10px; }
#cat-body .sec-head .seg { align-self: center; }

/* topbar currency switch (global for all analytics) */
.topbar-cluster { display: flex; align-items: center; gap: 16px; }
.topbar-cur { align-self: center; }
.topbar-cur button { padding: 7px 12px; font-size: 14px; }

/* summary: donut + group table side by side */
.cat-sum-row { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.cat-pie { flex: none; }
.cat-pie .pie-val { fill: var(--text); font-size: 20px; font-weight: 700; }
.cat-pie .pie-sub { fill: var(--text-faint); font-size: 11px; }
.cat-groups { flex: 1 1 320px; min-width: 0; }
.cg-row.cg-manual { border-top: 1px dashed var(--border); color: var(--text-dim); }
.cg-row.cg-manual .chip-drill { padding: 3px 10px; font-size: 12px; }

/* long top lists scroll inside their card */
.toplist { max-height: 640px; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }

@media (max-width: 560px) {
  .cat-sum-row { justify-content: center; }
  .topbar-cluster { flex-direction: column; align-items: flex-end; gap: 6px; }
}

/* ---- My Catalog v3 (feedback round 2) ---- */
/* uPlot legend: solid round color dots instead of empty squares, no colons */
.u-legend .u-marker {
  width: 10px !important; height: 10px !important;
  border-radius: 50%; border-width: 5px !important;
}
.u-inline th::after { content: "" !important; }
.u-legend th { font-weight: 500; }

/* per-list toolbar: group dropdown (+ range seg on Best Sellers) */
.list-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grp-sel {
  width: auto; min-width: 130px; padding: 7px 28px 7px 10px; font-size: 13px;
  color: var(--text-dim); background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%2398a1b3' fill='none' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
