/**
 * Wizard Chatbot — overlay blur + 8 pași + popup progres persistent
 *
 * Ultima modificare: 2026-04-17 20:20
 * Modificari:
 *   2026-04-17 20:30 — Fix SweetAlert2 confirm ascuns în spatele overlay: .swal2-container z-index 10700
 *   2026-04-17 20:20 — Fix definitiv widget peste overlay: ascundere #_aw + #allai-chat-frame + #claude-agent-glow-border (embed real cu z-index 2147483647)
 *   2026-04-17 11:45 — Creare inițială: overlay blur, stepper, carduri, progress popup
 */

/* ═══ OVERLAY BLUR ═══ */
#wizardOverlay {
    position: fixed; inset: 0; z-index: 10500;
    display: none;
    background: rgba(15, 18, 40, 0.55);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    overflow-y: auto;
    padding: 32px 16px;
    animation: wizardFadeIn .25s ease-out;
}
#wizardOverlay.active { display: block; }

/* Când wizardul e deschis, toate widget-urile/chat-bubbles injectate pe pagină trebuie ascunse complet.
   ID-uri REALE folosite de embed-ul AllAI: #_aw (bubble) + #allai-chat-frame (iframe chat) + #claude-agent-glow-border.
   Folosesc z-index 2147483647 (max int) → nu putem urca peste ei, trebuie să-i ASCUNDEM.
   Legacy: #_rb-buddy + #_rb-speech (allai-buddy robot) rămân blur în spate. */
body.wizard-active #_aw,
body.wizard-active #allai-chat-frame,
body.wizard-active #claude-agent-glow-border,
body.wizard-active [id*="allai-chatbot"],
body.wizard-active iframe[src*="chatbot"],
body.wizard-active .chatbot-widget-bubble,
body.wizard-active #allai-buddy-bubble,
body.wizard-active .allai-buddy-bubble,
body.wizard-active #allai-buddy-widget,
body.wizard-active .allai-buddy-widget {
    display: none !important;
}
/* Buddy-ul „robot" e doar decorativ — rămâne vizibil dar blur & neinteractiv */
body.wizard-active #_rb-buddy,
body.wizard-active #_rb-speech {
    z-index: 100 !important;
    pointer-events: none !important;
    filter: blur(2px);
    opacity: 0.35;
    transition: opacity .2s, filter .2s;
}

@keyframes wizardFadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ═══ CONTAINER WIZARD ═══ */
.wizard-container {
    max-width: 920px; margin: 0 auto;
    background: var(--bs-body-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,.35);
    overflow: hidden;
    position: relative;
}
[data-bs-theme="dark"] .wizard-container { background: #1e2236; }

.wizard-header {
    background: linear-gradient(135deg, #6b61fc 0%, #8b7fff 100%);
    color: #fff; padding: 22px 32px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
}
.wizard-header h2 {
    color: #fff; font-weight: 700; font-size: 1.35rem; margin: 0;
    display: flex; align-items: center; gap: 10px;
}
.wizard-header .badge {
    background: rgba(255,255,255,.22); color: #fff; font-weight: 600;
    padding: 6px 12px; border-radius: 999px; font-size: .75rem;
}
.wizard-close {
    background: rgba(255,255,255,.16); border: none; color: #fff;
    width: 36px; height: 36px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background .15s;
}
.wizard-close:hover { background: rgba(255,255,255,.32); }

/* ═══ STEPPER DOTS ═══ */
.wizard-stepper {
    padding: 22px 32px 6px; background: var(--bs-body-bg, #fff);
    border-bottom: 1px solid var(--bs-border-color, #e8eaf0);
}
[data-bs-theme="dark"] .wizard-stepper { background: #1e2236; border-bottom-color: #2a3049; }

.wizard-stepper .steps-row { display: flex; align-items: center; gap: 0; }
.wizard-stepper .step-dot {
    width: 30px; height: 30px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 700; flex-shrink: 0;
    transition: all .2s;
}
.wizard-stepper .step-dot.pending   { background: #e8eaf0; color: #94a3b8; }
.wizard-stepper .step-dot.current   { background: #6b61fc; color: #fff; transform: scale(1.1); box-shadow: 0 0 0 4px rgba(107,97,252,.22); }
.wizard-stepper .step-dot.completed { background: #6b61fc; color: #fff; }
[data-bs-theme="dark"] .wizard-stepper .step-dot.pending { background: #2a3049; color: #6b7290; }

.wizard-stepper .step-line {
    flex: 1; height: 3px; background: #e8eaf0; margin: 0 6px; border-radius: 2px;
    transition: background .25s;
}
.wizard-stepper .step-line.completed { background: #6b61fc; }
[data-bs-theme="dark"] .wizard-stepper .step-line { background: #2a3049; }

.wizard-stepper-meta {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 10px; font-size: .72rem; color: var(--bs-secondary-color, #94a3b8);
}
.wizard-stepper-meta .step-title { font-weight: 600; color: #6b61fc; }

/* ═══ STEPS CONTENT ═══ */
.wizard-body { padding: 28px 32px 20px; min-height: 400px; max-height: calc(100vh - 280px); overflow-y: auto; }
.wizard-step { display: none; animation: stepIn .25s ease-out; }
.wizard-step.active { display: block; }
@keyframes stepIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: translateY(0) } }

.wizard-step h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; color: var(--bs-body-color); }
.wizard-step .step-subtitle { color: var(--bs-secondary-color, #94a3b8); font-size: .9rem; margin-bottom: 20px; }

/* Suprimă orice ::after adăugat de Metronic pe label-uri (evită dublarea stelei) */
#wizardOverlay .form-label::after,
#wizardOverlay label::after { content: none !important; }

/* Select2 in wizard — match form-control-solid sm */
#wizardOverlay .select2-container--default .select2-selection--single {
    height: calc(1.5em + 0.75rem + 2px);
    background-color: #f5f8fa;
    border: 1px solid #f5f8fa;
    border-radius: .475rem;
    padding: 2px 6px;
    font-size: .875rem;
}
#wizardOverlay .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.9; padding-left: 6px; color: var(--bs-body-color);
}
#wizardOverlay .select2-container--default .select2-selection--single .select2-selection__arrow { height: 100%; }
#wizardOverlay .select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #6b61fc;
    background: #eef2ff;
}
/* Dropdown select2 — forțează deasupra overlay-ului */
.select2-container--open { z-index: 10600 !important; }
/* SweetAlert2 trebuie să apară DEASUPRA overlay-ului wizardului (inclusiv confirmul de închidere) */
.swal2-container { z-index: 10700 !important; }

.wizard-section-title {
    font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: #6b61fc; margin: 6px 0 12px; padding-bottom: 6px;
    border-bottom: 1px solid var(--bs-border-color, #e8eaf0);
    display: flex; align-items: center; gap: 6px;
}
.wizard-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.wizard-form-row.single { grid-template-columns: 1fr; }
.wizard-form-row-3 { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 14px; margin-bottom: 14px; }
.wizard-form-row .form-label { font-size: .78rem; font-weight: 600; margin-bottom: 4px; color: var(--bs-body-color); }
.wizard-form-row .form-label .required { color: #e74c3c; }

/* ═══ CHIP-URI & TOGGLE BUTTONS ═══ */
.wizard-chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.wizard-chip {
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--bs-border-color, #e8eaf0);
    cursor: pointer; font-size: .8rem; transition: all .15s;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color);
    user-select: none;
}
.wizard-chip:hover { border-color: #6b61fc; }
.wizard-chip.selected { background: #6b61fc; color: #fff; border-color: #6b61fc; }

.wizard-toggle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.wizard-toggle-btn {
    background: var(--bs-body-bg, #fff); border: 2px solid var(--bs-border-color, #e8eaf0);
    border-radius: 12px; padding: 14px 10px; cursor: pointer;
    text-align: center; transition: all .15s;
    font-size: .85rem; color: var(--bs-body-color);
}
.wizard-toggle-btn:hover { border-color: #6b61fc; }
.wizard-toggle-btn.active { border-color: #6b61fc; background: rgba(107,97,252,.08); color: #6b61fc; font-weight: 600; }
.wizard-toggle-btn .emoji { display: block; font-size: 1.4rem; margin-bottom: 4px; }

/* ═══ LINK ROWS & CUSTOM FIELDS ═══ */
.link-row, .custom-field-row { display: grid; gap: 8px; margin-bottom: 8px; align-items: center; }
.link-row, .custom-field-row { grid-template-columns: 1fr 2fr 30px; }
.link-row input, .custom-field-row input, .custom-field-row select { font-size: .85rem; }

/* ═══ SERVICE CARD ═══ */
.svc-card {
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #e8eaf0);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    animation: fadeIn 0.2s;
}
[data-bs-theme="dark"] .svc-card { background: #21253b; border-color: #2a3049; }
.svc-card .svc-header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.svc-card .svc-desc { margin-bottom: 8px; font-size: .85rem; }
.svc-card .svc-price-row {
    display: grid;
    grid-template-columns: 1.3fr 0.8fr 1.2fr 0.9fr auto;
    gap: 8px; align-items: end;
}
.svc-card .svc-price-row label { font-size: .7rem; color: var(--bs-secondary-color,#94a3b8); margin-bottom: 2px; display: block; font-weight: 500; }
.svc-card .svc-price-row input, .svc-card .svc-price-row select { font-size: .85rem; }
.svc-card .svc-price-from-wrap { display: flex; align-items: center; gap: 6px; padding-bottom: 6px; white-space: nowrap; font-size: .8rem; color: var(--bs-body-color); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.wizard-row-remove {
    background: transparent; border: none; color: #c0392b; cursor: pointer;
    width: 30px; height: 30px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem; line-height: 1;
}
.wizard-row-remove:hover { background: rgba(192,57,43,.12); }

/* ═══ SCHEDULE COMPLEX — Închis | Non-stop | Ziua | Intervale | + ═══ */
.sched-day-row { padding: 10px 0; border-bottom: 1px dashed var(--bs-border-color,#e8eaf0); }
.sched-day-row:last-child { border-bottom: none; }
.sched-day-head { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.sched-day-label { width: 90px; font-weight: 600; font-size: .85rem; color: var(--bs-body-color); flex-shrink: 0; }
.sched-check { font-size: .78rem; white-space: nowrap; margin-bottom: 0; display: flex; align-items: center; gap: 4px; cursor: pointer; }
.sched-check .form-check-input { margin: 0; width: 15px; height: 15px; }
.sched-intervals { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 220px; }
.sched-interval { display: flex; align-items: center; gap: 6px; }
.sched-interval input[type=time] { width: 105px; font-size: .82rem; }
.sched-remove-interval {
    background: transparent; border: none; color: #c0392b; cursor: pointer;
    width: 22px; height: 22px; border-radius: 50%; font-size: 1.1rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
.sched-remove-interval:hover { background: rgba(192,57,43,.12); }
.sched-add-interval {
    background: rgba(107,97,252,.1); border: none; color: #6b61fc;
    width: 28px; height: 28px; border-radius: 50%; font-size: 1.2rem; cursor: pointer;
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
}
.sched-add-interval:hover { background: #6b61fc; color: #fff; }
.sched-day-nonstop .sched-day-label::after { content: " 🟢 Non-stop"; color: #10b981; font-size: .7rem; font-weight: 500; }
.sched-day-closed .sched-day-label { opacity: 0.5; text-decoration: line-through; }
.sched-day-closed .sched-day-label::after { content: " (închis)"; color: #94a3b8; font-size: .7rem; font-weight: 400; text-decoration: none; display: inline-block; }

/* ═══ ADAPTIVE SECTIONS ═══ */
.adaptive-section { display: none; margin-top: 16px; }
.adaptive-section.visible { display: block; }

.adaptive-section .checkbox-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border: 1px solid var(--bs-border-color, #e8eaf0);
    border-radius: 8px; margin-bottom: 6px; cursor: pointer;
    transition: all .15s; font-size: .85rem;
}
.adaptive-section .checkbox-row:hover { border-color: #6b61fc; background: rgba(107,97,252,.04); }
.adaptive-section .checkbox-row input[type=checkbox] { accent-color: #6b61fc; width: 16px; height: 16px; }

/* ═══ CHANNEL CARDS ═══ */
.channel-card {
    border: 2px solid var(--bs-border-color, #e8eaf0);
    border-radius: 12px; padding: 16px; transition: all .15s;
    background: var(--bs-body-bg, #fff);
    margin-bottom: 10px; display: flex; gap: 14px; align-items: flex-start;
}
.channel-card.enabled { border-color: #6b61fc; background: rgba(107,97,252,.04); }
.channel-card .icon-box {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(107,97,252,.12); color: #6b61fc; font-size: 1.3rem; flex-shrink: 0;
}
.channel-card .info h5 { font-size: .95rem; font-weight: 700; margin: 0 0 4px; color: var(--bs-body-color); }
.channel-card .info p  { font-size: .8rem; color: var(--bs-secondary-color,#94a3b8); margin: 0; line-height: 1.5; }

/* ═══ WIDGET PREVIEW ═══ */
.wizard-preview-pane {
    background: linear-gradient(135deg, #f0f2f7 0%, #e6e9f2 100%);
    border-radius: 12px; min-height: 320px; position: relative; overflow: hidden;
    border: 1px solid var(--bs-border-color, #e8eaf0);
}
[data-bs-theme="dark"] .wizard-preview-pane { background: linear-gradient(135deg, #21253b 0%, #151827 100%); }

.wizard-preview-pane .preview-bubble {
    position: absolute; bottom: 16px; right: 16px;
    width: 60px; height: 60px; border-radius: 50%;
    background: #6b61fc; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem; box-shadow: 0 6px 20px rgba(107,97,252,.4); cursor: pointer;
}
.wizard-preview-pane .preview-chat {
    position: absolute; bottom: 88px; right: 16px;
    width: 300px; background: #fff; border-radius: 14px; overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
    font-size: .8rem;
}
.wizard-preview-pane .preview-chat .preview-header {
    background: #6b61fc; color: #fff; padding: 10px 14px;
    font-weight: 600; font-size: .85rem;
}
.wizard-preview-pane .preview-chat .preview-body { padding: 12px; }
.wizard-preview-pane .preview-chat .preview-msg {
    background: #f3f4f7; border-radius: 10px; padding: 8px 10px;
    font-size: .78rem; margin-bottom: 8px; color: #2c3e50;
}
.wizard-preview-pane .preview-chat .preview-sugs { display: flex; flex-wrap: wrap; gap: 4px; }
.wizard-preview-pane .preview-chat .preview-sug {
    background: #fff; border: 1px solid #d5d8e0; border-radius: 999px;
    padding: 3px 10px; font-size: .7rem; color: #6b61fc;
}

/* ═══ SUMMARY ═══ */
.wizard-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wizard-summary-card {
    border: 1px solid var(--bs-border-color, #e8eaf0);
    border-radius: 10px; padding: 12px 14px; background: var(--bs-body-bg, #fff);
}
.wizard-summary-card h6 {
    font-size: .85rem; font-weight: 700; margin: 0 0 8px;
    color: #6b61fc; display: flex; align-items: center; gap: 6px;
}
.wizard-summary-card .kv { display: grid; grid-template-columns: 1fr 1.5fr; gap: 4px 8px; font-size: .78rem; }
.wizard-summary-card .kv .k { color: var(--bs-secondary-color, #94a3b8); }
.wizard-summary-card .kv .v { font-weight: 600; color: var(--bs-body-color); overflow-wrap: anywhere; }

/* ═══ FOOTER NAV ═══ */
.wizard-footer {
    padding: 16px 32px;
    border-top: 1px solid var(--bs-border-color, #e8eaf0);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bs-body-bg, #fff);
    position: sticky; bottom: 0;
}
[data-bs-theme="dark"] .wizard-footer { background: #1e2236; border-top-color: #2a3049; }

.wizard-footer .step-hint { font-size: .75rem; color: var(--bs-secondary-color, #94a3b8); }

/* ═══ LAUNCH BUTTON (pas 8) ═══ */
.wizard-launch-btn {
    padding: 14px 36px; font-size: 1rem; font-weight: 700;
    background: linear-gradient(135deg, #6b61fc 0%, #8b7fff 100%);
    border: none; color: #fff; border-radius: 12px; cursor: pointer;
    box-shadow: 0 8px 24px rgba(107,97,252,.35);
    transition: transform .15s, box-shadow .15s;
}
.wizard-launch-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(107,97,252,.45); }
.wizard-launch-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* ═══ PROGRESS POPUP (M8) ═══ */
#autotrainProgressPopup {
    position: fixed; bottom: 110px; right: 20px; z-index: 10400;
    width: 340px; background: var(--bs-body-bg, #fff);
    border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.22);
    border: 1px solid var(--bs-border-color, #e8eaf0);
    overflow: hidden; display: none;
    animation: popupIn .3s ease-out;
}
[data-bs-theme="dark"] #autotrainProgressPopup { background: #1e2236; }
#autotrainProgressPopup.visible { display: block; }
@keyframes popupIn { from { transform: translateY(20px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

#autotrainProgressPopup .popup-header {
    background: linear-gradient(135deg, #6b61fc 0%, #8b7fff 100%);
    color: #fff; padding: 12px 16px;
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600;
}
#autotrainProgressPopup .popup-header .name { font-size: .9rem; }
#autotrainProgressPopup .popup-header .close-btn {
    background: rgba(255,255,255,.22); border: none; color: #fff;
    width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
#autotrainProgressPopup .popup-body { padding: 14px 16px; }
#autotrainProgressPopup .progress { height: 8px; border-radius: 4px; background: #eef0f5; overflow: hidden; margin-bottom: 10px; }
[data-bs-theme="dark"] #autotrainProgressPopup .progress { background: #2a3049; }
#autotrainProgressPopup .progress-bar {
    background: linear-gradient(90deg, #6b61fc, #8b7fff);
    height: 100%; border-radius: 4px; transition: width .6s ease;
}
#autotrainProgressPopup .popup-substep { font-size: .82rem; color: var(--bs-body-color); margin-bottom: 6px; }
#autotrainProgressPopup .popup-meta { font-size: .72rem; color: var(--bs-secondary-color,#94a3b8); display: flex; justify-content: space-between; }
#autotrainProgressPopup .popup-cta {
    display: block; text-align: center; padding: 10px; background: #6b61fc; color: #fff;
    border-radius: 8px; text-decoration: none; font-weight: 600; font-size: .85rem; margin-top: 10px;
}
#autotrainProgressPopup .popup-cta:hover { background: #5a4bd6; color: #fff; }
#autotrainProgressPopup.status-done .popup-header { background: linear-gradient(135deg,#10b981,#059669); }
#autotrainProgressPopup.status-failed .popup-header { background: linear-gradient(135deg,#ef4444,#b91c1c); }

@media (max-width: 820px) {
    .wizard-form-row, .wizard-form-row-3 { grid-template-columns: 1fr; }
    .svc-card .svc-price-row { grid-template-columns: 1fr 1fr; }
    .wizard-summary { grid-template-columns: 1fr; }
    #autotrainProgressPopup { width: calc(100vw - 32px); right: 16px; left: 16px; }
}
