/* ─────────────────────────────────────────────────────────────
   theme-editor — Editeur click-to-edit des couleurs.
   - .tpv-* : replica compacte de /m/:slug (classes préfixées pour
     isoler du reste du dashboard)
   - Zones [data-theme-zone] sur la preview → outline + crayon au hover
   - Popover flottant (desktop) / bottom sheet (mobile < 600px)
   - Verrouillage visuel quand le marchand est sur un preset
     (détection via :has(#color-grad-from:disabled) — Safari 15.4+ / Chrome 105+)

   NOTE de maintenance : les classes .tpv-* suivent la structure visuelle de
   frontend/client/index.html. Si un nouveau bloc thémable est ajouté à la
   carte client, il doit utiliser l'une des 7 variables existantes (grad_from,
   grad_to, accent, header_text, card_bg, btn_color, btn_text) pour être coloré
   automatiquement. Le dashboard doit refléter visuellement la carte, mais
   n'a pas besoin d'update si le nouveau bloc réutilise les 7 variables.
   ───────────────────────────────────────────────────────────── */

/* ── Replica carte client (.tpv = theme preview) ──────────── */
.tpv {
  border-radius: 16px;
  overflow: hidden;
  margin: 4px auto 14px;
  max-width: 340px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
  font-family: inherit;
  background: var(--tpv-card-bg, #F4F4F8);
}

html.dark .tpv { box-shadow: 0 6px 24px rgba(0,0,0,0.4); }

/* Header (gradient) */
.tpv-header {
  background: linear-gradient(145deg, var(--tpv-grad-from, #1C1C1E) 0%, var(--tpv-grad-to, #3A3A3C) 100%);
  padding: 14px 18px 12px;
  color: var(--tpv-header-text, #fff);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: background 0.3s;
}

.tpv-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent);
}

.tpv-header::after {
  content: '';
  position: absolute;
  top: -40px; right: -30px;
  width: 110px; height: 110px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  pointer-events: none;
}

.tpv-emoji {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  color: inherit;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.25));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.tpv-emoji svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }

.tpv-emoji img { width: 22px; height: 22px; border-radius: 4px; object-fit: contain; }

.tpv-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.tpv-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 2px;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpv-type {
  font-size: 10px;
  opacity: 0.55;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  color: inherit;
  margin: 0;
}

/* Body (card_bg) */
.tpv-body {
  padding: 12px 14px 14px;
  background: var(--tpv-card-bg, #F4F4F8);
  position: relative;
  transition: background 0.3s;
}

.tpv-body > *:not(.tpv-bg-image) {
  position: relative;
  z-index: 1;
}

.tpv-bg-image {
  display: none;
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.13;
  pointer-events: none;
  z-index: 0;
}

/* Points card */
.tpv-points {
  background: var(--tpv-surface, #fff);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: background 0.3s, color 0.3s;
}

.tpv-points-top {
  padding: 12px 14px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.tpv-points-label {
  font-size: 9.5px;
  color: var(--tpv-surface-text, #1C1C1E);
  opacity: 0.45;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tpv-points-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--tpv-surface-text, #1C1C1E);
  letter-spacing: -0.04em;
  line-height: 1;
}

.tpv-points-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--tpv-accent-bg, rgba(0,87,255,0.08));
  color: var(--tpv-accent, #007AFF);
  white-space: nowrap;
  margin-top: 2px;
  flex-shrink: 0;
  letter-spacing: -0.01em;
  transition: background 0.3s, color 0.3s;
}

.tpv-points-badge svg { width: 10px; height: 10px; stroke: currentColor; fill: none; stroke-width: 2; }

.tpv-points-bar {
  padding: 0 14px 10px;
}

.tpv-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 999px;
  overflow: hidden;
}

html.dark .tpv-progress-track { background: rgba(255,255,255,0.1); }

.tpv-progress-fill {
  height: 100%;
  width: 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--tpv-accent, #007AFF), #60A5FA);
  position: relative;
  transition: background 0.3s;
}

.tpv-progress-fill::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 20px; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4));
  border-radius: 999px;
}

.tpv-points-footer {
  padding: 7px 14px;
  background: rgba(0,0,0,0.02);
  border-top: 1px solid rgba(0,0,0,0.05);
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--tpv-surface-text, #1C1C1E);
  opacity: 0.5;
  font-weight: 500;
}

html.dark .tpv-points-footer { background: rgba(255,255,255,0.02); border-top-color: rgba(255,255,255,0.05); }

/* Reward box */
.tpv-reward {
  background: var(--tpv-surface, #fff);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  transition: background 0.3s, color 0.3s;
}

.tpv-reward-emoji {
  font-size: 22px;
  flex-shrink: 0;
  color: var(--tpv-accent, #007AFF);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s;
}
.tpv-reward-emoji svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }

.tpv-reward-text { flex: 1; min-width: 0; }

.tpv-reward-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--tpv-surface-text, #1C1C1E);
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}

.tpv-reward-sub {
  font-size: 11px;
  color: var(--tpv-surface-text, #1C1C1E);
  opacity: 0.55;
  line-height: 1.4;
  margin: 0;
}

/* Boutons */
.tpv-btn {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.2px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.tpv-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }

.tpv-btn-primary {
  background: var(--tpv-btn, #1C1C1E);
  color: var(--tpv-btn-text, #fff);
  margin-bottom: 8px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.18);
}

.tpv-btn-secondary {
  background: var(--tpv-btn-secondary-bg, #fff);
  color: var(--tpv-btn-secondary-text, var(--tpv-btn, #1C1C1E));
  border: 1.5px solid var(--tpv-btn-secondary-text, var(--tpv-btn, #1C1C1E));
  margin-bottom: 12px;
  box-shadow: none;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

/* Notif block */
.tpv-notif {
  background: var(--tpv-surface, #fff);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  transition: background 0.3s, color 0.3s;
}

.tpv-notif-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--tpv-accent-bg, rgba(0,87,255,0.08));
  color: var(--tpv-accent, #007AFF);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  transition: background 0.3s, color 0.3s;
}
.tpv-notif-icon svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

.tpv-notif-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--tpv-surface-text, #1C1C1E);
  margin: 0;
  letter-spacing: -0.01em;
}

.tpv-notif-desc {
  font-size: 10.5px;
  color: var(--tpv-surface-text, #1C1C1E);
  opacity: 0.55;
  margin: 0;
  line-height: 1.3;
}

/* Secure chip (au-dessous de la carte, pas dans le body) */
.tpv-secure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  background: var(--tpv-btn, #1C1C1E);
  transition: background 0.3s, color 0.3s;
}

.tpv-secure svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2.2; }

/* Hint sous la preview */
.theme-edit-hint {
  text-align: center;
  font-size: 12px;
  color: var(--secondary, #8E8E93);
  margin: -4px 0 18px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.theme-edit-hint-icon {
  display: inline-block;
  width: 13px;
  height: 13px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4L16.5 3.5z'/%3E%3C/svg%3E") center/13px no-repeat;
}


/* ── Zones éditables ── */
[data-theme-zone] {
  position: relative;
  cursor: pointer;
  transition: outline-color 0.15s, box-shadow 0.15s;
}

[data-theme-zone]:hover {
  outline: 2px dashed var(--blue, #007AFF);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0, 102, 255, 0.08);
}

[data-theme-zone]::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23007AFF' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4L16.5 3.5z'/%3E%3C/svg%3E") center/14px no-repeat;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  z-index: 4;
}

[data-theme-zone]:hover::after,
[data-theme-zone].tep-zone-active::after {
  opacity: 1;
  transform: scale(1);
}

[data-theme-zone].tep-zone-active {
  outline: 2px solid var(--blue, #007AFF);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0, 102, 255, 0.18);
}

/* Wrapper pour élargir la hit-area de la barre de progression (6px native → 22px tactile) */
.preview-bar-zone {
  padding: 8px 0;
  margin: 2px 0;
}

/* ── Verrouillage visuel quand le marchand est sur un preset ── */
/* Le lock s'appuie sur l'état disabled du 1er input color (maintenu par updateSpecialLock) */
.card:has(#color-grad-from:disabled) [data-theme-zone] {
  cursor: not-allowed;
}
.card:has(#color-grad-from:disabled) [data-theme-zone]:hover {
  outline: none;
  box-shadow: none;
}
.card:has(#color-grad-from:disabled) [data-theme-zone]::after,
.card:has(#color-grad-from:disabled) [data-theme-zone]:hover::after {
  display: none;
}

/* ── Popover — base partagée ── */
.tep {
  position: absolute;
  background: #fff;
  color: var(--primary, #1C1C1E);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 1100;
  width: 260px;
  padding: 14px;
  font-family: inherit;
  animation: tep-appear 0.16s cubic-bezier(0.2, 1.05, 0.4, 1);
}

.tep.hidden { display: none; }

html.dark .tep {
  background: var(--card, #1C1C1E);
  color: var(--text, #fff);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
}

@keyframes tep-appear {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.tep-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.tep-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary, #1C1C1E);
  letter-spacing: -0.2px;
}

html.dark .tep-label { color: var(--text, #fff); }

.tep-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  color: var(--secondary, #8E8E93);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.tep-close:hover { background: var(--bg, #F2F2F7); color: var(--primary, #1C1C1E); }
html.dark .tep-close:hover { background: rgba(255,255,255,0.08); color: #fff; }

.tep-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tep-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1.5px solid var(--separator, #E5E5EA);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--card, #fff);
}
.tep-field:hover { border-color: var(--blue, #007AFF); background: rgba(0,102,255,0.03); }
html.dark .tep-field { background: var(--surface, #1C1C1E); border-color: var(--separator, #38383A); }
html.dark .tep-field:hover { background: rgba(0,122,255,0.12); }

.tep-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary, #8E8E93);
  letter-spacing: 0.1px;
}

.tep-field-ctrl {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tep-hex {
  font-size: 11.5px;
  font-weight: 700;
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
  color: var(--secondary, #8E8E93);
  min-width: 62px;
  text-align: right;
  letter-spacing: 0.4px;
}

.tep-color {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--separator, #E5E5EA);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: #fff;
  outline: none;
}

/* ── Mobile : bottom sheet ── */
.tep.tep-bottom-sheet {
  position: fixed;
  top: auto !important;
  left: 0 !important;
  right: 0;
  bottom: 0;
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 16px 20px max(22px, env(safe-area-inset-bottom, 22px));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  animation: tep-slide-up 0.22s cubic-bezier(0.2, 1.05, 0.4, 1);
}

@keyframes tep-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.tep.tep-bottom-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--separator, #E5E5EA);
  margin: 0 auto 14px;
}

html.dark .tep.tep-bottom-sheet::before { background: rgba(255,255,255,0.16); }
