:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --panel: #ffffff;
  --text: #17201a;
  --muted: #66706a;
  --line: #dce1dd;
  --green: #1f7a4a;
  --red: #b33535;
  --blue: #2d5f9a;
  --amber: #9a6a16;
  --shadow: 0 10px 24px rgba(24, 38, 31, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121714;
  --panel: #1b211d;
  --text: #edf3ee;
  --muted: #a6b2ab;
  --line: #334039;
  --green: #45a875;
  --red: #e06d6d;
  --blue: #7da7e5;
  --amber: #d4a548;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
}

.filters {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  max-height: 100vh;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--amber);
  margin-top: 6px;
}

.status-dot.ok {
  background: var(--green);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

section h2 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.store-grid,
.toggles {
  display: grid;
  gap: 8px;
}

.store-grid {
  grid-template-columns: 1fr 1fr;
}

label {
  color: var(--text);
}

.store-grid label,
.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
  font-size: 14px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
}

.field.hidden,
section.hidden,
.hidden {
  display: none !important;
}

.hint {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(31, 122, 74, 0.18);
  border-color: var(--green);
}

.two,
.range-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-top: 16px;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 9px 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: #b8c4bd;
}

button.primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.content {
  padding: 20px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.topbar h2 {
  font-size: 24px;
  line-height: 1.2;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.summary span,
.badge {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}

.result-controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  margin-bottom: 14px;
}

.result-controls-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.result-controls-head h2 {
  margin: 0;
}

.result-controls-head span {
  color: var(--muted);
  font-size: 12px;
}

.result-control-grid {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(220px, 1fr);
  gap: 10px;
}

.result-control-grid.wide {
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
}

.result-control-grid.text-grid {
  grid-template-columns: repeat(2, minmax(180px, 1fr));
}

.result-toggles {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.result-controls .field {
  margin-bottom: 10px;
}

.result-controls .toggles label {
  min-height: 38px;
}

.run-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.run-panel.timeline {
  grid-template-columns: 1fr;
}

.run-status {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 10px;
  min-height: 72px;
}

.run-status strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.run-status span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.run-status.error {
  border-color: rgba(179, 53, 53, 0.35);
}

.run-status.error strong {
  color: var(--red);
}

.step-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 12px;
}

.step-status strong {
  display: block;
  font-size: 14px;
  margin-bottom: 3px;
}

.step-status span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.step-status time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.step-status.running {
  border-left: 4px solid var(--blue);
}

.step-status.done {
  border-left: 4px solid var(--green);
}

.step-status.error {
  border-left: 4px solid var(--red);
}

.step-status.error strong {
  color: var(--red);
}

.results {
  display: grid;
  gap: 12px;
}

.empty {
  border: 1px dashed #b9c3bd;
  border-radius: 8px;
  padding: 26px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.empty strong {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
}

.product-card {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  box-shadow: var(--shadow);
}

.thumb {
  width: 132px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 82%, var(--bg));
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.product-main {
  min-width: 0;
  display: grid;
  gap: 9px;
}

.product-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.retailer {
  color: var(--blue);
  font-size: 12px;
  margin-bottom: 3px;
}

.product-head h3 {
  font-size: 17px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.price {
  font-weight: 700;
  font-size: 19px;
  white-space: nowrap;
}

.metrics,
.nutrition {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.metric,
.nutrient {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
  font-size: 13px;
}

.metric strong,
.nutrient strong {
  margin-right: 4px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.open-link {
  color: var(--green);
  text-decoration: none;
  font-weight: 600;
  width: max-content;
}

.open-link:hover {
  text-decoration: underline;
}

.assist-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green);
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.assist-link:hover {
  border-color: var(--green);
}

.remote-body {
  min-height: 100vh;
}

.remote-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 10px;
}

.remote-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.remote-header h1 {
  font-size: 18px;
}

.remote-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.remote-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.remote-status .status-dot {
  margin-top: 5px;
}

.remote-status strong,
.remote-status span {
  display: block;
}

.remote-status span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  max-height: 34px;
  overflow: hidden;
}

.remote-toolbar,
.remote-inputs {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.remote-toolbar {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 8px 0;
}

.remote-toolbar.compact-toolbar {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(120px, 1.15fr) minmax(120px, 1.3fr);
}

.remote-toolbar.full-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 0;
  padding-bottom: 0;
}

.remote-toolbar button {
  min-height: 36px;
  padding: 6px 8px;
  font-size: 13px;
}

.confirm-button:not(:disabled) {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.remote-inputs {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.remote-inputs .field {
  margin-bottom: 0;
}

.remote-input-buttons {
  display: flex;
  gap: 8px;
}

.remote-extra {
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.remote-extra summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.remote-extra .remote-inputs {
  margin-top: 8px;
  border-bottom: 0;
}

.captcha-compact {
  display: grid;
  gap: 12px;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--line);
}

.captcha-compact.no-captcha {
  display: none;
}

.captcha-visual {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 220px;
  overflow: hidden;
}

.captcha-visual img {
  width: min(260px, 72vw);
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-drag: none;
}

.captcha-slider-panel {
  display: grid;
  gap: 8px;
}

.captcha-slider-touch {
  position: relative;
  display: block;
  width: min(360px, 100%);
  margin: 0 auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.captcha-slider-touch.dragging {
  cursor: grabbing;
}

.captcha-slider-touch img {
  display: block;
  width: 100%;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.captcha-slider-cursor {
  position: absolute;
  display: none;
  left: 0;
  top: 50%;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 2px solid color-mix(in srgb, var(--green) 72%, #fff);
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 16%, transparent);
  box-shadow: 0 7px 18px rgba(24, 38, 31, 0.18);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.captcha-slider-touch.has-position .captcha-slider-cursor {
  display: block;
}

.captcha-slider-cursor::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: inherit;
  background: var(--green);
}

.remote-stage {
  position: relative;
  padding: 0;
  margin: 8px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  height: min(720px, calc(100dvh - 152px));
  min-height: 390px;
}

.remote-stage img {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  object-fit: contain;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.remote-loader {
  display: none;
  position: absolute;
  inset: auto 10px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--muted);
  font-size: 13px;
}

.remote-loader.visible {
  display: block;
}

.remote-touch {
  display: none;
  position: absolute;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border: 2px solid var(--green);
  border-radius: 999px;
  background: rgba(69, 168, 117, 0.15);
  pointer-events: none;
}

.remote-touch.visible {
  display: block;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .filters {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    display: grid;
  }

  .summary {
    justify-content: flex-start;
  }

  .result-control-grid,
  .result-control-grid.text-grid {
    grid-template-columns: 1fr;
  }

  .remote-toolbar,
  .remote-inputs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .remote-toolbar.full-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .remote-input-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .content,
  .filters {
    padding: 14px;
  }

  .store-grid,
  .two,
  .range-grid {
    grid-template-columns: 1fr;
  }

  .product-card {
    grid-template-columns: 1fr;
  }

  .thumb {
    width: 100%;
    max-height: 220px;
  }

  .product-head {
    grid-template-columns: 1fr;
  }

  .price {
    white-space: normal;
  }

  .remote-shell {
    padding: 8px;
  }

  .remote-header {
    align-items: stretch;
  }

  .remote-header-actions {
    justify-content: flex-end;
  }

  .remote-toolbar {
    gap: 8px;
  }

  .remote-toolbar.compact-toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .captcha-visual {
    min-height: 190px;
  }

  .captcha-visual img {
    width: min(220px, 76vw);
  }

  .remote-stage {
    height: calc(100dvh - 140px);
    min-height: 390px;
  }

  .remote-inputs {
    grid-template-columns: 1fr;
  }
}
