/* SGH Configurator — front
   Palette pilotée par deux variables injectées par le shortcode, pour qu'un
   même moteur serve plusieurs univers de marque sans surcharge CSS. */

.sgh-cfg {
  --sgh-accent: #c4576b;
  --sgh-accent-soft: #fbeef1;
  --sgh-ink: #2e2a32;
  --sgh-muted: #7b7280;
  --sgh-line: #ece2e5;
  --sgh-surface: #ffffff;
  --sgh-canvas: #fdf8f9;
  --sgh-radius: 14px;
  --sgh-gap: clamp(16px, 2.4vw, 28px);

  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: var(--sgh-gap);
  align-items: start;
  color: var(--sgh-ink);
  font-size: 15px;
  line-height: 1.5;
}

@media (max-width: 880px) {
  .sgh-cfg {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}

.sgh-cfg *,
.sgh-cfg *::before,
.sgh-cfg *::after {
  box-sizing: border-box;
}

/* --- Scène ------------------------------------------------------------- */

.sgh-cfg__stagewrap {
  position: sticky;
  top: 24px;
  background: var(--sgh-canvas);
  border: 1px solid var(--sgh-line);
  border-radius: var(--sgh-radius);
  padding: 14px;
}

@media (max-width: 880px) {
  .sgh-cfg__stagewrap {
    position: static;
  }
}

.sgh-cfg__stagehead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.sgh-cfg__eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sgh-accent);
}

.sgh-cfg__note {
  font-size: 11px;
  color: var(--sgh-muted);
}

.sgh-cfg__stage {
  width: 100%;
  min-width: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--sgh-surface);
}

/* Konva fixe une largeur en pixels sur ses conteneurs : sans cette
   neutralisation, le canevas déborde dès que la colonne rétrécit. */
.sgh-cfg__stage > div {
  max-width: 100% !important;
}

.sgh-cfg__stage canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: 100%;
}

.sgh-cfg__stage-empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  text-align: center;
  color: var(--sgh-muted);
  font-size: 14px;
}

/* --- Le chapelet : composition lisible et cliquable --------------------- */

.sgh-cfg__track {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--sgh-line);
}

.sgh-slot {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px dashed var(--sgh-line);
  background: var(--sgh-surface);
  padding: 0;
  cursor: default;
  overflow: hidden;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.sgh-slot--filled {
  border: 1px solid var(--sgh-line);
  border-style: solid;
  cursor: pointer;
}

.sgh-slot--filled:hover,
.sgh-slot--filled:focus-visible {
  transform: translateY(-2px);
  border-color: var(--sgh-accent);
}

.sgh-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sgh-slot--filled::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  color: #fff;
  background: rgba(46, 42, 50, 0.55);
  opacity: 0;
  transition: opacity 0.14s ease;
}

.sgh-slot--filled:hover::after,
.sgh-slot--filled:focus-visible::after {
  opacity: 1;
}

/* --- Onglets d'articles (coffret) --------------------------------------- */

.sgh-cfg__pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.sgh-piecetab {
  border: 1px solid var(--sgh-line);
  background: var(--sgh-surface);
  color: var(--sgh-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

.sgh-piecetab[aria-selected="true"] {
  background: var(--sgh-accent);
  border-color: var(--sgh-accent);
  color: #fff;
}

/* --- Panneau de contrôles ----------------------------------------------- */

.sgh-cfg__intro {
  margin-bottom: 18px;
}

.sgh-cfg__title {
  margin: 0 0 6px;
  font-size: clamp(20px, 2.4vw, 26px);
  line-height: 1.2;
}

.sgh-cfg__lede {
  margin: 0;
  color: var(--sgh-muted);
}

.sgh-field {
  margin-bottom: 20px;
}

.sgh-field__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sgh-ink);
}

.sgh-field__count {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--sgh-muted);
}

.sgh-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sgh-chip {
  border: 1px solid var(--sgh-line);
  background: var(--sgh-surface);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--sgh-ink);
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.sgh-chip:hover {
  border-color: var(--sgh-accent);
}

.sgh-chip[aria-pressed="true"],
.sgh-chip[aria-selected="true"] {
  background: var(--sgh-accent-soft);
  border-color: var(--sgh-accent);
  color: var(--sgh-accent);
  font-weight: 600;
}

.sgh-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sgh-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--sgh-line);
  padding: 0;
  cursor: pointer;
  position: relative;
}

.sgh-swatch[aria-pressed="true"] {
  border-color: var(--sgh-accent);
  box-shadow: 0 0 0 3px var(--sgh-accent-soft);
}

.sgh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}

.sgh-tile {
  aspect-ratio: 1;
  border: 1px solid var(--sgh-line);
  border-radius: 10px;
  background: var(--sgh-surface);
  padding: 5px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.sgh-tile:hover {
  transform: translateY(-2px);
  border-color: var(--sgh-accent);
}

.sgh-tile[aria-pressed="true"] {
  border-color: var(--sgh-accent);
  box-shadow: 0 0 0 3px var(--sgh-accent-soft);
}

.sgh-tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.sgh-tile__extra {
  display: block;
  font-size: 10px;
  color: var(--sgh-accent);
  text-align: center;
}

.sgh-input {
  width: 100%;
  border: 1px solid var(--sgh-line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--sgh-ink);
  background: var(--sgh-surface);
}

.sgh-input:focus {
  outline: 2px solid var(--sgh-accent);
  outline-offset: 1px;
}

.sgh-fontlist {
  display: grid;
  gap: 6px;
}

.sgh-fontlist .sgh-chip {
  text-align: left;
  font-size: 18px;
  padding: 8px 14px;
}

/* --- Récapitulatif et actions ------------------------------------------- */

.sgh-cfg__summary {
  border-top: 1px solid var(--sgh-line);
  padding-top: 14px;
  margin-bottom: 16px;
}

.sgh-sum {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 3px 0;
  color: var(--sgh-muted);
}

.sgh-sum__value {
  color: var(--sgh-ink);
  text-align: right;
}

.sgh-sum--total {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--sgh-line);
  font-size: 17px;
  font-weight: 700;
  color: var(--sgh-ink);
}

.sgh-cfg__error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdecef;
  color: #96233a;
  font-size: 13px;
}

.sgh-cfg__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sgh-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.sgh-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sgh-btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.sgh-btn--primary {
  background: var(--sgh-accent);
  color: #fff;
  flex: 1 1 200px;
}

.sgh-btn--quiet {
  background: transparent;
  border-color: var(--sgh-line);
  color: var(--sgh-muted);
}

.sgh-btn--link {
  background: none;
  border: none;
  color: var(--sgh-muted);
  text-decoration: underline;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 500;
}

.sgh-cfg__adminhint {
  grid-column: 1 / -1;
  border-left: 3px solid #d19b2c;
  background: #fdf6e6;
  padding: 10px 14px;
  font-size: 13px;
  border-radius: 0 8px 8px 0;
}

.sgh-cart-preview {
  max-width: 72px;
  height: auto;
  border-radius: 6px;
}

.sgh-cfg :focus-visible {
  outline: 2px solid var(--sgh-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .sgh-cfg * {
    transition: none !important;
  }
}

/* --- Composition du coffret --------------------------------------------- */

.sgh-chip--piece[aria-pressed="false"] {
  opacity: 0.62;
  border-style: dashed;
}

.sgh-chip--locked {
  cursor: default;
  background: var(--sgh-accent-soft);
  border-color: var(--sgh-accent);
  color: var(--sgh-accent);
  opacity: 1;
}

.sgh-chip--locked::before {
  content: "✓ ";
}

.sgh-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--sgh-muted);
}


/* --- Petits écrans ------------------------------------------------------- */

@media (max-width: 600px) {
  .sgh-cfg {
    font-size: 14px;
  }

  .sgh-cfg__stagewrap {
    padding: 10px;
  }

  .sgh-cfg__track {
    gap: 5px;
  }

  .sgh-slot {
    width: 28px;
    height: 28px;
  }

  .sgh-grid {
    grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
    max-height: 220px;
  }

  .sgh-chip {
    padding: 6px 11px;
    font-size: 12px;
  }

  .sgh-swatch {
    width: 30px;
    height: 30px;
  }

  /* Les boutons restent dans le flux du panneau.
     En position collante, ils recouvraient la liste des polices et le
     sélecteur de couleur situés en dessous. */
  .sgh-cfg__actions {
    position: static;
    padding: 4px 0 0;
  }

  .sgh-btn--primary,
  .sgh-btn--quiet {
    flex: 1 1 100%;
  }
}

/* --- Rangée de motifs compacte ------------------------------------------ */

.sgh-strip {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding: 2px 2px 8px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

.sgh-strip::-webkit-scrollbar {
  height: 6px;
}

.sgh-strip::-webkit-scrollbar-thumb {
  background: var(--sgh-line);
  border-radius: 999px;
}

.sgh-strip__item {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  scroll-snap-align: start;
  border: 1px solid var(--sgh-line);
  border-radius: 12px;
  background: var(--sgh-surface);
  padding: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--sgh-muted);
  font-size: 15px;
  transition: border-color 0.14s ease, transform 0.14s ease;
}

.sgh-strip__item:hover {
  border-color: var(--sgh-accent);
  transform: translateY(-2px);
}

.sgh-strip__item[aria-pressed="true"] {
  border-color: var(--sgh-accent);
  background: var(--sgh-accent-soft);
  box-shadow: 0 0 0 2px var(--sgh-accent-soft);
}

.sgh-strip__item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.sgh-switchlink {
  display: inline-block;
  margin-top: 6px;
  padding-left: 0;
}

/* --- Mode diagnostic (?sgh_debug=1) -------------------------------------- */

.sgh-diag {
  grid-column: 1 / -1;
  background: #1d2327;
  color: #e6e6e6;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
}

.sgh-diag strong {
  display: block;
  margin-bottom: 8px;
  color: #f6c9d5;
  font-size: 13px;
}

.sgh-diag__row {
  display: grid;
  grid-template-columns: 18px 150px 1fr;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid #2f3439;
  word-break: break-word;
}

.sgh-diag__row span:first-child {
  font-weight: 700;
}

.sgh-diag__row span:last-child {
  color: #a7adb3;
}

.sgh-diag__foot {
  margin-top: 10px;
  color: #f6c9d5;
}
