:root {
  color-scheme: light;
  --background: #f5f5f3;
  --surface: #fff;
  --surface-muted: #fafaf9;
  --text: #181817;
  --muted: #6d6d68;
  --line: #deded9;
  --line-strong: #b9b9b2;
  --accent: #1d4ed8;
  --success: #16794d;
  --danger: #b42318;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--background); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button, a, input, select, textarea { touch-action: manipulation; }

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  padding: 8px 12px;
  color: white;
  background: var(--text);
  border-radius: 6px;
  transform: translateY(-180%);
}

.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
  padding: 48px 0 64px;
}

.tool-header, .panel-header, .results-header, .form-actions, .result-actions, .product-meta {
  display: flex;
  align-items: center;
}

.tool-header {
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font: 600 0.68rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
}

h1, h2, h3, p { overflow-wrap: anywhere; }

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.3rem);
  font-weight: 650;
  letter-spacing: -0.05em;
  line-height: 1;
}

.title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.finder-selectors {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.provider-menu,
.market-menu {
  flex: 0 0 auto;
}

.provider-menu select,
.market-menu select {
  width: 196px;
  height: 34px;
  padding: 0 30px 0 11px;
  color: var(--muted);
  background-color: transparent;
  border-color: var(--line-strong);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.provider-menu select {
  width: 92px;
  color: var(--text);
  background-color: var(--surface);
}

.provider-menu select:hover,
.market-menu select:hover {
  color: var(--text);
  background-color: var(--surface);
}

.intro {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.session-note {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.session-note span {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.82fr) minmax(0, 1.18fr);
  min-height: 660px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.input-panel, .preview-panel {
  min-width: 0;
  padding: clamp(24px, 3vw, 40px);
}

.input-panel { border-right: 1px solid var(--line); }

.panel-header, .results-header {
  justify-content: space-between;
  gap: 20px;
}

h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.text-button {
  padding: 4px 0;
  color: var(--accent);
  background: transparent;
  border: 0;
  font-size: 0.76rem;
  font-weight: 600;
}

label[for="product-list"] {
  display: block;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
}

label[for="product-list"] { margin-top: 28px; margin-bottom: 8px; }

select {
  display: block;
  width: 100%;
  height: 42px;
  padding: 0 38px 0 12px;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font: 500 0.82rem/1 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

select:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(29 78 216 / 10%);
}

textarea {
  display: block;
  width: 100%;
  min-height: 330px;
  resize: vertical;
  padding: 15px;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.75;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(29 78 216 / 10%);
}

textarea::placeholder { color: #92928c; }

.field-hint, .form-message, .progress-copy, .source-name, .row-error {
  color: var(--muted);
  font-size: 0.74rem;
}

.field-hint { margin: 8px 0 0; }

.form-actions { gap: 8px; margin-top: 24px; }

.primary-button, .secondary-button, .compact-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 7px;
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease;
}

.primary-button {
  flex: 1;
  color: white;
  background: var(--text);
  border: 1px solid var(--text);
}

.primary-button:hover { background: #32322f; }

.secondary-button, .compact-button {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

.secondary-button:hover, .compact-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.form-message { min-height: 1.4em; margin: 10px 0 0; }
.form-message[data-tone="error"] { color: var(--danger); }

button:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.cancel-job-button {
  color: var(--danger);
  border-color: #e5b5b0;
}

.cancel-job-button:hover:not(:disabled) {
  background: #fff6f5;
  border-color: #d88f88;
}

.job-status-panel {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  margin-top: 10px;
  background: #f7f8fb;
  border: 1px solid #d9deea;
  border-radius: 8px;
}

.job-status-panel[hidden] { display: none; }

.job-status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.72rem;
}

.job-status-line strong {
  color: var(--accent);
  font-size: 0.72rem;
}

.job-status-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.45;
}

.provider-cooldown-copy {
  color: var(--danger) !important;
  font-weight: 600;
}

.preview-panel { display: flex; background: var(--surface-muted); }

.empty-state { margin: auto; text-align: center; }
.empty-state p { margin: 0 0 5px; font-size: 0.86rem; font-weight: 600; }
.empty-state span { color: var(--muted); font-size: 0.78rem; }

.results { width: 100%; }
.result-actions { gap: 7px; }

.compact-button { min-height: 34px; padding: 0 11px; font-size: 0.72rem; }
.scan-button { color: var(--accent); border-color: #bdcaeb; }
.progress-copy { margin: 5px 0 0; }

.progress-track {
  height: 3px;
  margin: 20px 0;
  overflow: hidden;
  background: var(--line);
  border-radius: 2px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.product-list { display: grid; gap: 8px; }

.product-row {
  display: grid;
  grid-template-columns: 30px 96px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 116px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  transition: opacity 140ms ease, border-color 140ms ease;
}

.product-row:has(.product-checkbox:checked) { opacity: 0.5; border-color: #b9d9c8; }
.product-row:has(.product-checkbox:checked) .product-name { text-decoration: line-through; }

.check-control {
  position: relative;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  cursor: pointer;
}

.product-checkbox { position: absolute; width: 1px; height: 1px; opacity: 0; }

.custom-check {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: transparent;
  background: white;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
}

.product-checkbox:focus-visible + .custom-check {
  outline: 3px solid rgb(29 78 216 / 18%);
  outline-offset: 2px;
}

.product-checkbox:checked + .custom-check {
  color: white;
  background: var(--success);
  border-color: var(--success);
}

.product-image-wrap {
  position: relative;
  display: grid;
  width: 96px;
  height: 96px;
  overflow: hidden;
  place-items: center;
  background: #f0f0ed;
  border-radius: 7px;
}

.product-image { width: 100%; height: 100%; object-fit: contain; background: white; }

.image-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #ecece8 30%, #f8f8f6 45%, #ecece8 60%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}

.image-fallback { color: var(--muted); font-size: 0.68rem; }
@keyframes shimmer { to { background-position-x: -220%; } }

.product-copy { min-width: 0; }
.product-meta { flex-wrap: wrap; gap: 6px; }

.quantity-badge, .article-number {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 2px 7px;
  color: #555550;
  background: #efefec;
  border-radius: 5px;
  font: 600 0.64rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.quantity-badge { color: #1e4fb7; background: #eef3ff; }

.product-name {
  margin: 8px 0 0;
  font-size: 0.9rem;
  font-weight: 620;
  line-height: 1.4;
}

.source-name { margin: 3px 0 0; line-height: 1.4; }

.product-link {
  display: inline-block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  text-underline-offset: 2px;
}

.row-error { margin: 7px 0 0; color: var(--danger); line-height: 1.5; }
.product-row[data-state="error"] { border-color: #e6b7b2; }
.product-row.scan-confirmed { border-color: var(--success); box-shadow: 0 0 0 3px rgb(22 121 77 / 10%); }

.scan-dialog {
  width: min(520px, calc(100% - 24px));
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #e5e5e1;
  border-radius: 18px;
  box-shadow: 0 30px 90px rgb(0 0 0 / 28%);
}

.scan-dialog::backdrop,
.permission-dialog::backdrop {
  background: rgb(24 24 23 / 62%);
  backdrop-filter: blur(7px);
}

.scan-shell { padding: 28px; }

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

.scan-heading { min-width: 0; }

.scan-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 8px;
}

.scan-title-row .kicker { margin: 0; }

.scan-security-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: #14643f;
  background: #edf8f1;
  border: 1px solid #cae7d6;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 650;
}

.scan-security-badge span {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
}

.scan-header h2 {
  font-size: 1.25rem;
  letter-spacing: -0.035em;
}

.scan-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1.3rem;
  line-height: 1;
  transition: background 120ms ease, border-color 120ms ease;
}

.icon-button:hover { background: var(--surface-muted); border-color: var(--line-strong); }

.camera-frame {
  position: relative;
  display: grid;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  place-items: center;
  background: #111;
  border-radius: 14px;
}

.camera-frame video { width: 100%; height: 100%; object-fit: cover; }
.camera-frame[hidden] { display: none; }

.scan-guide {
  position: absolute;
  width: min(82%, 370px);
  height: 40%;
  border: 2px solid rgb(255 255 255 / 88%);
  border-radius: 7px;
  box-shadow: 0 0 0 999px rgb(0 0 0 / 20%);
  pointer-events: none;
}

.scan-status {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

.scan-status[data-tone="error"] { color: var(--danger); }
.scan-status[data-tone="success"] { color: var(--success); }

.permission-dialog {
  width: min(460px, calc(100% - 24px));
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #e5e5e1;
  border-radius: 18px;
  box-shadow: 0 30px 90px rgb(0 0 0 / 30%);
}

.permission-shell { padding: 24px; }

.permission-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.permission-header .kicker { margin-bottom: 6px; }
.permission-header h2 { font-size: 1.1rem; }

.permission-help {
  padding: 16px;
  background: #f8f8f6;
  border: 1px solid #dfdfda;
  border-radius: 14px;
}

.permission-hero {
  display: flex;
  align-items: center;
  gap: 14px;
}

.permission-icon {
  position: relative;
  display: block;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  background: var(--text);
  border-radius: 15px;
  box-shadow: 0 8px 20px rgb(24 24 23 / 14%);
}

.permission-icon::before {
  position: absolute;
  top: 18px;
  left: 13px;
  width: 26px;
  height: 18px;
  border: 2px solid white;
  border-radius: 5px;
  content: "";
}

.permission-icon::after {
  position: absolute;
  top: 23px;
  left: 23px;
  width: 6px;
  height: 6px;
  border: 2px solid white;
  border-radius: 50%;
  content: "";
}

.permission-icon span {
  position: absolute;
  top: 14px;
  left: 20px;
  width: 14px;
  height: 6px;
  background: white;
  border-radius: 3px 3px 0 0;
}

.permission-device {
  margin: 0 0 4px;
  color: var(--danger);
  font-size: 0.64rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.permission-summary {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.permission-help ol {
  display: grid;
  gap: 6px;
  padding: 0;
  margin: 16px 0 0;
  color: #454540;
  counter-reset: permission-step;
  font-size: 0.74rem;
  line-height: 1.45;
  list-style: none;
}

.permission-help li {
  position: relative;
  min-height: 28px;
  padding: 5px 0 5px 34px;
  counter-increment: permission-step;
}

.permission-help li::before {
  position: absolute;
  top: 3px;
  left: 0;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: white;
  background: var(--text);
  border-radius: 50%;
  content: counter(permission-step);
  font: 700 0.67rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.permission-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.permission-actions .primary-button,
.permission-actions .secondary-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 650;
}

.permission-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 13px;
}

.text-link { color: var(--accent); font-size: 0.72rem; font-weight: 600; text-underline-offset: 2px; }

.scan-source-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scan-dialog:not([data-view="chooser"]) .scan-source-actions { display: none; }

.scan-option {
  display: grid;
  min-width: 0;
  min-height: 132px;
  align-content: start;
  justify-items: start;
  gap: 11px;
  padding: 16px;
  color: var(--text);
  text-align: left;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.scan-option:hover {
  background: white;
  border-color: var(--line-strong);
  box-shadow: 0 10px 24px rgb(24 24 23 / 8%);
  transform: translateY(-2px);
}

.scan-option:focus-visible {
  outline: 3px solid rgb(29 78 216 / 16%);
  outline-offset: 2px;
}

.scan-option-icon {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  color: white;
  background: var(--text);
  border-radius: 12px;
}

.camera-choice-icon::before {
  position: absolute;
  top: 14px;
  left: 10px;
  width: 21px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 4px;
  content: "";
}

.camera-choice-icon::after {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 5px;
  height: 5px;
  border: 2px solid currentColor;
  border-radius: 50%;
  content: "";
}

.camera-choice-icon span {
  position: absolute;
  top: 10px;
  left: 16px;
  width: 12px;
  height: 6px;
  background: currentColor;
  border-radius: 3px 3px 0 0;
}

.photo-choice-icon { color: var(--accent); background: #eaf0ff; }

.photo-choice-icon::before {
  position: absolute;
  inset: 10px;
  border: 2px solid currentColor;
  border-radius: 4px;
  content: "";
}

.photo-choice-icon::after {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 13px;
  height: 10px;
  background: currentColor;
  clip-path: polygon(0 100%, 43% 35%, 62% 58%, 78% 38%, 100% 100%);
  content: "";
}

.photo-choice-icon span {
  position: absolute;
  top: 14px;
  right: 15px;
  width: 5px;
  height: 5px;
  background: currentColor;
  border-radius: 50%;
}

.scan-option-copy { min-width: 0; }
.scan-option-copy strong { display: block; font-size: 0.82rem; }
.scan-option-copy small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.69rem; line-height: 1.4; }

.scan-match {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-top: 16px;
  background: #f4faf7;
  border: 1px solid #b9d9c8;
  border-radius: 9px;
}

.scan-match[hidden] { display: none; }

.scan-match img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: white;
  border-radius: 6px;
}

.scan-match-copy { min-width: 0; }
.scan-match-copy p { margin: 0; color: var(--muted); font: 600 0.65rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.scan-match-copy h3 { margin: 6px 0 2px; font-size: 0.88rem; line-height: 1.35; }
.scan-match-copy span { color: var(--success); font-size: 0.7rem; }
.scan-match .primary-button { grid-column: 1 / -1; width: 100%; }
.scan-match .primary-button:disabled { cursor: default; opacity: 0.55; }

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  text-align: center;
}

.privacy-note::before {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  background: var(--success);
  border-radius: 50%;
  content: "";
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .app-shell { width: min(100% - 24px, 680px); padding: 28px 0 40px; }
  .tool-header { align-items: flex-start; }
  .workspace { grid-template-columns: 1fr; }
  .input-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-panel { min-height: 420px; }
}

@media (max-width: 520px) {
  .app-shell { width: min(100% - 16px, 500px); padding-top: 20px; }
  .tool-header { flex-direction: column; gap: 14px; }
  .workspace { border-radius: 9px; }
  .input-panel, .preview-panel { padding: 20px 14px; }
  .provider-menu select,
  .market-menu select,
  #product-list {
    font-size: 16px;
  }
  .finder-selectors { width: 100%; flex-wrap: nowrap; }
  .provider-menu { flex: 0 0 106px; }
  .market-menu { min-width: 0; flex: 1; }
  .provider-menu select,
  .market-menu select { width: 100%; max-width: 100%; height: 42px; }
  select { height: 48px; }
  textarea { min-height: 270px; }
  .primary-button, .secondary-button, .compact-button { min-height: 44px; }
  .text-button { min-height: 44px; padding: 0 4px; }
  .product-row { grid-template-columns: 26px 76px minmax(0, 1fr); gap: 9px; min-height: 96px; padding: 9px; }
  .product-image-wrap { width: 76px; height: 76px; }
  .source-name { display: none; }
  .results-header { align-items: flex-start; }
  .result-actions { flex-wrap: wrap; justify-content: flex-end; }
  .scan-dialog {
    width: 100%;
    max-width: none;
    margin: auto auto 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 22px 22px 0 0;
  }
  .scan-shell { padding: 22px 18px max(20px, env(safe-area-inset-bottom)); }
  .scan-header { margin-bottom: 18px; }
  .icon-button { width: 44px; height: 44px; }
  .permission-dialog { width: calc(100% - 24px); border-radius: 18px; }
  .permission-shell { padding: 18px; }
  .permission-help { padding: 14px; }
  .permission-hero { align-items: flex-start; }
  .scan-option { min-height: 124px; padding: 14px; }
  .permission-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  body { background: white; }
  .app-shell { width: 100%; padding: 0; }
  .tool-header, .input-panel, .result-actions, .progress-track, .product-link { display: none !important; }
  .workspace, .preview-panel { display: block; min-height: 0; padding: 0; background: white; border: 0; }
  .product-row { break-inside: avoid; }
}
