/* ===============================
   Tutorial / Guide System
   Professional Walkthrough Styling
   Enhanced with animations & polish
   =============================== */

/* ---- Keyframe Animations ---- */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes gentlePulse {
    0%, 100% { 
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 0 rgba(230, 126, 34, 0.4);
    }
    50% { 
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(230, 126, 34, 0);
    }
}

@keyframes buttonShimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

@keyframes contentFadeIn {
    from { opacity: 0; transform: translateX(-6px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Guide header bar - ABSOLUTE fixed at top right corner */
.guide-header-bar {
    position: fixed !important;
    top: 12px !important;
    right: 24px !important;
    z-index: 9999 !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    background: linear-gradient(135deg, rgba(13, 17, 23, 0.98) 0%, rgba(22, 27, 34, 0.98) 100%) !important;
    border: 1px solid rgba(230, 126, 34, 0.5) !important;
    border-radius: 24px !important;
    padding: 8px 14px 8px 16px !important;
    backdrop-filter: blur(16px) saturate(180%) !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5) !important;
    transform: translateZ(0) !important;
    will-change: transform, box-shadow !important;
    animation: fadeSlideIn 0.4s ease-out, gentlePulse 3s ease-in-out 2s infinite !important;
}

.guide-prompt-text {
    font-size: 12px;
    color: #8b949e;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: color 0.2s ease;
}

.guide-header-bar:hover .guide-prompt-text {
    color: #c9d1d9;
}

.guide-btn,
#btn-start-guide {
    font-size: 11px !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em !important;
    padding: 6px 18px !important;
    height: auto !important;
    border-radius: 16px !important;
    background: linear-gradient(135deg, #E67E22 0%, #D35400 50%, #E67E22 100%) !important;
    background-size: 200% auto !important;
    border: none !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(230, 126, 34, 0.35) !important;
    transition: all 0.25s ease !important;
    cursor: pointer !important;
}

#btn-start-guide:hover {
    transform: translateY(-2px) scale(1.02) !important;
    box-shadow: 0 6px 20px rgba(230, 126, 34, 0.55) !important;
    animation: buttonShimmer 1.5s ease infinite !important;
}

#btn-start-guide:active {
    transform: translateY(0) scale(0.98) !important;
}

/* ===============================
   Guide Popover Container
   =============================== */
.guide-popover-container,
#guide-popover {
    max-width: 440px !important;
    width: 440px !important;
    z-index: 2000 !important;
}

#guide-popover .popover {
    background: linear-gradient(180deg, #161b22 0%, #0d1117 100%) !important;
    border: 1px solid rgba(230, 126, 34, 0.35) !important;
    border-radius: 14px !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 
                0 0 0 1px rgba(230, 126, 34, 0.15),
                0 0 60px -10px rgba(230, 126, 34, 0.15) !important;
    overflow: hidden !important;
    animation: fadeSlideIn 0.3s ease-out !important;
}

#guide-popover .popover-arrow::before,
#guide-popover .popover-arrow::after {
    border-bottom-color: #161b22 !important;
}

/* Popover Header */
.guide-popover-header,
#guide-popover .popover-header {
    background: linear-gradient(135deg, rgba(230, 126, 34, 0.18) 0%, rgba(230, 126, 34, 0.06) 100%) !important;
    border-bottom: 1px solid rgba(230, 126, 34, 0.25) !important;
    color: #E67E22 !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    letter-spacing: 0.03em !important;
    padding: 16px 20px !important;
    text-transform: uppercase !important;
    position: relative !important;
}

.guide-popover-header::before,
#guide-popover .popover-header::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, #E67E22 0%, #D35400 100%);
    border-radius: 0 2px 2px 0;
}

/* Popover Body */
.guide-popover-content,
#guide-popover .popover-body {
    background: transparent !important;
    padding: 18px 20px 16px !important;
}

.guide-popover-body {
    color: #c9d1d9 !important;
    font-size: 13px !important;
    line-height: 1.65 !important;
    margin-bottom: 12px !important;
    animation: contentFadeIn 0.35s ease-out !important;
}

/* Better list styling inside tutorial */
.guide-popover-body ul {
    padding-left: 0 !important;
    list-style: none !important;
}

.guide-popover-body li {
    position: relative;
    padding-left: 18px;
    margin-bottom: 6px;
}

.guide-popover-body li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, #E67E22, #D35400);
    border-radius: 50%;
}

/* Progress indicator - enhanced with visual bar */
.guide-progress-indicator {
    font-size: 11px !important;
    color: #8b949e !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em !important;
    padding: 10px 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
    margin-top: 10px !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
}

.guide-progress-indicator::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, #E67E22, #D35400);
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
    box-shadow: 0 0 8px rgba(230, 126, 34, 0.5);
}

@keyframes pulse-dot {
    0%, 100% { 
        opacity: 0.6; 
        transform: scale(1);
        box-shadow: 0 0 4px rgba(230, 126, 34, 0.3);
    }
    50% { 
        opacity: 1; 
        transform: scale(1.15);
        box-shadow: 0 0 12px rgba(230, 126, 34, 0.6);
    }
}

/* Navigation buttons */
.guide-nav-buttons {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    margin-top: 16px !important;
    padding-top: 14px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.guide-nav-btn {
    font-size: 11px !important;
    font-weight: 600 !important;
    padding: 7px 16px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(139, 148, 158, 0.35) !important;
    color: #8b949e !important;
    background: rgba(139, 148, 158, 0.05) !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
}

.guide-nav-btn:hover {
    border-color: rgba(139, 148, 158, 0.6) !important;
    color: #c9d1d9 !important;
    background: rgba(139, 148, 158, 0.15) !important;
    transform: translateY(-1px) !important;
}

.guide-nav-btn:active {
    transform: translateY(0) !important;
}

.guide-nav-btn-primary,
#guide-next {
    font-size: 11px !important;
    font-weight: 700 !important;
    padding: 7px 20px !important;
    border-radius: 8px !important;
    background: linear-gradient(135deg, #E67E22 0%, #D35400 100%) !important;
    border: none !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(230, 126, 34, 0.35) !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
    position: relative !important;
    overflow: hidden !important;
}

.guide-nav-btn-primary::after,
#guide-next::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.guide-nav-btn-primary:active::after,
#guide-next:active::after {
    width: 200px;
    height: 200px;
}

.guide-nav-btn-primary:hover,
#guide-next:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(230, 126, 34, 0.45) !important;
}

.guide-nav-btn-primary:active,
#guide-next:active {
    transform: translateY(0) !important;
}

.guide-skip-btn,
#guide-skip {
    font-size: 10px !important;
    font-weight: 500 !important;
    color: #6e7681 !important;
    text-decoration: none !important;
    padding: 6px 12px !important;
    margin-left: auto !important;
    transition: all 0.2s ease !important;
    border-radius: 4px !important;
}

.guide-skip-btn:hover,
#guide-skip:hover {
    color: #8b949e !important;
    background: rgba(110, 118, 129, 0.1) !important;
}

/* Highlighted element during tour */
.tour-highlight {
    position: relative;
    z-index: 1050 !important;
    box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5),
                0 0 30px rgba(230, 126, 34, 0.25),
                inset 0 0 0 1px rgba(230, 126, 34, 0.2) !important;
    border-radius: 10px !important;
    animation: highlightPulse 2s ease-in-out infinite !important;
}

@keyframes highlightPulse {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5),
                    0 0 30px rgba(230, 126, 34, 0.25);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(230, 126, 34, 0.6),
                    0 0 40px rgba(230, 126, 34, 0.35);
    }
}

/* ===============================
   Additional Enhancements
   =============================== */

/* Smooth content transitions between steps */
#guide-popover .popover-body > div {
    animation: contentFadeIn 0.3s ease-out;
}

/* Better typography for paragraphs */
.guide-popover-body p {
    margin-bottom: 10px;
}

.guide-popover-body p:last-child {
    margin-bottom: 0;
}

/* Warning text styling */
.guide-popover-body .text-warning {
    background: rgba(230, 126, 34, 0.1);
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 3px solid #E67E22;
    display: block;
}

/* Muted text styling */
.guide-popover-body .text-muted {
    font-style: italic;
    opacity: 0.8;
}

/* Bold text emphasis */
.guide-popover-body .fw-bold {
    color: #e6edf3;
}

/* Horizontal rule styling in tutorial */
.guide-popover-body hr {
    border-color: rgba(230, 126, 34, 0.2);
    margin: 12px 0;
}

/* Small text helper */
.guide-popover-body small {
    display: block;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

/* Keyboard shortcut hints (if added later) */
.guide-kbd {
    background: rgba(110, 118, 129, 0.2);
    border: 1px solid rgba(110, 118, 129, 0.3);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 10px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    color: #8b949e;
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .guide-popover-container,
    #guide-popover {
        max-width: calc(100vw - 32px) !important;
        width: calc(100vw - 32px) !important;
    }
    
    .guide-header-bar {
        right: 12px !important;
        top: 8px !important;
        padding: 6px 12px !important;
    }
    
    .guide-prompt-text {
        display: none;
    }
}

/* ===============================
   Dynamic Tour Target Highlighting
   Elements glow when tutorial points to them
   =============================== */

/* When popover is targeting specific elements, add visual highlight */
#btn-open-upload-modal[aria-describedby*="guide-popover"],
#protocol-status-list[aria-describedby*="guide-popover"],
#guide-controls[aria-describedby*="guide-popover"],
#btn-all[aria-describedby*="guide-popover"],
#btn-toggle-rolling-table[aria-describedby*="guide-popover"],
#btn-toggle-heatmap-table[aria-describedby*="guide-popover"],
#pf-build[aria-describedby*="guide-popover"],
#btn-run-regime-analysis[aria-describedby*="guide-popover"],
#btn-launch-demo[aria-describedby*="guide-popover"],
#btn-toggle-data-tools[aria-describedby*="guide-popover"],
#btn-view-weights[aria-describedby*="guide-popover"],
#btn-equal-weights[aria-describedby*="guide-popover"],
#btn-reset-3d[aria-describedby*="guide-popover"],
#btn-download-factors[aria-describedby*="guide-popover"],
#glossary-accordion[aria-describedby*="guide-popover"] {
    position: relative;
    z-index: 1050 !important;
    box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5),
                0 0 30px rgba(230, 126, 34, 0.3) !important;
    border-radius: 8px !important;
    animation: targetHighlight 2s ease-in-out infinite !important;
    scroll-margin-top: 100px;
}

@keyframes targetHighlight {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5),
                    0 0 30px rgba(230, 126, 34, 0.3);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(230, 126, 34, 0.65),
                    0 0 45px rgba(230, 126, 34, 0.4);
    }
}

/* Ensure smooth scrolling when navigating tour */
html {
    scroll-behavior: smooth;
}

/* Fallback: general popover target highlight via Bootstrap aria attribute */
[aria-describedby="guide-popover"]:not(#btn-start-guide) {
    position: relative;
    z-index: 1050 !important;
    box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5),
                0 0 30px rgba(230, 126, 34, 0.3) !important;
    border-radius: 8px !important;
    animation: targetHighlight 2s ease-in-out infinite !important;
}
