/* Reusable components: cards, progress, alerts, modals, toasts, tables, product grid,
   PDF viewer, empty/loading states and the print sheet used for PDF generation. */

/* ----------------------------------------------------------------- card */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card--center {
  text-align: center;
}

.card--error {
  border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
}

.card--error p {
  color: var(--color-text-muted);
  margin: var(--space-2) 0 var(--space-5);
}

.card__header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: var(--text-lg);
  margin: 0;
}

.card__footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* --------------------------------------------------------------- alerts */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  align-items: flex-start;
}

.alert__body {
  min-width: 0;
  flex: 1;
}

.alert__title {
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.alert--info {
  background: var(--color-info-bg);
  border-color: color-mix(in srgb, var(--color-info) 25%, transparent);
  color: #0a4f9c;
}

.alert--success {
  background: var(--color-success-bg);
  border-color: color-mix(in srgb, var(--color-success) 25%, transparent);
  color: var(--color-success);
}

.alert--danger {
  background: var(--color-danger-bg);
  border-color: color-mix(in srgb, var(--color-danger) 25%, transparent);
  color: var(--color-danger);
}

.alert--warning {
  background: var(--color-warning-bg);
  border-color: color-mix(in srgb, var(--color-warning) 30%, transparent);
  color: var(--color-warning);
}

/* ---------------------------------------------------------------- badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.2em 0.7em;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge--neutral { background: var(--color-surface-alt); color: var(--color-text-muted); border-color: var(--color-border); }
.badge--new { background: var(--color-info-bg); color: var(--color-info); }
.badge--under_review { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--approved { background: var(--color-success-bg); color: var(--color-success); }
.badge--rejected { background: var(--color-danger-bg); color: var(--color-danger); }
.badge--more_info { background: #f4f0ff; color: #5c3ec2; }

/* ------------------------------------------------------------- progress */
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.step {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: var(--space-4);
  border-top: 3px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  min-width: 0;
}

.step__index {
  position: absolute;
  top: calc(-1 * var(--space-4) - 0.7em);
  left: 0;
  width: 1.65rem;
  height: 1.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-border-strong);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
}

.step__label {
  font-weight: 700;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step__meta {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step[data-state="current"] {
  border-top-color: var(--color-primary);
  color: var(--color-text);
}

.step[data-state="current"] .step__index {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
}

.step[data-state="current"] .step__label {
  color: var(--color-text);
}

.step[data-state="complete"] {
  border-top-color: var(--color-success);
}

.step[data-state="complete"] .step__index {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}

.step[data-state="complete"] .step__label {
  color: var(--color-success);
}

@media (max-width: 720px) {
  .steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4) var(--space-3);
  }
}

/* --------------------------------------------------------------- toasts */
.toast-region {
  position: fixed;
  z-index: 90;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(100% - 2rem, 28rem);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--color-text);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  animation: toast-in 200ms ease-out;
}

.toast--danger { background: var(--color-danger); }
.toast--success { background: var(--color-success); }

.toast__close {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.2rem;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 22, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fade-in 160ms ease-out;
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: min(100%, 44rem);
  max-height: min(92vh, 56rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 180ms ease-out;
}

.modal--wide {
  width: min(100%, 64rem);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  margin: 0;
  font-size: var(--text-lg);
}

.modal__body {
  padding: var(--space-5);
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.modal__body--flush {
  padding: 0;
  background: var(--color-surface-alt);
}

.modal__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  flex-wrap: wrap;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------- spinner / loading UI */
.spinner {
  width: 1.15em;
  height: 1.15em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 700ms linear infinite;
  vertical-align: -0.15em;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Full-screen loading overlay: page transitions and form submissions */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(2px);
  animation: fade-in 150ms ease;
  transition: opacity 200ms ease;
}

.page-loader.is-hiding {
  opacity: 0;
  pointer-events: none;
}

.page-loader__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
}

.page-loader__spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid color-mix(in srgb, var(--color-primary) 25%, transparent);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.page-loader__message {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
}

body.page-loader-open {
  overflow: hidden;
}

@media (max-width: 480px) {
  .page-loader__spinner {
    width: 1.75rem;
    height: 1.75rem;
  }
}

.loading-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--space-5) 0;
  justify-content: center;
}

.skel {
  background: linear-gradient(90deg, var(--color-surface-alt) 25%, #eceae3 37%, var(--color-surface-alt) 63%);
  background-size: 400% 100%;
  animation: skel 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skel { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* --------------------------------------------------------- empty states */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.empty-state__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.empty-state .btn {
  margin-top: var(--space-3);
}

/* ---------------------------------------------------------------- table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 46rem;
}

.table th,
.table td {
  padding: 0.75rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.table th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

.table tbody tr:hover {
  background: color-mix(in srgb, var(--color-surface-alt) 60%, transparent);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table .cell-wrap {
  overflow-wrap: anywhere;
  max-width: 22rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.pagination__controls {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* -------------------------------------------------------- product grid */
.product-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}

.product-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  min-width: 0;
}

.product-card__media {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-card__placeholder {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-3);
  text-align: center;
}

.product-card__number {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 700;
  z-index: 1;
}

.product-card__name {
  font-weight: 700;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.product-card__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.product-card__url {
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.product-card__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-2);
  flex-wrap: wrap;
}

.product-card--uploading .product-card__media {
  background: var(--color-surface-alt);
}

.upload-bar {
  height: 0.4rem;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.upload-bar__fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: inherit;
  transition: width var(--transition);
}

.upload-bar--indeterminate .upload-bar__fill {
  width: 40%;
  animation: indeterminate 1.1s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(275%); }
}

.product-dropzone {
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  text-align: center;
  background: var(--color-surface);
  transition: border-color var(--transition), background var(--transition);
}

.product-dropzone.is-dragover {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface));
}

.counter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.3em 0.9em;
  font-size: var(--text-sm);
  font-weight: 700;
}

.counter-chip--full {
  background: var(--color-success-bg);
  border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
  color: var(--color-success);
}

/* ----------------------------------------------------------- pdf viewer */
.pdf-viewer {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: min(78vh, 46rem);
  max-height: 100%;
  background: var(--color-surface-alt);
}

.pdf-viewer__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

.pdf-viewer__toolbar .spacer { flex: 1; }

.pdf-viewer__page-indicator {
  font-size: var(--text-sm);
  font-weight: 600;
  min-width: 6.5rem;
  text-align: center;
}

.pdf-viewer__canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4);
}

/* All pages live in one continuous scroll layer; the toolbar never changes
   its height, so scrolling never causes reflow. */
.pdf-viewer__pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.pdf-viewer__page {
  display: block;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 3px rgb(15 23 42 / 8%);
}

.pdf-viewer__page[data-current] {
  border-color: color-mix(in srgb, var(--color-primary, #2563eb) 55%, var(--color-border));
}

.pdf-viewer__page--pending {
  background: linear-gradient(100deg, var(--color-surface) 40%, var(--color-surface-alt) 50%, var(--color-surface) 60%);
  background-size: 200% 100%;
  animation: pdf-page-shimmer 1.4s linear infinite;
}

@keyframes pdf-page-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pdf-viewer__page--pending { animation: none; }
}

.pdf-viewer__page-canvas {
  display: block;
  background: #fff;
  max-width: 100%;
  height: auto;
}

.pdf-viewer__status {
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.pdf-viewer__fallback {
  width: 100%;
  height: 100%;
  min-height: 24rem;
  border: 0;
  background: #fff;
}

/* ------------------------------------------------------------ stat cards */
.stat-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.stat__label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 700;
}

.stat__value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: 1.1;
  margin-top: var(--space-2);
}

.stat__hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ------------------------------------------------------------- bar chart */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 8rem;
  padding-top: var(--space-3);
}

.bars__col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 100%;
}

.bars__bar {
  width: 100%;
  max-width: 2rem;
  background: color-mix(in srgb, var(--color-primary) 82%, white);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  transition: height var(--transition);
}

.bars__label {
  font-size: 0.6rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---------------------------------------------------------- print sheet */
.print-sheet {
  display: none;
}

@media print {
  body * {
    visibility: hidden !important;
  }

  .print-sheet,
  .print-sheet * {
    visibility: visible !important;
  }

  .print-sheet {
    display: block !important;
    position: absolute;
    inset: 0;
    padding: 0;
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .print-sheet h1 { font-size: 18pt; }
  .print-sheet h2 { font-size: 13pt; margin-top: 1.2em; }
  .print-sheet table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
  .print-sheet th,
  .print-sheet td { border: 1px solid #bbb; padding: 4pt 6pt; text-align: left; vertical-align: top; font-size: 10pt; }
  .print-sheet .print-products img { width: 44pt; height: 44pt; object-fit: cover; border: 1px solid #ccc; }
  .print-sheet .print-muted { color: #444; }
  .print-sheet .print-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1em; }

  /* Application snapshot: product images in the printed/PDF document */
  .print-sheet__product { page-break-inside: avoid; margin-bottom: 0.8em; }
  .print-sheet__products { padding-left: 1.2em; }
  .print-sheet__files {
    list-style: none;
    margin: 0.4em 0 0;
    padding: 0;
    display: grid;
    gap: 0.6em;
  }
  .print-sheet__files li { page-break-inside: avoid; }
  .print-sheet__img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 110mm;
    border: 1px solid #ccc;
    object-fit: contain;
  }
  .print-sheet__list { margin: 0 0 1em; }
  .print-sheet__list > div {
    display: grid;
    grid-template-columns: 9rem 1fr;
    gap: 0.5em;
    padding: 2pt 0;
    border-bottom: 1px solid #eee;
  }
  .print-sheet__list dt { color: #444; font-weight: 600; }

  @page {
    margin: 14mm;
  }
}
