/* ─── Alkemist CSS — Frontend Editor Styles ─────────────────────────────────── */
:root {
  --ak-grad-start: #6a11cb;
  --ak-grad-end:   #2575fc;
  --ak-gradient:   linear-gradient(135deg, var(--ak-grad-start), var(--ak-grad-end));
}

/* ─── Editable wrapper ──────────────────────────────────────────────────────── */
[data-alkemist-editable] {
  position: relative;
}

/* ─── Edit button ───────────────────────────────────────────────────────────── */
.alkemist-edit-btn {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 9990;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--ak-gradient);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(106,17,203,.35);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}

[data-alkemist-editable]:hover > .alkemist-edit-btn,
[data-alkemist-editable].alkemist-hovered > .alkemist-edit-btn {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.alkemist-edit-btn svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
  flex-shrink: 0;
}

/* ─── Hover outline ─────────────────────────────────────────────────────────── */
[data-alkemist-editable]:hover,
[data-alkemist-editable].alkemist-hovered {
  outline: 2px dashed rgba(106,17,203,.35);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ─── Backdrop ──────────────────────────────────────────────────────────────── */
#alkemist-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,15,35,.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 99990;
  opacity: 0;
  transition: opacity .22s ease;
}

#alkemist-backdrop.open {
  display: block;
}

#alkemist-backdrop.visible {
  opacity: 1;
}

/* ─── Modal ─────────────────────────────────────────────────────────────────── */
#alkemist-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -46%);
  z-index: 99999;
  width: min(540px, calc(100vw - 32px));
  background: rgba(255,255,255,.97);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15,15,35,.22), 0 2px 8px rgba(106,17,203,.08);
  border: 1px solid rgba(255,255,255,.6);
  overflow: hidden;
  opacity: 0;
  transition: opacity .22s ease, transform .22s ease;
}

#alkemist-modal.open {
  display: block;
}

#alkemist-modal.visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* Modal header */
.alkemist-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  background: linear-gradient(135deg, #f8f4ff, #f0f6ff);
  border-bottom: 1px solid #e2e8f0;
}

.alkemist-modal-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #1a202c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alkemist-modal-header h3::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ak-gradient);
  box-shadow: 0 0 6px rgba(106,17,203,.5);
}

.alkemist-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #94a3b8;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}

.alkemist-modal-close:hover { color: #1a202c; }

/* Modal body */
.alkemist-modal-body {
  padding: 24px;
}

/* ─── Toolbar ───────────────────────────────────────────────────────────────── */
.alkemist-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.alkemist-tool-btn {
  width: 34px;
  height: 34px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #475569;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.alkemist-tool-btn:hover {
  border-color: var(--ak-grad-end);
  color: var(--ak-grad-end);
}

.alkemist-tool-btn.active {
  background: var(--ak-gradient);
  color: #fff;
  border-color: transparent;
}

.alkemist-toolbar-sep {
  width: 1px;
  background: #e2e8f0;
  margin: 4px 2px;
}

/* ─── Editable area ─────────────────────────────────────────────────────────── */
.alkemist-edit-area {
  width: 100%;
  min-height: 100px;
  padding: 12px 16px;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  font-size: .95rem;
  line-height: 1.6;
  color: #1a202c;
  background: #fafafa;
  resize: vertical;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.alkemist-edit-area:focus {
  border-color: var(--ak-grad-end);
  box-shadow: 0 0 0 3px rgba(37,117,252,.12);
  background: #fff;
}

/* contenteditable */
[contenteditable].alkemist-edit-area {
  cursor: text;
}

/* ─── Image tabs nav ────────────────────────────────────────────────────────── */
.ak-img-tabs-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.ak-img-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.ak-img-tab:hover { border-color: #b8c6fb; color: #2575fc; }

.ak-img-tab.ak-active {
  background: var(--ak-gradient);
  color: #fff;
  border-color: transparent;
}

/* ─── Image panels ───────────────────────────────────────────────────────────── */
.ak-img-panel { }

/* ─── Image search row ───────────────────────────────────────────────────────── */
.ak-img-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.ak-img-search-input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  font-size: .875rem;
  color: #1a202c;
  background: #fafafa;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}

.ak-img-search-input:focus {
  border-color: #2575fc;
  box-shadow: 0 0 0 3px rgba(37,117,252,.12);
  background: #fff;
}

.ak-img-search-btn {
  padding: 9px 18px;
  background: var(--ak-gradient);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  font-family: inherit;
  white-space: nowrap;
}

.ak-img-search-btn:hover { opacity: .9; }
.ak-img-search-btn:disabled { opacity: .6; pointer-events: none; }

/* ─── Image grid ─────────────────────────────────────────────────────────────── */
.ak-img-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.ak-img-thumb {
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: border-color .15s, transform .15s;
  position: relative;
}

.ak-img-thumb:hover { border-color: #6a11cb; transform: scale(1.03); }
.ak-img-thumb.ak-selected { border-color: #2575fc; box-shadow: 0 0 0 2px rgba(37,117,252,.3); }

.ak-img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ak-img-loading,
.ak-img-error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  color: #94a3b8;
  font-size: .875rem;
}

.ak-img-error { color: #ef4444; }

.ak-img-credit {
  font-size: .75rem;
  color: #94a3b8;
  margin: 4px 0 0;
  text-align: right;
}

/* ─── URL label ───────────────────────────────────────────────────────────────── */
.ak-url-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 6px;
}

/* ─── Image section ─────────────────────────────────────────────────────────── */
.alkemist-image-section {
  text-align: center;
}

.alkemist-image-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}

.alkemist-image-placeholder {
  width: 100%;
  height: 140px;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #94a3b8;
  font-size: .875rem;
  margin-bottom: 12px;
}

.alkemist-select-img-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #f8f4ff, #f0f6ff);
  border: 1.5px solid #d4c5f9;
  border-radius: 10px;
  color: var(--ak-grad-start);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.alkemist-select-img-btn:hover {
  background: var(--ak-gradient);
  color: #fff;
  border-color: transparent;
}

/* ─── Modal footer ──────────────────────────────────────────────────────────── */
.alkemist-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid #e2e8f0;
}

.alkemist-btn {
  padding: 9px 22px;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .18s;
  font-family: inherit;
}

.alkemist-btn-cancel {
  background: #f1f5f9;
  color: #64748b;
}

.alkemist-btn-cancel:hover { background: #e2e8f0; }

.alkemist-btn-save {
  background: var(--ak-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(106,17,203,.25);
}

.alkemist-btn-save:hover { opacity: .9; transform: translateY(-1px); }
.alkemist-btn-save:active { transform: none; }

.alkemist-btn-save.loading {
  opacity: .7;
  pointer-events: none;
}

/* ─── Toast notification ────────────────────────────────────────────────────── */
#alkemist-toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999999;
  padding: 12px 20px;
  background: #1a202c;
  color: #fff;
  border-radius: 12px;
  font-size: .875rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transform: translateY(20px);
  opacity: 0;
  transition: all .25s ease;
  pointer-events: none;
}

#alkemist-toast.show {
  opacity: 1;
  transform: translateY(0);
}

#alkemist-toast.success { background: linear-gradient(135deg, #059669, #10b981); }
#alkemist-toast.error   { background: linear-gradient(135deg, #dc2626, #ef4444); }

/* ─── Gallery manage bar (visibile agli editor sotto ogni galleria Elementor) ── */
.alkemist-gallery-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 7px 8px;
  background: rgba(106,17,203,.05);
  border: 1px dashed rgba(106,17,203,.28);
  border-radius: 0 0 8px 8px;
  margin-top: 2px;
}

.alkemist-gallery-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 16px;
  background: var(--ak-gradient);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(106,17,203,.28);
  transition: opacity .15s;
}

.alkemist-gallery-bar-btn:hover { opacity: .88; }

.alkemist-gallery-bar-btn svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
  flex-shrink: 0;
}

/* ─── Gallery strip nel modale ──────────────────────────────────────────────── */
.alkemist-gal-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding: 2px;
}

.alkemist-gal-item {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color .15s;
  background: #f1f5f9;
}

.alkemist-gal-item:hover { border-color: rgba(106,17,203,.5); }
.alkemist-gal-item[draggable="true"] { cursor: grab; }
.alkemist-gal-item.dragging { opacity: .35; cursor: grabbing; }
.alkemist-gal-item.drag-over { border-color: #2575fc; box-shadow: 0 0 0 2px rgba(37,117,252,.3); }

.alkemist-gal-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.alkemist-gal-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(220,38,38,.85);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  font-family: inherit;
}

.alkemist-gal-item:hover .alkemist-gal-remove { opacity: 1; }

/* ─── Add button nel gallery manager ────────────────────────────────────────── */
.alkemist-gallery-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 18px;
  background: linear-gradient(135deg, #f8f4ff, #f0f6ff);
  border: 1.5px solid #d4c5f9;
  border-radius: 10px;
  color: var(--ak-grad-start);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.alkemist-gallery-add-btn:hover {
  background: var(--ak-gradient);
  color: #fff;
  border-color: transparent;
}

/* ─── Fix WP Media Modal tabs sul frontend ──────────────────────────────────── */
/* wp_enqueue_media() carica il modale senza tutto il CSS admin, i tab perdono  */
/* il colore del testo (bianco su bianco). Questi stili correggono la visibilità. */
.media-modal .media-router .media-menu-item {
  color: #1a202c !important;
  text-shadow: none !important;
  background: transparent !important;
}

.media-modal .media-router .media-menu-item:hover {
  color: var(--ak-grad-start) !important;
}

.media-modal .media-router .media-menu-item.active {
  color: #fff !important;
  background: var(--ak-gradient) !important;
  border-color: transparent !important;
}

/* Fix testo bianco su sfondi chiari nel modale media */
.media-modal,
.media-modal .media-sidebar,
.media-modal .media-frame-content,
.media-modal .attachment-details,
.media-modal .setting span {
  color: #1a202c;
}

.media-modal input[type="text"],
.media-modal input[type="url"],
.media-modal textarea {
  color: #1a202c !important;
}
