/* ============================================================
   components.css — Shared UI: alerts, tables, forms, buttons,
                    product cards, basket controls, status dots
   Loaded on every page via Page::displayHeader()
   ============================================================ */

/* ── Alerts ─────────────────────────────────────────────── */

.warning {
  font-size: 14px;
  padding: 8px 10px;
  border: solid 1px crimson;
  font-weight: bold;
  color: crimson;
  background-color: lavenderBlush;
}

.info {
  font-size: 14px;
  padding: 8px 10px;
  border: solid 1px lightgray;
  color: gray;
}

.success {
  font-size: 14px;
  padding: 8px 10px;
  border: solid 1px forestgreen;
  font-weight: bold;
  color: forestgreen;
  background-color: cornsilk;
}

/* ── Tables ─────────────────────────────────────────────── */

/* Wrap any <table class="list"> in a <div class="table-scroll">
   to get horizontal scrolling on narrow screens. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.list {
  border-collapse: collapse;
}

td.list-header {
  padding: 5px;
  background-color: gainsboro;
}

td.list {
  padding: 5px;
  border-top: 1px solid gainsboro;
  vertical-align: middle;
}

/* ── Form inputs ─────────────────────────────────────────── */

input.query {
  border-top: 0;
  border-right: 0;
  border-left: 0;
  border-bottom: 1px solid gainsboro;
  padding: 5px;
}

input[type=button],
input[type=submit],
input[type=reset] {
  background-color: var(--color-primary);
  color: white;
  border: none;
  text-decoration: none;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 36px;
}

/* Larger tap targets on mobile */
@media (max-width: 768px) {
  input[type=button],
  input[type=submit],
  input[type=reset] {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 15px;
  }
}

/* ── Product cards (panier-creation) ─────────────────────── */

.produit {
  height: 300px;
  width: 160px;
  display: inline-block;
  position: relative;
  text-align: center;
  border: solid 2px var(--color-primary);
  border-radius: var(--radius-md);
  margin: 5px;
  padding: 5px;
  cursor: pointer;
}

.product-name {
  display: block;
  height: 40px;
  font-weight: bold;
}

.add-to-cart {
  font-weight: bold;
  border-radius: var(--radius-md);
  font-size: 20px;
  height: 24px;
  width: 24px;
  position: absolute;
  background-color: var(--color-primary);
  color: white;
  bottom: 5px;
  right: 5px;
}

img.categorie {
  height: 40px;
  width: 40px;
  border-radius: var(--radius-md);
  display: inline-block;
  position: relative;
  text-align: center;
  border: solid 2px black;
  margin: 3px;
  padding: 3px;
  cursor: pointer;
}

/* ── Status dots ─────────────────────────────────────────── */

.dot-ok {
  height: 12px;
  width: 12px;
  background-color: lightgreen;
  border-radius: 50%;
  display: inline-block;
}

.dot-ko {
  height: 12px;
  width: 12px;
  background-color: red;
  border-radius: 50%;
  display: inline-block;
}

/* ── Basket / quantity controls ──────────────────────────── */

.quantity {
  font-weight: bold;
  text-align: center;
  width: 24px;
}

.quantity-change {
  font-weight: bold;
  border-radius: var(--radius-md);
  text-align: center;
  display: inline-block;
  font-size: 20px;
  height: 24px;
  width: 24px;
  background-color: var(--color-primary);
  color: white;
  cursor: pointer;
}

.titre-panier {
  font-weight: bold;
  font-size: 18px;
  margin: 5px;
}

/* ── Back-to-top button ──────────────────────────────────── */

.btn-scroll-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 102, 204, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.btn-scroll-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.btn-scroll-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 102, 204, .45);
}

/* ============================================================
   Card
   ============================================================ */

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

.card--clickable {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: box-shadow 200ms ease, transform 200ms ease, border-color 200ms ease;
}

.card--clickable:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--color-primary);
}

.card--clickable:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-color: var(--color-primary);
}

/* Square aspect-ratio card (stats hub) */
.card--square {
  aspect-ratio: 1 / 1;
  justify-content: center;
}

/* Accent left-border variants */
.card--info    { border-left: 4px solid var(--color-info); }
.card--success { border-left: 4px solid var(--color-success); }
.card--warning { border-left: 4px solid var(--color-warning); }
.card--danger  { border-left: 4px solid var(--color-danger); }

/* Inner elements */
.card__icon {
  display: block;
  margin-bottom: var(--space-3);
  opacity: 0.85;
}

.card__title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-primary);
  margin: 0 0 var(--space-1);
  line-height: var(--leading-tight);
}

.card__desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: var(--leading-loose);
  margin: 0;
}

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

@media (prefers-reduced-motion: reduce) {
  .card--clickable { transition: none; }
}

/* ============================================================
   Layout primitives — cluster, stack, grid
   ============================================================ */

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

.cluster--end      { justify-content: flex-end; }
.cluster--between  { justify-content: space-between; }
.cluster--start    { justify-content: flex-start; }

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.stack--tight { gap: var(--space-2); }
.stack--loose { gap: var(--space-5); }

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid--auto-fill { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.grid--auto-fit  { grid-template-columns: repeat(auto-fit,  minmax(240px, 1fr)); }
.grid--cols-2    { grid-template-columns: repeat(2, 1fr); }
.grid--cols-3    { grid-template-columns: repeat(3, 1fr); }
.grid--cols-4    { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .grid--cols-3,
  .grid--cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid--cols-2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .grid--auto-fill,
  .grid--auto-fit,
  .grid--cols-3,
  .grid--cols-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   Page header
   ============================================================ */

.page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3) var(--space-4);
  padding: var(--space-4) 0 var(--space-3);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}

.page__title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
  line-height: var(--leading-tight);
  margin: 0;
}

.page__subtitle {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  margin: 0;
}

.page__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-left: auto;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  min-height: 36px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
  box-sizing: border-box;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Variants */

.btn--primary {
  background: var(--color-primary);
  color: var(--color-primary-fg);
  border-color: var(--color-primary);
}

.btn--primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-primary-fg);
}

.btn--primary:active {
  background: var(--color-primary-active);
  border-color: var(--color-primary-active);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn--secondary:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--ghost:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-border-strong);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.btn--danger:hover {
  background: var(--red-700);
  border-color: var(--red-700);
}

.btn--brand {
  background: var(--color-brand);
  color: var(--color-brand-fg);
  border-color: var(--color-brand);
}

.btn--brand:hover {
  background: var(--color-brand-hover);
  border-color: var(--color-brand-hover);
}

.btn--link {
  background: transparent;
  color: var(--color-primary);
  border-color: transparent;
  padding-left: 0;
  padding-right: 0;
}

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

/* Sizes */

.btn--sm {
  padding: var(--space-1) var(--space-3);
  min-height: 28px;
  font-size: var(--text-sm);
}

.btn--lg {
  padding: var(--space-3) var(--space-5);
  min-height: 48px;
  font-size: var(--text-md);
}

/* Modifiers */

.btn--icon {
  padding: var(--space-2);
  min-width: 36px;
  width: 36px;
  height: 36px;
}

.btn--icon.btn--sm {
  min-width: 28px;
  width: 28px;
  height: 28px;
  padding: var(--space-1);
}

.btn--block {
  width: 100%;
  justify-content: center;
}

/* Inner elements */

.btn__icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.btn__label { /* plain text node — no extra styles needed */ }

/* Loading state */

.btn--loading {
  cursor: wait;
  pointer-events: none;
}

.btn__spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 700ms linear infinite;
  flex-shrink: 0;
}

.btn--secondary .btn__spinner,
.btn--ghost .btn__spinner,
.btn--link .btn__spinner {
  border-color: rgba(0, 102, 204, 0.3);
  border-top-color: var(--color-primary);
}

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

@media (prefers-reduced-motion: reduce) {
  .btn__spinner { animation: none; opacity: 0.7; }
  .btn          { transition: none; }
}

/* Mobile: larger tap targets */
@media (max-width: 768px) {
  .btn:not(.btn--sm):not(.btn--icon) {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
  }
}

/* ============================================================
   Filter bar
   ============================================================ */

.filter-bar {
  padding: var(--space-3) 0 var(--space-2);
}

.filter-bar--sticky {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) 0;
  margin-bottom: var(--space-3);
}

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

.filter-bar__field {
  flex: 1 1 160px;
  min-width: 130px;
  max-width: 240px;
}

.filter-bar__field--grow {
  flex: 2 1 200px;
}

.filter-bar__search {
  position: relative;
  flex: 1 1 200px;
  min-width: 160px;
}

.filter-bar__search-icon {
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.filter-bar__input {
  font: inherit;
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-5) + var(--space-1));
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 150ms;
}

.filter-bar__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.filter-bar__input.is-active {
  border-width: 2.5px;
  border-color: #f97316;
}

.filter-bar__select {
  font: inherit;
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 150ms;
}

.filter-bar__select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.filter-bar__select.is-active {
  border-width: 2.5px;
  border-color: #f97316;
}

.filter-bar__reset {
  flex: 0 0 auto;
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, border-color 150ms, color 150ms;
}

.filter-bar__reset:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.filter-bar__reset:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* Mobile: full-width stack */
@media (max-width: 768px) {
  .filter-bar__field,
  .filter-bar__field--grow,
  .filter-bar__search {
    flex: 1 1 100%;
    max-width: 100%;
  }
}

/* ============================================================
   Table (modern) — .table
   Legacy aliases: table.list, td.list, td.list-header still work.
   ============================================================ */

/* Scroll wrapper */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  background: var(--color-surface);
}

/* Override the bare .table-scroll already in legacy components.css —
   we're re-declaring it with the new tokens. The border/radius/shadow
   are additions; overflow-x and -webkit- are kept. */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
}

.table th,
.table thead td {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  vertical-align: middle;
}

.table tbody tr:nth-child(even) td {
  background: var(--color-surface-alt);
}

.table tbody tr:hover td {
  background: var(--color-primary-light);
}

.table .num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table tr.is-muted td {
  opacity: 0.45;
}

/* Modifiers */

.table--compact th,
.table--compact td {
  padding: var(--space-2) var(--space-3);
}

.table--sticky-head th,
.table--sticky-head thead td {
  position: sticky;
  top: 0;
  z-index: 5;
}

/* Product-list specific columns */
.table .col-thumb    { width: 60px; }
.table .col-id       { width: 60px; }
.table .col-price    { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.table .col-tva      { width: 60px; }
.table .col-ecoscore { width: 60px; }
.table .col-origin   { width: 120px; }
.table .col-desc     { font-size: var(--text-xs); max-width: 320px; }

/* Hide lower-priority columns on small screens */
@media (max-width: 480px) {
  [data-priority="2"] { display: none; }
}

/* Sortable column headers */
.table th[data-sortable],
.table thead td[data-sortable] {
  cursor: pointer;
  user-select: none;
}

.table th[data-sortable]:hover,
.table thead td[data-sortable]:hover {
  background: var(--color-surface-alt);
  filter: brightness(0.96);
}

.table th[data-sortable]:focus-visible,
.table thead td[data-sortable]:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-xs);
}

.table__sort-arrow {
  display: inline-block;
  margin-left: var(--space-1);
  font-size: var(--text-2xs);
  color: var(--color-text-soft, var(--color-text-muted));
  opacity: 0.5;
  transition: opacity 0.15s;
}

.table th[data-sortable]:hover .table__sort-arrow,
.table th[data-sortable]:focus-visible .table__sort-arrow {
  opacity: 1;
}

.table th[aria-sort="ascending"]  .table__sort-arrow::after { content: " ▲"; color: var(--color-primary); opacity: 1; }
.table th[aria-sort="descending"] .table__sort-arrow::after { content: " ▼"; color: var(--color-primary); opacity: 1; }

/* Numeric column alignment helper for sortable headers */
.table th[data-sortable].num {
  text-align: right;
}

/* Thumbnail helpers */
.product-thumb,
.supplier-thumb {
  display: block;
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: var(--radius-xs);
  border: 1px solid var(--color-border);
  background: var(--grey-50);
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-5);
  max-width: 480px;
  margin: 0 auto;
}

.empty-state--compact {
  padding: var(--space-5) var(--space-4);
}

.empty-state__icon {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
  opacity: 0.6;
}

.empty-state__title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 var(--space-2);
}

.empty-state--compact .empty-state__title {
  font-size: var(--text-lg);
}

.empty-state__desc {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-4);
  line-height: var(--leading-loose);
}

.empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
}

/* ============================================================
   Utilities
   ============================================================ */

.u-text-muted   { color: var(--color-text-muted) !important; }
.u-text-center  { text-align: center !important; }
.u-text-right   { text-align: right !important; }
.u-num          { font-variant-numeric: tabular-nums; text-align: right; }
.u-hidden       { display: none !important; }
.u-bold         { font-weight: 700 !important; }

/* Visually hidden, but readable by screen readers */
.u-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 768px) {
  .u-hidden-mobile { display: none !important; }
}
