:root {
  --ink: #14171c;
  --ink-soft: #3a3f47;
  --muted: #6a6f76;
  --line: #e5e6e8;
  --panel: #f7f7f8;
  --red: #c8161f;
  --red-dark: #a01019;
  --green: #1a8a4a;
  --amber: #b8860b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- topbar ---------- */

.topbar {
  background: var(--ink);
  color: #fff;
  border-bottom: 3px solid var(--red);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  letter-spacing: 0.3px;
}
.brand span { color: var(--red); }
.topbar nav { flex: 1; display: flex; gap: 20px; }
.topbar nav a { color: #cfd2d6; font-size: 13.5px; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cfd2d6; }
.logout-link { color: #cfd2d6 !important; }
.logout-link:hover { color: #fff !important; }

/* ---------- layout ---------- */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px 24px;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 22px;
}
.card h2 { margin-top: 0; font-size: 16px; }
.muted { color: var(--muted); }

.flash-box {
  background: #fff3f3;
  border: 1px solid #f0c4c6;
  color: var(--red-dark);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 13.5px;
}

/* ---------- forms ---------- */

.form-row { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.field-btn { min-width: unset; }
label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
input[type="text"], input[type="password"], input[type="file"], select {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
}

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { text-decoration: none; background: var(--panel); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-block { width: 100%; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn-danger { color: var(--red-dark); border-color: #f0c4c6; }
.inline-form { display: inline-block; margin: 0; }

/* ---------- progress ---------- */

.progress-box { margin-top: 20px; }
.progress-box.hidden { display: none; }
.progress-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; font-weight: 600; }
.progress-track { height: 10px; background: var(--panel); border-radius: 6px; overflow: hidden; }
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--red), #e8535c);
  transition: width 0.4s ease;
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}
.progress-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- tables ---------- */

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border-bottom: 2px solid var(--line);
  padding: 8px 10px;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }

.status-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status-ok, .status-completed { background: #e6f4ea; color: var(--green); }
.status-not_found, .status-failed { background: #fdeceb; color: var(--red-dark); }
.status-pending, .status-running { background: #fdf3e0; color: var(--amber); }

.role-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.role-view { background: #eef0f2; color: var(--ink-soft); }
.role-run { background: #e3edfb; color: #1a56b0; }
.role-admin { background: #fdecea; color: var(--red-dark); }

/* ---------- run header ---------- */

.run-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 18px; }
.back-link { display: inline-block; margin-bottom: 10px; font-size: 13px; }
.run-header h1 { margin: 4px 0; font-size: 20px; }

/* ---------- product grid ---------- */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.product-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.product-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-2px); }
.product-thumb {
  width: 100%;
  height: 140px;
  background: var(--panel);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 10px;
}
.product-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.thumb-placeholder { color: var(--muted); font-size: 12px; }
.product-code { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.product-name { font-size: 13px; margin: 4px 0 8px 0; min-height: 34px; }
.source-link { display: inline-block; margin-top: 6px; font-size: 11.5px; }
.modal-position { font-size: 12px; margin-top: -6px; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,23,28,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 30px;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: 10px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted);
}
.modal h2 { margin-top: 4px; }
.modal h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 18px 0 6px 0; }
.modal-images { display: flex; gap: 12px; margin: 14px 0; }
.modal-images img { max-height: 160px; border: 1px solid var(--line); border-radius: 6px; }
.specs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.specs-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); }
.specs-table td:first-child { color: var(--muted); width: 45%; }

/* ---------- column picker ---------- */

.column-picker { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13.5px; }

/* ---------- catalog home / prefill ---------- */

.prefill-cell { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.prefill-progress { min-width: 180px; }
.prefill-progress-inner { display: flex; flex-direction: column; gap: 3px; }
.prefill-top-line { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.prefill-pct { font-weight: 700; font-size: 12px; }
.mini-progress-track { height: 6px; background: var(--panel); border-radius: 4px; overflow: hidden; }
.mini-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--red), #e8535c);
  transition: width 0.4s ease;
}
.prefill-bottom-line { display: flex; justify-content: space-between; font-size: 11px; }

/* ---------- catalog browser ---------- */

.catalog-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.catalog-toolbar #search-box {
  flex: 1;
  min-width: 220px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13.5px;
}
.export-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.export-panel.hidden { display: none; }
.export-panel .column-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.catalog-table td { vertical-align: middle; }
.catalog-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.code-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
}
.clickable-name { cursor: pointer; }
.clickable-name:hover { text-decoration: underline; }
.pagination { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

/* ---------- login ---------- */

.login-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  font-family: 'Segoe UI', Arial, sans-serif;
}
.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 36px 34px;
  width: 340px;
}
.login-brand { font-size: 22px; font-weight: 700; color: var(--ink); text-align: center; }
.login-brand span { color: var(--red); }
.login-sub { text-align: center; color: var(--muted); font-size: 12.5px; margin: 4px 0 20px 0; }
.login-card label { display: block; margin-top: 12px; }
.login-card input { width: 100%; margin-top: 4px; }
.login-card button { margin-top: 20px; }
