: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, textarea { font: inherit; }
button { cursor: pointer; }

.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;
}

.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: 28px 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

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); }

.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; }
.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; }

.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; }
  textarea { min-height: 270px; }
  .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; }
}

@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; }
}
