@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,500;1,6..72,500&display=swap");

:root {
  --orange: #e0672c;
  --orange-dark: #c8551f;
  --bg: #f7f3ee;
  --surface: #ffffff;
  --ink: #241f19;
  --ink-soft: #6b6155;
  --ink-faint: #a89d8d;
  --line: rgba(36, 31, 25, 0.09);

  --shadow-border:
    0px 0px 0px 1px rgba(36, 31, 25, 0.07),
    0px 1px 2px -1px rgba(36, 31, 25, 0.06),
    0px 2px 6px 0px rgba(36, 31, 25, 0.04);
  --shadow-border-hover:
    0px 0px 0px 1px rgba(36, 31, 25, 0.1),
    0px 2px 4px -1px rgba(36, 31, 25, 0.08),
    0px 4px 10px 0px rgba(36, 31, 25, 0.06);
  --shadow-raised:
    0px 0px 0px 1px rgba(36, 31, 25, 0.06),
    0px 4px 10px -2px rgba(36, 31, 25, 0.08),
    0px 12px 24px -6px rgba(36, 31, 25, 0.08);

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --radius-card: 20px;
  --radius-field: 12px;
  --radius-btn: 12px;
  --radius-tag: 999px;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  position: relative;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(circle at 15% 10%, rgba(224, 103, 44, 0.06), transparent 45%),
    radial-gradient(circle at 85% 0%, rgba(224, 103, 44, 0.04), transparent 40%);
}

h1, h2, h3 { text-wrap: balance; margin: 0; }
p { text-wrap: pretty; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 243, 238, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

/* ---------- View switch ---------- */

.view-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-border);
}

.view-tab {
  --tap-scale: 0.97;
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition-property: background, color, scale;
  transition-duration: 180ms;
  transition-timing-function: var(--ease);
}
.view-tab:active { scale: var(--tap-scale); }
.view-tab.active { background: var(--ink); color: var(--bg); }

.view-tab-count {
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}
.view-tab-count:empty { display: none; }

.topbar-meta { display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px 5px 11px;
  border-radius: var(--radius-tag);
  background: var(--surface);
  box-shadow: var(--shadow-border);
  color: var(--orange-dark);
}
.topbar-hint { font-size: 12px; color: var(--ink-faint); }

/* ---------- Layout ---------- */

.layout {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 28px 80px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.stage-wide { grid-column: 1 / -1; }
.layout-single { grid-template-columns: 1fr; }
.layout[hidden] { display: none; }

.stage {
  opacity: 0;
  transform: translateY(10px);
  filter: blur(3px);
  animation: stageEnter 480ms var(--ease) forwards;
}
.stage[data-stage="1"] { animation-delay: 0ms; }
.stage[data-stage="2"] { animation-delay: 90ms; }
.stage[data-stage="3"] { animation-delay: 180ms; }
.stage[data-stage="4"] { animation-delay: 270ms; }

@keyframes stageEnter {
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.stage-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 0 4px 14px;
}

.stage-num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.stage-head h2 {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stage-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 3px 0 0;
  line-height: 1.4;
}

/* ---------- Card ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-border);
  transition-property: box-shadow;
  transition-duration: 200ms;
  transition-timing-function: var(--ease);
}

.card-flush { padding: 8px; }

/* ---------- Fields ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-of-type { margin-bottom: 0; }
.field-compact { flex: none; width: 200px; margin-bottom: 0; }
.field-row { display: flex; gap: 12px; margin-bottom: 14px; }
.field-row .field { margin-bottom: 0; flex: 1; }

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

input, textarea {
  width: 100%;
  padding: 10px 13px;
  border: none;
  border-radius: var(--radius-field);
  background: var(--bg);
  box-shadow: 0 0 0 1px transparent;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  resize: vertical;
  transition-property: box-shadow, background;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

input:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 1.5px var(--orange), var(--shadow-border);
}

textarea { min-height: 82px; line-height: 1.5; }

input[type="number"] { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */

.btn {
  --tap-scale: 0.96;
  position: relative;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-btn);
  padding: 12px 18px 11px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.3;
  transition-property: scale, box-shadow, background, opacity;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}

.btn:active:not(:disabled) { scale: var(--tap-scale); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-block { width: 100%; margin-top: 16px; }

.btn-primary {
  background: var(--orange);
  color: white;
  box-shadow: 0 1px 2px rgba(224, 103, 44, 0.25), 0 4px 10px -3px rgba(224, 103, 44, 0.4);
}
.btn-primary:hover:not(:disabled) { background: var(--orange-dark); }

.btn-secondary {
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-border);
}
.btn-secondary:hover:not(:disabled) { box-shadow: var(--shadow-border-hover); }

.btn-label { }
.btn-sub { font-size: 10.5px; font-weight: 500; opacity: 0.72; }

.btn-copy {
  --tap-scale: 0.96;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: var(--radius-tag);
  transition-property: scale, background, color;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}
.btn-copy:hover { background: var(--bg); color: var(--ink); }
.btn-copy:active { scale: 0.96; }

.image-actions { display: flex; align-items: flex-end; gap: 12px; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--bg);
  border-radius: 14px;
  margin-bottom: 8px;
}

.tab {
  --tap-scale: 0.97;
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition-property: background, color, scale, box-shadow;
  transition-duration: 180ms;
  transition-timing-function: var(--ease);
}

.tab:active { scale: var(--tap-scale); }

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-border);
}

/* ---------- Result box ---------- */

.result-box {
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg);
  border-radius: calc(var(--radius-card) - 8px);
  padding: 16px;
  max-height: 320px;
  overflow-y: auto;
  color: var(--ink);
  white-space: pre-wrap;
}

.result-box-tight { max-height: none; }

.empty-hint { color: var(--ink-faint); font-size: 12.5px; margin: 0; }

.result-group { margin-top: 16px; }
.result-group:first-child { margin-top: 0; }
.result-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.result-group-head label { margin: 0; }

.listing-result {
  margin-top: 16px;
  opacity: 0;
  transform: translateY(8px);
  animation: stageEnter 380ms var(--ease) forwards;
}

/* ---------- Tags ---------- */

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  background: var(--bg);
  padding: 5px 12px;
  border-radius: var(--radius-tag);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  opacity: 0;
  transform: scale(0.9);
  animation: tagIn 320ms var(--ease) forwards;
}
@keyframes tagIn {
  to { opacity: 1; transform: scale(1); }
}

/* ---------- Images ---------- */

.img-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.img-grid-single { grid-template-columns: 1fr; max-width: 420px; }
.img-grid:empty { display: none; }

.img-grid img {
  width: 100%;
  display: block;
  border-radius: 14px;
  outline: 1px solid rgba(36, 31, 25, 0.1);
  outline-offset: -1px;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  filter: blur(6px);
  animation: imgIn 500ms var(--ease) forwards;
}

@keyframes imgIn {
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

/* ---------- Misc ---------- */

.divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
}

.status {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 10px 0 0;
  min-height: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status:empty { margin: 0; min-height: 0; }
.status.status-error { color: #c1442a; }

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-tag);
  box-shadow: var(--shadow-raised);
  opacity: 0;
  pointer-events: none;
  transition-property: opacity, transform;
  transition-duration: 220ms;
  transition-timing-function: var(--ease);
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Rich research content (markdown render) ---------- */

.result-box-rich h4 {
  font-size: 13px;
  font-weight: 700;
  margin: 14px 0 6px;
}
.result-box-rich h4:first-child { margin-top: 0; }
.result-box-rich p { margin: 6px 0; }
.result-box-rich ul { margin: 4px 0 10px; padding-left: 18px; }
.result-box-rich li { margin: 3px 0; }
.result-box-rich strong { font-weight: 700; color: var(--ink); }

/* ---------- Products list ---------- */

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

.product-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-border);
  padding: 16px;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 16px;
  align-items: center;
  transition-property: box-shadow;
  transition-duration: 200ms;
  transition-timing-function: var(--ease);
  opacity: 0;
  transform: translateY(8px);
  animation: stageEnter 380ms var(--ease) forwards;
}
.product-card:hover { box-shadow: var(--shadow-border-hover); }

.product-thumb {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  object-fit: cover;
  outline: 1px solid rgba(36, 31, 25, 0.1);
  outline-offset: -1px;
  background: var(--bg);
}

.product-info { min-width: 0; }
.product-title {
  font-size: 13.5px;
  font-weight: 600;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-meta {
  font-size: 11.5px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: var(--radius-tag);
}
.status-badge.draft_pending { background: #fdf0e0; color: #96600f; }
.status-badge.draft_created { background: #e4ecfb; color: #2b57ab; }
.status-badge.published { background: #e1f3e4; color: #1f7a35; }

.product-actions { display: flex; gap: 8px; flex: none; }
.product-actions .btn { padding: 8px 13px 7px; font-size: 12px; }

.products-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-faint);
  font-size: 13px;
}

/* ---------- Product detail overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  justify-content: flex-end;
}
.overlay[hidden] { display: none; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(36, 31, 25, 0.35);
  backdrop-filter: blur(2px);
  opacity: 0;
  animation: fadeIn 200ms var(--ease) forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

.overlay-panel {
  position: relative;
  width: min(720px, 92vw);
  height: 100%;
  background: var(--bg);
  box-shadow: var(--shadow-raised);
  overflow-y: auto;
  transform: translateX(24px);
  opacity: 0;
  animation: panelIn 260ms var(--ease) forwards;
}
@keyframes panelIn { to { transform: translateX(0); opacity: 1; } }

.overlay-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(247, 243, 238, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-icon {
  --tap-scale: 0.94;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition-property: scale, box-shadow, color;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}
.btn-icon:hover { color: var(--ink); box-shadow: var(--shadow-border-hover); }
.btn-icon:active { scale: var(--tap-scale); }

.overlay-body { padding: 20px; }

.detail-section { margin-bottom: 24px; }
.detail-section h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.detail-hero {
  width: 100%;
  border-radius: var(--radius-card);
  outline: 1px solid rgba(36, 31, 25, 0.1);
  outline-offset: -1px;
  margin-bottom: 8px;
}

.detail-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 6px;
}

.detail-price {
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- Job status panel ---------- */

.job-steps { display: flex; flex-direction: column; gap: 2px; }

.job-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(6px);
  animation: stageEnter 320ms var(--ease) forwards;
}

.job-step-icon {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.job-step-icon.done { background: #e1f3e4; color: #1f7a35; }
.job-step-icon.in_progress { background: transparent; }
.job-step-icon.error { background: #fbe1de; color: #c1442a; }

.job-step-label { flex: 1; color: var(--ink); }
.job-step.in_progress .job-step-label { color: var(--ink-soft); }
.job-step-time { font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.job-error-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fbe1de;
  color: #a3341c;
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- Ads guide ---------- */

.ads-guide {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.ads-section h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 10px;
}

.ads-section p { font-size: 13px; color: var(--ink-soft); margin: 0 0 8px; }

.ads-section ul, .ads-section ol {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ads-section li { font-size: 13px; line-height: 1.5; color: var(--ink); }
.ads-section strong { font-weight: 700; }

@media (max-width: 860px) {
  .ads-guide { grid-template-columns: 1fr; }
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; }
  .image-actions { flex-direction: column; align-items: stretch; }
  .field-compact { width: auto; }
}
