/* ── Tour Overlay ────────────────────────────────────────────── */

/* SVG backdrop with cutout — covers entire viewport, blocks all clicks */
.tour-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: auto;
    cursor: default;
    transition: opacity .3s ease;
}

.tour-backdrop svg {
    width: 100%;
    height: 100%;
}

/* FreeInteract / WaitForElement — backdrop visible but doesn't block clicks */
.tour-backdrop--passthrough {
    pointer-events: none;
}
/* Ensure card buttons remain clickable when backdrop is passthrough */
.tour-card {
    pointer-events: auto;
}

/* Highlighted target must be above the backdrop for WaitForClick */
[data-tour-click-target="true"] {
    position: relative;
    z-index: 10001 !important;
    pointer-events: auto !important;
}

/* Pulsing animation on click target */
.tour-click-target-pulse {
    animation: tourTargetPulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
}

@keyframes tourTargetPulse {
    0%   { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    50%  { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

/* ── Tour Card ──────────────────────────────────────────────── */
.tour-card {
    position: fixed;
    z-index: 10002;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: var(--bs-card-bg, #1e293b);
    border: 1px solid var(--bs-border-color, #334155);
    border-radius: .625rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255,255,255,.05);
    padding: 1.25rem;
    transition: top .35s cubic-bezier(.4,0,.2,1),
                left .35s cubic-bezier(.4,0,.2,1),
                opacity .25s ease;
    animation: tourCardEnter .35s cubic-bezier(.4,0,.2,1);
}

@keyframes tourCardEnter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tour-card__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .625rem;
}

.tour-card__icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(59, 130, 246, .15);
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .875rem;
    flex-shrink: 0;
}

.tour-card__title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--bs-body-color, #e2e8f0);
    margin: 0;
    line-height: 1.3;
}

.tour-card__body {
    font-size: .825rem;
    line-height: 1.55;
    color: var(--bs-secondary-color, #94a3b8);
    margin-bottom: 1rem;
}

.tour-card__body strong {
    color: var(--bs-body-color, #e2e8f0);
    font-weight: 600;
}

/* ── Footer: progress + buttons ─────────────────────────────── */
.tour-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
}

.tour-card__progress {
    font-size: .75rem;
    color: var(--bs-secondary-color, #64748b);
    white-space: nowrap;
}

.tour-card__actions {
    display: flex;
    gap: .375rem;
    margin-left: auto;
    flex-shrink: 0;
}

.tour-card__btn {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .325rem .75rem;
    border-radius: .375rem;
    font-size: .8rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background .15s, transform .1s;
    white-space: nowrap;
}

.tour-card__btn:active {
    transform: scale(.96);
}

.tour-card__btn--ghost {
    background: transparent;
    color: var(--bs-secondary-color, #94a3b8);
}

.tour-card__btn--ghost:hover {
    background: rgba(255,255,255,.06);
    color: var(--bs-body-color, #e2e8f0);
}

.tour-card__btn--secondary {
    background: rgba(255,255,255,.08);
    color: var(--bs-body-color, #e2e8f0);
}

.tour-card__btn--secondary:hover {
    background: rgba(255,255,255,.12);
}

.tour-card__btn--primary {
    background: #3b82f6;
    color: #fff;
}

.tour-card__btn--primary:hover {
    background: #2563eb;
}

/* ── Progress bar dots ──────────────────────────────────────── */
.tour-card__dots {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
    flex: 1 1 auto;
    row-gap: 3px;
}

.tour-card__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bs-border-color, #334155);
    transition: background .2s, width .2s;
}

.tour-card__dot--active {
    width: 18px;
    border-radius: 3px;
    background: #3b82f6;
}

.tour-card__dot--done {
    background: rgba(59, 130, 246, .4);
}

/* ── Spotlight pulse animation ──────────────────────────────── */
.tour-spotlight-ring {
    animation: tourPulse 2s ease-in-out infinite;
}

@keyframes tourPulse {
    0%, 100% { opacity: .4; }
    50% { opacity: .15; }
}

/* ── Arrow/pointer from card to target ──────────────────────── */
.tour-card__arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--bs-card-bg, #1e293b);
    border: 1px solid var(--bs-border-color, #334155);
    transform: rotate(45deg);
}

.tour-card__arrow--top {
    bottom: -7px;
    left: 50%;
    margin-left: -6px;
    border-top: none;
    border-left: none;
}

.tour-card__arrow--bottom {
    top: -7px;
    left: 50%;
    margin-left: -6px;
    border-bottom: none;
    border-right: none;
}

.tour-card__arrow--left {
    right: -7px;
    top: 50%;
    margin-top: -6px;
    border-bottom: none;
    border-left: none;
}

.tour-card__arrow--right {
    left: -7px;
    top: 50%;
    margin-top: -6px;
    border-top: none;
    border-right: none;
}

/* ── Tour Launcher card (in settings) ───────────────────────── */
.tour-launcher-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.tour-launcher-card {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: 1rem;
    border-radius: .5rem;
    border: 1px solid var(--bs-border-color, #334155);
    background: var(--bs-card-bg, #1e293b);
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}

.tour-launcher-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px rgba(59,130,246,.25);
}

.tour-launcher-card__icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(59,130,246,.12);
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.tour-launcher-card__text h6 {
    margin: 0 0 .25rem;
    font-size: .875rem;
    font-weight: 600;
}

.tour-launcher-card__text p {
    margin: 0;
    font-size: .78rem;
    color: var(--bs-secondary-color, #94a3b8);
    line-height: 1.4;
}

/* ══════════════════════════════════════════════════════════════
   TOUR SANDBOX — Override styles for demo/sandbox pages
   QuickGrid rows, pills, editor elements, etc.
   ══════════════════════════════════════════════════════════════ */

/* Fix: .quickgrid hides rows without aria-rowindex — sandbox tables are plain HTML */
.tour-sandbox .quickgrid tbody tr {
    display: table-row !important;
}

/* ── Instrument pills (from InstrumentOverview/Instruments inline styles) ── */
.tour-sandbox .instr-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}
.tour-sandbox .pill-online  { background: rgba(40,167,69,.15);  color: #28a745; }
.tour-sandbox .pill-offline { background: rgba(108,117,125,.12); color: #6c757d; }
.tour-sandbox .pill-on      { background: rgba(253,126,20,.15);  color: #fd7e14; }
.tour-sandbox .pill-off     { background: rgba(108,117,125,.10); color: #adb5bd; }
.tour-sandbox .pill-alarm   { background: rgba(220,53,69,.15);   color: #dc3545; }
.tour-sandbox .pill-online i { animation: instr-pulse-icon 2s infinite; }
@keyframes instr-pulse-icon {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* (Dashboard editor tour now runs on real editor — no sandbox CSS needed) */

/* ── Canvas glow during tutorial (drop target highlight) ───── */
.tour-canvas-glow {
    animation: tourCanvasGlow 2s ease-in-out infinite;
    box-shadow: inset 0 0 30px rgba(59, 130, 246, 0.15) !important;
    border: 2px dashed rgba(59, 130, 246, 0.5) !important;
}
@keyframes tourCanvasGlow {
    0%, 100% { box-shadow: inset 0 0 30px rgba(59, 130, 246, 0.15); border-color: rgba(59, 130, 246, 0.5); }
    50% { box-shadow: inset 0 0 50px rgba(59, 130, 246, 0.3); border-color: rgba(59, 130, 246, 0.8); }
}

/* ── Canvas "drop target" overlay shown during drag-a-tag steps ── */
/* Stronger visual than plain glow — pulsing center label + bigger border */
.tour-canvas-glow::after {
    content: "Trascina qui";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: .5rem 1rem;
    background: rgba(59, 130, 246, 0.92);
    color: #fff;
    font-weight: 600;
    font-size: .8rem;
    border-radius: .4rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    pointer-events: none;
    animation: tourCanvasLabelPulse 1.4s ease-in-out infinite;
    z-index: 50;
}
@keyframes tourCanvasLabelPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1);   opacity: 1;   }
    50%      { transform: translate(-50%, -50%) scale(1.08); opacity: .75; }
}

/* ── Drag hint arrow — shown during drag-a-tag steps ─────────── */
/* Simple pointer sitting on the tags panel with an arrow nudging toward the canvas.
   Rendered by TourOverlay when the active step's selector is the tags panel and
   the next-action is "drag to canvas". */
.tour-drag-arrow {
    position: fixed;
    z-index: 10050;
    pointer-events: none;
    width: 120px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #38bdf8;
    font-size: .8rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    animation: tourDragArrow 1.5s ease-in-out infinite;
    text-shadow: 0 0 6px rgba(56, 189, 248, .8), 0 0 12px rgba(56, 189, 248, .5);
}
.tour-drag-arrow::after {
    content: "→";
    margin-left: .3rem;
    font-size: 1.6rem;
}
@keyframes tourDragArrow {
    0%, 100% { transform: translateX(0);    opacity: 1;  }
    50%      { transform: translateX(20px); opacity: .6; }
}

/* ── Sandbox pre-tutorial overlay ──────────────────────────── */
/* Shown briefly while /tour/editor is loading and the tour hasn't started yet,
   so users can't click anything in the editor by accident. */
.tour-sandbox-preload {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99998;
    background: rgba(8, 15, 30, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    animation: tourPreloadFade .25s ease-out;
}
.tour-sandbox-preload__card {
    background: var(--bs-card-bg, #1e293b);
    border: 1px solid var(--bs-border-color, #334155);
    border-radius: .75rem;
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    max-width: 360px;
}
@keyframes tourPreloadFade {
    from { opacity: 0; } to { opacity: 1; }
}

/* ── Tour end dialog ───────────────────────────────────────── */
.tour-end-dialog {
    position: fixed;
    inset: 0;
    z-index: 10100;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
}
.tour-end-dialog__card {
    background: var(--bs-card-bg, #1e293b);
    border: 1px solid var(--bs-border-color, #334155);
    border-radius: .75rem;
    padding: 2rem;
    max-width: 420px;
    width: 90vw;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.tour-end-dialog__card h5 { margin-bottom: 1rem; }
.tour-end-dialog__card p { font-size: .875rem; color: var(--bs-secondary-color, #94a3b8); margin-bottom: 1.5rem; }
.tour-end-dialog__actions { display: flex; gap: .75rem; justify-content: center; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 576px) {
    .tour-card {
        width: calc(100vw - 24px);
        left: 12px !important;
    }
}
