/* Tutorial System Styles
 *
 * Flat z-index structure (all elements are siblings in DOM):
 * - Backdrop: z-index: 100000 (dark overlay, blocks clicks)
 * - Spotlight: z-index: 100000 (visual only, no pointer events)
 * - Highlighted Element: z-index: 100001 (clickable, above backdrop)
 * - Tooltip: z-index: 100002 (always on top, clickable)
 *
 * Note: High values needed because desktop/windows use z-index 9999-10000+
 */

/* ========================================
   BACKDROP - Dark overlay
   ======================================== */
.tutorial-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    cursor: not-allowed;
}

.tutorial-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Hide backdrop when spotlight is active (spotlight has its own dark overlay via box-shadow) */
.tutorial-backdrop.active.has-spotlight {
    opacity: 0;
}

/* ========================================
   SPOTLIGHT - Visual highlight
   ======================================== */
.tutorial-spotlight {
    position: fixed;
    z-index: 100000;
    border-radius: 8px;
    box-shadow:
        0 0 0 9999px rgba(0, 0, 0, 0.7),
        0 0 20px rgba(240, 171, 0, 0.5),
        inset 0 0 10px rgba(240, 171, 0, 0.3);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease-out;
}

.tutorial-spotlight.active {
    opacity: 1;
    visibility: visible;
}

/* Pulsing border animation */
.tutorial-spotlight::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border: 2px solid var(--sap-yellow);
    border-radius: 10px;
    animation: spotlightPulse 2s ease-in-out infinite;
}

@keyframes spotlightPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.02);
    }
}

/* ========================================
   HIGHLIGHTED ELEMENT
   ======================================== */
.tutorial-highlight {
    position: relative;
    z-index: 100001 !important;
    pointer-events: auto !important;
}

/* Ensure all children of highlighted element are also interactive */
.tutorial-highlight *,
.tutorial-highlight input,
.tutorial-highlight button,
.tutorial-highlight select,
.tutorial-highlight textarea {
    pointer-events: auto !important;
}

/* SAP popups/modals inside highlighted element need higher z-index */
.tutorial-highlight .sap-dropdown-menu,
.tutorial-highlight .sap-command-dropdown {
    z-index: 100003 !important;
}

/* ========================================
   SAP POPUPS DURING TUTORIAL
   F4 Help and other modals need to be above
   the tutorial overlay (100001) and tooltip (100002)
   ======================================== */
.tutorial-backdrop.active ~ .f4-help-modal,
.tutorial-backdrop.active ~ .f4-help-overlay,
.tutorial-backdrop.active ~ .sap-modal,
.tutorial-backdrop.active ~ .sap-popup,
.tutorial-backdrop.active ~ .achievement-popup,
.tutorial-backdrop.active ~ .levelup-screen {
    z-index: 100003 !important;
}

/* F4 Help modal - always on top during tutorial */
body:has(.tutorial-backdrop.active) .f4-help-modal {
    z-index: 100003 !important;
    pointer-events: auto !important;
}

/* Popup overlay (F4 Help, confirmations, etc.) - above tutorial */
body:has(.tutorial-backdrop.active) #popup-overlay,
body:has(.tutorial-backdrop.active) .popup-overlay {
    z-index: 100003 !important;
}

body:has(.tutorial-backdrop.active) #popup-overlay .popup,
body:has(.tutorial-backdrop.active) .popup-overlay .popup {
    pointer-events: auto !important;
}

/* Loading overlay during tutorial */
body:has(.tutorial-backdrop.active) #loading-overlay {
    z-index: 100004 !important;
}

/* Notifications during tutorial - above overlay for demo */
body:has(.tutorial-backdrop.active) .notification-toast {
    z-index: 100003 !important;
}

/* ========================================
   TOOLTIP - The dialog box
   ======================================== */
.tutorial-tooltip {
    position: fixed;
    z-index: 100002;
    background: white;
    border-radius: 12px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(0, 0, 0, 0.1);
    /* Responsive sizing - adapts to content */
    width: auto;
    min-width: 400px;
    max-width: min(700px, calc(100vw - 40px));
    max-height: calc(100vh - 80px);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.tutorial-tooltip.active {
    opacity: 1;
    visibility: visible;
    animation: tooltipAppear 0.3s ease-out;
}

@keyframes tooltipAppear {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ----------------------------------------
   Tooltip Header (draggable)
   ---------------------------------------- */
.tutorial-tooltip-header {
    background: linear-gradient(135deg, var(--sap-blue), var(--sap-dark-blue));
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: grab;
    user-select: none;
}

.tutorial-tooltip-header:active {
    cursor: grabbing;
}

.tutorial-step-indicator {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.tutorial-title {
    flex: 1;
    font-size: 18px;
    font-weight: 600;
}

.tutorial-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.tutorial-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* ----------------------------------------
   Tooltip Content
   ---------------------------------------- */
.tutorial-content {
    padding: 20px;
    font-size: 14px;
    line-height: 1.7;
    color: #333;
    /* Responsive height - grows with content, scrolls if too tall */
    max-height: calc(100vh - 250px);
    overflow-y: auto;
}

.tutorial-content strong {
    color: var(--sap-blue);
}

.tutorial-content code {
    background: #f0f4f8;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: #c0392b;
}

.tutorial-content ul,
.tutorial-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.tutorial-content li {
    margin: 4px 0;
}

/* ----------------------------------------
   Tooltip Footer
   ---------------------------------------- */
.tutorial-footer {
    padding: 16px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tutorial-skip {
    background: none;
    border: none;
    color: #666;
    font-size: 13px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.tutorial-skip:hover {
    background: #e9ecef;
    color: #333;
}

.tutorial-nav {
    display: flex;
    gap: 8px;
}

.tutorial-prev,
.tutorial-next {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tutorial-prev {
    background: #e9ecef;
    color: #333;
}

.tutorial-prev:hover:not(:disabled) {
    background: #dee2e6;
}

.tutorial-prev:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tutorial-next {
    background: linear-gradient(135deg, var(--sap-blue), var(--sap-dark-blue));
    color: white;
    min-width: 100px;
}

.tutorial-next:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(53, 74, 95, 0.3);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 720px) {
    .tutorial-tooltip {
        min-width: 320px;
        max-width: calc(100vw - 20px);
    }
}

@media (max-width: 480px) {
    .tutorial-tooltip {
        min-width: unset;
        width: calc(100vw - 20px);
        max-height: 85vh;
    }

    .tutorial-content {
        max-height: calc(100vh - 280px);
        padding: 16px;
    }

    .tutorial-footer {
        flex-direction: column;
        gap: 12px;
    }

    .tutorial-skip {
        order: 2;
    }

    .tutorial-nav {
        width: 100%;
    }

    .tutorial-prev,
    .tutorial-next {
        flex: 1;
    }
}

/* ========================================
   SPECIAL EFFECTS
   ======================================== */

/* Shake animation for attention */
.tutorial-tooltip.shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
    25% { transform: translate(-50%, -50%) rotate(-1deg); }
    75% { transform: translate(-50%, -50%) rotate(1deg); }
}

/* Keyboard hint */
.tutorial-keyboard-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #666;
    margin-top: 8px;
}

.tutorial-keyboard-hint kbd {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ========================================
   LEVEL LADDER - Career progression display
   ======================================== */
.level-ladder {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 12px 0;
    padding: 12px;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 8px;
    border: 1px solid #0f3460;
}

.level-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    font-size: 12px;
    color: #a0a0a0;
    transition: all 0.2s;
}

.level-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.level-goal {
    font-size: 10px;
    color: #666;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
}

.level-item.level-top {
    background: linear-gradient(135deg, #f0ab00 0%, #e6a200 100%);
    color: #1a1a2e;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(240, 171, 0, 0.4);
}

.level-item.level-top .level-goal {
    background: rgba(0, 0, 0, 0.2);
    color: #1a1a2e;
}

.level-item.level-current {
    background: linear-gradient(135deg, var(--sap-blue) 0%, var(--sap-dark-blue) 100%);
    color: white;
    font-weight: 500;
    border: 2px solid #4a90d9;
    animation: currentLevelPulse 2s ease-in-out infinite;
}

.level-item.level-current .level-goal {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

@keyframes currentLevelPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74, 144, 217, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(74, 144, 217, 0.2); }
}
